OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkBlurMask.h" | 9 #include "SkBlurMask.h" |
10 #include "SkBlurMaskFilter.h" | 10 #include "SkBlurMaskFilter.h" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkGraphics.h" | 12 #include "SkGraphics.h" |
13 #include "SkLayerDrawLooper.h" | 13 #include "SkLayerDrawLooper.h" |
14 #include "SkRandom.h" | 14 #include "SkRandom.h" |
15 | 15 |
16 #define WIDTH 200 | 16 #define WIDTH 200 |
17 #define HEIGHT 200 | 17 #define HEIGHT 200 |
18 | 18 |
19 class DrawLooperGM : public skiagm::GM { | 19 class DrawLooperGM : public skiagm::GM { |
20 public: | 20 public: |
21 DrawLooperGM() : fLooper(nullptr) { | 21 DrawLooperGM() : fLooper(nullptr) { |
22 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); | 22 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); |
23 } | 23 } |
24 | 24 |
25 virtual ~DrawLooperGM() { | |
26 SkSafeUnref(fLooper); | |
27 } | |
28 | |
29 protected: | 25 protected: |
30 virtual SkISize onISize() override { | 26 virtual SkISize onISize() override { |
31 return SkISize::Make(520, 160); | 27 return SkISize::Make(520, 160); |
32 } | 28 } |
33 | 29 |
34 SkString onShortName() override { | 30 SkString onShortName() override { |
35 return SkString("drawlooper"); | 31 return SkString("drawlooper"); |
36 } | 32 } |
37 | 33 |
38 void onDraw(SkCanvas* canvas) override { | 34 void onDraw(SkCanvas* canvas) override { |
39 this->init(); | 35 this->init(); |
40 | 36 |
41 SkPaint paint; | 37 SkPaint paint; |
42 paint.setAntiAlias(true); | 38 paint.setAntiAlias(true); |
43 sk_tool_utils::set_portable_typeface(&paint); | 39 sk_tool_utils::set_portable_typeface(&paint); |
44 paint.setTextSize(SkIntToScalar(72)); | 40 paint.setTextSize(SkIntToScalar(72)); |
45 paint.setLooper(fLooper); | 41 paint.setLooper(fLooper); |
46 | 42 |
47 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50), | 43 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50), |
48 SkIntToScalar(30), paint); | 44 SkIntToScalar(30), paint); |
49 | 45 |
50 canvas->drawRectCoords(SkIntToScalar(150), SkIntToScalar(50), | 46 canvas->drawRectCoords(SkIntToScalar(150), SkIntToScalar(50), |
51 SkIntToScalar(200), SkIntToScalar(100), paint); | 47 SkIntToScalar(200), SkIntToScalar(100), paint); |
52 | 48 |
53 canvas->drawText("Looper", 6, SkIntToScalar(230), SkIntToScalar(100), | 49 canvas->drawText("Looper", 6, SkIntToScalar(230), SkIntToScalar(100), |
54 paint); | 50 paint); |
55 } | 51 } |
56 | 52 |
57 private: | 53 private: |
58 SkLayerDrawLooper* fLooper; | 54 sk_sp<SkDrawLooper> fLooper; |
59 | 55 |
60 void init() { | 56 void init() { |
61 if (fLooper) return; | 57 if (fLooper) return; |
62 | 58 |
63 static const struct { | 59 static const struct { |
64 SkColor fColor; | 60 SkColor fColor; |
65 SkPaint::Style fStyle; | 61 SkPaint::Style fStyle; |
66 SkScalar fWidth; | 62 SkScalar fWidth; |
67 SkScalar fOffset; | 63 SkScalar fOffset; |
68 SkScalar fBlur; | 64 SkScalar fBlur; |
(...skipping 15 matching lines...) Expand all Loading... |
84 SkPaint* paint = looperBuilder.addLayer(info); | 80 SkPaint* paint = looperBuilder.addLayer(info); |
85 paint->setColor(gParams[i].fColor); | 81 paint->setColor(gParams[i].fColor); |
86 paint->setStyle(gParams[i].fStyle); | 82 paint->setStyle(gParams[i].fStyle); |
87 paint->setStrokeWidth(gParams[i].fWidth); | 83 paint->setStrokeWidth(gParams[i].fWidth); |
88 if (gParams[i].fBlur > 0) { | 84 if (gParams[i].fBlur > 0) { |
89 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, | 85 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, |
90 SkBlurMask::ConvertRadiusToSigma(gParam
s[i].fBlur)); | 86 SkBlurMask::ConvertRadiusToSigma(gParam
s[i].fBlur)); |
91 paint->setMaskFilter(mf)->unref(); | 87 paint->setMaskFilter(mf)->unref(); |
92 } | 88 } |
93 } | 89 } |
94 fLooper = looperBuilder.detachLooper(); | 90 fLooper = looperBuilder.detach(); |
95 } | 91 } |
96 | 92 |
97 typedef GM INHERITED; | 93 typedef GM INHERITED; |
98 }; | 94 }; |
99 | 95 |
100 ////////////////////////////////////////////////////////////////////////////// | 96 ////////////////////////////////////////////////////////////////////////////// |
101 | 97 |
102 DEF_GM( return new DrawLooperGM; ) | 98 DEF_GM( return new DrawLooperGM; ) |
OLD | NEW |