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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColorFilter.h" | 10 #include "SkColorFilter.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 FailImageFilter::CreateProc, | 25 FailImageFilter::CreateProc, |
26 FailImageFilter::GetFlattenableType()); | 26 FailImageFilter::GetFlattenableType()); |
27 } | 27 } |
28 }; | 28 }; |
29 static FailImageFilter* Create() { return new FailImageFilter; } | 29 static FailImageFilter* Create() { return new FailImageFilter; } |
30 | 30 |
31 SK_TO_STRING_OVERRIDE() | 31 SK_TO_STRING_OVERRIDE() |
32 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter) | 32 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter) |
33 | 33 |
34 protected: | 34 protected: |
35 FailImageFilter() : INHERITED(0, NULL) {} | 35 FailImageFilter() : INHERITED(0, nullptr) {} |
36 | 36 |
37 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 37 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
38 SkBitmap* result, SkIPoint* offset) const override { | 38 SkBitmap* result, SkIPoint* offset) const override { |
39 return false; | 39 return false; |
40 } | 40 } |
41 | 41 |
42 private: | 42 private: |
43 typedef SkImageFilter INHERITED; | 43 typedef SkImageFilter INHERITED; |
44 }; | 44 }; |
45 | 45 |
(...skipping 14 matching lines...) Expand all Loading... |
60 class IdentityImageFilter : public SkImageFilter { | 60 class IdentityImageFilter : public SkImageFilter { |
61 public: | 61 public: |
62 class Registrar { | 62 class Registrar { |
63 public: | 63 public: |
64 Registrar() { | 64 Registrar() { |
65 SkFlattenable::Register("IdentityImageFilter", | 65 SkFlattenable::Register("IdentityImageFilter", |
66 IdentityImageFilter::CreateProc, | 66 IdentityImageFilter::CreateProc, |
67 IdentityImageFilter::GetFlattenableType()); | 67 IdentityImageFilter::GetFlattenableType()); |
68 } | 68 } |
69 }; | 69 }; |
70 static IdentityImageFilter* Create(SkImageFilter* input = NULL) { | 70 static IdentityImageFilter* Create(SkImageFilter* input = nullptr) { |
71 return new IdentityImageFilter(input); | 71 return new IdentityImageFilter(input); |
72 } | 72 } |
73 | 73 |
74 SK_TO_STRING_OVERRIDE() | 74 SK_TO_STRING_OVERRIDE() |
75 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter) | 75 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter) |
76 protected: | 76 protected: |
77 IdentityImageFilter(SkImageFilter* input) : INHERITED(1, &input) {} | 77 IdentityImageFilter(SkImageFilter* input) : INHERITED(1, &input) {} |
78 | 78 |
79 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 79 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
80 SkBitmap* result, SkIPoint* offset) const override { | 80 SkBitmap* result, SkIPoint* offset) const override { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 SkPaint paint; | 153 SkPaint paint; |
154 paint.setImageFilter(imf); | 154 paint.setImageFilter(imf); |
155 | 155 |
156 SkIRect bounds; | 156 SkIRect bounds; |
157 r.roundOut(&bounds); | 157 r.roundOut(&bounds); |
158 | 158 |
159 SkBitmap bm; | 159 SkBitmap bm; |
160 bm.allocN32Pixels(bounds.width(), bounds.height()); | 160 bm.allocN32Pixels(bounds.width(), bounds.height()); |
161 bm.eraseColor(SK_ColorTRANSPARENT); | 161 bm.eraseColor(SK_ColorTRANSPARENT); |
162 SkCanvas c(bm); | 162 SkCanvas c(bm); |
163 draw_path(&c, r, NULL); | 163 draw_path(&c, r, nullptr); |
164 | 164 |
165 canvas->drawBitmap(bm, 0, 0, &paint); | 165 canvas->drawBitmap(bm, 0, 0, &paint); |
166 } | 166 } |
167 | 167 |
168 static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 168 static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
169 SkPaint paint; | 169 SkPaint paint; |
170 paint.setImageFilter(imf); | 170 paint.setImageFilter(imf); |
171 | 171 |
172 SkIRect bounds; | 172 SkIRect bounds; |
173 r.roundOut(&bounds); | 173 r.roundOut(&bounds); |
174 | 174 |
175 SkBitmap bm; | 175 SkBitmap bm; |
176 bm.allocN32Pixels(bounds.width(), bounds.height()); | 176 bm.allocN32Pixels(bounds.width(), bounds.height()); |
177 bm.eraseColor(SK_ColorTRANSPARENT); | 177 bm.eraseColor(SK_ColorTRANSPARENT); |
178 SkCanvas c(bm); | 178 SkCanvas c(bm); |
179 draw_path(&c, r, NULL); | 179 draw_path(&c, r, nullptr); |
180 | 180 |
181 SkPoint loc = { r.fLeft, r.fTop }; | 181 SkPoint loc = { r.fLeft, r.fTop }; |
182 canvas->getTotalMatrix().mapPoints(&loc, 1); | 182 canvas->getTotalMatrix().mapPoints(&loc, 1); |
183 canvas->drawSprite(bm, | 183 canvas->drawSprite(bm, |
184 SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY), | 184 SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY), |
185 &paint); | 185 &paint); |
186 } | 186 } |
187 | 187 |
188 /////////////////////////////////////////////////////////////////////////////// | 188 /////////////////////////////////////////////////////////////////////////////// |
189 | 189 |
(...skipping 19 matching lines...) Expand all Loading... |
209 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { | 209 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { |
210 draw_paint, | 210 draw_paint, |
211 draw_line, draw_rect, draw_path, draw_text, | 211 draw_line, draw_rect, draw_path, draw_text, |
212 draw_bitmap, | 212 draw_bitmap, |
213 draw_sprite | 213 draw_sprite |
214 }; | 214 }; |
215 | 215 |
216 SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED, | 216 SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED, |
217 SkXfermode::kSrcIn_Mode); | 217 SkXfermode::kSrcIn_Mode); |
218 SkImageFilter* filters[] = { | 218 SkImageFilter* filters[] = { |
219 NULL, | 219 nullptr, |
220 IdentityImageFilter::Create(), | 220 IdentityImageFilter::Create(), |
221 FailImageFilter::Create(), | 221 FailImageFilter::Create(), |
222 SkColorFilterImageFilter::Create(cf), | 222 SkColorFilterImageFilter::Create(cf), |
223 SkBlurImageFilter::Create(12.0f, 0.0f), | 223 SkBlurImageFilter::Create(12.0f, 0.0f), |
224 SkDropShadowImageFilter::Create(10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLU
E, | 224 SkDropShadowImageFilter::Create(10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLU
E, |
225 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode), | 225 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode), |
226 }; | 226 }; |
227 cf->unref(); | 227 cf->unref(); |
228 | 228 |
229 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); | 229 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 for (int doSaveLayer = 0; doSaveLayer <= 1; ++doSaveLayer) { | 302 for (int doSaveLayer = 0; doSaveLayer <= 1; ++doSaveLayer) { |
303 SkAutoCanvasRestore acr(canvas, true); | 303 SkAutoCanvasRestore acr(canvas, true); |
304 for (int useFilter = 0; useFilter <= 1; ++useFilter) { | 304 for (int useFilter = 0; useFilter <= 1; ++useFilter) { |
305 SkAutoCanvasRestore acr2(canvas, true); | 305 SkAutoCanvasRestore acr2(canvas, true); |
306 | 306 |
307 SkPaint paint; | 307 SkPaint paint; |
308 if (useFilter) { | 308 if (useFilter) { |
309 this->installFilter(&paint); | 309 this->installFilter(&paint); |
310 } | 310 } |
311 if (doSaveLayer) { | 311 if (doSaveLayer) { |
312 canvas->saveLayer(NULL, &paint); | 312 canvas->saveLayer(nullptr, &paint); |
313 paint.setImageFilter(NULL); | 313 paint.setImageFilter(nullptr); |
314 } | 314 } |
315 this->drawWaterfall(canvas, paint); | 315 this->drawWaterfall(canvas, paint); |
316 | 316 |
317 acr2.restore(); | 317 acr2.restore(); |
318 canvas->translate(250, 0); | 318 canvas->translate(250, 0); |
319 } | 319 } |
320 acr.restore(); | 320 acr.restore(); |
321 canvas->translate(0, 200); | 321 canvas->translate(0, 200); |
322 } | 322 } |
323 } | 323 } |
(...skipping 15 matching lines...) Expand all Loading... |
339 class ImageFiltersText_CF : public ImageFiltersTextBaseGM { | 339 class ImageFiltersText_CF : public ImageFiltersTextBaseGM { |
340 public: | 340 public: |
341 ImageFiltersText_CF() : ImageFiltersTextBaseGM("color") {} | 341 ImageFiltersText_CF() : ImageFiltersTextBaseGM("color") {} |
342 | 342 |
343 void installFilter(SkPaint* paint) override { | 343 void installFilter(SkPaint* paint) override { |
344 paint->setColorFilter(SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXf
ermode::kSrcIn_Mode))->unref(); | 344 paint->setColorFilter(SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXf
ermode::kSrcIn_Mode))->unref(); |
345 } | 345 } |
346 }; | 346 }; |
347 DEF_GM( return new ImageFiltersText_CF; ) | 347 DEF_GM( return new ImageFiltersText_CF; ) |
348 | 348 |
OLD | NEW |