diff options
author | 2016-03-17 12:24:23 -0700 | |
---|---|---|
committer | 2016-03-17 12:24:23 -0700 | |
commit | 0e3129d734212089f872f0e7de8f2537861a3f89 (patch) | |
tree | a5c9e45f0166af306abd93da69bee65402501da7 /tests/ImageFilterTest.cpp | |
parent | c9a99872274ab63f2130caeccc75a2f52b8677a3 (diff) |
Fix pointer aliasing bug in SkImageFilter::computeFastBounds.
Since src and dst are explicitly allowed to alias (according to a comment in
SkPaint.h), it is problematic to have the first input filter mutate dst, since
we still need access to the previous value to provide to the other input
filters.
To resolve this, SkImageFilter::computeFastBounds makes a copy of src on the
stack, and passes that to its inputs instead.
Also add a unit test that would have detected the issue.
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1800263002
Review URL: https://codereview.chromium.org/1800263002
Diffstat (limited to 'tests/ImageFilterTest.cpp')
-rw-r--r-- | tests/ImageFilterTest.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
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) { |