Skip to content

Commit 06c9362

Browse files
authored
Handle nested display list clips in Impeller dispatcher (flutter#43442)
Fixes flutter/flutter#130084 If a display list is drawn into another display list and the child display list establishes a small clip, subsequent drawing operations are discarded when really they should not be. The test is expected to render both a blue and a red square; before the fix it renders only the blue square since the red square is incorrectly clipped out. See also dnfield/flutter_svg#938
1 parent e2c12a2 commit 06c9362

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

impeller/display_list/dl_dispatcher.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,10 @@ void DlDispatcher::drawDisplayList(
10521052
Matrix saved_initial_matrix = initial_matrix_;
10531053
int restore_count = canvas_.GetSaveCount();
10541054

1055+
// The display list may alter the clip, which must be restored to the current
1056+
// clip at the end of playback.
1057+
canvas_.Save();
1058+
10551059
// Establish a new baseline for interpreting the new DL.
10561060
// Matrix and clip are left untouched, the current
10571061
// transform is saved as the new base matrix, and paint

impeller/display_list/dl_unittests.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ flutter::DlColor toColor(const float* components) {
4545
using DisplayListTest = DlPlayground;
4646
INSTANTIATE_PLAYGROUND_SUITE(DisplayListTest);
4747

48+
TEST_P(DisplayListTest, DrawPictureWithAClip) {
49+
flutter::DisplayListBuilder sub_builder;
50+
sub_builder.ClipRect(SkRect::MakeXYWH(0, 0, 24, 24));
51+
sub_builder.DrawPaint(flutter::DlPaint(flutter::DlColor::kBlue()));
52+
53+
auto display_list = sub_builder.Build();
54+
flutter::DisplayListBuilder builder;
55+
builder.DrawDisplayList(display_list);
56+
builder.DrawRect(SkRect::MakeXYWH(30, 30, 24, 24),
57+
flutter::DlPaint(flutter::DlColor::kRed()));
58+
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
59+
}
60+
4861
TEST_P(DisplayListTest, CanDrawRect) {
4962
flutter::DisplayListBuilder builder;
5063
builder.DrawRect(SkRect::MakeXYWH(10, 10, 100, 100),

0 commit comments

Comments
 (0)