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

Side by Side Diff: gm/imagefiltersbase.cpp

Issue 182983003: Factory methods for heap-allocated SkImageFilter objects. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 6 years, 9 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/imageblurtiled.cpp ('k') | gm/imagefiltersclipped.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 FailImageFilter() : INHERITED(0) {} 21 static FailImageFilter* Create() {
22 return SkNEW(FailImageFilter);
23 }
22 24
23 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter) 25 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter)
24 protected: 26 protected:
27 FailImageFilter() : INHERITED(0) {}
25 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, 28 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
26 SkBitmap* result, SkIPoint* offset) const { 29 SkBitmap* result, SkIPoint* offset) const {
27 return false; 30 return false;
28 } 31 }
29 32
30 FailImageFilter(SkReadBuffer& buffer) 33 FailImageFilter(SkReadBuffer& buffer)
31 : INHERITED(1, buffer) {} 34 : INHERITED(1, buffer) {}
32 35
33 private: 36 private:
34 typedef SkImageFilter INHERITED; 37 typedef SkImageFilter INHERITED;
35 }; 38 };
36 39
37 // register the filter with the flattenable registry 40 // register the filter with the flattenable registry
38 static SkFlattenable::Registrar gFailImageFilterReg("FailImageFilter", 41 static SkFlattenable::Registrar gFailImageFilterReg("FailImageFilter",
39 FailImageFilter::CreateProc, 42 FailImageFilter::CreateProc,
40 FailImageFilter::GetFlattena bleType()); 43 FailImageFilter::GetFlattena bleType());
41 44
42 class IdentityImageFilter : public SkImageFilter { 45 class IdentityImageFilter : public SkImageFilter {
43 public: 46 public:
44 IdentityImageFilter() : INHERITED(0) {} 47 static IdentityImageFilter* Create() {
48 return SkNEW(IdentityImageFilter);
49 }
45 50
46 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter) 51 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter)
47 protected: 52 protected:
53 IdentityImageFilter() : INHERITED(0) {}
48 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, 54 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
49 SkBitmap* result, SkIPoint* offset) const { 55 SkBitmap* result, SkIPoint* offset) const {
50 *result = src; 56 *result = src;
51 return true; 57 return true;
52 } 58 }
53 59
54 IdentityImageFilter(SkReadBuffer& buffer) 60 IdentityImageFilter(SkReadBuffer& buffer)
55 : INHERITED(1, buffer) {} 61 : INHERITED(1, buffer) {}
56 62
57 private: 63 private:
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 draw_paint, 187 draw_paint,
182 draw_line, draw_rect, draw_path, draw_text, 188 draw_line, draw_rect, draw_path, draw_text,
183 draw_bitmap, 189 draw_bitmap,
184 draw_sprite 190 draw_sprite
185 }; 191 };
186 192
187 SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED, 193 SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED,
188 SkXfermode::kSrcIn_Mode); 194 SkXfermode::kSrcIn_Mode);
189 SkImageFilter* filters[] = { 195 SkImageFilter* filters[] = {
190 NULL, 196 NULL,
191 new IdentityImageFilter, 197 IdentityImageFilter::Create(),
192 new FailImageFilter, 198 FailImageFilter::Create(),
193 SkColorFilterImageFilter::Create(cf), 199 SkColorFilterImageFilter::Create(cf),
194 new SkBlurImageFilter(12.0f, 0.0f), 200 SkBlurImageFilter::Create(12.0f, 0.0f),
195 new SkDropShadowImageFilter(10.0f, 5.0f, 3.0f, SK_ColorBLUE), 201 SkDropShadowImageFilter::Create(10.0f, 5.0f, 3.0f, SK_ColorBLUE),
196 }; 202 };
197 cf->unref(); 203 cf->unref();
198 204
199 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); 205 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
200 SkScalar MARGIN = SkIntToScalar(16); 206 SkScalar MARGIN = SkIntToScalar(16);
201 SkScalar DX = r.width() + MARGIN; 207 SkScalar DX = r.width() + MARGIN;
202 SkScalar DY = r.height() + MARGIN; 208 SkScalar DY = r.height() + MARGIN;
203 209
204 canvas->translate(MARGIN, MARGIN); 210 canvas->translate(MARGIN, MARGIN);
205 for (size_t i = 0; i < SK_ARRAY_COUNT(drawProc); ++i) { 211 for (size_t i = 0; i < SK_ARRAY_COUNT(drawProc); ++i) {
(...skipping 14 matching lines...) Expand all
220 } 226 }
221 227
222 private: 228 private:
223 typedef GM INHERITED; 229 typedef GM INHERITED;
224 }; 230 };
225 231
226 /////////////////////////////////////////////////////////////////////////////// 232 ///////////////////////////////////////////////////////////////////////////////
227 233
228 static skiagm::GM* MyFactory(void*) { return new ImageFiltersBaseGM; } 234 static skiagm::GM* MyFactory(void*) { return new ImageFiltersBaseGM; }
229 static skiagm::GMRegistry reg(MyFactory); 235 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « gm/imageblurtiled.cpp ('k') | gm/imagefiltersclipped.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698