1a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
2a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org/*
3a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org * Copyright 2013 Google Inc.
4a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org *
5a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be
6a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org * found in the LICENSE file.
7a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org */
8a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
9a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org#include "gm.h"
10a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org#include "SkTArray.h"
11a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org#include "SkRandom.h"
12a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org#include "SkMatrix.h"
13a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org#include "SkBlurMaskFilter.h"
14a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org#include "SkGradientShader.h"
15a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org#include "SkBlurDrawLooper.h"
16a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org#include "SkRect.h"
17a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org#include "SkRRect.h"
18a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
19a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.orgnamespace skiagm {
20a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
21a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.orgclass RoundRectGM : public GM {
22a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.orgpublic:
23a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    RoundRectGM() {
24a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        this->setBGColor(0xFF000000);
25a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        this->makePaints();
26a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        this->makeMatrices();
27a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    }
28a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
29a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.orgprotected:
30a90c6803865766d28e92091f56f718f5e41fe80fcommit-bot@chromium.org    virtual uint32_t onGetFlags() const SK_OVERRIDE {
31a90c6803865766d28e92091f56f718f5e41fe80fcommit-bot@chromium.org        return kSkipTiled_Flag;
32a90c6803865766d28e92091f56f718f5e41fe80fcommit-bot@chromium.org    }
33a90c6803865766d28e92091f56f718f5e41fe80fcommit-bot@chromium.org
34a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    virtual SkString onShortName() SK_OVERRIDE {
35a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        return SkString("roundrects");
36a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    }
37a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
38a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    virtual SkISize onISize() SK_OVERRIDE {
39f539318f0d3dba743ec1886d5d9df0fb1be628a1tfarina        return SkISize::Make(1200, 900);
40a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    }
41a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
42a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    void makePaints() {
43a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        {
44a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        // no AA
45a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkPaint p;
46a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        fPaints.push_back(p);
47a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
48a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
49a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        {
50a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        // AA
51a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkPaint p;
52a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        p.setAntiAlias(true);
53a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        fPaints.push_back(p);
54a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
55a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
56a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        {
57a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        // AA with stroke style
58a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkPaint p;
59a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        p.setAntiAlias(true);
60a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        p.setStyle(SkPaint::kStroke_Style);
61a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        p.setStrokeWidth(SkIntToScalar(5));
62a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        fPaints.push_back(p);
63a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
64a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
65a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        {
66a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        // AA with stroke style, width = 0
67a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkPaint p;
68a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        p.setAntiAlias(true);
69a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        p.setStyle(SkPaint::kStroke_Style);
70a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        fPaints.push_back(p);
71a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
72a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
73a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        {
74a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        // AA with stroke and fill style
75a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkPaint p;
76a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        p.setAntiAlias(true);
77a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        p.setStyle(SkPaint::kStrokeAndFill_Style);
78a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        p.setStrokeWidth(SkIntToScalar(3));
79a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        fPaints.push_back(p);
80a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
81a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    }
82a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
83a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    void makeMatrices() {
84a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        {
85a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkMatrix m;
86a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        m.setIdentity();
87a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        fMatrices.push_back(m);
88a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
89a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
90a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        {
91a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkMatrix m;
92a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        m.setScale(SkIntToScalar(3), SkIntToScalar(2));
93a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        fMatrices.push_back(m);
94a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
95a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
96a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        {
97a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkMatrix m;
98a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        m.setScale(SkIntToScalar(2), SkIntToScalar(2));
99a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        fMatrices.push_back(m);
100a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
101a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
102a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        {
103a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkMatrix m;
104a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        m.setScale(SkIntToScalar(1), SkIntToScalar(2));
105a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        fMatrices.push_back(m);
106a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
107a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
108a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        {
109a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkMatrix m;
110a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        m.setScale(SkIntToScalar(4), SkIntToScalar(1));
111a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        fMatrices.push_back(m);
112a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
113a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
114a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        {
115a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkMatrix m;
116a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        m.setRotate(SkIntToScalar(90));
117a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        fMatrices.push_back(m);
118a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
119a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
120a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        {
121a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkMatrix m;
122a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        m.setSkew(SkIntToScalar(2), SkIntToScalar(3));
123a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        fMatrices.push_back(m);
124a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
125a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
126a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        {
127a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkMatrix m;
128a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        m.setRotate(SkIntToScalar(60));
129a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        fMatrices.push_back(m);
130a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
131a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    }
132a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
133e0e7cfe44bb9d66d76120a79e5275c294bacaa22commit-bot@chromium.org    SkColor genColor(SkRandom* rand) {
134a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkScalar hsv[3];
1354b413c8bb123e42ca4b9c7bfa6bc2167283cb84ccommit-bot@chromium.org        hsv[0] = rand->nextRangeF(0.0f, 360.0f);
1364b413c8bb123e42ca4b9c7bfa6bc2167283cb84ccommit-bot@chromium.org        hsv[1] = rand->nextRangeF(0.75f, 1.0f);
1374b413c8bb123e42ca4b9c7bfa6bc2167283cb84ccommit-bot@chromium.org        hsv[2] = rand->nextRangeF(0.75f, 1.0f);
138a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
139a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        return SkHSVToColor(hsv);
140a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    }
141a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
142a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
143e0e7cfe44bb9d66d76120a79e5275c294bacaa22commit-bot@chromium.org        SkRandom rand(1);
144a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1);
145a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkRect rect = SkRect::MakeLTRB(-20, -30, 20, 30);
146a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkRRect circleRect;
147a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        circleRect.setRectXY(rect, 5, 5);
148a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
149a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        const SkScalar kXStart = 60.0f;
150a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        const SkScalar kYStart = 80.0f;
151a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        const int kXStep = 150;
152a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        const int kYStep = 160;
153a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        int maxX = fMatrices.count();
154a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
155a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkPaint rectPaint;
156a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        rectPaint.setAntiAlias(true);
157a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        rectPaint.setStyle(SkPaint::kStroke_Style);
158a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        rectPaint.setStrokeWidth(SkIntToScalar(0));
159a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        rectPaint.setColor(SK_ColorLTGRAY);
160a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
161a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        int testCount = 0;
162e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com        for (int i = 0; i < fPaints.count(); ++i) {
163a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            for (int j = 0; j < fMatrices.count(); ++j) {
164a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                canvas->save();
165a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                SkMatrix mat = fMatrices[j];
166a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                // position the roundrect, and make it at off-integer coords.
167e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com                mat.postTranslate(kXStart + SK_Scalar1 * kXStep * (testCount % maxX) +
168a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                                  SK_Scalar1 / 4,
169e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com                                  kYStart + SK_Scalar1 * kYStep * (testCount / maxX) +
170a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                                  3 * SK_Scalar1 / 4);
171a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                canvas->concat(mat);
172e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com
173a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                SkColor color = genColor(&rand);
174a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                fPaints[i].setColor(color);
175a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
176a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                canvas->drawRect(rect, rectPaint);
177a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                canvas->drawRRect(circleRect, fPaints[i]);
178a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
179a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                canvas->restore();
180a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
181a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                ++testCount;
182a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            }
183a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
184a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
185a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        // special cases
186a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
187a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        // non-scaled tall and skinny roundrect
188e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com        for (int i = 0; i < fPaints.count(); ++i) {
189a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkRect rect = SkRect::MakeLTRB(-20, -60, 20, 60);
190a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkRRect ellipseRect;
191a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            ellipseRect.setRectXY(rect, 5, 10);
192a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
193a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->save();
194a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            // position the roundrect, and make it at off-integer coords.
195a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->translate(kXStart + SK_Scalar1 * kXStep * 2.55f + SK_Scalar1 / 4,
196a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                              kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4);
197e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com
198a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkColor color = genColor(&rand);
199a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            fPaints[i].setColor(color);
200a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
201a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->drawRect(rect, rectPaint);
202a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->drawRRect(ellipseRect, fPaints[i]);
203a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->restore();
204a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
205a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
206a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        // non-scaled wide and short roundrect
207e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com        for (int i = 0; i < fPaints.count(); ++i) {
208a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkRect rect = SkRect::MakeLTRB(-80, -30, 80, 30);
209a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkRRect ellipseRect;
210a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            ellipseRect.setRectXY(rect, 20, 5);
211a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
212a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->save();
213a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            // position the roundrect, and make it at off-integer coords.
214a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->translate(kXStart + SK_Scalar1 * kXStep * 4 + SK_Scalar1 / 4,
215a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                              kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4 +
216a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                              SK_ScalarHalf * kYStep);
217e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com
218a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkColor color = genColor(&rand);
219a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            fPaints[i].setColor(color);
220a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
221a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->drawRect(rect, rectPaint);
222a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->drawRRect(ellipseRect, fPaints[i]);
223a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->restore();
224a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
225a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
226a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        // super skinny roundrect
227e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com        for (int i = 0; i < fPaints.count(); ++i) {
228a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkRect rect = SkRect::MakeLTRB(0, -60, 1, 60);
229a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkRRect circleRect;
230a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            circleRect.setRectXY(rect, 5, 5);
231a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
232a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->save();
233a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            // position the roundrect, and make it at off-integer coords.
234a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->translate(kXStart + SK_Scalar1 * kXStep * 3.25f + SK_Scalar1 / 4,
235a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                              kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4);
236e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com
237a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkColor color = genColor(&rand);
238a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            fPaints[i].setColor(color);
239a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
240a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->drawRRect(circleRect, fPaints[i]);
241a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->restore();
242a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
243a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
244a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        // super short roundrect
245e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com        for (int i = 0; i < fPaints.count(); ++i) {
246a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkRect rect = SkRect::MakeLTRB(-80, -1, 80, 0);
247a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkRRect circleRect;
248a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            circleRect.setRectXY(rect, 5, 5);
249a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
250a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->save();
251a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            // position the roundrect, and make it at off-integer coords.
252a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->translate(kXStart + SK_Scalar1 * kXStep * 2.5f + SK_Scalar1 / 4,
253a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                              kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4 +
254a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                              SK_ScalarHalf * kYStep);
255e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com
256a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkColor color = genColor(&rand);
257a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            fPaints[i].setColor(color);
258a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
259a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->drawRRect(circleRect, fPaints[i]);
260a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->restore();
261a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
262e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com
263a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        // radial gradient
264a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkPoint center = SkPoint::Make(SkIntToScalar(0), SkIntToScalar(0));
265a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
266a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
267a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center,
268a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                                                     SkIntToScalar(20),
269a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                                                     colors,
270a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                                                     pos,
271a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                                                     SK_ARRAY_COUNT(colors),
272a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                                                     SkShader::kClamp_TileMode));
273a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
274a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        for (int i = 0; i < fPaints.count(); ++i) {
275a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->save();
276a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            // position the path, and make it at off-integer coords.
277a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->translate(kXStart + SK_Scalar1 * kXStep * 0 + SK_Scalar1 / 4,
278a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                              kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4 +
279a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                              SK_ScalarHalf * kYStep);
280e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com
281a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkColor color = genColor(&rand);
282a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            fPaints[i].setColor(color);
283a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            fPaints[i].setShader(shader);
284a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
285a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->drawRect(rect, rectPaint);
286a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->drawRRect(circleRect, fPaints[i]);
287a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
288a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            fPaints[i].setShader(NULL);
289a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
290a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            canvas->restore();
291a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
292a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
293a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        // strokes and radii
294e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com        {
295a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkScalar radii[][2] = {
296a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                {10,10},
297a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                {5,15},
298a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                {5,15},
299a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                {5,15}
300a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            };
301a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
302a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            SkScalar strokeWidths[] = {
303a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                20, 10, 20, 40
304a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            };
305a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
306a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            for (int i = 0; i < 4; ++i) {
307a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                SkRRect circleRect;
308a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                circleRect.setRectXY(rect, radii[i][0], radii[i][1]);
309a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
310a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                canvas->save();
311a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                // position the roundrect, and make it at off-integer coords.
312a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                canvas->translate(kXStart + SK_Scalar1 * kXStep * 5 + SK_Scalar1 / 4,
313a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                                  kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4 +
314a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                                  SK_ScalarHalf * kYStep);
315e36a168d132a70d04eb696d8b50e2aea5c725bffskia.committer@gmail.com
316a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                SkColor color = genColor(&rand);
317a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
318a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                SkPaint p;
319a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                p.setAntiAlias(true);
320a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                p.setStyle(SkPaint::kStroke_Style);
321a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                p.setStrokeWidth(strokeWidths[i]);
322a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                p.setColor(color);
323a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
324a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                canvas->drawRRect(circleRect, p);
325a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org                canvas->restore();
326a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org            }
327a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org        }
328a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
329a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    }
330a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
331a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.orgprivate:
332a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    SkTArray<SkPaint> fPaints;
333a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    SkTArray<SkMatrix> fMatrices;
334a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
335a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org    typedef GM INHERITED;
336a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org};
337a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
338a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org//////////////////////////////////////////////////////////////////////////////
339a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
340a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.orgstatic GM* MyFactory(void*) { return new RoundRectGM; }
341a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.orgstatic GMRegistry reg(MyFactory);
342a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org
343a534b84237ae492e70078238f8a3f6fd0b162b79commit-bot@chromium.org}
344