Skip to content

Commit c897a86

Browse files
committed
Reduce reland to EntityPassClipStack fix and DisplayListToTexture tests
- Revert Canvas and ClipContents changes from the original PR back to master, restoring direct root-target flips in DisplayListToTexture snapshots and strict clip-depth FML_DCHECKs without std::min clamping. - Replace is_onscreen-gated CreateTestCanvas tests with direct DisplayListToTexture GPU pixel-readback tests in canvas_unittests.cc and clip-stack replay tests in clip_stack_unittests.cc.
1 parent b723062 commit c897a86

9 files changed

Lines changed: 335 additions & 273 deletions

File tree

‎engine/src/flutter/impeller/display_list/BUILD.gn‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ template("aiks_unittests_component") {
203203
"//flutter/impeller/geometry:geometry_asserts",
204204
"//flutter/impeller/golden_tests:golden_playground_test",
205205
"//flutter/impeller/playground:playground_test",
206-
"//flutter/impeller/renderer/testing:mocks",
207206
"//flutter/testing:testing_lib",
208207
"//flutter/txt",
209208
]

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

Lines changed: 26 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -159,78 +159,33 @@ TEST_P(AiksTest, DilatedContentOutsideClip) {
159159
}
160160

161161
TEST_P(AiksTest, CanRenderClippedBackdropFilterWithSuperellipse) {
162-
DisplayListBuilder root_builder;
163-
164-
root_builder.Scale(GetContentScale().x, GetContentScale().y);
165-
166-
// 1. Draw a dark background on the root pass.
167-
DlPaint bg_paint;
168-
bg_paint.setColor(DlColor::kBlack());
169-
root_builder.DrawPaint(bg_paint);
170-
171-
// 2. Wrap in TransformLayer (matching CupertinoSheetTransition scale +
172-
// slide).
173-
root_builder.Save();
174-
root_builder.Scale(0.9f, 0.9f);
175-
root_builder.Translate(33.4f, 3.5f);
176-
177-
// 3. Apply ClipRoundSuperellipse with top-only rounded corners (matching
178-
// CupertinoSheet).
179-
DlRect sheet_rect = DlRect::MakeXYWH(0, 42, 400, 500);
180-
DlRoundingRadii top_radii = {
181-
.top_left = {12, 12},
182-
.top_right = {12, 12},
183-
.bottom_left = {0, 0},
184-
.bottom_right = {0, 0},
185-
};
186-
DlRoundSuperellipse clip_rse =
187-
DlRoundSuperellipse::MakeRectRadii(sheet_rect, top_radii);
188-
root_builder.ClipRoundSuperellipse(clip_rse, DlClipOp::kIntersect);
189-
190-
// 4. Wrap in OpacityLayer offset (matching CupertinoSheetRoute offset: (0,
191-
// 42)).
192-
root_builder.Save();
193-
root_builder.Translate(0.0f, 42.0f);
194-
195-
// 5. Layer 1: DisplayListLayer for sheet body with Ink features.
196-
for (int i = 0; i < 5; i++) {
197-
DisplayListBuilder item_builder;
198-
DlPaint ink_paint;
199-
ink_paint.setColor(DlColor::RGBA(0.0f, 0.0f, 0.0f, 0.07f));
200-
item_builder.DrawRect(DlRect::MakeXYWH(0, i * 50, 400, 45), ink_paint);
201-
root_builder.DrawDisplayList(item_builder.Build());
202-
}
162+
SetWindowSize({400, 400});
163+
DisplayListBuilder builder;
164+
builder.Scale(GetContentScale().x, GetContentScale().y);
165+
builder.DrawPaint(DlPaint(DlColor::kBlack()));
166+
167+
// Clip to a centered superellipse with large rounded corners.
168+
DlRect rect = DlRect::MakeXYWH(50, 50, 300, 300);
169+
builder.ClipRoundSuperellipse(DlRoundSuperellipse::MakeRectXY(rect, 80, 80));
170+
171+
// Draw backdrop content inside a child DisplayList with a containing
172+
// ClipRect; restoring its scope must preserve the parent superellipse clip.
173+
DisplayListBuilder child_builder;
174+
child_builder.ClipRect(DlRect::MakeXYWH(0, 0, 400, 400));
175+
child_builder.DrawRect(DlRect::MakeXYWH(50, 50, 150, 300),
176+
DlPaint(DlColor::kCornflowerBlue()));
177+
child_builder.DrawRect(DlRect::MakeXYWH(200, 50, 150, 300),
178+
DlPaint(DlColor::kOrange()));
179+
builder.DrawDisplayList(child_builder.Build());
180+
181+
// Apply a BackdropFilter with a translucent white fill across the full rect.
182+
// Its corners remain rounded only if the superellipse clip is replayed.
183+
auto filter = DlImageFilter::MakeBlur(20.0f, 20.0f, DlTileMode::kClamp);
184+
builder.SaveLayer(rect, nullptr, filter.get());
185+
builder.DrawPaint(DlPaint(DlColor::kWhite().withAlpha(160)));
186+
builder.Restore();
203187

204-
// 6. Layer 2: BackdropFilterLayer (_glassBar).
205-
root_builder.Save();
206-
DlRect glass_rect = DlRect::MakeXYWH(20, 350, 360, 60);
207-
DlRoundRect glass_rrect = DlRoundRect::MakeRectXY(glass_rect, 14, 14);
208-
root_builder.ClipRoundRect(glass_rrect, DlClipOp::kIntersect);
209-
210-
DlPaint save_paint;
211-
auto backdrop_filter =
212-
DlImageFilter::MakeBlur(12.0f, 12.0f, DlTileMode::kClamp);
213-
root_builder.SaveLayer(glass_rect, &save_paint, backdrop_filter.get());
214-
DisplayListBuilder glass_builder;
215-
DlPaint orange_paint;
216-
orange_paint.setColor(DlColor::RGBA(1.0f, 0.6f, 0.0f, 0.6f));
217-
glass_builder.DrawRect(glass_rect, orange_paint);
218-
root_builder.DrawDisplayList(glass_builder.Build());
219-
root_builder.Restore(); // Restore SaveLayer
220-
root_builder.Restore(); // Restore glass clip
221-
222-
// 7. Layer 3: DisplayListLayer for Scaffold AppBar / header drawn AFTER
223-
// backdrop filter.
224-
DisplayListBuilder appbar_builder;
225-
DlPaint white_paint;
226-
white_paint.setColor(DlColor::kWhite());
227-
appbar_builder.DrawRect(DlRect::MakeXYWH(0, 0, 400, 80), white_paint);
228-
root_builder.DrawDisplayList(appbar_builder.Build());
229-
230-
root_builder.Restore(); // Restore OpacityLayer offset
231-
root_builder.Restore(); // Restore TransformLayer
232-
233-
ASSERT_TRUE(OpenPlaygroundHere(root_builder.Build()));
188+
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
234189
}
235190

