OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkComposeImageFilter.h" | 8 #include "SkComposeImageFilter.h" |
9 | 9 |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
11 #include "SkSpecialImage.h" | 11 #include "SkSpecialImage.h" |
12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
13 | 13 |
14 | 14 |
15 SkRect SkComposeImageFilter::computeFastBounds(const SkRect& src) const { | 15 SkRect SkComposeImageFilter::computeFastBounds(const SkRect& src) const { |
16 SkImageFilter* outer = getInput(0); | 16 SkImageFilter* outer = getInput(0); |
17 SkImageFilter* inner = getInput(1); | 17 SkImageFilter* inner = getInput(1); |
18 | 18 |
19 return outer->computeFastBounds(inner->computeFastBounds(src)); | 19 return outer->computeFastBounds(inner->computeFastBounds(src)); |
20 } | 20 } |
21 | 21 |
22 SkSpecialImage* SkComposeImageFilter::onFilterImage(SkSpecialImage* source, cons
t Context& ctx, | 22 sk_sp<SkSpecialImage> SkComposeImageFilter::onFilterImage(SkSpecialImage* source
, |
23 SkIPoint* offset) const { | 23 const Context& ctx, |
| 24 SkIPoint* offset) cons
t { |
24 // The bounds passed to the inner filter must be filtered by the outer | 25 // The bounds passed to the inner filter must be filtered by the outer |
25 // filter, so that the inner filter produces the pixels that the outer | 26 // filter, so that the inner filter produces the pixels that the outer |
26 // filter requires as input. This matters if the outer filter moves pixels. | 27 // filter requires as input. This matters if the outer filter moves pixels. |
27 SkIRect innerClipBounds; | 28 SkIRect innerClipBounds; |
28 innerClipBounds = getInput(0)->filterBounds(ctx.clipBounds(), ctx.ctm()); | 29 innerClipBounds = getInput(0)->filterBounds(ctx.clipBounds(), ctx.ctm()); |
29 Context innerContext(ctx.ctm(), innerClipBounds, ctx.cache()); | 30 Context innerContext(ctx.ctm(), innerClipBounds, ctx.cache()); |
30 SkIPoint innerOffset = SkIPoint::Make(0, 0); | 31 SkIPoint innerOffset = SkIPoint::Make(0, 0); |
31 SkAutoTUnref<SkSpecialImage> inner(this->filterInput(1, source, innerContext
, &innerOffset)); | 32 sk_sp<SkSpecialImage> inner(this->filterInput(1, source, innerContext, &inne
rOffset)); |
32 if (!inner) { | 33 if (!inner) { |
33 return nullptr; | 34 return nullptr; |
34 } | 35 } |
35 | 36 |
36 SkMatrix outerMatrix(ctx.ctm()); | 37 SkMatrix outerMatrix(ctx.ctm()); |
37 outerMatrix.postTranslate(SkIntToScalar(-innerOffset.x()), SkIntToScalar(-in
nerOffset.y())); | 38 outerMatrix.postTranslate(SkIntToScalar(-innerOffset.x()), SkIntToScalar(-in
nerOffset.y())); |
38 SkIRect clipBounds = ctx.clipBounds(); | 39 SkIRect clipBounds = ctx.clipBounds(); |
39 clipBounds.offset(-innerOffset.x(), -innerOffset.y()); | 40 clipBounds.offset(-innerOffset.x(), -innerOffset.y()); |
40 Context outerContext(outerMatrix, clipBounds, ctx.cache()); | 41 Context outerContext(outerMatrix, clipBounds, ctx.cache()); |
41 | 42 |
42 SkIPoint outerOffset = SkIPoint::Make(0, 0); | 43 SkIPoint outerOffset = SkIPoint::Make(0, 0); |
43 SkAutoTUnref<SkSpecialImage> outer(this->filterInput(0, inner, outerContext,
&outerOffset)); | 44 sk_sp<SkSpecialImage> outer(this->filterInput(0, inner.get(), outerContext,
&outerOffset)); |
44 if (!outer) { | 45 if (!outer) { |
45 return nullptr; | 46 return nullptr; |
46 } | 47 } |
47 | 48 |
48 *offset = innerOffset + outerOffset; | 49 *offset = innerOffset + outerOffset; |
49 return outer.release(); | 50 return outer; |
50 } | 51 } |
51 | 52 |
52 SkIRect SkComposeImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix&
ctm, | 53 SkIRect SkComposeImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix&
ctm, |
53 MapDirection direction) const { | 54 MapDirection direction) const { |
54 SkImageFilter* outer = this->getInput(0); | 55 SkImageFilter* outer = this->getInput(0); |
55 SkImageFilter* inner = this->getInput(1); | 56 SkImageFilter* inner = this->getInput(1); |
56 | 57 |
57 return outer->filterBounds(inner->filterBounds(src, ctm, direction), ctm, di
rection); | 58 return outer->filterBounds(inner->filterBounds(src, ctm, direction), ctm, di
rection); |
58 } | 59 } |
59 | 60 |
(...skipping 11 matching lines...) Expand all Loading... |
71 | 72 |
72 str->appendf("outer: "); | 73 str->appendf("outer: "); |
73 outer->toString(str); | 74 outer->toString(str); |
74 | 75 |
75 str->appendf("inner: "); | 76 str->appendf("inner: "); |
76 inner->toString(str); | 77 inner->toString(str); |
77 | 78 |
78 str->appendf(")"); | 79 str->appendf(")"); |
79 } | 80 } |
80 #endif | 81 #endif |
OLD | NEW |