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 "SkOffsetImageFilter.h" |
| 17 #include "SkResizeImageFilter.h" |
17 #include "SkScalar.h" | 18 #include "SkScalar.h" |
18 | 19 |
| 20 #define RESIZE_FACTOR_X SkIntToScalar(2) |
| 21 #define RESIZE_FACTOR_Y SkIntToScalar(5) |
| 22 |
19 namespace skiagm { | 23 namespace skiagm { |
20 | 24 |
21 class ImageFiltersClippedGM : public GM { | 25 class ImageFiltersClippedGM : public GM { |
22 public: | 26 public: |
23 ImageFiltersClippedGM() : fInitialized(false) { | 27 ImageFiltersClippedGM() : fInitialized(false) { |
24 this->setBGColor(0x00000000); | 28 this->setBGColor(0x00000000); |
25 } | 29 } |
26 | 30 |
27 protected: | 31 protected: |
28 virtual SkString onShortName() { | 32 virtual SkString onShortName() { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 new SkDropShadowImageFilter(SkIntToScalar(10), SkIntToScalar(10), Sk
IntToScalar(3), | 93 new SkDropShadowImageFilter(SkIntToScalar(10), SkIntToScalar(10), Sk
IntToScalar(3), |
90 SK_ColorGREEN), | 94 SK_ColorGREEN), |
91 new SkDisplacementMapEffect(SkDisplacementMapEffect::kR_ChannelSelec
torType, | 95 new SkDisplacementMapEffect(SkDisplacementMapEffect::kR_ChannelSelec
torType, |
92 SkDisplacementMapEffect::kR_ChannelSelec
torType, | 96 SkDisplacementMapEffect::kR_ChannelSelec
torType, |
93 SkIntToScalar(12), | 97 SkIntToScalar(12), |
94 gradient.get(), | 98 gradient.get(), |
95 checkerboard.get()), | 99 checkerboard.get()), |
96 new SkDilateImageFilter(2, 2, checkerboard.get()), | 100 new SkDilateImageFilter(2, 2, checkerboard.get()), |
97 new SkErodeImageFilter(2, 2, checkerboard.get()), | 101 new SkErodeImageFilter(2, 2, checkerboard.get()), |
98 new SkOffsetImageFilter(SkIntToScalar(-16), SkIntToScalar(32)), | 102 new SkOffsetImageFilter(SkIntToScalar(-16), SkIntToScalar(32)), |
| 103 new SkResizeImageFilter(RESIZE_FACTOR_X, RESIZE_FACTOR_Y, SkPaint::k
None_FilterLevel), |
99 }; | 104 }; |
100 | 105 |
101 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); | 106 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); |
102 SkScalar margin = SkIntToScalar(16); | 107 SkScalar margin = SkIntToScalar(16); |
103 SkRect bounds = r; | 108 SkRect bounds = r; |
104 bounds.outset(margin, margin); | 109 bounds.outset(margin, margin); |
105 | 110 |
106 for (int xOffset = 0; xOffset < 80; xOffset += 16) { | 111 for (int xOffset = 0; xOffset < 80; xOffset += 16) { |
107 canvas->save(); | 112 canvas->save(); |
108 bounds.fLeft = SkIntToScalar(xOffset); | 113 bounds.fLeft = SkIntToScalar(xOffset); |
109 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 114 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
110 SkPaint paint; | 115 SkPaint paint; |
111 paint.setColor(SK_ColorWHITE); | 116 paint.setColor(SK_ColorWHITE); |
112 paint.setImageFilter(filters[i]); | 117 paint.setImageFilter(filters[i]); |
113 paint.setAntiAlias(true); | 118 paint.setAntiAlias(true); |
114 canvas->save(); | 119 canvas->save(); |
115 canvas->clipRect(bounds); | 120 canvas->clipRect(bounds); |
116 if (i == 5) { | 121 if (5 == i) { |
117 canvas->translate(SkIntToScalar(16), SkIntToScalar(-32)); | 122 canvas->translate(SkIntToScalar(16), SkIntToScalar(-32)); |
| 123 } else if (6 == i) { |
| 124 canvas->scale(SkScalarInvert(RESIZE_FACTOR_X), |
| 125 SkScalarInvert(RESIZE_FACTOR_Y)); |
118 } | 126 } |
119 canvas->drawCircle(r.centerX(), r.centerY(), | 127 canvas->drawCircle(r.centerX(), r.centerY(), |
120 SkScalarDiv(r.width()*2, SkIntToScalar(5)), p
aint); | 128 SkScalarDiv(r.width()*2, SkIntToScalar(5)), p
aint); |
121 canvas->restore(); | 129 canvas->restore(); |
122 canvas->translate(r.width() + margin, 0); | 130 canvas->translate(r.width() + margin, 0); |
123 } | 131 } |
124 canvas->restore(); | 132 canvas->restore(); |
125 canvas->translate(0, r.height() + margin); | 133 canvas->translate(0, r.height() + margin); |
126 } | 134 } |
127 | 135 |
128 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 136 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
129 SkSafeUnref(filters[i]); | 137 SkSafeUnref(filters[i]); |
130 } | 138 } |
131 } | 139 } |
132 | 140 |
133 private: | 141 private: |
134 bool fInitialized; | 142 bool fInitialized; |
135 SkBitmap fCheckerboard; | 143 SkBitmap fCheckerboard; |
136 SkBitmap fGradientCircle; | 144 SkBitmap fGradientCircle; |
137 typedef GM INHERITED; | 145 typedef GM INHERITED; |
138 }; | 146 }; |
139 | 147 |
140 ////////////////////////////////////////////////////////////////////////////// | 148 ////////////////////////////////////////////////////////////////////////////// |
141 | 149 |
142 static GM* MyFactory(void*) { return new ImageFiltersClippedGM; } | 150 static GM* MyFactory(void*) { return new ImageFiltersClippedGM; } |
143 static GMRegistry reg(MyFactory); | 151 static GMRegistry reg(MyFactory); |
144 | 152 |
145 } | 153 } |
OLD | NEW |