blob: 2fb1615cf95a5fce382e6ed58f6df56a22090ca4 [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"
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +00009#include "SkBlurDrawLooper.h"
10
11namespace skiagm {
12
13///////////////////////////////////////////////////////////////////////////////
14
reed@google.come3605d02011-05-26 15:12:35 +000015static void setup(SkPaint* paint, SkColor c, SkScalar strokeWidth) {
16 paint->setColor(c);
17 if (strokeWidth < 0) {
18 paint->setStyle(SkPaint::kFill_Style);
19 } else {
20 paint->setStyle(SkPaint::kStroke_Style);
21 paint->setStrokeWidth(strokeWidth);
22 }
23}
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000024
reed@google.come3605d02011-05-26 15:12:35 +000025class ShadowsGM : public GM {
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000026public:
27 SkPath fCirclePath;
reed@google.come3605d02011-05-26 15:12:35 +000028 SkRect fRect;
29
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000030 ShadowsGM() {
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000031 this->setBGColor(0xFFDDDDDD);
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000032 fCirclePath.addCircle(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(10) );
reed@google.come3605d02011-05-26 15:12:35 +000033 fRect.set(SkIntToScalar(10), SkIntToScalar(10),
34 SkIntToScalar(30), SkIntToScalar(30));
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000035 }
36
37protected:
38 virtual SkString onShortName() {
39 return SkString("shadows");
40 }
41
42 virtual SkISize onISize() {
junov@chromium.org7c545bd2012-04-05 13:20:59 +000043 return make_isize(200, 120);
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000044 }
45
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000046 virtual void onDraw(SkCanvas* canvas) {
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000047 SkBlurDrawLooper* shadowLoopers[5];
48 shadowLoopers[0] =
epoger@google.com8f096722011-05-24 17:07:01 +000049 new SkBlurDrawLooper (SkIntToScalar(10), SkIntToScalar(5),
50 SkIntToScalar(10), 0xFF0000FF,
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000051 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
52 SkBlurDrawLooper::kOverrideColor_BlurFlag |
53 SkBlurDrawLooper::kHighQuality_BlurFlag );
54 SkAutoUnref aurL0(shadowLoopers[0]);
55 shadowLoopers[1] =
epoger@google.com8f096722011-05-24 17:07:01 +000056 new SkBlurDrawLooper (SkIntToScalar(10), SkIntToScalar(5),
57 SkIntToScalar(10), 0xFF0000FF,
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000058 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
59 SkBlurDrawLooper::kOverrideColor_BlurFlag );
60 SkAutoUnref aurL1(shadowLoopers[1]);
61 shadowLoopers[2] =
epoger@google.com8f096722011-05-24 17:07:01 +000062 new SkBlurDrawLooper (SkIntToScalar(5), SkIntToScalar(5),
63 SkIntToScalar(10), 0xFF000000,
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000064 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
65 SkBlurDrawLooper::kHighQuality_BlurFlag );
66 SkAutoUnref aurL2(shadowLoopers[2]);
67 shadowLoopers[3] =
epoger@google.com8f096722011-05-24 17:07:01 +000068 new SkBlurDrawLooper (SkIntToScalar(5), SkIntToScalar(-5),
69 SkIntToScalar(-10), 0x7FFF0000,
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000070 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
71 SkBlurDrawLooper::kOverrideColor_BlurFlag |
72 SkBlurDrawLooper::kHighQuality_BlurFlag );
73 SkAutoUnref aurL3(shadowLoopers[3]);
74 shadowLoopers[4] =
epoger@google.com8f096722011-05-24 17:07:01 +000075 new SkBlurDrawLooper (SkIntToScalar(0), SkIntToScalar(5),
76 SkIntToScalar(5), 0xFF000000,
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000077 SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
78 SkBlurDrawLooper::kOverrideColor_BlurFlag |
79 SkBlurDrawLooper::kHighQuality_BlurFlag );
80 SkAutoUnref aurL4(shadowLoopers[4]);
81
reed@google.come3605d02011-05-26 15:12:35 +000082 static const struct {
83 SkColor fColor;
84 SkScalar fStrokeWidth;
85 } gRec[] = {
86 { SK_ColorRED, -SK_Scalar1 },
87 { SK_ColorGREEN, SkIntToScalar(4) },
junov@chromium.org7c545bd2012-04-05 13:20:59 +000088 { SK_ColorBLUE, SkIntToScalar(0)},
reed@google.come3605d02011-05-26 15:12:35 +000089 };
90
91 SkPaint paint;
92 paint.setAntiAlias(true);
93 for (size_t i = 0; i < SK_ARRAY_COUNT(shadowLoopers); ++i) {
94 SkAutoCanvasRestore acr(canvas, true);
95
96 paint.setLooper(shadowLoopers[i]);
97
tomhudson@google.comffe39bd2012-05-17 15:38:00 +000098 canvas->translate(SkIntToScalar((unsigned int)i*40), SkIntToScalar(0));
reed@google.come3605d02011-05-26 15:12:35 +000099 setup(&paint, gRec[0].fColor, gRec[0].fStrokeWidth);
100 canvas->drawRect(fRect, paint);
101
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +0000102 canvas->translate(SkIntToScalar(0), SkIntToScalar(40));
reed@google.come3605d02011-05-26 15:12:35 +0000103 setup(&paint, gRec[1].fColor, gRec[1].fStrokeWidth);
104 canvas->drawPath(fCirclePath, paint);
junov@chromium.org7c545bd2012-04-05 13:20:59 +0000105
106 canvas->translate(SkIntToScalar(0), SkIntToScalar(40));
107 setup(&paint, gRec[2].fColor, gRec[2].fStrokeWidth);
108 canvas->drawPath(fCirclePath, paint);
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +0000109 }
110}
111
112private:
113 typedef GM INHERITED;
114};
115
116///////////////////////////////////////////////////////////////////////////////
117
118static GM* MyFactory(void*) { return new ShadowsGM; }
119static GMRegistry reg(MyFactory);
120
121}