Skip to content

Commit b8a2aa4

Browse files
Revert: Fix square corner issue (flutter#193189)
Reverts: [Fix square corner issue](flutter#191096) Initiated by: @andywolff Reason for reverting: seems to have caused a test order dependency flutter#192992 Original PR Author: @andywolff Reviewed By: @gaaclarke The original PR description is provided below: Fixes flutter#190602, see my [comment](flutter#190602 (comment)) on that issue for details about the problems I identified. Also fixes flutter#162172 ## What changed When a route contained rounded clips (such as `CupertinoSheetRoute`), intermediate child ink features, and a backdrop filter (such as a blurred app bar), the clip stack replay logic prematurely popped parent clips and exceeded the depth buffer budget across render pass splits, causing subsequent header draws to render with 90° square corners. This PR addresses both mechanisms: First, `EntityPassClipStack::RecordRestore` was popping replay entities unconditionally whenever any clip was restored. In a sheet containing ink decorations (like list item ripple effects), child clip restores at deeper heights would prematurely discard the root parent clip. We now track `clip_height` in `ReplayResult` so that restorations only pop entities when `clip_height > restore_height`, preserving parent clips across sibling restores. When replaying those clips in `ClipContents::Render`, we also supply the entity's model matrix to properly recompute the MVP matrix against the new pass's orthographic projection instead of reusing the stale matrix from the prior pass. Second, the pass depth budget was exhausting across backdrop splits. `Canvas::kMaxDepth` (`1 << 24`) was mismatched with `Entity::kDepthEpsilon` (`1.0 / 262144.0`, or `2^-18`), allowing integer depths to exceed the 18-bit precision of the depth buffer. Aligning `Canvas::kMaxDepth` to `262,143` and capping depth allocations in `Save`/`SaveLayer` to `min(current_depth_ + total_content_depth, parent_clip_depth)` keeps clip replay and subsequent draw operations within valid precision bounds. In `Canvas::Restore`, we also prevent unconditional depth jumps to `kMaxDepth` for unclipped saves, preserving the allocated budget for subsequent sibling draws. ## Testing Reproducing this interaction in automated tests required testing the onscreen pass-splitting branch (`IsOnscreen()`), which normal offscreen unit tests bypass. We added a `ScopedOnscreenOverride` test hook in `Canvas` and constructed a multi-layer display list recreating the route clip, child ink items, blurred backdrop bar, and trailing app bar: * `clip_stack_unittests.cc`: Added `EntityPassClipStackTest.RestoringChildClipPreservesParentReplayEntities` to isolate parent clip retention across sibling restores. * `canvas_unittests.cc`: Added `AiksTest.ClipDepthMaintainedAcrossBackdropFilterAndLayers` to verify depth invariants and precision bounds (`<= kMaxDepth`), and `AiksTest.ParentClipDepthBudgetPreservedAfterBackdropLayerRestore` to verify parent depth budget restoration. * `dl_golden_unittests.cc` (`impeller_golden_tests`): Added `DlGoldenTest.CanRenderClippedBackdropFilterWithSuperellipse` for pixel-accurate golden image verification in CI against Skia Gold. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md Co-authored-by: Andy Wolff <[email protected]>
1 parent e91c38b commit b8a2aa4

10 files changed

Lines changed: 42 additions & 342 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
@@ -196,7 +196,6 @@ template("aiks_unittests_component") {
196196
"//flutter/impeller/geometry:geometry_asserts",
197197
"//flutter/impeller/golden_tests:golden_playground_test",
198198
"//flutter/impeller/playground:playground_test",
199-
"//flutter/impeller/renderer/testing:mocks",
200199
"//flutter/testing:testing_lib",
201200
"//flutter/txt",
202201
]

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

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include "flutter/display_list/dl_color.h"
1010
#include "flutter/display_list/dl_paint.h"
1111
#include "flutter/display_list/effects/dl_color_filter.h"
12-
#include "flutter/display_list/effects/dl_image_filter.h"
13-
#include "flutter/display_list/geometry/dl_geometry_types.h"
1412
#include "flutter/display_list/geometry/dl_path_builder.h"
1513
#include "flutter/testing/testing.h"
1614

@@ -141,80 +139,5 @@ TEST_P(AiksTest, FramebufferBlendsRespectClips) {
141139
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
142140
}
143141

144-
TEST_P(AiksTest, CanRenderClippedBackdropFilterWithSuperellipse) {
145-
DisplayListBuilder root_builder;
146-
147-
root_builder.Scale(GetContentScale().x, GetContentScale().y);
148-
149-
// 1. Draw a dark background on the root pass.
150-
DlPaint bg_paint;
151-
bg_paint.setColor(DlColor::kBlack());
152-
root_builder.DrawPaint(bg_paint);
153-
154-
// 2. Wrap in TransformLayer (matching CupertinoSheetTransition scale +
155-
// slide).
156-
root_builder.Save();
157-
root_builder.Scale(0.9f, 0.9f);
158-
root_builder.Translate(33.4f, 3.5f);
159-
160-
// 3. Apply ClipRoundSuperellipse with top-only rounded corners (matching
161-
// CupertinoSheet).
162-
DlRect sheet_rect = DlRect::MakeXYWH(0, 42, 400, 500);
163-
DlRoundingRadii top_radii = {
164-
.top_left = {12, 12},
165-
.top_right = {12, 12},
166-
.bottom_left = {0, 0},
167-
.bottom_right = {0, 0},
168-
};
169-
DlRoundSuperellipse clip_rse =
170-
DlRoundSuperellipse::MakeRectRadii(sheet_rect, top_radii);
171-
root_builder.ClipRoundSuperellipse(clip_rse, DlClipOp::kIntersect);
172-
173-
// 4. Wrap in OpacityLayer offset (matching CupertinoSheetRoute offset: (0,
174-
// 42)).
175-
root_builder.Save();
176-
root_builder.Translate(0.0f, 42.0f);
177-
178-
// 5. Layer 1: DisplayListLayer for sheet body with Ink features.
179-
for (int i = 0; i < 5; i++) {
180-
DisplayListBuilder item_builder;
181-
DlPaint ink_paint;
182-
ink_paint.setColor(DlColor::RGBA(0.0f, 0.0f, 0.0f, 0.07f));
183-
item_builder.DrawRect(DlRect::MakeXYWH(0, i * 50, 400, 45), ink_paint);
184-
root_builder.DrawDisplayList(item_builder.Build());
185-
}
186-
187-
// 6. Layer 2: BackdropFilterLayer (_glassBar).
188-
root_builder.Save();
189-
DlRect glass_rect = DlRect::MakeXYWH(20, 350, 360, 60);
190-
DlRoundRect glass_rrect = DlRoundRect::MakeRectXY(glass_rect, 14, 14);
191-
root_builder.ClipRoundRect(glass_rrect, DlClipOp::kIntersect);
192-
193-
DlPaint save_paint;
194-
auto backdrop_filter =
195-
DlImageFilter::MakeBlur(12.0f, 12.0f, DlTileMode::kClamp);
196-
root_builder.SaveLayer(glass_rect, &save_paint, backdrop_filter.get());
197-
DisplayListBuilder glass_builder;
198-
DlPaint orange_paint;
199-
orange_paint.setColor(DlColor::RGBA(1.0f, 0.6f, 0.0f, 0.6f));
200-
glass_builder.DrawRect(glass_rect, orange_paint);
201-
root_builder.DrawDisplayList(glass_builder.Build());
202-
root_builder.Restore(); // Restore SaveLayer
203-
root_builder.Restore(); // Restore glass clip
204-
205-
// 7. Layer 3: DisplayListLayer for Scaffold AppBar / header drawn AFTER
206-
// backdrop filter.
207-
DisplayListBuilder appbar_builder;
208-
DlPaint white_paint;
209-
white_paint.setColor(DlColor::kWhite());
210-
appbar_builder.DrawRect(DlRect::MakeXYWH(0, 0, 400, 80), white_paint);
211-
root_builder.DrawDisplayList(appbar_builder.Build());
212-
213-
root_builder.Restore(); // Restore OpacityLayer offset
214-
root_builder.Restore(); // Restore TransformLayer
215-
216-
ASSERT_TRUE(OpenPlaygroundHere(root_builder.Build()));
217-
}
218-
219142
} // namespace testing
220143
} // namespace impeller

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

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

