blob: b4cfef28c1a0699a6dab5689e005e6a4fffdc086 [file] [log] [blame]
bsalomon@google.com0b26c152012-04-16 14:19:32 +00001
2/*
3 * Copyright 2012 Intel Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8#include "gm.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00009#include "SkBlurDrawLooper.h"
10#include "SkBlurMask.h"
bsalomon@google.com0b26c152012-04-16 14:19:32 +000011#include "SkBlurMaskFilter.h"
12#include "SkGradientShader.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +000013#include "SkMatrix.h"
14#include "SkRandom.h"
15#include "SkTArray.h"
bsalomon@google.com0b26c152012-04-16 14:19:32 +000016
17namespace skiagm {
18
19class CircleGM : public GM {
20public:
21 CircleGM() {
22 this->setBGColor(0xFF000000);
23 this->makePaints();
24 this->makeMatrices();
25 }
26
27protected:
28 virtual SkString onShortName() SK_OVERRIDE {
29 return SkString("circles");
30 }
31
32 virtual SkISize onISize() SK_OVERRIDE {
33 return make_isize(1200, 900);
34 }
35
36 void makePaints() {
37 {
38 // no AA
39 SkPaint p;
40 fPaints.push_back(p);
41 }
42
43 {
44 // AA
45 SkPaint p;
46 p.setAntiAlias(true);
47 fPaints.push_back(p);
48 }
49
50 {
51 // AA with mask filter
52 SkPaint p;
53 p.setAntiAlias(true);
robertphillips@google.comb7061172013-09-06 14:16:12 +000054 SkMaskFilter* mf = SkBlurMaskFilter::Create(
bsalomon@google.com0b26c152012-04-16 14:19:32 +000055 SkBlurMaskFilter::kNormal_BlurStyle,
robertphillips@google.comb7061172013-09-06 14:16:12 +000056 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
bsalomon@google.com0b26c152012-04-16 14:19:32 +000057 SkBlurMaskFilter::kHighQuality_BlurFlag);
58 p.setMaskFilter(mf)->unref();
59 fPaints.push_back(p);
60 }
61
62 {
63 // AA with radial shader
64 SkPaint p;
65 p.setAntiAlias(true);
66 SkPoint center = SkPoint::Make(SkIntToScalar(40), SkIntToScalar(40));
67 SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
68 SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
69 SkShader* s = SkGradientShader::CreateRadial(center,
70 SkIntToScalar(20),
71 colors,
72 pos,
73 SK_ARRAY_COUNT(colors),
74 SkShader::kClamp_TileMode);
75 p.setShader(s)->unref();
76 fPaints.push_back(p);
77 }
78
79 {
80 // AA with blur
81 SkPaint p;
82 p.setAntiAlias(true);
83 SkBlurDrawLooper* shadowLooper =
skia.committer@gmail.comb3ec29d2013-09-07 07:01:16 +000084 new SkBlurDrawLooper (SK_ColorBLUE,
85 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
robertphillips@google.comb7061172013-09-06 14:16:12 +000086 SkIntToScalar(5), SkIntToScalar(10),
bsalomon@google.com0b26c152012-04-16 14:19:32 +000087 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
88 SkBlurDrawLooper::kOverrideColor_BlurFlag |
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000089 SkBlurDrawLooper::kHighQuality_BlurFlag);
bsalomon@google.com0b26c152012-04-16 14:19:32 +000090 SkAutoUnref aurL0(shadowLooper);
91 p.setLooper(shadowLooper);
92 fPaints.push_back(p);
93 }
94
95 {
96 // AA with stroke style
97 SkPaint p;
98 p.setAntiAlias(true);
99 p.setStyle(SkPaint::kStroke_Style);
100 p.setStrokeWidth(SkIntToScalar(3));
101 fPaints.push_back(p);
102 }
103
104 {
105 // AA with stroke style, width = 0
106 SkPaint p;
107 p.setAntiAlias(true);
108 p.setStyle(SkPaint::kStroke_Style);
109 fPaints.push_back(p);
110 }
111
112 {
113 // AA with stroke and fill style
114 SkPaint p;
115 p.setAntiAlias(true);
116 p.setStyle(SkPaint::kStrokeAndFill_Style);
117 p.setStrokeWidth(SkIntToScalar(2));
118 fPaints.push_back(p);
119 }
120 }
121
122 void makeMatrices() {
123 {
124 SkMatrix m;
125 m.setScale(SkIntToScalar(2), SkIntToScalar(3));
126 fMatrices.push_back(m);
127 }
128
129 {
130 SkMatrix m;
131 m.setScale(SkIntToScalar(2), SkIntToScalar(2));
132 fMatrices.push_back(m);
133 }
134
135 {
136 SkMatrix m;
137 m.setSkew(SkIntToScalar(2), SkIntToScalar(3));
138 fMatrices.push_back(m);
139 }
140
141 {
142 SkMatrix m;
143 m.setSkew(SkIntToScalar(2), SkIntToScalar(2));
144 fMatrices.push_back(m);
145 }
146
147 {
148 SkMatrix m;
149 m.setRotate(SkIntToScalar(30));
150 fMatrices.push_back(m);
151 }
152 }
153
154 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000155 SkLCGRandom rand;
bsalomon@google.com0b26c152012-04-16 14:19:32 +0000156 canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1);
bsalomon@google.com0b26c152012-04-16 14:19:32 +0000157 int i;
158 for (i = 0; i < fPaints.count(); ++i) {
159 canvas->save();
160 // position the path, and make it at off-integer coords.
161 canvas->translate(SK_Scalar1 * 200 * (i % 5) + SK_Scalar1 / 4,
162 SK_Scalar1 * 200 * (i / 5) + 3 * SK_Scalar1 / 4);
163 SkColor color = rand.nextU();
164 color |= 0xff000000;
165 fPaints[i].setColor(color);
166
167 canvas->drawCircle(SkIntToScalar(40), SkIntToScalar(40),
168 SkIntToScalar(20),
169 fPaints[i]);
170 canvas->restore();
171 }
172
173 for (int j = 0; j < fMatrices.count(); ++j, ++i) {
174 canvas->save();
175
176 canvas->translate(SK_Scalar1 * 200 * (i % 5) + SK_Scalar1 / 4,
177 SK_Scalar1 * 200 * (i / 5) + 3 * SK_Scalar1 / 4);
178
179 canvas->concat(fMatrices[j]);
180
181 SkPaint paint;
182 paint.setAntiAlias(true);
183
184 SkColor color = rand.nextU();
185 color |= 0xff000000;
186 paint.setColor(color);
187
188 canvas->drawCircle(SkIntToScalar(40), SkIntToScalar(40),
189 SkIntToScalar(20),
190 paint);
191
192 canvas->restore();
193 }
194 }
195
196private:
197 typedef GM INHERITED;
198 SkTArray<SkPaint> fPaints;
199 SkTArray<SkMatrix> fMatrices;
200};
201
202//////////////////////////////////////////////////////////////////////////////
203
204static GM* MyFactory(void*) { return new CircleGM; }
205static GMRegistry reg(MyFactory);
206
207}