Skip to content

Commit fae5d0d

Browse files
[Impeller] Do not clamp the local coverage limit to the root render target (flutter#195860)
`Canvas::GetLocalCoverageLimit()` intersected its result with the root render target. Inside a subpass this is too tight: content outside the root RT can still end up on-screen, for example when an ancestor `SaveLayer` has a matrix image filter that translates it. Both callers were affected: - `DrawDisplayList` uses the limit as its cull rect, so a nested DisplayList (e.g. a `dart:ui` Picture) drawn off-screen inside such a layer was culled. - `SaveLayer` uses the limit to size the subpass, so a child `SaveLayer` inside such a layer lost its off-screen content. This PR removes the root RT intersection. The limit is now bounded only by the current pass texture and the clip. On the root pass the pass texture is the root RT, so the result there is unchanged. Subpass textures in the affected cases can be larger, because they now have to hold the content that the ancestor filter moves on-screen. Tests: - `DrawDisplayListInTranslatedSaveLayerIsNotCulled`: a circle drawn through `DrawDisplayList` inside a translated SaveLayer. - `NestedSaveLayerInTranslatedSaveLayerIsNotCulled`: a circle drawn inside a child SaveLayer inside a translated SaveLayer. Each test also draws a control circle directly into the parent layer. Before the fix only the control circle renders. Both scenarios reproduce with plain `dart:ui` on Flutter 3.38.3 (`flutter test --enable-impeller`): the circle is missing on Impeller and present on Skia. See flutter#195859. Fixes flutter#195859
1 parent 9e1d055 commit fae5d0d

2 files changed

Lines changed: 66 additions & 11 deletions

File tree

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,5 +2861,64 @@ TEST_P(AiksTest, DrawImageFromYUVTextures) {
28612861
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
28622862
}
28632863

2864+
// Regression test for https://github.com/flutter/flutter/issues/195859.
2865+
// Renders two green circles, one above the other. Both are drawn at x=-100
2866+
// inside a SaveLayer whose image filter translates them +300 on-screen. The
2867+
// top one is drawn directly; the bottom one is drawn through DrawDisplayList
2868+
// (a nested DisplayList with an RTree, like a dart:ui Picture). If only the
2869+
// top circle is visible, the nested DisplayList was culled against the root
2870+
// render target instead of the subpass.
2871+
TEST_P(AiksTest, DrawDisplayListInTranslatedSaveLayerIsNotCulled) {
2872+
DlPaint green;
2873+
green.setColor(DlColor::kGreen());
2874+
2875+
DisplayListBuilder inner_builder(/*prepare_rtree=*/true);
2876+
inner_builder.DrawCircle(DlPoint(-100, 300), 80, green);
2877+
auto inner_dl = inner_builder.Build();
2878+
2879+
DisplayListBuilder builder;
2880+
builder.Scale(GetContentScale().x, GetContentScale().y);
2881+
2882+
DlPaint paint;
2883+
paint.setImageFilter(DlImageFilter::MakeMatrix(
2884+
DlMatrix::MakeTranslation({300, 0}), DlImageSampling::kLinear));
2885+
builder.SaveLayer(std::nullopt, &paint);
2886+
// Control: drawn directly, not subject to DisplayList culling.
2887+
builder.DrawCircle(DlPoint(-100, 100), 80, green);
2888+
// Drawn through DrawDisplayList; was culled before the fix.
2889+
builder.DrawDisplayList(inner_dl, 1.0f);
2890+
builder.Restore();
2891+
2892+
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2893+
}
2894+
2895+
// Regression test for https://github.com/flutter/flutter/issues/195859.
2896+
// Same as DrawDisplayListInTranslatedSaveLayerIsNotCulled, but the bottom
2897+
// circle is drawn inside a nested SaveLayer. If only the top circle is
2898+
// visible, the child SaveLayer's subpass was clamped to the root render target
2899+
// and its off-screen content was dropped before the parent filter moved it.
2900+
TEST_P(AiksTest, NestedSaveLayerInTranslatedSaveLayerIsNotCulled) {
2901+
DlPaint green;
2902+
green.setColor(DlColor::kGreen());
2903+
2904+
DisplayListBuilder builder;
2905+
builder.Scale(GetContentScale().x, GetContentScale().y);
2906+
2907+
DlPaint paint;
2908+
paint.setImageFilter(DlImageFilter::MakeMatrix(
2909+
DlMatrix::MakeTranslation({300, 0}), DlImageSampling::kLinear));
2910+
builder.SaveLayer(std::nullopt, &paint);
2911+
// Control: drawn directly into the parent layer.
2912+
builder.DrawCircle(DlPoint(-100, 100), 80, green);
2913+
DlPaint child_paint;
2914+
builder.SaveLayer(std::nullopt, &child_paint);
2915+
// Drawn inside the child SaveLayer; not visible when SaveLayer clamps.
2916+
builder.DrawCircle(DlPoint(-100, 300), 80, green);
2917+
builder.Restore();
2918+
builder.Restore();
2919+
2920+
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2921+
}
2922+
28642923
} // namespace testing
28652924
} // namespace impeller

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,17 +1814,13 @@ std::optional<Rect> Canvas::GetLocalCoverageLimit() const {
18141814

18151815
// The maximum coverage of the subpass. Subpasses textures should never
18161816
// extend outside the parent pass texture or the current clip coverage.
1817-
std::optional<Rect> maybe_coverage_limit =
1818-
Rect::MakeOriginSize(GetGlobalPassPosition(),
1819-
Size(back_texture->GetSize()))
1820-
.Intersection(current_clip_coverage);
1821-
1822-
if (!maybe_coverage_limit.has_value() || maybe_coverage_limit->IsEmpty()) {
1823-
return std::nullopt;
1824-
}
1825-
1826-
return maybe_coverage_limit->Intersection(
1827-
Rect::MakeSize(render_target_.GetRenderTargetSize()));
1817+
//
1818+
// Do not intersect with the root render target. Inside a subpass, content
1819+
// outside the root RT can still end up on-screen (e.g. an ancestor image
1820+
// filter translates it).
1821+
return Rect::MakeOriginSize(GetGlobalPassPosition(),
1822+
Size(back_texture->GetSize()))
1823+
.Intersection(current_clip_coverage);
18281824
}
18291825

18301826
void Canvas::SaveLayer(const Paint& paint,

0 commit comments

Comments
 (0)