17761776
auto entry = CanvasStackEntry{};
17771777
entry.transform = transform_stack_.back().transform;
1778-
entry.clip_depth = std::min<uint32_t>(current_depth_ + total_content_depth,
1779-
transform_stack_.back().clip_depth);
1778+
entry.clip_depth = current_depth_ + total_content_depth;
17801779
entry.distributed_opacity = transform_stack_.back().distributed_opacity;
1780+
FML_DCHECK(entry.clip_depth <= transform_stack_.back().clip_depth)
1781+
<< entry.clip_depth << " <=? " << transform_stack_.back().clip_depth
1782+
<< " after allocating " << total_content_depth;
17811783
entry.clip_height = transform_stack_.back().clip_height;
17821784
entry.rendering_mode = Entity::RenderingMode::kDirect;
17831785
transform_stack_.push_back(entry);
@@ -1940,7 +1942,7 @@ void Canvas::SaveLayer(const Paint& paint,
19401942
// 3. The current render pass is for the onscreen pass.
19411943
const bool should_use_onscreen =
19421944
renderer_.GetDeviceCapabilities().SupportsFramebufferFetch() &&
1943-
backdrop_count_ == 0 && render_passes_.size() == 1u && is_onscreen_;
1945+
backdrop_count_ == 0 && render_passes_.size() == 1u;
19441946
input_texture = FlipBackdrop(
19451947
GetGlobalPassPosition(), //
19461948
/*should_remove_texture=*/will_cache_backdrop_texture, //
@@ -2026,8 +2028,10 @@ void Canvas::SaveLayer(const Paint& paint,
20262028

20272029
CanvasStackEntry entry;
20282030
entry.transform = transform_stack_.back().transform;
2029-
entry.clip_depth = std::min<uint32_t>(current_depth_ + total_content_depth,
2030-
transform_stack_.back().clip_depth);
2031+
entry.clip_depth = current_depth_ + total_content_depth;
2032+
FML_DCHECK(entry.clip_depth <= transform_stack_.back().clip_depth)
2033+
<< entry.clip_depth << " <=? " << transform_stack_.back().clip_depth
2034+
<< " after allocating " << total_content_depth;
20312035
entry.clip_height = transform_stack_.back().clip_height;
20322036
entry.rendering_mode = Entity::RenderingMode::kSubpassAppendSnapshotTransform;
20332037
entry.did_round_out = did_round_out;
@@ -2072,16 +2076,9 @@ bool Canvas::Restore() {
20722076
// to be overly conservative, but we need to jump the depth to
20732077
// the clip depth so that the next rendering op will get a
20742078
// larger depth (it will pre-increment the current_depth_ value).
2075-
//
2076-
// Only advance depth if clips were recorded and the allocated clip depth
2077-
// was finite. This prevents premature exhaustion of the parent pass depth
2078-
// budget.
2079-
if (transform_stack_.back().num_clips > 0 &&
2080-
transform_stack_.back().clip_depth < kMaxDepth) {
2081-
FML_DCHECK(current_depth_ <= transform_stack_.back().clip_depth)
2082-
<< current_depth_ << " <=? " << transform_stack_.back().clip_depth;
2083-
current_depth_ = transform_stack_.back().clip_depth;
2084-
}
2079+
FML_DCHECK(current_depth_ <= transform_stack_.back().clip_depth)
2080+
<< current_depth_ << " <=? " << transform_stack_.back().clip_depth;
2081+
current_depth_ = transform_stack_.back().clip_depth;
20852082

20862083
if (IsSkipping()) {
20872084
transform_stack_.pop_back();
@@ -2631,6 +2628,8 @@ std::shared_ptr<Texture> Canvas::FlipBackdrop(Point global_pass_position,
26312628
return nullptr;
26322629
}
26332630

2631+
// Restore any clips that were recorded before the backdrop filter was
2632+
// applied.
26342633
auto& replay_entities = clip_coverage_stack_.GetReplayEntities();
26352634
uint64_t current_depth =
26362635
post_depth_increment ? current_depth_ - 1 : current_depth_;
@@ -2642,7 +2641,7 @@ std::shared_ptr<Texture> Canvas::FlipBackdrop(Point global_pass_position,
26422641
SetClipScissor(replay.clip_coverage, current_render_pass,
26432642
global_pass_position);
26442643
if (!replay.clip_contents.Render(renderer_, current_render_pass,
2645-
replay.clip_depth, replay.transform)) {
2644+
replay.clip_depth)) {
26462645
VALIDATION_LOG << "Failed to render entity for clip restore.";
26472646
}
26482647
}

‎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)