From 8b78205e72259760a6f96c1eaa4a008c6eaca751 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Fri, 10 Feb 2023 05:01:21 -0800 Subject: [PATCH] [Impeller] Use minimal coverage for EntityPass clip restores --- impeller/entity/entity_pass.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/impeller/entity/entity_pass.cc b/impeller/entity/entity_pass.cc index df9e860f2c48b..fa4220a1f19b3 100644 --- a/impeller/entity/entity_pass.cc +++ b/impeller/entity/entity_pass.cc @@ -12,6 +12,7 @@ #include "flutter/fml/macros.h" #include "flutter/fml/trace_event.h" #include "impeller/base/validation.h" +#include "impeller/entity/contents/clip_contents.h" #include "impeller/entity/contents/content_context.h" #include "impeller/entity/contents/filters/color_filter_contents.h" #include "impeller/entity/contents/filters/inputs/filter_input.h" @@ -456,12 +457,24 @@ bool EntityPass::OnRender( element_entity.GetStencilDepth() - stencil_depth_floor; FML_DCHECK(restoration_depth < stencil_stack.size()); + // We only need to restore the area that covers the coverage of the + // stencil rect at target depth + 1. + std::optional restore_coverage = + (restoration_depth + 1 < stencil_stack.size()) + ? stencil_stack[restoration_depth + 1].coverage + : std::nullopt; + stencil_stack.resize(restoration_depth + 1); if (!stencil_stack.back().coverage.has_value()) { // Running this restore op won't make anything renderable, so skip it. return true; } + + auto restore_contents = static_cast( + element_entity.GetContents().get()); + restore_contents->SetRestoreCoverage(restore_coverage); + } break; }