236191
} // namespace testing

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,9 +1780,11 @@ void Canvas::Save(uint32_t total_content_depth) {
17801780

17811781
auto entry = CanvasStackEntry{};
17821782
entry.transform = transform_stack_.back().transform;
1783-
entry.clip_depth = std::min<uint32_t>(current_depth_ + total_content_depth,
1784-
transform_stack_.back().clip_depth);
1783+
entry.clip_depth = current_depth_ + total_content_depth;
17851784
entry.distributed_opacity = transform_stack_.back().distributed_opacity;
1785+
FML_DCHECK(entry.clip_depth <= transform_stack_.back().clip_depth)
1786+
<< entry.clip_depth << " <=? " << transform_stack_.back().clip_depth
1787+
<< " after allocating " << total_content_depth;
17861788
entry.clip_height = transform_stack_.back().clip_height;
17871789
entry.rendering_mode = Entity::RenderingMode::kDirect;
17881790
transform_stack_.push_back(entry);
@@ -1945,7 +1947,7 @@ void Canvas::SaveLayer(const Paint& paint,
19451947
// 3. The current render pass is for the onscreen pass.
19461948
const bool should_use_onscreen =
19471949
renderer_.GetDeviceCapabilities().SupportsFramebufferFetch() &&
1948-
backdrop_count_ == 0 && render_passes_.size() == 1u && is_onscreen_;
1950+
backdrop_count_ == 0 && render_passes_.size() == 1u;
19491951
input_texture = FlipBackdrop(
19501952
GetGlobalPassPosition(), //
19511953
/*should_remove_texture=*/will_cache_backdrop_texture, //
@@ -2031,8 +2033,10 @@ void Canvas::SaveLayer(const Paint& paint,
20312033

20322034
CanvasStackEntry entry;
20332035
entry.transform = transform_stack_.back().transform;
2034-
entry.clip_depth = std::min<uint32_t>(current_depth_ + total_content_depth,
2035-
transform_stack_.back().clip_depth);
2036+
entry.clip_depth = current_depth_ + total_content_depth;
2037+
FML_DCHECK(entry.clip_depth <= transform_stack_.back().clip_depth)
2038+
<< entry.clip_depth << " <=? " << transform_stack_.back().clip_depth
2039+
<< " after allocating " << total_content_depth;
20362040
entry.clip_height = transform_stack_.back().clip_height;
20372041
entry.rendering_mode = Entity::RenderingMode::kSubpassAppendSnapshotTransform;
20382042
entry.did_round_out = did_round_out;
@@ -2077,16 +2081,9 @@ bool Canvas::Restore() {
20772081
// to be overly conservative, but we need to jump the depth to
20782082
// the clip depth so that the next rendering op will get a
20792083
// larger depth (it will pre-increment the current_depth_ value).
2080-
//
2081-
// Only advance depth if clips were recorded and the allocated clip depth
2082-
// was finite. This prevents premature exhaustion of the parent pass depth
2083-
// budget.
2084-
if (transform_stack_.back().num_clips > 0 &&
2085-
transform_stack_.back().clip_depth < kMaxDepth) {
2086-
FML_DCHECK(current_depth_ <= transform_stack_.back().clip_depth)
2087-
<< current_depth_ << " <=? " << transform_stack_.back().clip_depth;
2088-
current_depth_ = transform_stack_.back().clip_depth;
2089-
}
2084+
FML_DCHECK(current_depth_ <= transform_stack_.back().clip_depth)
2085+
<< current_depth_ << " <=? " << transform_stack_.back().clip_depth;
2086+
current_depth_ = transform_stack_.back().clip_depth;
20902087

20912088
if (IsSkipping()) {
20922089
transform_stack_.pop_back();
@@ -2648,6 +2645,8 @@ std::shared_ptr<Texture> Canvas::FlipBackdrop(Point global_pass_position,
26482645
}
26492646
}
26502647

2648+
// Restore any clips that were recorded before the backdrop filter was
2649+
// applied.
26512650
auto& replay_entities = clip_coverage_stack_.GetReplayEntities();
26522651
uint64_t current_depth =
26532652
post_depth_increment ? current_depth_ - 1 : current_depth_;
@@ -2659,7 +2658,7 @@ std::shared_ptr<Texture> Canvas::FlipBackdrop(Point global_pass_position,
26592658
SetClipScissor(replay.clip_coverage, current_render_pass,
26602659
global_pass_position);
26612660
if (!replay.clip_contents.Render(renderer_, current_render_pass,
2662-
replay.clip_depth, replay.transform)) {
2661+
replay.clip_depth)) {
26632662
VALIDATION_LOG << "Failed to render entity for clip restore.";
26642663
}
26652664
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ class LazyRenderingConfig {
121121

122122
class Canvas {
123123
public:
124-
/// Maximum discrete integer depth level within the 18-bit depth precision
125-
/// limit defined by `Entity::kDepthEpsilon`.
126-
static constexpr uint32_t kMaxDepth = (1 << 18) - 1;
124+
static constexpr uint32_t kMaxDepth = 1 << 24;
127125

128126
Canvas(ContentContext& renderer,
129127
const RenderTarget& render_target,

0 commit comments

Comments
 (0)