3 * Copyright 2012 Intel Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
9 #include "SkBlurDrawLooper.h"
10 #include "SkBlurMask.h"
11 #include "SkBlurMaskFilter.h"
12 #include "SkGradientShader.h"
19 class CircleGM : public GM {
22 this->setBGColor(0xFF000000);
29 SkString onShortName() SK_OVERRIDE {
30 return SkString("circles");
33 SkISize onISize() SK_OVERRIDE {
34 return SkISize::Make(1200, 900);
52 // AA with mask filter
55 SkMaskFilter* mf = SkBlurMaskFilter::Create(
57 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
58 SkBlurMaskFilter::kHighQuality_BlurFlag);
59 p.setMaskFilter(mf)->unref();
64 // AA with radial shader
67 SkPoint center = SkPoint::Make(SkIntToScalar(40), SkIntToScalar(40));
68 SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
69 SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
70 SkShader* s = SkGradientShader::CreateRadial(center,
74 SK_ARRAY_COUNT(colors),
75 SkShader::kClamp_TileMode);
76 p.setShader(s)->unref();
84 SkBlurDrawLooper* shadowLooper =
85 SkBlurDrawLooper::Create(SK_ColorBLUE,
86 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
87 SkIntToScalar(5), SkIntToScalar(10),
88 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
89 SkBlurDrawLooper::kOverrideColor_BlurFlag |
90 SkBlurDrawLooper::kHighQuality_BlurFlag);
91 SkAutoUnref aurL0(shadowLooper);
92 p.setLooper(shadowLooper);
97 // AA with stroke style
100 p.setStyle(SkPaint::kStroke_Style);
101 p.setStrokeWidth(SkIntToScalar(3));
102 fPaints.push_back(p);
106 // AA with stroke style, width = 0
108 p.setAntiAlias(true);
109 p.setStyle(SkPaint::kStroke_Style);
110 fPaints.push_back(p);
114 // AA with stroke and fill style
116 p.setAntiAlias(true);
117 p.setStyle(SkPaint::kStrokeAndFill_Style);
118 p.setStrokeWidth(SkIntToScalar(2));
119 fPaints.push_back(p);
123 void makeMatrices() {
126 m.setScale(SkIntToScalar(2), SkIntToScalar(3));
127 fMatrices.push_back(m);
132 m.setScale(SkIntToScalar(2), SkIntToScalar(2));
133 fMatrices.push_back(m);
138 m.setSkew(SkIntToScalar(2), SkIntToScalar(3));
139 fMatrices.push_back(m);
144 m.setSkew(SkIntToScalar(2), SkIntToScalar(2));
145 fMatrices.push_back(m);
150 m.setRotate(SkIntToScalar(30));
151 fMatrices.push_back(m);
155 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
156 // Draw a giant AA circle as the background.
157 SkISize size = this->getISize();
158 SkScalar giantRadius = SkTMin(SkIntToScalar(size.fWidth),
159 SkIntToScalar(size.fHeight)) / 2.f;
160 SkPoint giantCenter = SkPoint::Make(SkIntToScalar(size.fWidth/2),
161 SkIntToScalar(size.fHeight/2));
163 giantPaint.setAntiAlias(true);
164 giantPaint.setColor(0x80808080);
165 canvas->drawCircle(giantCenter.fX, giantCenter.fY, giantRadius, giantPaint);
168 canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1);
170 for (i = 0; i < fPaints.count(); ++i) {
172 // position the path, and make it at off-integer coords.
173 canvas->translate(SK_Scalar1 * 200 * (i % 5) + SK_Scalar1 / 4,
174 SK_Scalar1 * 200 * (i / 5) + 3 * SK_Scalar1 / 4);
175 SkColor color = rand.nextU();
177 fPaints[i].setColor(color);
179 canvas->drawCircle(SkIntToScalar(40), SkIntToScalar(40),
185 for (int j = 0; j < fMatrices.count(); ++j, ++i) {
188 canvas->translate(SK_Scalar1 * 200 * (i % 5) + SK_Scalar1 / 4,
189 SK_Scalar1 * 200 * (i / 5) + 3 * SK_Scalar1 / 4);
191 canvas->concat(fMatrices[j]);
194 paint.setAntiAlias(true);
196 SkColor color = rand.nextU();
198 paint.setColor(color);
200 canvas->drawCircle(SkIntToScalar(40), SkIntToScalar(40),
209 typedef GM INHERITED;
210 SkTArray<SkPaint> fPaints;
211 SkTArray<SkMatrix> fMatrices;
214 //////////////////////////////////////////////////////////////////////////////
216 static GM* MyFactory(void*) { return new CircleGM; }
217 static GMRegistry reg(MyFactory);