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 12 matching lines...) Expand all Loading... |
23 Registrar() { | 23 Registrar() { |
24 SkFlattenable::Register("FailImageFilter", | 24 SkFlattenable::Register("FailImageFilter", |
25 FailImageFilter::CreateProc, | 25 FailImageFilter::CreateProc, |
26 FailImageFilter::GetFlattenableType()); | 26 FailImageFilter::GetFlattenableType()); |
27 } | 27 } |
28 }; | 28 }; |
29 static FailImageFilter* Create() { | 29 static FailImageFilter* Create() { |
30 return SkNEW(FailImageFilter); | 30 return SkNEW(FailImageFilter); |
31 } | 31 } |
32 | 32 |
| 33 SK_TO_STRING_OVERRIDE() |
33 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter) | 34 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter) |
34 | 35 |
35 protected: | 36 protected: |
36 FailImageFilter() : INHERITED(0, NULL) {} | 37 FailImageFilter() : INHERITED(0, NULL) {} |
37 | 38 |
38 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 39 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
39 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE { | 40 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE { |
40 return false; | 41 return false; |
41 } | 42 } |
42 | 43 |
43 private: | 44 private: |
44 typedef SkImageFilter INHERITED; | 45 typedef SkImageFilter INHERITED; |
45 }; | 46 }; |
46 | 47 |
47 static FailImageFilter::Registrar gReg0; | 48 static FailImageFilter::Registrar gReg0; |
48 | 49 |
49 SkFlattenable* FailImageFilter::CreateProc(SkReadBuffer& buffer) { | 50 SkFlattenable* FailImageFilter::CreateProc(SkReadBuffer& buffer) { |
50 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0); | 51 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0); |
51 return FailImageFilter::Create(); | 52 return FailImageFilter::Create(); |
52 } | 53 } |
53 | 54 |
| 55 #ifndef SK_IGNORE_TO_STRING |
| 56 void FailImageFilter::toString(SkString* str) const { |
| 57 str->appendf("FailImageFilter: ("); |
| 58 str->append(")"); |
| 59 } |
| 60 #endif |
| 61 |
54 class IdentityImageFilter : public SkImageFilter { | 62 class IdentityImageFilter : public SkImageFilter { |
55 public: | 63 public: |
56 class Registrar { | 64 class Registrar { |
57 public: | 65 public: |
58 Registrar() { | 66 Registrar() { |
59 SkFlattenable::Register("IdentityImageFilter", | 67 SkFlattenable::Register("IdentityImageFilter", |
60 IdentityImageFilter::CreateProc, | 68 IdentityImageFilter::CreateProc, |
61 IdentityImageFilter::GetFlattenableType()); | 69 IdentityImageFilter::GetFlattenableType()); |
62 } | 70 } |
63 }; | 71 }; |
64 static IdentityImageFilter* Create(SkImageFilter* input = NULL) { | 72 static IdentityImageFilter* Create(SkImageFilter* input = NULL) { |
65 return SkNEW_ARGS(IdentityImageFilter, (input)); | 73 return SkNEW_ARGS(IdentityImageFilter, (input)); |
66 } | 74 } |
67 | 75 |
| 76 SK_TO_STRING_OVERRIDE() |
68 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter) | 77 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter) |
69 protected: | 78 protected: |
70 IdentityImageFilter(SkImageFilter* input) : INHERITED(1, &input) {} | 79 IdentityImageFilter(SkImageFilter* input) : INHERITED(1, &input) {} |
71 | 80 |
72 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 81 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
73 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE { | 82 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE { |
74 *result = src; | 83 *result = src; |
75 offset->set(0, 0); | 84 offset->set(0, 0); |
76 return true; | 85 return true; |
77 } | 86 } |
78 | 87 |
79 private: | 88 private: |
80 typedef SkImageFilter INHERITED; | 89 typedef SkImageFilter INHERITED; |
81 }; | 90 }; |
82 | 91 |
83 static IdentityImageFilter::Registrar gReg1; | 92 static IdentityImageFilter::Registrar gReg1; |
84 | 93 |
85 SkFlattenable* IdentityImageFilter::CreateProc(SkReadBuffer& buffer) { | 94 SkFlattenable* IdentityImageFilter::CreateProc(SkReadBuffer& buffer) { |
86 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 95 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
87 return IdentityImageFilter::Create(common.getInput(0)); | 96 return IdentityImageFilter::Create(common.getInput(0)); |
88 } | 97 } |
89 | 98 |
| 99 #ifndef SK_IGNORE_TO_STRING |
| 100 void IdentityImageFilter::toString(SkString* str) const { |
| 101 str->appendf("IdentityImageFilter: ("); |
| 102 str->append(")"); |
| 103 } |
| 104 #endif |
| 105 |
90 /////////////////////////////////////////////////////////////////////////////// | 106 /////////////////////////////////////////////////////////////////////////////// |
91 | 107 |
92 static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 108 static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
93 SkPaint paint; | 109 SkPaint paint; |
94 paint.setImageFilter(imf); | 110 paint.setImageFilter(imf); |
95 paint.setColor(SK_ColorGREEN); | 111 paint.setColor(SK_ColorGREEN); |
96 canvas->save(); | 112 canvas->save(); |
97 canvas->clipRect(r); | 113 canvas->clipRect(r); |
98 canvas->drawPaint(paint); | 114 canvas->drawPaint(paint); |
99 canvas->restore(); | 115 canvas->restore(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 } | 260 } |
245 | 261 |
246 private: | 262 private: |
247 typedef GM INHERITED; | 263 typedef GM INHERITED; |
248 }; | 264 }; |
249 | 265 |
250 /////////////////////////////////////////////////////////////////////////////// | 266 /////////////////////////////////////////////////////////////////////////////// |
251 | 267 |
252 static skiagm::GM* MyFactory(void*) { return new ImageFiltersBaseGM; } | 268 static skiagm::GM* MyFactory(void*) { return new ImageFiltersBaseGM; } |
253 static skiagm::GMRegistry reg(MyFactory); | 269 static skiagm::GMRegistry reg(MyFactory); |
OLD | NEW |