| 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" |
| 11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
| 12 #include "SkShader.h" | 12 #include "SkShader.h" |
| 13 | 13 |
| 14 #include "SkBlurImageFilter.h" | 14 #include "SkBlurImageFilter.h" |
| 15 #include "SkColorFilterImageFilter.h" | 15 #include "SkColorFilterImageFilter.h" |
| 16 #include "SkDropShadowImageFilter.h" | 16 #include "SkDropShadowImageFilter.h" |
| 17 #include "SkTestImageFilters.h" | 17 #include "SkTestImageFilters.h" |
| 18 | 18 |
| 19 class FailImageFilter : public SkImageFilter { | 19 class FailImageFilter : public SkImageFilter { |
| 20 public: | 20 public: |
| 21 static FailImageFilter* Create() { | 21 static FailImageFilter* Create() { |
| 22 return SkNEW(FailImageFilter); | 22 return SkNEW(FailImageFilter); |
| 23 } | 23 } |
| 24 | 24 |
| 25 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter) | 25 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter) |
| 26 |
| 26 protected: | 27 protected: |
| 27 FailImageFilter() : INHERITED(0, NULL) {} | 28 FailImageFilter() : INHERITED(0, NULL) { |
| 29 static bool gOnce; |
| 30 if (!gOnce) { |
| 31 gOnce = true; |
| 32 SkFlattenable::Register("FailImageFilter", this->getFactory(), |
| 33 this->GetFlattenableType()); |
| 34 } |
| 35 } |
| 36 |
| 28 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 37 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
| 29 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE { | 38 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE { |
| 30 return false; | 39 return false; |
| 31 } | 40 } |
| 32 | 41 |
| 33 FailImageFilter(SkReadBuffer& buffer) | 42 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
| 34 : INHERITED(0, buffer) {} | 43 FailImageFilter(SkReadBuffer& buffer) : INHERITED(0, buffer) {} |
| 44 #endif |
| 35 | 45 |
| 36 private: | 46 private: |
| 37 typedef SkImageFilter INHERITED; | 47 typedef SkImageFilter INHERITED; |
| 38 }; | 48 }; |
| 39 | 49 |
| 40 // register the filter with the flattenable registry | 50 SkFlattenable* FailImageFilter::CreateProc(SkReadBuffer& buffer) { |
| 41 static SkFlattenable::Registrar gFailImageFilterReg("FailImageFilter", | 51 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0); |
| 42 FailImageFilter::CreateProc, | 52 return FailImageFilter::Create(); |
| 43 FailImageFilter::GetFlattena
bleType()); | 53 } |
| 44 | 54 |
| 45 class IdentityImageFilter : public SkImageFilter { | 55 class IdentityImageFilter : public SkImageFilter { |
| 46 public: | 56 public: |
| 47 static IdentityImageFilter* Create(SkImageFilter* input = NULL) { | 57 static IdentityImageFilter* Create(SkImageFilter* input = NULL) { |
| 48 return SkNEW_ARGS(IdentityImageFilter, (input)); | 58 return SkNEW_ARGS(IdentityImageFilter, (input)); |
| 49 } | 59 } |
| 50 | 60 |
| 51 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter) | 61 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter) |
| 52 protected: | 62 protected: |
| 53 IdentityImageFilter(SkImageFilter* input) : INHERITED(1, &input) {} | 63 IdentityImageFilter(SkImageFilter* input) : INHERITED(1, &input) { |
| 64 static bool gOnce; |
| 65 if (!gOnce) { |
| 66 gOnce = true; |
| 67 SkFlattenable::Register("IdentityImageFilter", this->getFactory(), |
| 68 this->GetFlattenableType()); |
| 69 } |
| 70 } |
| 71 |
| 54 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 72 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
| 55 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE { | 73 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE { |
| 56 *result = src; | 74 *result = src; |
| 57 offset->set(0, 0); | 75 offset->set(0, 0); |
| 58 return true; | 76 return true; |
| 59 } | 77 } |
| 60 | 78 |
| 61 IdentityImageFilter(SkReadBuffer& buffer) | 79 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
| 62 : INHERITED(1, buffer) {} | 80 IdentityImageFilter(SkReadBuffer& buffer) : INHERITED(1, buffer) {} |
| 81 #endif |
| 63 | 82 |
| 64 private: | 83 private: |
| 65 typedef SkImageFilter INHERITED; | 84 typedef SkImageFilter INHERITED; |
| 66 }; | 85 }; |
| 67 | 86 |
| 68 // register the filter with the flattenable registry | 87 SkFlattenable* IdentityImageFilter::CreateProc(SkReadBuffer& buffer) { |
| 69 static SkFlattenable::Registrar gIdentityImageFilterReg("IdentityImageFilter", | 88 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
| 70 IdentityImageFilter::Cre
ateProc, | 89 return IdentityImageFilter::Create(common.inputAt(0)); |
| 71 IdentityImageFilter::Get
FlattenableType()); | 90 } |
| 72 | |
| 73 | 91 |
| 74 /////////////////////////////////////////////////////////////////////////////// | 92 /////////////////////////////////////////////////////////////////////////////// |
| 75 | 93 |
| 76 static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 94 static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
| 77 SkPaint paint; | 95 SkPaint paint; |
| 78 paint.setImageFilter(imf); | 96 paint.setImageFilter(imf); |
| 79 paint.setColor(SK_ColorGREEN); | 97 paint.setColor(SK_ColorGREEN); |
| 80 canvas->save(); | 98 canvas->save(); |
| 81 canvas->clipRect(r); | 99 canvas->clipRect(r); |
| 82 canvas->drawPaint(paint); | 100 canvas->drawPaint(paint); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 245 } |
| 228 | 246 |
| 229 private: | 247 private: |
| 230 typedef GM INHERITED; | 248 typedef GM INHERITED; |
| 231 }; | 249 }; |
| 232 | 250 |
| 233 /////////////////////////////////////////////////////////////////////////////// | 251 /////////////////////////////////////////////////////////////////////////////// |
| 234 | 252 |
| 235 static skiagm::GM* MyFactory(void*) { return new ImageFiltersBaseGM; } | 253 static skiagm::GM* MyFactory(void*) { return new ImageFiltersBaseGM; } |
| 236 static skiagm::GMRegistry reg(MyFactory); | 254 static skiagm::GMRegistry reg(MyFactory); |
| OLD | NEW |