2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkBlurDrawLooper.h"
10 #include "SkBlurMask.h"
11 #include "SkBlurMaskFilter.h"
12 #include "SkColorFilter.h"
13 #include "SkGradientShader.h"
19 class RectsGM : public GM {
22 this->setBGColor(0xFF000000);
30 SkString onShortName() override {
31 return SkString("rects");
34 SkISize onISize() override {
35 return SkISize::Make(1200, 900);
42 p.setColor(SK_ColorWHITE);
49 p.setColor(SK_ColorWHITE);
55 // AA with translucent
57 p.setColor(SK_ColorWHITE);
64 // AA with mask filter
66 p.setColor(SK_ColorWHITE);
68 p.setMaskFilter(SkBlurMaskFilter::Make(
70 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
71 SkBlurMaskFilter::kHighQuality_BlurFlag));
76 // AA with radial shader
78 p.setColor(SK_ColorWHITE);
80 SkPoint center = SkPoint::Make(SkIntToScalar(-5), SkIntToScalar(30));
81 SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
82 SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
83 p.setShader(SkGradientShader::MakeRadial(center, 20, colors, pos,
84 SK_ARRAY_COUNT(colors),
85 SkShader::kClamp_TileMode));
92 p.setColor(SK_ColorWHITE);
94 p.setLooper(SkBlurDrawLooper::Make(SK_ColorWHITE,
95 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
96 SkIntToScalar(5), SkIntToScalar(10)));
101 // AA with stroke style
103 p.setColor(SK_ColorWHITE);
104 p.setAntiAlias(true);
105 p.setStyle(SkPaint::kStroke_Style);
106 p.setStrokeWidth(SkIntToScalar(3));
107 fPaints.push_back(p);
111 // AA with bevel-stroke style
113 p.setColor(SK_ColorWHITE);
114 p.setAntiAlias(true);
115 p.setStyle(SkPaint::kStroke_Style);
116 p.setStrokeJoin(SkPaint::kBevel_Join);
117 p.setStrokeWidth(SkIntToScalar(3));
118 fPaints.push_back(p);
122 // AA with round-stroke style
124 p.setColor(SK_ColorWHITE);
125 p.setAntiAlias(true);
126 p.setStyle(SkPaint::kStroke_Style);
127 p.setStrokeJoin(SkPaint::kRound_Join);
128 p.setStrokeWidth(SkIntToScalar(3));
129 fPaints.push_back(p);
133 // AA with stroke style, width = 0
135 p.setColor(SK_ColorWHITE);
136 p.setAntiAlias(true);
137 p.setStyle(SkPaint::kStroke_Style);
138 fPaints.push_back(p);
142 // AA with stroke style, width wider than rect width and/or height
144 p.setColor(SK_ColorWHITE);
145 p.setAntiAlias(true);
146 p.setStyle(SkPaint::kStroke_Style);
147 p.setStrokeWidth(SkIntToScalar(40));
148 fPaints.push_back(p);
152 // AA with stroke and fill style
154 p.setColor(SK_ColorWHITE);
155 p.setAntiAlias(true);
156 p.setStyle(SkPaint::kStrokeAndFill_Style);
157 p.setStrokeWidth(SkIntToScalar(2));
158 fPaints.push_back(p);
162 void makeMatrices() {
167 fMatrices.push_back(m);
173 m.setScale(1.5f, 1.5f);
174 fMatrices.push_back(m);
181 fMatrices.push_back(m);
187 m.setSkew(1.5f, 1.5f);
188 fMatrices.push_back(m);
192 // 30 degree rotation
194 m.setRotate(SkIntToScalar(30));
195 fMatrices.push_back(m);
199 // 90 degree rotation
201 m.setRotate(SkIntToScalar(90));
202 fMatrices.push_back(m);
209 SkRect r = SkRect::MakeLTRB(0, 0, 30, 30);
215 SkRect r = SkRect::MakeLTRB(0, 0, 2, 40);
221 SkRect r = SkRect::MakeLTRB(0, 0, 40, 2);
227 SkRect r = SkRect::MakeLTRB(0, 0, 0.25f, 10);
233 SkRect r = SkRect::MakeLTRB(0, 0, 60, 60);
238 // position the current test on the canvas
239 static void position(SkCanvas* canvas, int testCount) {
240 canvas->translate(SK_Scalar1 * 100 * (testCount % 10) + SK_Scalar1 / 4,
241 SK_Scalar1 * 100 * (testCount / 10) + 3 * SK_Scalar1 / 4);
244 void onDraw(SkCanvas* canvas) override {
245 canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1);
249 for (int i = 0; i < fPaints.count(); ++i) {
250 for (int j = 0; j < fRects.count(); ++j, ++testCount) {
252 this->position(canvas, testCount);
253 canvas->drawRect(fRects[j], fPaints[i]);
259 paint.setColor(SK_ColorWHITE);
260 paint.setAntiAlias(true);
262 for (int i = 0; i < fMatrices.count(); ++i) {
263 for (int j = 0; j < fRects.count(); ++j, ++testCount) {
265 this->position(canvas, testCount);
266 canvas->concat(fMatrices[i]);
267 canvas->drawRect(fRects[j], paint);
274 SkTArray<SkPaint> fPaints;
275 SkTArray<SkMatrix> fMatrices;
276 SkTArray<SkRect> fRects;
278 typedef GM INHERITED;
281 //////////////////////////////////////////////////////////////////////////////
283 static GM* MyFactory(void*) { return new RectsGM; }
284 static GMRegistry reg(MyFactory);