@@ -1696,7 +1696,11 @@ void Canvas::Save(uint32_t total_content_depth) {
16961696
16971697 auto entry = CanvasStackEntry{};
16981698 entry.transform = transform_stack_.back ().transform ;
1699- entry.clip_depth = current_depth_ + total_content_depth;
1699+ entry.clip_depth =
1700+ (total_content_depth == kMaxDepth )
1701+ ? transform_stack_.back ().clip_depth
1702+ : std::min<uint32_t >(current_depth_ + total_content_depth,
1703+ transform_stack_.back ().clip_depth );
17001704 entry.distributed_opacity = transform_stack_.back ().distributed_opacity ;
17011705 FML_DCHECK (entry.clip_depth <= transform_stack_.back ().clip_depth )
17021706 << entry.clip_depth << " <=? " << transform_stack_.back ().clip_depth
@@ -1861,9 +1865,9 @@ void Canvas::SaveLayer(const Paint& paint,
18611865 // 1. The device supports framebuffer fetch
18621866 // 2. There are no more backdrop filters
18631867 // 3. The current render pass is for the onscreen pass.
1864- const bool should_use_onscreen =
1868+ const bool should_use_onscreen = override_should_use_onscreen_. value_or (
18651869 renderer_.GetDeviceCapabilities ().SupportsFramebufferFetch () &&
1866- backdrop_count_ == 0 && render_passes_.size () == 1u ;
1870+ backdrop_count_ == 0 && render_passes_.size () == 1u ) ;
18671871 input_texture = FlipBackdrop (
18681872 GetGlobalPassPosition (), //
18691873 /* should_remove_texture=*/ will_cache_backdrop_texture, //
@@ -1946,7 +1950,11 @@ void Canvas::SaveLayer(const Paint& paint,
19461950
19471951 CanvasStackEntry entry;
19481952 entry.transform = transform_stack_.back ().transform ;
1949- entry.clip_depth = current_depth_ + total_content_depth;
1953+ entry.clip_depth =
1954+ (total_content_depth == kMaxDepth )
1955+ ? transform_stack_.back ().clip_depth
1956+ : std::min<uint32_t >(current_depth_ + total_content_depth,
1957+ transform_stack_.back ().clip_depth );
19501958 FML_DCHECK (entry.clip_depth <= transform_stack_.back ().clip_depth )
19511959 << entry.clip_depth << " <=? " << transform_stack_.back ().clip_depth
19521960 << " after allocating " << total_content_depth;
@@ -1994,9 +2002,12 @@ bool Canvas::Restore() {
19942002 // to be overly conservative, but we need to jump the depth to
19952003 // the clip depth so that the next rendering op will get a
19962004 // larger depth (it will pre-increment the current_depth_ value).
1997- FML_DCHECK (current_depth_ <= transform_stack_.back ().clip_depth )
1998- << current_depth_ << " <=? " << transform_stack_.back ().clip_depth ;
1999- current_depth_ = transform_stack_.back ().clip_depth ;
2005+ if (transform_stack_.back ().num_clips > 0 &&
2006+ transform_stack_.back ().clip_depth < kMaxDepth ) {
2007+ FML_DCHECK (current_depth_ <= transform_stack_.back ().clip_depth )
2008+ << current_depth_ << " <=? " << transform_stack_.back ().clip_depth ;
2009+ current_depth_ = transform_stack_.back ().clip_depth ;
2010+ }
20002011
20012012 if (IsSkipping ()) {
20022013 transform_stack_.pop_back ();
@@ -2087,6 +2098,13 @@ bool Canvas::Restore() {
20872098 );
20882099 clip_coverage_stack_.PopSubpass ();
20892100 transform_stack_.pop_back ();
2101+ if (!transform_stack_.empty ()) {
2102+ CanvasStackEntry& entry = transform_stack_.back ();
2103+ if (entry.pre_split_clip_depth .has_value ()) {
2104+ entry.clip_depth = entry.pre_split_clip_depth .value ();
2105+ entry.pre_split_clip_depth = std::nullopt ;
2106+ }
2107+ }
20902108
20912109 // We don't need to restore clips if a saveLayer was performed, as the clip
20922110 // state is per render target, and no more rendering operations will be
@@ -2096,6 +2114,13 @@ bool Canvas::Restore() {
20962114
20972115 size_t num_clips = transform_stack_.back ().num_clips ;
20982116 transform_stack_.pop_back ();
2117+ if (!transform_stack_.empty ()) {
2118+ CanvasStackEntry& entry = transform_stack_.back ();
2119+ if (entry.pre_split_clip_depth .has_value ()) {
2120+ entry.clip_depth = entry.pre_split_clip_depth .value ();
2121+ entry.pre_split_clip_depth = std::nullopt ;
2122+ }
2123+ }
20992124
21002125 if (num_clips > 0 ) {
21012126 EntityPassClipStack::ClipStateResult clip_state_result =
@@ -2540,20 +2565,19 @@ std::shared_ptr<Texture> Canvas::FlipBackdrop(Point global_pass_position,
25402565 return nullptr ;
25412566 }
25422567
2543- // Restore any clips that were recorded before the backdrop filter was
2544- // applied.
25452568 auto & replay_entities = clip_coverage_stack_.GetReplayEntities ();
2546- uint64_t current_depth =
2547- post_depth_increment ? current_depth_ - 1 : current_depth_;
2548- for (const auto & replay : replay_entities) {
2549- if (replay.clip_depth <= current_depth) {
2550- continue ;
2569+ current_depth_ = 0 ;
2570+ for (auto & entry : transform_stack_) {
2571+ if (!entry.pre_split_clip_depth .has_value ()) {
2572+ entry.pre_split_clip_depth = entry.clip_depth ;
25512573 }
2552-
2574+ entry.clip_depth = kMaxDepth ;
2575+ }
2576+ for (const auto & replay : replay_entities) {
25532577 SetClipScissor (replay.clip_coverage , current_render_pass,
25542578 global_pass_position);
2555- if (!replay.clip_contents .Render (renderer_, current_render_pass,
2556- replay.clip_depth )) {
2579+ if (!replay.clip_contents .Render (renderer_, current_render_pass, kMaxDepth ,
2580+ replay.transform )) {
25572581 VALIDATION_LOG << " Failed to render entity for clip restore." ;
25582582 }
25592583 }
0 commit comments