epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 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.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 8 | #include "gm.h" |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 9 | #include "SkBlurDrawLooper.h" |
| 10 | |
| 11 | namespace skiagm { |
| 12 | |
| 13 | /////////////////////////////////////////////////////////////////////////////// |
| 14 | |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 15 | static 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.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 24 | |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 25 | class ShadowsGM : public GM { |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 26 | public: |
| 27 | SkPath fCirclePath; |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 28 | SkRect fRect; |
| 29 | |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 30 | ShadowsGM() { |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 31 | this->setBGColor(0xFFDDDDDD); |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 32 | fCirclePath.addCircle(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(10) ); |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 33 | fRect.set(SkIntToScalar(10), SkIntToScalar(10), |
| 34 | SkIntToScalar(30), SkIntToScalar(30)); |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | protected: |
| 38 | virtual SkString onShortName() { |
| 39 | return SkString("shadows"); |
| 40 | } |
| 41 | |
| 42 | virtual SkISize onISize() { |
junov@chromium.org | 7c545bd | 2012-04-05 13:20:59 +0000 | [diff] [blame] | 43 | return make_isize(200, 120); |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 44 | } |
| 45 | |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 46 | virtual void onDraw(SkCanvas* canvas) { |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 47 | SkBlurDrawLooper* shadowLoopers[5]; |
| 48 | shadowLoopers[0] = |
epoger@google.com | 8f09672 | 2011-05-24 17:07:01 +0000 | [diff] [blame] | 49 | new SkBlurDrawLooper (SkIntToScalar(10), SkIntToScalar(5), |
| 50 | SkIntToScalar(10), 0xFF0000FF, |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 51 | SkBlurDrawLooper::kIgnoreTransform_BlurFlag | |
| 52 | SkBlurDrawLooper::kOverrideColor_BlurFlag | |
| 53 | SkBlurDrawLooper::kHighQuality_BlurFlag ); |
| 54 | SkAutoUnref aurL0(shadowLoopers[0]); |
| 55 | shadowLoopers[1] = |
epoger@google.com | 8f09672 | 2011-05-24 17:07:01 +0000 | [diff] [blame] | 56 | new SkBlurDrawLooper (SkIntToScalar(10), SkIntToScalar(5), |
| 57 | SkIntToScalar(10), 0xFF0000FF, |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 58 | SkBlurDrawLooper::kIgnoreTransform_BlurFlag | |
| 59 | SkBlurDrawLooper::kOverrideColor_BlurFlag ); |
| 60 | SkAutoUnref aurL1(shadowLoopers[1]); |
| 61 | shadowLoopers[2] = |
epoger@google.com | 8f09672 | 2011-05-24 17:07:01 +0000 | [diff] [blame] | 62 | new SkBlurDrawLooper (SkIntToScalar(5), SkIntToScalar(5), |
| 63 | SkIntToScalar(10), 0xFF000000, |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 64 | SkBlurDrawLooper::kIgnoreTransform_BlurFlag | |
| 65 | SkBlurDrawLooper::kHighQuality_BlurFlag ); |
| 66 | SkAutoUnref aurL2(shadowLoopers[2]); |
| 67 | shadowLoopers[3] = |
epoger@google.com | 8f09672 | 2011-05-24 17:07:01 +0000 | [diff] [blame] | 68 | new SkBlurDrawLooper (SkIntToScalar(5), SkIntToScalar(-5), |
| 69 | SkIntToScalar(-10), 0x7FFF0000, |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 70 | SkBlurDrawLooper::kIgnoreTransform_BlurFlag | |
| 71 | SkBlurDrawLooper::kOverrideColor_BlurFlag | |
| 72 | SkBlurDrawLooper::kHighQuality_BlurFlag ); |
| 73 | SkAutoUnref aurL3(shadowLoopers[3]); |
| 74 | shadowLoopers[4] = |
epoger@google.com | 8f09672 | 2011-05-24 17:07:01 +0000 | [diff] [blame] | 75 | new SkBlurDrawLooper (SkIntToScalar(0), SkIntToScalar(5), |
| 76 | SkIntToScalar(5), 0xFF000000, |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 77 | SkBlurDrawLooper::kIgnoreTransform_BlurFlag | |
| 78 | SkBlurDrawLooper::kOverrideColor_BlurFlag | |
| 79 | SkBlurDrawLooper::kHighQuality_BlurFlag ); |
| 80 | SkAutoUnref aurL4(shadowLoopers[4]); |
| 81 | |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 82 | static const struct { |
| 83 | SkColor fColor; |
| 84 | SkScalar fStrokeWidth; |
| 85 | } gRec[] = { |
| 86 | { SK_ColorRED, -SK_Scalar1 }, |
| 87 | { SK_ColorGREEN, SkIntToScalar(4) }, |
junov@chromium.org | 7c545bd | 2012-04-05 13:20:59 +0000 | [diff] [blame] | 88 | { SK_ColorBLUE, SkIntToScalar(0)}, |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 89 | }; |
| 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.com | ffe39bd | 2012-05-17 15:38:00 +0000 | [diff] [blame] | 98 | canvas->translate(SkIntToScalar((unsigned int)i*40), SkIntToScalar(0)); |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 99 | setup(&paint, gRec[0].fColor, gRec[0].fStrokeWidth); |
| 100 | canvas->drawRect(fRect, paint); |
| 101 | |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 102 | canvas->translate(SkIntToScalar(0), SkIntToScalar(40)); |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 103 | setup(&paint, gRec[1].fColor, gRec[1].fStrokeWidth); |
| 104 | canvas->drawPath(fCirclePath, paint); |
junov@chromium.org | 7c545bd | 2012-04-05 13:20:59 +0000 | [diff] [blame] | 105 | |
| 106 | canvas->translate(SkIntToScalar(0), SkIntToScalar(40)); |
| 107 | setup(&paint, gRec[2].fColor, gRec[2].fStrokeWidth); |
| 108 | canvas->drawPath(fCirclePath, paint); |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | private: |
| 113 | typedef GM INHERITED; |
| 114 | }; |
| 115 | |
| 116 | /////////////////////////////////////////////////////////////////////////////// |
| 117 | |
| 118 | static GM* MyFactory(void*) { return new ShadowsGM; } |
| 119 | static GMRegistry reg(MyFactory); |
| 120 | |
| 121 | } |