blob: 9ec7881f90916b0a1150aae7513d6a6c891ee92c [file] [log] [blame]
robertphillips@google.com14c3fc62013-03-19 14:11:15 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00009#include "SkBlurDrawLooper.h"
10#include "SkBlurMask.h"
robertphillips@google.com14c3fc62013-03-19 14:11:15 +000011#include "SkBlurMaskFilter.h"
12#include "SkGradientShader.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +000013#include "SkMatrix.h"
14#include "SkTArray.h"
robertphillips@google.com14c3fc62013-03-19 14:11:15 +000015
16namespace skiagm {
17
18class RectsGM : public GM {
19public:
20 RectsGM() {
21 this->setBGColor(0xFF000000);
22 this->makePaints();
23 this->makeMatrices();
24 this->makeRects();
25 }
26
27protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000028
mtklein36352bf2015-03-25 18:17:31 -070029 SkString onShortName() override {
robertphillips@google.com14c3fc62013-03-19 14:11:15 +000030 return SkString("rects");
31 }
32
mtklein36352bf2015-03-25 18:17:31 -070033 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070034 return SkISize::Make(1200, 900);
robertphillips@google.com14c3fc62013-03-19 14:11:15 +000035 }
36
37 void makePaints() {
38 {
39 // no AA
40 SkPaint p;
41 p.setColor(SK_ColorWHITE);
42 fPaints.push_back(p);
43 }
44
45 {
46 // AA
47 SkPaint p;
48 p.setColor(SK_ColorWHITE);
49 p.setAntiAlias(true);
50 fPaints.push_back(p);
51 }
52
53 {
commit-bot@chromium.orga0fd1b32013-11-01 11:54:29 +000054 // AA with translucent
55 SkPaint p;
56 p.setColor(SK_ColorWHITE);
57 p.setAntiAlias(true);
58 p.setAlpha(0x66);
59 fPaints.push_back(p);
60 }
61
62 {
robertphillips@google.com14c3fc62013-03-19 14:11:15 +000063 // AA with mask filter
64 SkPaint p;
65 p.setColor(SK_ColorWHITE);
66 p.setAntiAlias(true);
reedefdfd512016-04-04 10:02:58 -070067 p.setMaskFilter(SkBlurMaskFilter::Make(
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000068 kNormal_SkBlurStyle,
robertphillips@google.comb7061172013-09-06 14:16:12 +000069 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
reedefdfd512016-04-04 10:02:58 -070070 SkBlurMaskFilter::kHighQuality_BlurFlag));
robertphillips@google.com14c3fc62013-03-19 14:11:15 +000071 fPaints.push_back(p);
72 }
73
74 {
75 // AA with radial shader
76 SkPaint p;
77 p.setColor(SK_ColorWHITE);
78 p.setAntiAlias(true);
79 SkPoint center = SkPoint::Make(SkIntToScalar(-5), SkIntToScalar(30));
80 SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
81 SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
reed1a9b9642016-03-13 14:13:58 -070082 p.setShader(SkGradientShader::MakeRadial(center, 20, colors, pos,
83 SK_ARRAY_COUNT(colors),
84 SkShader::kClamp_TileMode));
robertphillips@google.com14c3fc62013-03-19 14:11:15 +000085 fPaints.push_back(p);
86 }
87
88 {
89 // AA with blur
90 SkPaint p;
91 p.setColor(SK_ColorWHITE);
92 p.setAntiAlias(true);
reed7b380d02016-03-21 13:25:16 -070093 p.setLooper(SkBlurDrawLooper::Make(SK_ColorWHITE,
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000094 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
95 SkIntToScalar(5), SkIntToScalar(10),
96 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
97 SkBlurDrawLooper::kOverrideColor_BlurFlag |
reed7b380d02016-03-21 13:25:16 -070098 SkBlurDrawLooper::kHighQuality_BlurFlag));
robertphillips@google.com14c3fc62013-03-19 14:11:15 +000099 fPaints.push_back(p);
100 }
101
102 {
103 // AA with stroke style
104 SkPaint p;
105 p.setColor(SK_ColorWHITE);
106 p.setAntiAlias(true);
107 p.setStyle(SkPaint::kStroke_Style);
108 p.setStrokeWidth(SkIntToScalar(3));
109 fPaints.push_back(p);
110 }
111
112 {
commit-bot@chromium.orga0fd1b32013-11-01 11:54:29 +0000113 // AA with bevel-stroke style
114 SkPaint p;
115 p.setColor(SK_ColorWHITE);
116 p.setAntiAlias(true);
117 p.setStyle(SkPaint::kStroke_Style);
118 p.setStrokeJoin(SkPaint::kBevel_Join);
119 p.setStrokeWidth(SkIntToScalar(3));
120 fPaints.push_back(p);
121 }
122
123 {
124 // AA with round-stroke style
125 SkPaint p;
126 p.setColor(SK_ColorWHITE);
127 p.setAntiAlias(true);
128 p.setStyle(SkPaint::kStroke_Style);
129 p.setStrokeJoin(SkPaint::kRound_Join);
130 p.setStrokeWidth(SkIntToScalar(3));
131 fPaints.push_back(p);
132 }
133
134 {
robertphillips@google.com14c3fc62013-03-19 14:11:15 +0000135 // AA with stroke style, width = 0
136 SkPaint p;
137 p.setColor(SK_ColorWHITE);
138 p.setAntiAlias(true);
139 p.setStyle(SkPaint::kStroke_Style);
140 fPaints.push_back(p);
141 }
142
143 {
commit-bot@chromium.orga0fd1b32013-11-01 11:54:29 +0000144 // AA with stroke style, width wider than rect width and/or height
145 SkPaint p;
146 p.setColor(SK_ColorWHITE);
147 p.setAntiAlias(true);
148 p.setStyle(SkPaint::kStroke_Style);
149 p.setStrokeWidth(SkIntToScalar(40));
150 fPaints.push_back(p);
151 }
152
153 {
robertphillips@google.com14c3fc62013-03-19 14:11:15 +0000154 // AA with stroke and fill style
155 SkPaint p;
156 p.setColor(SK_ColorWHITE);
157 p.setAntiAlias(true);
158 p.setStyle(SkPaint::kStrokeAndFill_Style);
159 p.setStrokeWidth(SkIntToScalar(2));
160 fPaints.push_back(p);
161 }
162 }
163
164 void makeMatrices() {
165 {
166 // 1x1.5 scale
167 SkMatrix m;
reed@google.com56a2e0d2013-03-19 14:50:41 +0000168 m.setScale(1, 1.5f);
robertphillips@google.com14c3fc62013-03-19 14:11:15 +0000169 fMatrices.push_back(m);
170 }
171
172 {
173 // 1.5x1.5 scale
174 SkMatrix m;
reed@google.com56a2e0d2013-03-19 14:50:41 +0000175 m.setScale(1.5f, 1.5f);
robertphillips@google.com14c3fc62013-03-19 14:11:15 +0000176 fMatrices.push_back(m);
177 }
178
179 {
180 // 1x1.5 skew
181 SkMatrix m;
reed@google.com56a2e0d2013-03-19 14:50:41 +0000182 m.setSkew(1, 1.5f);
robertphillips@google.com14c3fc62013-03-19 14:11:15 +0000183 fMatrices.push_back(m);
184 }
185
186 {
187 // 1.5x1.5 skew
188 SkMatrix m;
reed@google.com56a2e0d2013-03-19 14:50:41 +0000189 m.setSkew(1.5f, 1.5f);
robertphillips@google.com14c3fc62013-03-19 14:11:15 +0000190 fMatrices.push_back(m);
191 }
192
193 {
194 // 30 degree rotation
195 SkMatrix m;
196 m.setRotate(SkIntToScalar(30));
197 fMatrices.push_back(m);
198 }
robertphillips@google.com6f5abdd2013-04-29 17:44:45 +0000199
200 {
201 // 90 degree rotation
202 SkMatrix m;
203 m.setRotate(SkIntToScalar(90));
204 fMatrices.push_back(m);
205 }
robertphillips@google.com14c3fc62013-03-19 14:11:15 +0000206 }
207
208 void makeRects() {
209 {
210 // small square
211 SkRect r = SkRect::MakeLTRB(0, 0, 30, 30);
212 fRects.push_back(r);
213 }
214
215 {
216 // thin vertical
217 SkRect r = SkRect::MakeLTRB(0, 0, 2, 40);
218 fRects.push_back(r);
219 }
220
221 {
222 // thin horizontal
223 SkRect r = SkRect::MakeLTRB(0, 0, 40, 2);
224 fRects.push_back(r);
225 }
226
227 {
228 // very thin
229 SkRect r = SkRect::MakeLTRB(0, 0, 0.25f, 10);
230 fRects.push_back(r);
231 }
232
233 {
234 // zaftig
235 SkRect r = SkRect::MakeLTRB(0, 0, 60, 60);
236 fRects.push_back(r);
237 }
238 }
239
240 // position the current test on the canvas
241 static void position(SkCanvas* canvas, int testCount) {
242 canvas->translate(SK_Scalar1 * 100 * (testCount % 10) + SK_Scalar1 / 4,
243 SK_Scalar1 * 100 * (testCount / 10) + 3 * SK_Scalar1 / 4);
244 }
245
mtklein36352bf2015-03-25 18:17:31 -0700246 void onDraw(SkCanvas* canvas) override {
robertphillips@google.com14c3fc62013-03-19 14:11:15 +0000247 canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1);
248
249 int testCount = 0;
250
251 for (int i = 0; i < fPaints.count(); ++i) {
252 for (int j = 0; j < fRects.count(); ++j, ++testCount) {
253 canvas->save();
254 this->position(canvas, testCount);
255 canvas->drawRect(fRects[j], fPaints[i]);
256 canvas->restore();
257 }
258 }
259
robertphillips@google.com14c3fc62013-03-19 14:11:15 +0000260 SkPaint paint;
261 paint.setColor(SK_ColorWHITE);
262 paint.setAntiAlias(true);
263
264 for (int i = 0; i < fMatrices.count(); ++i) {
265 for (int j = 0; j < fRects.count(); ++j, ++testCount) {
266 canvas->save();
267 this->position(canvas, testCount);
268 canvas->concat(fMatrices[i]);
269 canvas->drawRect(fRects[j], paint);
270 canvas->restore();
271 }
272 }
273 }
274
275private:
276 SkTArray<SkPaint> fPaints;
277 SkTArray<SkMatrix> fMatrices;
278 SkTArray<SkRect> fRects;
279
280 typedef GM INHERITED;
281};
282
283//////////////////////////////////////////////////////////////////////////////
284
285static GM* MyFactory(void*) { return new RectsGM; }
286static GMRegistry reg(MyFactory);
287
288}