OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkColor.h" | 9 #include "SkColor.h" |
10 #include "SkBitmapSource.h" | 10 #include "SkBitmapSource.h" |
11 #include "SkBlurImageFilter.h" | 11 #include "SkBlurImageFilter.h" |
12 #include "SkDisplacementMapEffect.h" | 12 #include "SkDisplacementMapEffect.h" |
13 #include "SkDropShadowImageFilter.h" | 13 #include "SkDropShadowImageFilter.h" |
14 #include "SkGradientShader.h" | 14 #include "SkGradientShader.h" |
15 #include "SkMorphologyImageFilter.h" | 15 #include "SkMorphologyImageFilter.h" |
| 16 #include "SkOffsetImageFilter.h" |
16 #include "SkScalar.h" | 17 #include "SkScalar.h" |
17 | 18 |
18 namespace skiagm { | 19 namespace skiagm { |
19 | 20 |
20 class ImageFiltersScaledGM : public GM { | 21 class ImageFiltersClippedGM : public GM { |
21 public: | 22 public: |
22 ImageFiltersScaledGM() : fInitialized(false) { | 23 ImageFiltersClippedGM() : fInitialized(false) { |
23 this->setBGColor(0x00000000); | 24 this->setBGColor(0x00000000); |
24 } | 25 } |
25 | 26 |
26 protected: | 27 protected: |
27 virtual SkString onShortName() { | 28 virtual SkString onShortName() { |
28 return SkString("imagefiltersscaled"); | 29 return SkString("imagefiltersclipped"); |
29 } | 30 } |
30 | 31 |
31 virtual SkISize onISize() { | 32 virtual SkISize onISize() { |
32 return make_isize(860, 500); | 33 return make_isize(860, 500); |
33 } | 34 } |
34 | 35 |
35 void make_checkerboard() { | 36 void make_checkerboard() { |
36 fCheckerboard.allocN32Pixels(64, 64); | 37 fCheckerboard.allocN32Pixels(64, 64); |
37 SkBitmapDevice device(fCheckerboard); | 38 SkBitmapDevice device(fCheckerboard); |
38 SkCanvas canvas(&device); | 39 SkCanvas canvas(&device); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 this->make_checkerboard(); | 80 this->make_checkerboard(); |
80 this->make_gradient_circle(64, 64); | 81 this->make_gradient_circle(64, 64); |
81 fInitialized = true; | 82 fInitialized = true; |
82 } | 83 } |
83 canvas->clear(0x00000000); | 84 canvas->clear(0x00000000); |
84 | 85 |
85 SkAutoTUnref<SkImageFilter> gradient(new SkBitmapSource(fGradientCircle)
); | 86 SkAutoTUnref<SkImageFilter> gradient(new SkBitmapSource(fGradientCircle)
); |
86 SkAutoTUnref<SkImageFilter> checkerboard(new SkBitmapSource(fCheckerboar
d)); | 87 SkAutoTUnref<SkImageFilter> checkerboard(new SkBitmapSource(fCheckerboar
d)); |
87 | 88 |
88 SkImageFilter* filters[] = { | 89 SkImageFilter* filters[] = { |
89 new SkBlurImageFilter(SkIntToScalar(4), SkIntToScalar(4)), | 90 new SkBlurImageFilter(SkIntToScalar(12), SkIntToScalar(12)), |
90 new SkDropShadowImageFilter(SkIntToScalar(5), SkIntToScalar(10), SkI
ntToScalar(3), | 91 new SkDropShadowImageFilter(SkIntToScalar(10), SkIntToScalar(10), Sk
IntToScalar(3), |
91 SK_ColorYELLOW), | 92 SK_ColorGREEN), |
92 new SkDisplacementMapEffect(SkDisplacementMapEffect::kR_ChannelSelec
torType, | 93 new SkDisplacementMapEffect(SkDisplacementMapEffect::kR_ChannelSelec
torType, |
93 SkDisplacementMapEffect::kR_ChannelSelec
torType, | 94 SkDisplacementMapEffect::kR_ChannelSelec
torType, |
94 SkIntToScalar(12), | 95 SkIntToScalar(12), |
95 gradient.get(), | 96 gradient.get(), |
96 checkerboard.get()), | 97 checkerboard.get()), |
97 new SkDilateImageFilter(1, 1, checkerboard.get()), | 98 new SkDilateImageFilter(2, 2, checkerboard.get()), |
98 new SkErodeImageFilter(1, 1, checkerboard.get()), | 99 new SkErodeImageFilter(2, 2, checkerboard.get()), |
99 }; | 100 new SkOffsetImageFilter(SkIntToScalar(-16), SkIntToScalar(32)), |
100 | |
101 SkVector scales[] = { | |
102 SkVector::Make(SkScalarInvert(2), SkScalarInvert(2)), | |
103 SkVector::Make(SkIntToScalar(1), SkIntToScalar(1)), | |
104 SkVector::Make(SkIntToScalar(1), SkIntToScalar(2)), | |
105 SkVector::Make(SkIntToScalar(2), SkIntToScalar(1)), | |
106 SkVector::Make(SkIntToScalar(2), SkIntToScalar(2)), | |
107 }; | 101 }; |
108 | 102 |
109 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); | 103 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); |
110 SkScalar margin = SkIntToScalar(16); | 104 SkScalar margin = SkIntToScalar(16); |
111 SkRect bounds = r; | 105 SkRect bounds = r; |
112 bounds.outset(margin, margin); | 106 bounds.outset(margin, margin); |
113 | 107 |
114 for (size_t j = 0; j < SK_ARRAY_COUNT(scales); ++j) { | 108 for (int xOffset = 0; xOffset < 80; xOffset += 16) { |
115 canvas->save(); | 109 canvas->save(); |
| 110 bounds.fLeft = SkIntToScalar(xOffset); |
116 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 111 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
117 SkPaint paint; | 112 SkPaint paint; |
118 paint.setColor(SK_ColorBLUE); | 113 paint.setColor(SK_ColorWHITE); |
119 paint.setImageFilter(filters[i]); | 114 paint.setImageFilter(filters[i]); |
120 paint.setAntiAlias(true); | 115 paint.setAntiAlias(true); |
121 canvas->save(); | 116 canvas->save(); |
122 canvas->scale(scales[j].fX, scales[j].fY); | |
123 canvas->clipRect(bounds); | 117 canvas->clipRect(bounds); |
| 118 if (i == 5) { |
| 119 canvas->translate(SkIntToScalar(16), SkIntToScalar(-32)); |
| 120 } |
124 canvas->drawCircle(r.centerX(), r.centerY(), | 121 canvas->drawCircle(r.centerX(), r.centerY(), |
125 SkScalarDiv(r.width()*2, SkIntToScalar(5)), p
aint); | 122 SkScalarDiv(r.width()*2, SkIntToScalar(5)), p
aint); |
126 canvas->restore(); | 123 canvas->restore(); |
127 canvas->translate(r.width() * scales[j].fX + margin, 0); | 124 canvas->translate(r.width() + margin, 0); |
128 } | 125 } |
129 canvas->restore(); | 126 canvas->restore(); |
130 canvas->translate(0, r.height() * scales[j].fY + margin); | 127 canvas->translate(0, r.height() + margin); |
131 } | |
132 | |
133 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | |
134 filters[i]->unref(); | |
135 } | 128 } |
136 } | 129 } |
137 | 130 |
138 private: | 131 private: |
139 bool fInitialized; | 132 bool fInitialized; |
140 SkBitmap fCheckerboard; | 133 SkBitmap fCheckerboard; |
141 SkBitmap fGradientCircle; | 134 SkBitmap fGradientCircle; |
142 typedef GM INHERITED; | 135 typedef GM INHERITED; |
143 }; | 136 }; |
144 | 137 |
145 ////////////////////////////////////////////////////////////////////////////// | 138 ////////////////////////////////////////////////////////////////////////////// |
146 | 139 |
147 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; } | 140 static GM* MyFactory(void*) { return new ImageFiltersClippedGM; } |
148 static GMRegistry reg(MyFactory); | 141 static GMRegistry reg(MyFactory); |
149 | 142 |
150 } | 143 } |
OLD | NEW |