OLD | NEW |
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" |
(...skipping 20 matching lines...) Expand all Loading... |
31 SkFlattenable::Register("SimpleOffsetFilter", | 31 SkFlattenable::Register("SimpleOffsetFilter", |
32 SimpleOffsetFilter::CreateProc, | 32 SimpleOffsetFilter::CreateProc, |
33 SimpleOffsetFilter::GetFlattenableType()); | 33 SimpleOffsetFilter::GetFlattenableType()); |
34 } | 34 } |
35 }; | 35 }; |
36 static SkImageFilter* Create(SkScalar dx, SkScalar dy, SkImageFilter* input)
{ | 36 static SkImageFilter* Create(SkScalar dx, SkScalar dy, SkImageFilter* input)
{ |
37 return SkNEW_ARGS(SimpleOffsetFilter, (dx, dy, input)); | 37 return SkNEW_ARGS(SimpleOffsetFilter, (dx, dy, input)); |
38 } | 38 } |
39 | 39 |
40 virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const Context&
ctx, | 40 virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const Context&
ctx, |
41 SkBitmap* dst, SkIPoint* offset) const SK_OVERRID
E { | 41 SkBitmap* dst, SkIPoint* offset) const override { |
42 SkBitmap source = src; | 42 SkBitmap source = src; |
43 SkImageFilter* input = getInput(0); | 43 SkImageFilter* input = getInput(0); |
44 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 44 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
45 if (input && !input->filterImage(proxy, src, ctx, &source, &srcOffset))
{ | 45 if (input && !input->filterImage(proxy, src, ctx, &source, &srcOffset))
{ |
46 return false; | 46 return false; |
47 } | 47 } |
48 | 48 |
49 SkIRect bounds; | 49 SkIRect bounds; |
50 if (!this->applyCropRect(ctx, proxy, source, &srcOffset, &bounds, &sourc
e)) { | 50 if (!this->applyCropRect(ctx, proxy, source, &srcOffset, &bounds, &sourc
e)) { |
51 return false; | 51 return false; |
52 } | 52 } |
53 | 53 |
54 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bo
unds.height())); | 54 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bo
unds.height())); |
55 SkCanvas canvas(device); | 55 SkCanvas canvas(device); |
56 SkPaint paint; | 56 SkPaint paint; |
57 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 57 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
58 canvas.drawBitmap(source, fDX - bounds.left(), fDY - bounds.top(), &pain
t); | 58 canvas.drawBitmap(source, fDX - bounds.left(), fDY - bounds.top(), &pain
t); |
59 *dst = device->accessBitmap(false); | 59 *dst = device->accessBitmap(false); |
60 offset->fX += bounds.left(); | 60 offset->fX += bounds.left(); |
61 offset->fY += bounds.top(); | 61 offset->fY += bounds.top(); |
62 return true; | 62 return true; |
63 } | 63 } |
64 | 64 |
65 SK_TO_STRING_OVERRIDE() | 65 SK_TO_STRING_OVERRIDE() |
66 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SimpleOffsetFilter); | 66 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SimpleOffsetFilter); |
67 | 67 |
68 protected: | 68 protected: |
69 void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE { | 69 void flatten(SkWriteBuffer& buffer) const override { |
70 this->INHERITED::flatten(buffer); | 70 this->INHERITED::flatten(buffer); |
71 buffer.writeScalar(fDX); | 71 buffer.writeScalar(fDX); |
72 buffer.writeScalar(fDY); | 72 buffer.writeScalar(fDY); |
73 } | 73 } |
74 | 74 |
75 private: | 75 private: |
76 SimpleOffsetFilter(SkScalar dx, SkScalar dy, SkImageFilter* input) | 76 SimpleOffsetFilter(SkScalar dx, SkScalar dy, SkImageFilter* input) |
77 : SkImageFilter(1, &input), fDX(dx), fDY(dy) {} | 77 : SkImageFilter(1, &input), fDX(dx), fDY(dy) {} |
78 | 78 |
79 SkScalar fDX, fDY; | 79 SkScalar fDX, fDY; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 224 |
225 private: | 225 private: |
226 typedef GM INHERITED; | 226 typedef GM INHERITED; |
227 SkBitmap fBitmap; | 227 SkBitmap fBitmap; |
228 }; | 228 }; |
229 | 229 |
230 /////////////////////////////////////////////////////////////////////////////// | 230 /////////////////////////////////////////////////////////////////////////////// |
231 | 231 |
232 static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; } | 232 static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; } |
233 static skiagm::GMRegistry reg(MyFactory); | 233 static skiagm::GMRegistry reg(MyFactory); |
OLD | NEW |