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

Side by Side Diff: gm/imagefiltersgraph.cpp

Issue 203273002: Put SimpleOffsetFilter on heap. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: interface 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 | « no previous file | 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 "SkOnce.h" 21 #include "SkOnce.h"
22 #include "SkTestImageFilters.h" 22 #include "SkTestImageFilters.h"
23 #include "SkXfermodeImageFilter.h" 23 #include "SkXfermodeImageFilter.h"
24 24
25 // More closely models how Blink's OffsetFilter works as of 10/23/13. SkOffsetIm ageFilter doesn't 25 // More closely models how Blink's OffsetFilter works as of 10/23/13. SkOffsetIm ageFilter doesn't
26 // perform a draw and this one does. 26 // perform a draw and this one does.
27 class SimpleOffsetFilter : public SkImageFilter { 27 class SimpleOffsetFilter : public SkImageFilter {
28 public: 28 public:
29 SimpleOffsetFilter(SkScalar dx, SkScalar dy, SkImageFilter* input) 29 static SkImageFilter* Create(SkScalar dx, SkScalar dy, SkImageFilter* input) {
30 : SkImageFilter(input), fDX(dx), fDY(dy) {} 30 return SkNEW_ARGS(SimpleOffsetFilter, (dx, dy, input));
31 }
31 32
32 virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const Context& ctx, 33 virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const Context& ctx,
33 SkBitmap* dst, SkIPoint* offset) const SK_OVERRID E { 34 SkBitmap* dst, SkIPoint* offset) const SK_OVERRID E {
34 SkBitmap source = src; 35 SkBitmap source = src;
35 SkImageFilter* input = getInput(0); 36 SkImageFilter* input = getInput(0);
36 SkIPoint srcOffset = SkIPoint::Make(0, 0); 37 SkIPoint srcOffset = SkIPoint::Make(0, 0);
37 if (NULL != input && !input->filterImage(proxy, src, ctx, &source, &srcO ffset)) { 38 if (NULL != input && !input->filterImage(proxy, src, ctx, &source, &srcO ffset)) {
38 return false; 39 return false;
39 } 40 }
40 41
(...skipping 22 matching lines...) Expand all
63 fDY = buffer.readScalar(); 64 fDY = buffer.readScalar();
64 } 65 }
65 66
66 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE { 67 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE {
67 this->SkImageFilter::flatten(buffer); 68 this->SkImageFilter::flatten(buffer);
68 buffer.writeScalar(fDX); 69 buffer.writeScalar(fDX);
69 buffer.writeScalar(fDY); 70 buffer.writeScalar(fDY);
70 } 71 }
71 72
72 private: 73 private:
74 SimpleOffsetFilter(SkScalar dx, SkScalar dy, SkImageFilter* input)
75 : SkImageFilter(input), fDX(dx), fDY(dy) {}
76
73 SkScalar fDX, fDY; 77 SkScalar fDX, fDY;
74 }; 78 };
75 79
76 static void init_flattenable(int*) { 80 static void init_flattenable(int*) {
77 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SimpleOffsetFilter) 81 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SimpleOffsetFilter)
78 } 82 }
79 83
80 class ImageFiltersGraphGM : public skiagm::GM { 84 class ImageFiltersGraphGM : public skiagm::GM {
81 public: 85 public:
82 ImageFiltersGraphGM() : fInitialized(false) { 86 ImageFiltersGraphGM() : fInitialized(false) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 drawClippedBitmap(canvas, fBitmap, paint); 154 drawClippedBitmap(canvas, fBitmap, paint);
151 canvas->translate(SkIntToScalar(100), 0); 155 canvas->translate(SkIntToScalar(100), 0);
152 } 156 }
153 { 157 {
154 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, 158 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
155 0, SK_Scalar1, 0, 0, 0, 159 0, SK_Scalar1, 0, 0, 0,
156 0, 0, SK_Scalar1, 0, 0, 160 0, 0, SK_Scalar1, 0, 0,
157 0, 0, 0, 0.5f, 0 }; 161 0, 0, 0, 0.5f, 0 };
158 SkAutoTUnref<SkColorMatrixFilter> matrixCF(SkColorMatrixFilter::Crea te(matrix)); 162 SkAutoTUnref<SkColorMatrixFilter> matrixCF(SkColorMatrixFilter::Crea te(matrix));
159 SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::C reate(matrixCF)); 163 SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::C reate(matrixCF));
160 SimpleOffsetFilter offsetFilter(SkIntToScalar(10), SkIntToScalar(10) , matrixFilter); 164 SkAutoTUnref<SkImageFilter> offsetFilter(
165 SimpleOffsetFilter::Create(10.0f, 10.f, matrixFilter));
161 166
162 SkAutoTUnref<SkXfermode> arith(SkArithmeticMode::Create(0, SK_Scalar 1, SK_Scalar1, 0)); 167 SkAutoTUnref<SkXfermode> arith(SkArithmeticMode::Create(0, SK_Scalar 1, SK_Scalar1, 0));
163 SkAutoTUnref<SkXfermodeImageFilter> arithFilter( 168 SkAutoTUnref<SkXfermodeImageFilter> arithFilter(
164 SkXfermodeImageFilter::Create(arith, matrixFilter, &offsetFilter )); 169 SkXfermodeImageFilter::Create(arith, matrixFilter, offsetFilter) );
165 170
166 SkPaint paint; 171 SkPaint paint;
167 paint.setImageFilter(arithFilter); 172 paint.setImageFilter(arithFilter);
168 drawClippedBitmap(canvas, fBitmap, paint); 173 drawClippedBitmap(canvas, fBitmap, paint);
169 canvas->translate(SkIntToScalar(100), 0); 174 canvas->translate(SkIntToScalar(100), 0);
170 } 175 }
171 { 176 {
172 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create( 177 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(
173 SkIntToScalar(10), SkIntToScalar(10))); 178 SkIntToScalar(10), SkIntToScalar(10)));
174 179
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 private: 211 private:
207 typedef GM INHERITED; 212 typedef GM INHERITED;
208 SkBitmap fBitmap; 213 SkBitmap fBitmap;
209 bool fInitialized; 214 bool fInitialized;
210 }; 215 };
211 216
212 /////////////////////////////////////////////////////////////////////////////// 217 ///////////////////////////////////////////////////////////////////////////////
213 218
214 static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; } 219 static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; }
215 static skiagm::GMRegistry reg(MyFactory); 220 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698