blob: 3ecbdd833fce45062d43082dcd7214bbcc7429d6 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +00008#include "gm.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00009#include "SkBlurMask.h"
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000010#include "SkBlurDrawLooper.h"
11
12namespace skiagm {
13
14///////////////////////////////////////////////////////////////////////////////
15
reed@google.come3605d02011-05-26 15:12:35 +000016static void setup(SkPaint* paint, SkColor c, SkScalar strokeWidth) {
17 paint->setColor(c);
18 if (strokeWidth < 0) {
19 paint->setStyle(SkPaint::kFill_Style);
20 } else {
21 paint->setStyle(SkPaint::kStroke_Style);
22 paint->setStrokeWidth(strokeWidth);
23 }
24}
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000025
reed@google.come3605d02011-05-26 15:12:35 +000026class ShadowsGM : public GM {
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000027public:
28 SkPath fCirclePath;
reed@google.come3605d02011-05-26 15:12:35 +000029 SkRect fRect;
30
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000031 ShadowsGM() {
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000032 this->setBGColor(0xFFDDDDDD);
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000033 fCirclePath.addCircle(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(10) );
reed@google.come3605d02011-05-26 15:12:35 +000034 fRect.set(SkIntToScalar(10), SkIntToScalar(10),
35 SkIntToScalar(30), SkIntToScalar(30));
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000036 }
37
38protected:
39 virtual SkString onShortName() {
40 return SkString("shadows");
41 }
42
43 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070044 return SkISize::Make(200, 120);
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000045 }
46
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000047 virtual void onDraw(SkCanvas* canvas) {
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000048 SkBlurDrawLooper* shadowLoopers[5];
49 shadowLoopers[0] =
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000050 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);
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000056 SkAutoUnref aurL0(shadowLoopers[0]);
57 shadowLoopers[1] =
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000058 SkBlurDrawLooper::Create(SK_ColorBLUE,
59 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
60 SkIntToScalar(5), SkIntToScalar(10),
61 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
62 SkBlurDrawLooper::kOverrideColor_BlurFlag);
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000063 SkAutoUnref aurL1(shadowLoopers[1]);
64 shadowLoopers[2] =
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000065 SkBlurDrawLooper::Create(SK_ColorBLACK,
66 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
67 SkIntToScalar(5),
68 SkIntToScalar(10),
69 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
70 SkBlurDrawLooper::kHighQuality_BlurFlag);
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000071 SkAutoUnref aurL2(shadowLoopers[2]);
72 shadowLoopers[3] =
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000073 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);
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000079 SkAutoUnref aurL3(shadowLoopers[3]);
80 shadowLoopers[4] =
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000081 SkBlurDrawLooper::Create(SK_ColorBLACK, SkIntToScalar(0),
82 SkIntToScalar(5), SkIntToScalar(5),
83 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
84 SkBlurDrawLooper::kOverrideColor_BlurFlag |
85 SkBlurDrawLooper::kHighQuality_BlurFlag);
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000086 SkAutoUnref aurL4(shadowLoopers[4]);
87
reed@google.come3605d02011-05-26 15:12:35 +000088 static const struct {
89 SkColor fColor;
90 SkScalar fStrokeWidth;
91 } gRec[] = {
92 { SK_ColorRED, -SK_Scalar1 },
93 { SK_ColorGREEN, SkIntToScalar(4) },
junov@chromium.org7c545bd2012-04-05 13:20:59 +000094 { SK_ColorBLUE, SkIntToScalar(0)},
reed@google.come3605d02011-05-26 15:12:35 +000095 };
96
97 SkPaint paint;
98 paint.setAntiAlias(true);
99 for (size_t i = 0; i < SK_ARRAY_COUNT(shadowLoopers); ++i) {
100 SkAutoCanvasRestore acr(canvas, true);
101
102 paint.setLooper(shadowLoopers[i]);
103
tomhudson@google.comffe39bd2012-05-17 15:38:00 +0000104 canvas->translate(SkIntToScalar((unsigned int)i*40), SkIntToScalar(0));
reed@google.come3605d02011-05-26 15:12:35 +0000105 setup(&paint, gRec[0].fColor, gRec[0].fStrokeWidth);
106 canvas->drawRect(fRect, paint);
107
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +0000108 canvas->translate(SkIntToScalar(0), SkIntToScalar(40));
reed@google.come3605d02011-05-26 15:12:35 +0000109 setup(&paint, gRec[1].fColor, gRec[1].fStrokeWidth);
110 canvas->drawPath(fCirclePath, paint);
junov@chromium.org7c545bd2012-04-05 13:20:59 +0000111
112 canvas->translate(SkIntToScalar(0), SkIntToScalar(40));
113 setup(&paint, gRec[2].fColor, gRec[2].fStrokeWidth);
114 canvas->drawPath(fCirclePath, paint);
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +0000115 }
116}
117
118private:
119 typedef GM INHERITED;
120};
121
122///////////////////////////////////////////////////////////////////////////////
123
124static GM* MyFactory(void*) { return new ShadowsGM; }
125static GMRegistry reg(MyFactory);
126
127}