Skip to content

Commit a8705cc

Browse files
committed
bluk feedback
1 parent e74b62e commit a8705cc

2 files changed

Lines changed: 41 additions & 19 deletions

File tree

‎engine/src/flutter/impeller/display_list/dl_dispatcher.cc‎

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -999,21 +999,18 @@ void FirstPassDispatcher::saveLayer(const DlRect& bounds,
999999
std::optional<int64_t> backdrop_id) {
10001000
save();
10011001

1002+
const bool has_layer_bounds =
1003+
!bounds.IsMaximum() &&
1004+
(!bounds.IsEmpty() || options.bounds_from_caller());
1005+
10021006
backdrop_count_ += (backdrop == nullptr ? 0 : 1);
10031007
if (backdrop != nullptr && backdrop_id.has_value()) {
10041008
std::shared_ptr<flutter::DlImageFilter> shared_backdrop =
10051009
backdrop->shared();
10061010
Rect layer_coverage = cull_rect_state_.back();
1007-
if (options.bounds_from_caller()) {
1008-
if (!bounds.IsMaximum()) {
1009-
layer_coverage =
1010-
layer_coverage.IntersectionOrEmpty(bounds.TransformBounds(matrix_));
1011-
}
1012-
} else {
1013-
if (!bounds.IsEmpty() && !bounds.IsMaximum()) {
1014-
layer_coverage =
1015-
layer_coverage.IntersectionOrEmpty(bounds.TransformBounds(matrix_));
1016-
}
1011+
if (has_layer_bounds) {
1012+
layer_coverage =
1013+
layer_coverage.IntersectionOrEmpty(bounds.TransformBounds(matrix_));
10171014
}
10181015
std::unordered_map<int64_t, BackdropData>::iterator existing =
10191016
backdrop_data_.find(backdrop_id.value());
@@ -1041,15 +1038,9 @@ void FirstPassDispatcher::saveLayer(const DlRect& bounds,
10411038
auto global_cull_rect = cull_rect_state_.back();
10421039
if (has_image_filter_ || global_cull_rect.IsMaximum()) {
10431040
cull_rect_state_.back() = Rect::MakeMaximum();
1044-
} else if (options.bounds_from_caller() ||
1045-
(!bounds.IsEmpty() && !bounds.IsMaximum())) {
1046-
auto global_save_bounds = bounds.TransformBounds(matrix_);
1047-
auto new_cull_rect = global_cull_rect.Intersection(global_save_bounds);
1048-
if (new_cull_rect.has_value()) {
1049-
cull_rect_state_.back() = new_cull_rect.value();
1050-
} else {
1051-
cull_rect_state_.back() = Rect::MakeLTRB(0, 0, 0, 0);
1052-
}
1041+
} else if (has_layer_bounds) {
1042+
cull_rect_state_.back() =
1043+
global_cull_rect.IntersectionOrEmpty(bounds.TransformBounds(matrix_));
10531044
}
10541045
}
10551046

‎engine/src/flutter/impeller/display_list/dl_unittests.cc‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,5 +1860,36 @@ TEST_P(DisplayListTest,
18601860
EXPECT_EQ(it->second.coverage_union, Rect::MakeLTRB(10, 20, 60, 80));
18611861
}
18621862

1863+
TEST_P(DisplayListTest,
1864+
FirstPassDispatcherSaveLayerMaximalBoundsDoesNotClipCullRect) {
1865+
auto blur =
1866+
flutter::DlImageFilter::MakeBlur(10, 10, flutter::DlTileMode::kClamp);
1867+
// A perspective transform where homogeneous coordinates (w) flip sign for
1868+
// distant points if maximal bounds are transformed.
1869+
Matrix transform(1.0f, 0.0f, 0.0f, 0.0001f, //
1870+
0.0f, 1.0f, 0.0f, 0.0f, //
1871+
0.0f, 0.0f, 1.0f, 0.0f, //
1872+
0.0f, 0.0f, 0.0f, 1.0f);
1873+
FirstPassDispatcher collector(GetContentContext(), transform,
1874+
Rect::MakeLTRB(0, 0, 1000, 1000));
1875+
flutter::SaveLayerOptions options;
1876+
options = options.with_bounds_from_caller();
1877+
1878+
// Maximal bounds with bounds_from_caller.
1879+
collector.saveLayer(DlRect::MakeMaximum(), options, nullptr, std::nullopt);
1880+
// Inner layer with backdrop filter.
1881+
collector.saveLayer(DlRect(), flutter::SaveLayerOptions(), blur.get(),
1882+
/*backdrop_id=*/1);
1883+
collector.restore();
1884+
collector.restore();
1885+
1886+
auto [backdrop_data, backdrop_count] = collector.TakeBackdropData();
1887+
EXPECT_EQ(backdrop_count, 1u);
1888+
auto it = backdrop_data.find(1);
1889+
ASSERT_TRUE(it != backdrop_data.end());
1890+
EXPECT_FALSE(it->second.coverage_union.IsEmpty());
1891+
EXPECT_EQ(it->second.coverage_union, Rect::MakeLTRB(0, 0, 1000, 1000));
1892+
}
1893+
18631894
} // namespace testing
18641895
} // namespace impeller

0 commit comments

Comments
 (0)