Skip to content

Commit 132e1c6

Browse files
krll-kovgaaclarke
andauthored
[Skia][DisplayList] Map local bounds through the local matrix in DlLocalMatrixImageFilter (flutter#193963)
Fixes flutter#170535 `DlLocalMatrixImageFilter::map_local_bounds` ignored `matrix_`, so on Skia raster cached `Transform` with `filterQuality` got wrong bounds, and `DisplayListBuilder` skipped drawing it when it was only partly visible. The bounds are now mapped through `matrix_`, as `map_device_bounds` already does. This line comes from flutter-team-archive/engine#34878, where the review asked for a comparison with Skia ([comment](flutter-team-archive/engine#34878 (comment))). This PR adds it for `map_local_bounds` in `LocalImageFilterBounds`, plus a `LocalMatrixBounds` test. Both fail without the fix ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making. - [x] All existing and new tests are passing. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [CLA]: https://cla.developers.google.com/ --------- Co-authored-by: gaaclarke <[email protected]>
1 parent b0a88aa commit 132e1c6

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎engine/src/flutter/display_list/effects/dl_image_filter_unittests.cc‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,24 @@ TEST(DisplayListImageFilter, ColorFilterModifiesTransparencyBounds) {
751751
TestInvalidBounds(filter, DlMatrix(), input_bounds);
752752
}
753753

754+
TEST(DisplayListImageFilter, LocalMatrixBounds) {
755+
// Inner filter scales by 1.25 about center of 200x100 rect at origin
756+
DlRect local_bounds = DlRect::MakeXYWH(0, 0, 200, 100);
757+
DlPoint center = local_bounds.GetCenter();
758+
DlMatrix scale = DlMatrix::MakeTranslation(center) *
759+
DlMatrix::MakeScale({1.25, 1.25, 1.0}) *
760+
DlMatrix::MakeTranslation(-center);
761+
DlMatrixImageFilter inner(scale, DlImageSampling::kLinear);
762+
// Local matrix shifts inner filter space by offset: center is (900, 1250)
763+
DlPoint offset = DlPoint(800, 1200);
764+
DlLocalMatrixImageFilter filter(DlMatrix::MakeTranslation(offset),
765+
inner.shared());
766+
DlRect input_bounds = local_bounds.Shift(offset);
767+
// 200x100 scaled by 1.25 about its center is 250x125
768+
DlRect expected_output_bounds = input_bounds.Expand(25, 12.5);
769+
TestBounds(filter, input_bounds, expected_output_bounds);
770+
}
771+
754772
TEST(DisplayListImageFilter, LocalImageFilterBounds) {
755773
auto filter_matrix = DlMatrix::MakeRow(2.0, 0.0, 0.0, 10, //
756774
0.5, 3.0, 0.0, 15, //
@@ -865,6 +883,19 @@ TEST(DisplayListImageFilter, LocalImageFilterBounds) {
865883
ASSERT_FALSE(sk_local_filter->canComputeFastBounds()) << desc;
866884
}
867885
}
886+
{
887+
SkRect input_bounds = SkRect::MakeLTRB(20, 20, 80, 80);
888+
DlRect dl_rect;
889+
if (dl_local_filter->map_local_bounds(ToDlRect(input_bounds),
890+
dl_rect)) {
891+
SkRect sk_rect = sk_local_filter->computeFastBounds(input_bounds);
892+
ASSERT_EQ(sk_rect.roundOut(), ToSkIRect(DlIRect::RoundOut(dl_rect)))
893+
<< desc;
894+
} else {
895+
ASSERT_TRUE(dl_local_filter->modifies_transparent_black()) << desc;
896+
ASSERT_FALSE(sk_local_filter->canComputeFastBounds()) << desc;
897+
}
898+
}
868899
{
869900
// Test for: Know the outset bounds to get the inset bounds
870901
// Skia have some bounds calculate error of DilateFilter and

‎engine/src/flutter/display_list/effects/image_filters/dl_local_matrix_image_filter.cc‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@ DlRect* DlLocalMatrixImageFilter::map_local_bounds(
2828
output_bounds = input_bounds;
2929
return &output_bounds;
3030
}
31-
return image_filter_->map_local_bounds(input_bounds, output_bounds);
31+
if (!matrix_.IsInvertible()) {
32+
output_bounds = input_bounds;
33+
return nullptr;
34+
}
35+
DlRect filter_bounds = input_bounds.TransformAndClipBounds(matrix_.Invert());
36+
DlRect mapped_bounds;
37+
if (!image_filter_->map_local_bounds(filter_bounds, mapped_bounds)) {
38+
output_bounds = input_bounds;
39+
return nullptr;
40+
}
41+
output_bounds = mapped_bounds.TransformAndClipBounds(matrix_);
42+
return &output_bounds;
3243
}
3344

3445
DlIRect* DlLocalMatrixImageFilter::map_device_bounds(

0 commit comments

Comments
 (0)