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 void SkComposeImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) con
st { | 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 SkRect tmp; | 19 return outer->computeFastBounds(inner->computeFastBounds(src)); |
20 inner->computeFastBounds(src, &tmp); | |
21 outer->computeFastBounds(tmp, dst); | |
22 } | 20 } |
23 | 21 |
24 SkSpecialImage* SkComposeImageFilter::onFilterImage(SkSpecialImage* source, cons
t Context& ctx, | 22 SkSpecialImage* SkComposeImageFilter::onFilterImage(SkSpecialImage* source, cons
t Context& ctx, |
25 SkIPoint* offset) const { | 23 SkIPoint* offset) const { |
26 // The bounds passed to the inner filter must be filtered by the outer | 24 // The bounds passed to the inner filter must be filtered by the outer |
27 // filter, so that the inner filter produces the pixels that the outer | 25 // filter, so that the inner filter produces the pixels that the outer |
28 // filter requires as input. This matters if the outer filter moves pixels. | 26 // filter requires as input. This matters if the outer filter moves pixels. |
29 SkIRect innerClipBounds; | 27 SkIRect innerClipBounds; |
30 getInput(0)->filterBounds(ctx.clipBounds(), ctx.ctm(), &innerClipBounds); | 28 innerClipBounds = getInput(0)->filterBounds(ctx.clipBounds(), ctx.ctm()); |
31 Context innerContext(ctx.ctm(), innerClipBounds, ctx.cache()); | 29 Context innerContext(ctx.ctm(), innerClipBounds, ctx.cache()); |
32 SkIPoint innerOffset = SkIPoint::Make(0, 0); | 30 SkIPoint innerOffset = SkIPoint::Make(0, 0); |
33 SkAutoTUnref<SkSpecialImage> inner(this->filterInput(1, source, innerContext
, &innerOffset)); | 31 SkAutoTUnref<SkSpecialImage> inner(this->filterInput(1, source, innerContext
, &innerOffset)); |
34 if (!inner) { | 32 if (!inner) { |
35 return nullptr; | 33 return nullptr; |
36 } | 34 } |
37 | 35 |
38 SkMatrix outerMatrix(ctx.ctm()); | 36 SkMatrix outerMatrix(ctx.ctm()); |
39 outerMatrix.postTranslate(SkIntToScalar(-innerOffset.x()), SkIntToScalar(-in
nerOffset.y())); | 37 outerMatrix.postTranslate(SkIntToScalar(-innerOffset.x()), SkIntToScalar(-in
nerOffset.y())); |
40 SkIRect clipBounds = ctx.clipBounds(); | 38 SkIRect clipBounds = ctx.clipBounds(); |
41 clipBounds.offset(-innerOffset.x(), -innerOffset.y()); | 39 clipBounds.offset(-innerOffset.x(), -innerOffset.y()); |
42 Context outerContext(outerMatrix, clipBounds, ctx.cache()); | 40 Context outerContext(outerMatrix, clipBounds, ctx.cache()); |
43 | 41 |
44 SkIPoint outerOffset = SkIPoint::Make(0, 0); | 42 SkIPoint outerOffset = SkIPoint::Make(0, 0); |
45 SkAutoTUnref<SkSpecialImage> outer(this->filterInput(0, inner, outerContext,
&outerOffset)); | 43 SkAutoTUnref<SkSpecialImage> outer(this->filterInput(0, inner, outerContext,
&outerOffset)); |
46 if (!outer) { | 44 if (!outer) { |
47 return nullptr; | 45 return nullptr; |
48 } | 46 } |
49 | 47 |
50 *offset = innerOffset + outerOffset; | 48 *offset = innerOffset + outerOffset; |
51 return outer.release(); | 49 return outer.release(); |
52 } | 50 } |
53 | 51 |
54 bool SkComposeImageFilter::onFilterBounds(const SkIRect& src, | 52 SkIRect SkComposeImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix&
ctm, |
55 const SkMatrix& ctm, | 53 MapDirection direction) const { |
56 SkIRect* dst, | |
57 MapDirection direction) const { | |
58 SkImageFilter* outer = this->getInput(0); | 54 SkImageFilter* outer = this->getInput(0); |
59 SkImageFilter* inner = this->getInput(1); | 55 SkImageFilter* inner = this->getInput(1); |
60 | 56 |
61 SkIRect tmp; | 57 return outer->filterBounds(inner->filterBounds(src, ctm, direction), ctm, di
rection); |
62 return inner->filterBounds(src, ctm, &tmp, direction) && | |
63 outer->filterBounds(tmp, ctm, dst, direction); | |
64 } | 58 } |
65 | 59 |
66 SkFlattenable* SkComposeImageFilter::CreateProc(SkReadBuffer& buffer) { | 60 SkFlattenable* SkComposeImageFilter::CreateProc(SkReadBuffer& buffer) { |
67 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 2); | 61 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 2); |
68 return SkComposeImageFilter::Create(common.getInput(0), common.getInput(1)); | 62 return SkComposeImageFilter::Create(common.getInput(0), common.getInput(1)); |
69 } | 63 } |
70 | 64 |
71 #ifndef SK_IGNORE_TO_STRING | 65 #ifndef SK_IGNORE_TO_STRING |
72 void SkComposeImageFilter::toString(SkString* str) const { | 66 void SkComposeImageFilter::toString(SkString* str) const { |
73 SkImageFilter* outer = getInput(0); | 67 SkImageFilter* outer = getInput(0); |
74 SkImageFilter* inner = getInput(1); | 68 SkImageFilter* inner = getInput(1); |
75 | 69 |
76 str->appendf("SkComposeImageFilter: ("); | 70 str->appendf("SkComposeImageFilter: ("); |
77 | 71 |
78 str->appendf("outer: "); | 72 str->appendf("outer: "); |
79 outer->toString(str); | 73 outer->toString(str); |
80 | 74 |
81 str->appendf("inner: "); | 75 str->appendf("inner: "); |
82 inner->toString(str); | 76 inner->toString(str); |
83 | 77 |
84 str->appendf(")"); | 78 str->appendf(")"); |
85 } | 79 } |
86 #endif | 80 #endif |
OLD | NEW |