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 ImageFiltersScaledGM : public GM { |
21 public: | 22 public: |
22 ImageFiltersScaledGM() : fInitialized(false) { | 23 ImageFiltersScaledGM() : fInitialized(false) { |
23 this->setBGColor(0x00000000); | 24 this->setBGColor(0x00000000); |
24 } | 25 } |
25 | 26 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 new SkBlurImageFilter(SkIntToScalar(4), SkIntToScalar(4)), | 90 new SkBlurImageFilter(SkIntToScalar(4), SkIntToScalar(4)), |
90 new SkDropShadowImageFilter(SkIntToScalar(5), SkIntToScalar(10), SkI
ntToScalar(3), | 91 new SkDropShadowImageFilter(SkIntToScalar(5), SkIntToScalar(10), SkI
ntToScalar(3), |
91 SK_ColorYELLOW), | 92 SK_ColorYELLOW), |
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(1, 1, checkerboard.get()), |
98 new SkErodeImageFilter(1, 1, checkerboard.get()), | 99 new SkErodeImageFilter(1, 1, checkerboard.get()), |
| 100 new SkOffsetImageFilter(SkIntToScalar(32), 0), |
99 }; | 101 }; |
100 | 102 |
101 SkVector scales[] = { | 103 SkVector scales[] = { |
102 SkVector::Make(SkScalarInvert(2), SkScalarInvert(2)), | 104 SkVector::Make(SkScalarInvert(2), SkScalarInvert(2)), |
103 SkVector::Make(SkIntToScalar(1), SkIntToScalar(1)), | 105 SkVector::Make(SkIntToScalar(1), SkIntToScalar(1)), |
104 SkVector::Make(SkIntToScalar(1), SkIntToScalar(2)), | 106 SkVector::Make(SkIntToScalar(1), SkIntToScalar(2)), |
105 SkVector::Make(SkIntToScalar(2), SkIntToScalar(1)), | 107 SkVector::Make(SkIntToScalar(2), SkIntToScalar(1)), |
106 SkVector::Make(SkIntToScalar(2), SkIntToScalar(2)), | 108 SkVector::Make(SkIntToScalar(2), SkIntToScalar(2)), |
107 }; | 109 }; |
108 | 110 |
109 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); | 111 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); |
110 SkScalar margin = SkIntToScalar(16); | 112 SkScalar margin = SkIntToScalar(16); |
111 SkRect bounds = r; | 113 SkRect bounds = r; |
112 bounds.outset(margin, margin); | 114 bounds.outset(margin, margin); |
113 | 115 |
114 for (size_t j = 0; j < SK_ARRAY_COUNT(scales); ++j) { | 116 for (size_t j = 0; j < SK_ARRAY_COUNT(scales); ++j) { |
115 canvas->save(); | 117 canvas->save(); |
116 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 118 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
117 SkPaint paint; | 119 SkPaint paint; |
118 paint.setColor(SK_ColorBLUE); | 120 paint.setColor(SK_ColorBLUE); |
119 paint.setImageFilter(filters[i]); | 121 paint.setImageFilter(filters[i]); |
120 paint.setAntiAlias(true); | 122 paint.setAntiAlias(true); |
121 canvas->save(); | 123 canvas->save(); |
122 canvas->scale(scales[j].fX, scales[j].fY); | 124 canvas->scale(scales[j].fX, scales[j].fY); |
123 canvas->clipRect(bounds); | 125 if (5 == i) { |
| 126 canvas->translate(SkIntToScalar(-32), 0); |
| 127 } |
124 canvas->drawCircle(r.centerX(), r.centerY(), | 128 canvas->drawCircle(r.centerX(), r.centerY(), |
125 SkScalarDiv(r.width()*2, SkIntToScalar(5)), p
aint); | 129 SkScalarDiv(r.width()*2, SkIntToScalar(5)), p
aint); |
126 canvas->restore(); | 130 canvas->restore(); |
127 canvas->translate(r.width() * scales[j].fX + margin, 0); | 131 canvas->translate(r.width() * scales[j].fX + margin, 0); |
128 } | 132 } |
129 canvas->restore(); | 133 canvas->restore(); |
130 canvas->translate(0, r.height() * scales[j].fY + margin); | 134 canvas->translate(0, r.height() * scales[j].fY + margin); |
131 } | 135 } |
132 | 136 |
133 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 137 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
134 filters[i]->unref(); | 138 filters[i]->unref(); |
135 } | 139 } |
136 } | 140 } |
137 | 141 |
138 private: | 142 private: |
139 bool fInitialized; | 143 bool fInitialized; |
140 SkBitmap fCheckerboard; | 144 SkBitmap fCheckerboard; |
141 SkBitmap fGradientCircle; | 145 SkBitmap fGradientCircle; |
142 typedef GM INHERITED; | 146 typedef GM INHERITED; |
143 }; | 147 }; |
144 | 148 |
145 ////////////////////////////////////////////////////////////////////////////// | 149 ////////////////////////////////////////////////////////////////////////////// |
146 | 150 |
147 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; } | 151 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; } |
148 static GMRegistry reg(MyFactory); | 152 static GMRegistry reg(MyFactory); |
149 | 153 |
150 } | 154 } |
OLD | NEW |