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" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 9 | #include "SkBlurMask.h" |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 10 | #include "SkBlurDrawLooper.h" |
| 11 | |
| 12 | namespace skiagm { |
| 13 | |
| 14 | /////////////////////////////////////////////////////////////////////////////// |
| 15 | |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 16 | static 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.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 25 | |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 26 | class ShadowsGM : public GM { |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 27 | public: |
| 28 | SkPath fCirclePath; |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 29 | SkRect fRect; |
| 30 | |
caryclark | 63c684a | 2015-02-25 09:04:04 -0800 | [diff] [blame] | 31 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 32 | void onOnceBeforeDraw() override { |
caryclark | 65cdba6 | 2015-06-15 06:51:08 -0700 | [diff] [blame] | 33 | this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 34 | fCirclePath.addCircle(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(10) ); |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 35 | fRect.set(SkIntToScalar(10), SkIntToScalar(10), |
| 36 | SkIntToScalar(30), SkIntToScalar(30)); |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 37 | } |
| 38 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 39 | SkString onShortName() override { |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 40 | return SkString("shadows"); |
| 41 | } |
| 42 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 43 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 44 | return SkISize::Make(200, 120); |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 45 | } |
| 46 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 47 | void onDraw(SkCanvas* canvas) override { |
| 48 | SkBlurDrawLooper* shadowLoopers[5]; |
| 49 | shadowLoopers[0] = |
| 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]); |
| 57 | shadowLoopers[1] = |
| 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]); |
| 64 | shadowLoopers[2] = |
| 65 | SkBlurDrawLooper::Create(SK_ColorBLACK, |
| 66 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)), |
| 67 | SkIntToScalar(5), |
| 68 | SkIntToScalar(10), |
| 69 | SkBlurDrawLooper::kIgnoreTransform_BlurFlag | |
| 70 | SkBlurDrawLooper::kHighQuality_BlurFlag); |
| 71 | SkAutoUnref aurL2(shadowLoopers[2]); |
| 72 | shadowLoopers[3] = |
| 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]); |
| 80 | shadowLoopers[4] = |
| 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]); |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 87 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 88 | static const struct { |
| 89 | SkColor fColor; |
| 90 | SkScalar fStrokeWidth; |
| 91 | } gRec[] = { |
| 92 | { SK_ColorRED, -SK_Scalar1 }, |
| 93 | { SK_ColorGREEN, SkIntToScalar(4) }, |
| 94 | { SK_ColorBLUE, SkIntToScalar(0)}, |
| 95 | }; |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 96 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 97 | SkPaint paint; |
| 98 | paint.setAntiAlias(true); |
| 99 | for (size_t i = 0; i < SK_ARRAY_COUNT(shadowLoopers); ++i) { |
| 100 | SkAutoCanvasRestore acr(canvas, true); |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 101 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 102 | paint.setLooper(shadowLoopers[i]); |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 103 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 104 | canvas->translate(SkIntToScalar((unsigned int)i*40), SkIntToScalar(0)); |
| 105 | setup(&paint, gRec[0].fColor, gRec[0].fStrokeWidth); |
| 106 | canvas->drawRect(fRect, paint); |
reed@google.com | e3605d0 | 2011-05-26 15:12:35 +0000 | [diff] [blame] | 107 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 108 | canvas->translate(SkIntToScalar(0), SkIntToScalar(40)); |
| 109 | setup(&paint, gRec[1].fColor, gRec[1].fStrokeWidth); |
| 110 | canvas->drawPath(fCirclePath, paint); |
junov@chromium.org | 7c545bd | 2012-04-05 13:20:59 +0000 | [diff] [blame] | 111 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 112 | canvas->translate(SkIntToScalar(0), SkIntToScalar(40)); |
| 113 | setup(&paint, gRec[2].fColor, gRec[2].fStrokeWidth); |
| 114 | canvas->drawPath(fCirclePath, paint); |
| 115 | } |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 116 | } |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 117 | |
| 118 | private: |
| 119 | typedef GM INHERITED; |
| 120 | }; |
| 121 | |
| 122 | /////////////////////////////////////////////////////////////////////////////// |
| 123 | |
| 124 | static GM* MyFactory(void*) { return new ShadowsGM; } |
| 125 | static GMRegistry reg(MyFactory); |
| 126 | |
| 127 | } |