diff options
-rw-r--r-- | src/core/SkImageFilter.cpp | 11 | ||||
-rw-r--r-- | tests/ImageFilterTest.cpp | 22 |
2 files changed, 29 insertions, 4 deletions
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index 374a561030..85f4e468dd 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -313,21 +313,24 @@ void SkImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { *dst = src; return; } + // We can't work directly on dst, since src and dst may alias. + SkRect combinedBounds; if (this->getInput(0)) { - this->getInput(0)->computeFastBounds(src, dst); + this->getInput(0)->computeFastBounds(src, &combinedBounds); } else { - *dst = src; + combinedBounds = src; } for (int i = 1; i < fInputCount; i++) { SkImageFilter* input = this->getInput(i); if (input) { SkRect bounds; input->computeFastBounds(src, &bounds); - dst->join(bounds); + combinedBounds.join(bounds); } else { - dst->join(src); + combinedBounds.join(src); } } + *dst = combinedBounds; } bool SkImageFilter::canComputeFastBounds() const { diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index d4e92762fa..0c2f124b4c 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -796,6 +796,28 @@ DEF_TEST(ImageFilterComposedBlurFastBounds, reporter) { REPORTER_ASSERT(reporter, boundsDst == expectedBounds); } +DEF_TEST(ImageFilterUnionBounds, reporter) { + SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create(50, 0)); + // Regardless of which order they appear in, the image filter bounds should + // be combined correctly. + { + SkAutoTUnref<SkImageFilter> composite(SkXfermodeImageFilter::Create( + nullptr, offset.get(), nullptr)); + SkRect bounds = SkRect::MakeWH(100, 100); + // Intentionally aliasing here, as that's what the real callers do. + composite->computeFastBounds(bounds, &bounds); + REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); + } + { + SkAutoTUnref<SkImageFilter> composite(SkXfermodeImageFilter::Create( + nullptr, nullptr, offset.get())); + SkRect bounds = SkRect::MakeWH(100, 100); + // Intentionally aliasing here, as that's what the real callers do. + composite->computeFastBounds(bounds, &bounds); + REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); + } +} + static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy, skiatest::Reporter* reporter, GrContext* context) { |