3 * Copyright 2013 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
13 #include "SkBlurMaskFilter.h"
14 #include "SkGradientShader.h"
15 #include "SkBlurDrawLooper.h"
20 class OvalGM : public GM {
23 this->setBGColor(0xFF000000);
30 SkString onShortName() SK_OVERRIDE {
31 return SkString("ovals");
34 SkISize onISize() SK_OVERRIDE {
35 return SkISize::Make(1200, 900);
53 // AA with stroke style
56 p.setStyle(SkPaint::kStroke_Style);
57 p.setStrokeWidth(SkIntToScalar(5));
62 // AA with stroke style, width = 0
65 p.setStyle(SkPaint::kStroke_Style);
70 // AA with stroke and fill style
73 p.setStyle(SkPaint::kStrokeAndFill_Style);
74 p.setStrokeWidth(SkIntToScalar(3));
83 fMatrices.push_back(m);
88 m.setScale(SkIntToScalar(3), SkIntToScalar(2));
89 fMatrices.push_back(m);
94 m.setScale(SkIntToScalar(2), SkIntToScalar(2));
95 fMatrices.push_back(m);
100 m.setScale(SkIntToScalar(1), SkIntToScalar(2));
101 fMatrices.push_back(m);
106 m.setScale(SkIntToScalar(4), SkIntToScalar(1));
107 fMatrices.push_back(m);
112 m.setRotate(SkIntToScalar(90));
113 fMatrices.push_back(m);
118 m.setSkew(SkIntToScalar(2), SkIntToScalar(3));
119 fMatrices.push_back(m);
124 m.setRotate(SkIntToScalar(60));
125 fMatrices.push_back(m);
129 SkColor genColor(SkRandom* rand) {
131 hsv[0] = rand->nextRangeF(0.0f, 360.0f);
132 hsv[1] = rand->nextRangeF(0.75f, 1.0f);
133 hsv[2] = rand->nextRangeF(0.75f, 1.0f);
135 return SkHSVToColor(hsv);
138 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
140 canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1);
141 SkRect oval = SkRect::MakeLTRB(-20, -30, 20, 30);
143 const SkScalar kXStart = 60.0f;
144 const SkScalar kYStart = 80.0f;
145 const int kXStep = 150;
146 const int kYStep = 160;
147 int maxX = fMatrices.count();
150 rectPaint.setAntiAlias(true);
151 rectPaint.setStyle(SkPaint::kStroke_Style);
152 rectPaint.setStrokeWidth(SkIntToScalar(0));
153 rectPaint.setColor(SK_ColorLTGRAY);
156 for (int i = 0; i < fPaints.count(); ++i) {
157 for (int j = 0; j < fMatrices.count(); ++j) {
159 SkMatrix mat = fMatrices[j];
160 // position the oval, and make it at off-integer coords.
161 mat.postTranslate(kXStart + SK_Scalar1 * kXStep * (testCount % maxX) +
163 kYStart + SK_Scalar1 * kYStep * (testCount / maxX) +
167 SkColor color = genColor(&rand);
168 fPaints[i].setColor(color);
170 canvas->drawRect(oval, rectPaint);
171 canvas->drawOval(oval, fPaints[i]);
181 // non-scaled tall and skinny oval
182 for (int i = 0; i < fPaints.count(); ++i) {
183 SkRect oval = SkRect::MakeLTRB(-20, -60, 20, 60);
185 // position the oval, and make it at off-integer coords.
186 canvas->translate(kXStart + SK_Scalar1 * kXStep * 2.55f + SK_Scalar1 / 4,
187 kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4);
189 SkColor color = genColor(&rand);
190 fPaints[i].setColor(color);
192 canvas->drawRect(oval, rectPaint);
193 canvas->drawOval(oval, fPaints[i]);
197 // non-scaled wide and short oval
198 for (int i = 0; i < fPaints.count(); ++i) {
199 SkRect oval = SkRect::MakeLTRB(-80, -30, 80, 30);
201 // position the oval, and make it at off-integer coords.
202 canvas->translate(kXStart + SK_Scalar1 * kXStep * 4 + SK_Scalar1 / 4,
203 kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4 +
204 SK_ScalarHalf * kYStep);
206 SkColor color = genColor(&rand);
207 fPaints[i].setColor(color);
209 canvas->drawRect(oval, rectPaint);
210 canvas->drawOval(oval, fPaints[i]);
215 for (int i = 0; i < fPaints.count(); ++i) {
216 SkRect oval = SkRect::MakeLTRB(0, -60, 1, 60);
218 // position the oval, and make it at off-integer coords.
219 canvas->translate(kXStart + SK_Scalar1 * kXStep * 3.25f + SK_Scalar1 / 4,
220 kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4);
222 SkColor color = genColor(&rand);
223 fPaints[i].setColor(color);
225 canvas->drawOval(oval, fPaints[i]);
230 for (int i = 0; i < fPaints.count(); ++i) {
231 SkRect oval = SkRect::MakeLTRB(-80, -1, 80, 0);
233 // position the oval, and make it at off-integer coords.
234 canvas->translate(kXStart + SK_Scalar1 * kXStep * 2.5f + SK_Scalar1 / 4,
235 kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4 +
236 SK_ScalarHalf * kYStep);
238 SkColor color = genColor(&rand);
239 fPaints[i].setColor(color);
241 canvas->drawOval(oval, fPaints[i]);
246 SkPoint center = SkPoint::Make(SkIntToScalar(0), SkIntToScalar(0));
247 SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
248 SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
249 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center,
253 SK_ARRAY_COUNT(colors),
254 SkShader::kClamp_TileMode));
256 for (int i = 0; i < fPaints.count(); ++i) {
258 // position the path, and make it at off-integer coords.
259 canvas->translate(kXStart + SK_Scalar1 * kXStep * 0 + SK_Scalar1 / 4,
260 kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4 +
261 SK_ScalarHalf * kYStep);
263 SkColor color = genColor(&rand);
264 fPaints[i].setColor(color);
265 fPaints[i].setShader(shader);
267 canvas->drawRect(oval, rectPaint);
268 canvas->drawOval(oval, fPaints[i]);
270 fPaints[i].setShader(NULL);
277 SkTArray<SkPaint> fPaints;
278 SkTArray<SkMatrix> fMatrices;
280 typedef GM INHERITED;
283 //////////////////////////////////////////////////////////////////////////////
285 static GM* MyFactory(void*) { return new OvalGM; }
286 static GMRegistry reg(MyFactory);