Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(727)

Side by Side Diff: gm/imagefiltersbase.cpp

Issue 498453003: use globals to register custom effects (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gm/imagefiltersgraph.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 class Registrar {
22 public:
23 Registrar() {
24 SkFlattenable::Register("FailImageFilter",
25 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
26 FailImageFilter::DeepCreateProc,
27 #else
28 FailImageFilter::CreateProc,
29 #endif
30 FailImageFilter::GetFlattenableType());
31 }
32 };
21 static FailImageFilter* Create() { 33 static FailImageFilter* Create() {
22 return SkNEW(FailImageFilter); 34 return SkNEW(FailImageFilter);
23 } 35 }
24 36
25 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter) 37 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter)
26 38
27 protected: 39 protected:
28 FailImageFilter() : INHERITED(0, NULL) { 40 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 41
37 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 42 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
38 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE { 43 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE {
39 return false; 44 return false;
40 } 45 }
41 46
42 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING 47 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
43 FailImageFilter(SkReadBuffer& buffer) : INHERITED(0, buffer) {} 48 FailImageFilter(SkReadBuffer& buffer) : INHERITED(0, buffer) {}
44 #endif 49 #endif
45 50
46 private: 51 private:
47 typedef SkImageFilter INHERITED; 52 typedef SkImageFilter INHERITED;
48 }; 53 };
49 54
55 static FailImageFilter::Registrar gReg0;
56
50 SkFlattenable* FailImageFilter::CreateProc(SkReadBuffer& buffer) { 57 SkFlattenable* FailImageFilter::CreateProc(SkReadBuffer& buffer) {
51 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0); 58 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0);
52 return FailImageFilter::Create(); 59 return FailImageFilter::Create();
53 } 60 }
54 61
55 class IdentityImageFilter : public SkImageFilter { 62 class IdentityImageFilter : public SkImageFilter {
56 public: 63 public:
64 class Registrar {
65 public:
66 Registrar() {
67 SkFlattenable::Register("IdentityImageFilter",
68 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
69 IdentityImageFilter::DeepCreateProc,
70 #else
71 IdentityImageFilter::CreateProc,
72 #endif
73 IdentityImageFilter::GetFlattenableType());
74 }
75 };
57 static IdentityImageFilter* Create(SkImageFilter* input = NULL) { 76 static IdentityImageFilter* Create(SkImageFilter* input = NULL) {
58 return SkNEW_ARGS(IdentityImageFilter, (input)); 77 return SkNEW_ARGS(IdentityImageFilter, (input));
59 } 78 }
60 79
61 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter) 80 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter)
62 protected: 81 protected:
63 IdentityImageFilter(SkImageFilter* input) : INHERITED(1, &input) { 82 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 83
72 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 84 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
73 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE { 85 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE {
74 *result = src; 86 *result = src;
75 offset->set(0, 0); 87 offset->set(0, 0);
76 return true; 88 return true;
77 } 89 }
78 90
79 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING 91 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
80 IdentityImageFilter(SkReadBuffer& buffer) : INHERITED(1, buffer) {} 92 IdentityImageFilter(SkReadBuffer& buffer) : INHERITED(1, buffer) {}
81 #endif 93 #endif
82 94
83 private: 95 private:
84 typedef SkImageFilter INHERITED; 96 typedef SkImageFilter INHERITED;
85 }; 97 };
86 98
99 static IdentityImageFilter::Registrar gReg1;
100
87 SkFlattenable* IdentityImageFilter::CreateProc(SkReadBuffer& buffer) { 101 SkFlattenable* IdentityImageFilter::CreateProc(SkReadBuffer& buffer) {
88 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); 102 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
89 return IdentityImageFilter::Create(common.getInput(0)); 103 return IdentityImageFilter::Create(common.getInput(0));
90 } 104 }
91 105
92 /////////////////////////////////////////////////////////////////////////////// 106 ///////////////////////////////////////////////////////////////////////////////
93 107
94 static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { 108 static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
95 SkPaint paint; 109 SkPaint paint;
96 paint.setImageFilter(imf); 110 paint.setImageFilter(imf);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 259 }
246 260
247 private: 261 private:
248 typedef GM INHERITED; 262 typedef GM INHERITED;
249 }; 263 };
250 264
251 /////////////////////////////////////////////////////////////////////////////// 265 ///////////////////////////////////////////////////////////////////////////////
252 266
253 static skiagm::GM* MyFactory(void*) { return new ImageFiltersBaseGM; } 267 static skiagm::GM* MyFactory(void*) { return new ImageFiltersBaseGM; }
254 static skiagm::GMRegistry reg(MyFactory); 268 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | gm/imagefiltersgraph.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698