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

Side by Side Diff: gm/imagefiltersgraph.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 | « gm/imagefiltersbase.cpp ('k') | no next file » | 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 2012 Google Inc. 2 * Copyright 2012 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 9
10 #include "SkArithmeticMode.h" 10 #include "SkArithmeticMode.h"
11 #include "SkDevice.h" 11 #include "SkDevice.h"
12 #include "SkBitmapSource.h" 12 #include "SkBitmapSource.h"
13 #include "SkBlurImageFilter.h" 13 #include "SkBlurImageFilter.h"
14 #include "SkColorFilter.h" 14 #include "SkColorFilter.h"
15 #include "SkColorFilterImageFilter.h" 15 #include "SkColorFilterImageFilter.h"
16 #include "SkColorMatrixFilter.h" 16 #include "SkColorMatrixFilter.h"
17 #include "SkReadBuffer.h" 17 #include "SkReadBuffer.h"
18 #include "SkWriteBuffer.h" 18 #include "SkWriteBuffer.h"
19 #include "SkMergeImageFilter.h" 19 #include "SkMergeImageFilter.h"
20 #include "SkMorphologyImageFilter.h" 20 #include "SkMorphologyImageFilter.h"
21 #include "SkTestImageFilters.h" 21 #include "SkTestImageFilters.h"
22 #include "SkXfermodeImageFilter.h" 22 #include "SkXfermodeImageFilter.h"
23 23
24 // More closely models how Blink's OffsetFilter works as of 10/23/13. SkOffsetIm ageFilter doesn't 24 // More closely models how Blink's OffsetFilter works as of 10/23/13. SkOffsetIm ageFilter doesn't
25 // perform a draw and this one does. 25 // perform a draw and this one does.
26 class SimpleOffsetFilter : public SkImageFilter { 26 class SimpleOffsetFilter : public SkImageFilter {
27 public: 27 public:
28 class Registrar {
29 public:
30 Registrar() {
31 SkFlattenable::Register("SimpleOffsetFilter",
32 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
33 SimpleOffsetFilter::DeepCreateProc,
34 #else
35 SimpleOffsetFilter::CreateProc,
36 #endif
37 SimpleOffsetFilter::GetFlattenableType());
38 }
39 };
28 static SkImageFilter* Create(SkScalar dx, SkScalar dy, SkImageFilter* input) { 40 static SkImageFilter* Create(SkScalar dx, SkScalar dy, SkImageFilter* input) {
29 return SkNEW_ARGS(SimpleOffsetFilter, (dx, dy, input)); 41 return SkNEW_ARGS(SimpleOffsetFilter, (dx, dy, input));
30 } 42 }
31 43
32 virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const Context& ctx, 44 virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const Context& ctx,
33 SkBitmap* dst, SkIPoint* offset) const SK_OVERRID E { 45 SkBitmap* dst, SkIPoint* offset) const SK_OVERRID E {
34 SkBitmap source = src; 46 SkBitmap source = src;
35 SkImageFilter* input = getInput(0); 47 SkImageFilter* input = getInput(0);
36 SkIPoint srcOffset = SkIPoint::Make(0, 0); 48 SkIPoint srcOffset = SkIPoint::Make(0, 0);
37 if (NULL != input && !input->filterImage(proxy, src, ctx, &source, &srcO ffset)) { 49 if (NULL != input && !input->filterImage(proxy, src, ctx, &source, &srcO ffset)) {
(...skipping 28 matching lines...) Expand all
66 #endif 78 #endif
67 79
68 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE { 80 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE {
69 this->INHERITED::flatten(buffer); 81 this->INHERITED::flatten(buffer);
70 buffer.writeScalar(fDX); 82 buffer.writeScalar(fDX);
71 buffer.writeScalar(fDY); 83 buffer.writeScalar(fDY);
72 } 84 }
73 85
74 private: 86 private:
75 SimpleOffsetFilter(SkScalar dx, SkScalar dy, SkImageFilter* input) 87 SimpleOffsetFilter(SkScalar dx, SkScalar dy, SkImageFilter* input)
76 : SkImageFilter(1, &input), fDX(dx), fDY(dy) { 88 : SkImageFilter(1, &input), fDX(dx), fDY(dy) {}
77 static bool gOnce;
78 if (!gOnce) {
79 gOnce = true;
80 SkFlattenable::Register("SimpleOffsetFilter", this->getFactory(),
81 this->GetFlattenableType());
82 }
83 }
84 89
85 SkScalar fDX, fDY; 90 SkScalar fDX, fDY;
86 91
87 typedef SkImageFilter INHERITED; 92 typedef SkImageFilter INHERITED;
88 }; 93 };
89 94
95 static SimpleOffsetFilter::Registrar gReg;
96
90 SkFlattenable* SimpleOffsetFilter::CreateProc(SkReadBuffer& buffer) { 97 SkFlattenable* SimpleOffsetFilter::CreateProc(SkReadBuffer& buffer) {
91 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); 98 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
92 SkScalar dx = buffer.readScalar(); 99 SkScalar dx = buffer.readScalar();
93 SkScalar dy = buffer.readScalar(); 100 SkScalar dy = buffer.readScalar();
94 return Create(dx, dy, common.getInput(0)); 101 return Create(dx, dy, common.getInput(0));
95 } 102 }
96 103
97 class ImageFiltersGraphGM : public skiagm::GM { 104 class ImageFiltersGraphGM : public skiagm::GM {
98 public: 105 public:
99 ImageFiltersGraphGM() {} 106 ImageFiltersGraphGM() {}
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 231
225 private: 232 private:
226 typedef GM INHERITED; 233 typedef GM INHERITED;
227 SkBitmap fBitmap; 234 SkBitmap fBitmap;
228 }; 235 };
229 236
230 /////////////////////////////////////////////////////////////////////////////// 237 ///////////////////////////////////////////////////////////////////////////////
231 238
232 static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; } 239 static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; }
233 static skiagm::GMRegistry reg(MyFactory); 240 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « gm/imagefiltersbase.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698