Skip to content

Commit 379e320

Browse files
[Impeller] Do not clamp DrawDisplayList cull rect to the root render target
DrawDisplayList culls a nested DisplayList against Canvas::GetLocalCoverageLimit(), which always intersects 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. Such content is culled and never drawn. Add a clamp_to_root parameter (default true) and pass false only from DrawDisplayList. SaveLayer keeps the clamped value, because it can be returned directly as the subpass size and unclamping it would grow offscreen textures. On the root pass the two values are identical. Test: DrawDisplayListInTranslatedSaveLayerIsNotCulled. Fixes flutter#195859
1 parent b5879a3 commit 379e320

4 files changed

Lines changed: 48 additions & 3 deletions

File tree

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,5 +2861,36 @@ 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 side by side. Both are drawn at x=-100 inside a
2866+
// SaveLayer whose image filter translates them +300 on-screen. The left one
2867+
// is drawn directly; the right one is drawn through DrawDisplayList (a nested
2868+
// DisplayList with an RTree, like a dart:ui Picture). If only the left circle
2869+
// is visible, the nested DisplayList was culled against the root render
2870+
// 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+
28642895
} // namespace testing
28652896
} // namespace impeller

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ void Canvas::Save(uint32_t total_content_depth) {
17901790
transform_stack_.push_back(entry);
17911791
}
17921792

1793-
std::optional<Rect> Canvas::GetLocalCoverageLimit() const {
1793+
std::optional<Rect> Canvas::GetLocalCoverageLimit(bool clamp_to_root) const {
17941794
if (!clip_coverage_stack_.HasCoverage()) {
17951795
// The current clip is empty. This means the pass texture won't be
17961796
// visible, so skip it.
@@ -1823,6 +1823,13 @@ std::optional<Rect> Canvas::GetLocalCoverageLimit() const {
18231823
return std::nullopt;
18241824
}
18251825

1826+
// Inside a subpass, content outside the root RT can still become visible
1827+
// (e.g. an ancestor image filter translates it on-screen), so callers that
1828+
// use this rect for culling pass clamp_to_root=false. On the root pass,
1829+
// pass_texture == root_RT and this intersection is a no-op either way.
1830+
if (!clamp_to_root) {
1831+
return maybe_coverage_limit;
1832+
}
18261833
return maybe_coverage_limit->Intersection(
18271834
Rect::MakeSize(render_target_.GetRenderTargetSize()));
18281835
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,13 @@ class Canvas {
153153

154154
/// @brief Return the culling bounds of the current render target, or nullopt
155155
/// if there is no coverage.
156-
std::optional<Rect> GetLocalCoverageLimit() const;
156+
///
157+
/// @param clamp_to_root If true (default), the result is intersected with
158+
/// the root render target size. Pass false when the result is used
159+
/// as a cull rect (e.g. DrawDisplayList): inside a subpass, content
160+
/// outside the root RT may still be moved on-screen by an ancestor
161+
/// image filter.
162+
std::optional<Rect> GetLocalCoverageLimit(bool clamp_to_root = true) const;
157163

158164
void Save(uint32_t total_content_depth = kMaxDepth);
159165

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,8 @@ void DlDispatcherBase::drawDisplayList(
827827
// the ops based on a rectangle expressed in its "destination bounds"
828828
// so we need the canvas to transform those into the current local
829829
// coordinate space into which the DisplayList will be rendered.
830-
auto global_culling_bounds = GetCanvas().GetLocalCoverageLimit();
830+
auto global_culling_bounds =
831+
GetCanvas().GetLocalCoverageLimit(/*clamp_to_root=*/false);
831832
if (global_culling_bounds.has_value()) {
832833
Rect cull_rect = global_culling_bounds->TransformBounds(
833834
GetCanvas().GetCurrentTransform().Invert());

0 commit comments

Comments
 (0)