Fix the best guess results from DlComposeImageFilter with unbounded children (flutter/engine#34956)
This commit is contained in:
@@ -27,4 +27,67 @@ std::shared_ptr<DlImageFilter> DlImageFilter::From(
|
||||
return std::make_shared<DlUnknownImageFilter>(sk_ref_sp(sk_filter));
|
||||
}
|
||||
|
||||
SkRect* DlComposeImageFilter::map_local_bounds(const SkRect& input_bounds,
|
||||
SkRect& output_bounds) const {
|
||||
SkRect cur_bounds = input_bounds;
|
||||
SkRect* ret = &output_bounds;
|
||||
// We set this result in case neither filter is present.
|
||||
output_bounds = input_bounds;
|
||||
if (inner_) {
|
||||
if (!inner_->map_local_bounds(cur_bounds, output_bounds)) {
|
||||
ret = nullptr;
|
||||
}
|
||||
cur_bounds = output_bounds;
|
||||
}
|
||||
if (outer_) {
|
||||
if (!outer_->map_local_bounds(cur_bounds, output_bounds)) {
|
||||
ret = nullptr;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
SkIRect* DlComposeImageFilter::map_device_bounds(const SkIRect& input_bounds,
|
||||
const SkMatrix& ctm,
|
||||
SkIRect& output_bounds) const {
|
||||
SkIRect cur_bounds = input_bounds;
|
||||
SkIRect* ret = &output_bounds;
|
||||
// We set this result in case neither filter is present.
|
||||
output_bounds = input_bounds;
|
||||
if (inner_) {
|
||||
if (!inner_->map_device_bounds(cur_bounds, ctm, output_bounds)) {
|
||||
ret = nullptr;
|
||||
}
|
||||
cur_bounds = output_bounds;
|
||||
}
|
||||
if (outer_) {
|
||||
if (!outer_->map_device_bounds(cur_bounds, ctm, output_bounds)) {
|
||||
ret = nullptr;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
SkIRect* DlComposeImageFilter::get_input_device_bounds(
|
||||
const SkIRect& output_bounds,
|
||||
const SkMatrix& ctm,
|
||||
SkIRect& input_bounds) const {
|
||||
SkIRect cur_bounds = output_bounds;
|
||||
SkIRect* ret = &input_bounds;
|
||||
// We set this result in case neither filter is present.
|
||||
input_bounds = output_bounds;
|
||||
if (outer_) {
|
||||
if (!outer_->get_input_device_bounds(cur_bounds, ctm, input_bounds)) {
|
||||
ret = nullptr;
|
||||
}
|
||||
cur_bounds = input_bounds;
|
||||
}
|
||||
if (inner_) {
|
||||
if (!inner_->get_input_device_bounds(cur_bounds, ctm, input_bounds)) {
|
||||
ret = nullptr;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -519,63 +519,15 @@ class DlComposeImageFilter final : public DlImageFilter {
|
||||
}
|
||||
|
||||
SkRect* map_local_bounds(const SkRect& input_bounds,
|
||||
SkRect& output_bounds) const override {
|
||||
SkRect cur_bounds = input_bounds;
|
||||
// We set this result in case neither filter is present.
|
||||
output_bounds = input_bounds;
|
||||
if (inner_) {
|
||||
if (!inner_->map_local_bounds(cur_bounds, output_bounds)) {
|
||||
return nullptr;
|
||||
}
|
||||
cur_bounds = output_bounds;
|
||||
}
|
||||
if (outer_) {
|
||||
if (!outer_->map_local_bounds(cur_bounds, output_bounds)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return &output_bounds;
|
||||
}
|
||||
SkRect& output_bounds) const override;
|
||||
|
||||
SkIRect* map_device_bounds(const SkIRect& input_bounds,
|
||||
const SkMatrix& ctm,
|
||||
SkIRect& output_bounds) const override {
|
||||
SkIRect cur_bounds = input_bounds;
|
||||
// We set this result in case neither filter is present.
|
||||
output_bounds = input_bounds;
|
||||
if (inner_) {
|
||||
if (!inner_->map_device_bounds(cur_bounds, ctm, output_bounds)) {
|
||||
return nullptr;
|
||||
}
|
||||
cur_bounds = output_bounds;
|
||||
}
|
||||
if (outer_) {
|
||||
if (!outer_->map_device_bounds(cur_bounds, ctm, output_bounds)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return &output_bounds;
|
||||
}
|
||||
SkIRect& output_bounds) const override;
|
||||
|
||||
SkIRect* get_input_device_bounds(const SkIRect& output_bounds,
|
||||
const SkMatrix& ctm,
|
||||
SkIRect& input_bounds) const override {
|
||||
SkIRect cur_bounds = output_bounds;
|
||||
// We set this result in case neither filter is present.
|
||||
input_bounds = output_bounds;
|
||||
if (outer_) {
|
||||
if (!outer_->get_input_device_bounds(cur_bounds, ctm, input_bounds)) {
|
||||
return nullptr;
|
||||
}
|
||||
cur_bounds = output_bounds;
|
||||
}
|
||||
if (inner_) {
|
||||
if (!inner_->get_input_device_bounds(cur_bounds, ctm, input_bounds)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return &input_bounds;
|
||||
}
|
||||
SkIRect& input_bounds) const override;
|
||||
|
||||
sk_sp<SkImageFilter> skia_object() const override {
|
||||
return SkImageFilters::Compose(outer_->skia_object(),
|
||||
|
||||
@@ -253,8 +253,8 @@ static void TestBounds(const DlImageFilter& filter,
|
||||
ASSERT_TRUE(matrix.invert(nullptr));
|
||||
TestBoundsWithMatrix(filter, matrix, sourceBounds,
|
||||
expectedLocalOutputQuad);
|
||||
matrix.setPerspX(0.01);
|
||||
matrix.setPerspY(0.01);
|
||||
matrix.setPerspX(0.001);
|
||||
matrix.setPerspY(0.001);
|
||||
ASSERT_TRUE(matrix.invert(nullptr));
|
||||
TestBoundsWithMatrix(filter, matrix, sourceBounds,
|
||||
expectedLocalOutputQuad);
|
||||
@@ -591,6 +591,87 @@ TEST(DisplayListImageFilter, ComposeBounds) {
|
||||
TestBounds(filter, inputBounds, expectOutputBounds);
|
||||
}
|
||||
|
||||
static void TestUnboundedBounds(DlImageFilter& filter,
|
||||
const SkRect& sourceBounds,
|
||||
const SkRect& expectedOutputBounds,
|
||||
const SkRect& expectedInputBounds) {
|
||||
SkRect bounds;
|
||||
EXPECT_EQ(filter.map_local_bounds(sourceBounds, bounds), nullptr);
|
||||
EXPECT_EQ(bounds, expectedOutputBounds);
|
||||
|
||||
SkIRect ibounds;
|
||||
EXPECT_EQ(
|
||||
filter.map_device_bounds(sourceBounds.roundOut(), SkMatrix::I(), ibounds),
|
||||
nullptr);
|
||||
EXPECT_EQ(ibounds, expectedOutputBounds.roundOut());
|
||||
|
||||
EXPECT_EQ(filter.get_input_device_bounds(sourceBounds.roundOut(),
|
||||
SkMatrix::I(), ibounds),
|
||||
nullptr);
|
||||
EXPECT_EQ(ibounds, expectedInputBounds.roundOut());
|
||||
}
|
||||
|
||||
TEST(DisplayListImageFilter, ComposeBoundsWithUnboundedInner) {
|
||||
auto inputBounds = SkRect::MakeLTRB(20, 20, 80, 80);
|
||||
auto expectedBounds = SkRect::MakeLTRB(5, 2, 95, 98);
|
||||
|
||||
DlBlendColorFilter color_filter(DlColor::kRed(), DlBlendMode::kSrcOver);
|
||||
auto outer = DlBlurImageFilter(5.0, 6.0, DlTileMode::kRepeat);
|
||||
auto inner = DlColorFilterImageFilter(color_filter.shared());
|
||||
auto composed = DlComposeImageFilter(outer.shared(), inner.shared());
|
||||
|
||||
TestUnboundedBounds(composed, inputBounds, expectedBounds, expectedBounds);
|
||||
}
|
||||
|
||||
TEST(DisplayListImageFilter, ComposeBoundsWithUnboundedOuter) {
|
||||
auto inputBounds = SkRect::MakeLTRB(20, 20, 80, 80);
|
||||
auto expectedBounds = SkRect::MakeLTRB(5, 2, 95, 98);
|
||||
|
||||
DlBlendColorFilter color_filter(DlColor::kRed(), DlBlendMode::kSrcOver);
|
||||
auto outer = DlColorFilterImageFilter(color_filter.shared());
|
||||
auto inner = DlBlurImageFilter(5.0, 6.0, DlTileMode::kRepeat);
|
||||
auto composed = DlComposeImageFilter(outer.shared(), inner.shared());
|
||||
|
||||
TestUnboundedBounds(composed, inputBounds, expectedBounds, expectedBounds);
|
||||
}
|
||||
|
||||
TEST(DisplayListImageFilter, ComposeBoundsWithUnboundedInnerAndOuter) {
|
||||
auto inputBounds = SkRect::MakeLTRB(20, 20, 80, 80);
|
||||
auto expectedBounds = inputBounds;
|
||||
|
||||
DlBlendColorFilter color_filter1(DlColor::kRed(), DlBlendMode::kSrcOver);
|
||||
DlBlendColorFilter color_filter2(DlColor::kBlue(), DlBlendMode::kSrcOver);
|
||||
auto outer = DlColorFilterImageFilter(color_filter1.shared());
|
||||
auto inner = DlColorFilterImageFilter(color_filter2.shared());
|
||||
auto composed = DlComposeImageFilter(outer.shared(), inner.shared());
|
||||
|
||||
TestUnboundedBounds(composed, inputBounds, expectedBounds, expectedBounds);
|
||||
}
|
||||
|
||||
// See https://github.com/flutter/flutter/issues/108433
|
||||
TEST(DisplayListImageFilter, Issue_108433) {
|
||||
auto inputBounds = SkIRect::MakeLTRB(20, 20, 80, 80);
|
||||
|
||||
auto sk_filter = SkColorFilters::Blend(SK_ColorRED, SkBlendMode::kSrcOver);
|
||||
auto sk_outer = SkImageFilters::Blur(5.0, 6.0, SkTileMode::kRepeat, nullptr);
|
||||
auto sk_inner = SkImageFilters::ColorFilter(sk_filter, nullptr);
|
||||
auto sk_compose = SkImageFilters::Compose(sk_outer, sk_inner);
|
||||
|
||||
DlBlendColorFilter dl_color_filter(DlColor::kRed(), DlBlendMode::kSrcOver);
|
||||
auto dl_outer = DlBlurImageFilter(5.0, 6.0, DlTileMode::kRepeat);
|
||||
auto dl_inner = DlColorFilterImageFilter(dl_color_filter.shared());
|
||||
auto dl_compose = DlComposeImageFilter(dl_outer, dl_inner);
|
||||
|
||||
auto sk_bounds = sk_compose->filterBounds(
|
||||
inputBounds, SkMatrix::I(),
|
||||
SkImageFilter::MapDirection::kForward_MapDirection);
|
||||
|
||||
SkIRect dl_bounds;
|
||||
EXPECT_EQ(dl_compose.map_device_bounds(inputBounds, SkMatrix::I(), dl_bounds),
|
||||
nullptr);
|
||||
ASSERT_EQ(dl_bounds, sk_bounds);
|
||||
}
|
||||
|
||||
TEST(DisplayListImageFilter, ColorFilterConstructor) {
|
||||
DlBlendColorFilter dl_color_filter(DlColor::kRed(), DlBlendMode::kLighten);
|
||||
DlColorFilterImageFilter filter(dl_color_filter);
|
||||
|
||||
Reference in New Issue
Block a user