3 * Copyright 2011 Google 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 "SkBlurMask.h"
10 #include "SkBlurDrawLooper.h"
14 ///////////////////////////////////////////////////////////////////////////////
16 static void setup(SkPaint* paint, SkColor c, SkScalar strokeWidth) {
18 if (strokeWidth < 0) {
19 paint->setStyle(SkPaint::kFill_Style);
21 paint->setStyle(SkPaint::kStroke_Style);
22 paint->setStrokeWidth(strokeWidth);
26 class ShadowsGM : public GM {
32 void onOnceBeforeDraw() override {
33 this->setBGColor(0xFFDDDDDD);
34 fCirclePath.addCircle(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(10) );
35 fRect.set(SkIntToScalar(10), SkIntToScalar(10),
36 SkIntToScalar(30), SkIntToScalar(30));
39 virtual SkString onShortName() {
40 return SkString("shadows");
43 virtual SkISize onISize() {
44 return SkISize::Make(200, 120);
47 virtual void onDraw(SkCanvas* canvas) {
48 SkBlurDrawLooper* shadowLoopers[5];
50 SkBlurDrawLooper::Create(SK_ColorBLUE,
51 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
52 SkIntToScalar(5), SkIntToScalar(10),
53 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
54 SkBlurDrawLooper::kOverrideColor_BlurFlag |
55 SkBlurDrawLooper::kHighQuality_BlurFlag);
56 SkAutoUnref aurL0(shadowLoopers[0]);
58 SkBlurDrawLooper::Create(SK_ColorBLUE,
59 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
60 SkIntToScalar(5), SkIntToScalar(10),
61 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
62 SkBlurDrawLooper::kOverrideColor_BlurFlag);
63 SkAutoUnref aurL1(shadowLoopers[1]);
65 SkBlurDrawLooper::Create(SK_ColorBLACK,
66 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
69 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
70 SkBlurDrawLooper::kHighQuality_BlurFlag);
71 SkAutoUnref aurL2(shadowLoopers[2]);
73 SkBlurDrawLooper::Create(0x7FFF0000,
74 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
75 SkIntToScalar(-5), SkIntToScalar(-10),
76 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
77 SkBlurDrawLooper::kOverrideColor_BlurFlag |
78 SkBlurDrawLooper::kHighQuality_BlurFlag);
79 SkAutoUnref aurL3(shadowLoopers[3]);
81 SkBlurDrawLooper::Create(SK_ColorBLACK, SkIntToScalar(0),
82 SkIntToScalar(5), SkIntToScalar(5),
83 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
84 SkBlurDrawLooper::kOverrideColor_BlurFlag |
85 SkBlurDrawLooper::kHighQuality_BlurFlag);
86 SkAutoUnref aurL4(shadowLoopers[4]);
90 SkScalar fStrokeWidth;
92 { SK_ColorRED, -SK_Scalar1 },
93 { SK_ColorGREEN, SkIntToScalar(4) },
94 { SK_ColorBLUE, SkIntToScalar(0)},
98 paint.setAntiAlias(true);
99 for (size_t i = 0; i < SK_ARRAY_COUNT(shadowLoopers); ++i) {
100 SkAutoCanvasRestore acr(canvas, true);
102 paint.setLooper(shadowLoopers[i]);
104 canvas->translate(SkIntToScalar((unsigned int)i*40), SkIntToScalar(0));
105 setup(&paint, gRec[0].fColor, gRec[0].fStrokeWidth);
106 canvas->drawRect(fRect, paint);
108 canvas->translate(SkIntToScalar(0), SkIntToScalar(40));
109 setup(&paint, gRec[1].fColor, gRec[1].fStrokeWidth);
110 canvas->drawPath(fCirclePath, paint);
112 canvas->translate(SkIntToScalar(0), SkIntToScalar(40));
113 setup(&paint, gRec[2].fColor, gRec[2].fStrokeWidth);
114 canvas->drawPath(fCirclePath, paint);
119 typedef GM INHERITED;
122 ///////////////////////////////////////////////////////////////////////////////
124 static GM* MyFactory(void*) { return new ShadowsGM; }
125 static GMRegistry reg(MyFactory);