Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a80d775

Browse files
author
Jonah Williams
authored
[Impeller] port clip stack fixes to new canvas. (#54727)
From c99eda4
1 parent e8521f6 commit a80d775

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

impeller/aiks/experimental_canvas.cc

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
#include "impeller/aiks/experimental_canvas.h"
6+
#include <limits>
67
#include "fml/logging.h"
78
#include "fml/trace_event.h"
89
#include "impeller/aiks/canvas.h"
@@ -57,6 +58,7 @@ static void ApplyFramebufferBlend(Entity& entity) {
5758
static std::shared_ptr<Texture> FlipBackdrop(
5859
std::vector<LazyRenderingConfig>& render_passes,
5960
Point global_pass_position,
61+
size_t current_clip_depth,
6062
EntityPassClipStack& clip_coverage_stack,
6163
ContentContext& renderer) {
6264
auto rendering_config = std::move(render_passes.back());
@@ -132,16 +134,21 @@ static std::shared_ptr<Texture> FlipBackdrop(
132134

133135
// Restore any clips that were recorded before the backdrop filter was
134136
// applied.
135-
auto& replay_entities = clip_coverage_stack.GetReplayEntities();
136-
for (const auto& replay : replay_entities) {
137+
clip_coverage_stack.ActivateClipReplay();
138+
139+
// If there are any pending clips to replay, render any that may affect
140+
// the entity we're about to render.
141+
while (const EntityPassClipStack::ReplayResult* next_replay_clip =
142+
clip_coverage_stack.GetNextReplayResult(current_clip_depth)) {
143+
auto& replay_entity = next_replay_clip->entity;
137144
SetClipScissor(
138-
clip_coverage_stack.CurrentClipCoverage(),
145+
next_replay_clip->clip_coverage,
139146
*render_passes.back().inline_pass_context->GetRenderPass(0).pass,
140147
global_pass_position);
141-
if (!replay.entity.Render(
148+
if (!replay_entity.Render(
142149
renderer,
143150
*render_passes.back().inline_pass_context->GetRenderPass(0).pass)) {
144-
VALIDATION_LOG << "Failed to render entity for clip restore.";
151+
VALIDATION_LOG << "Failed to render entity for clip replay.";
145152
}
146153
}
147154

@@ -375,8 +382,12 @@ void ExperimentalCanvas::SaveLayer(
375382
return filter;
376383
};
377384

378-
auto input_texture = FlipBackdrop(render_passes_, GetGlobalPassPosition(),
379-
clip_coverage_stack_, renderer_);
385+
auto input_texture = FlipBackdrop(render_passes_, //
386+
GetGlobalPassPosition(), //
387+
std::numeric_limits<uint32_t>::max(), //
388+
clip_coverage_stack_, //
389+
renderer_ //
390+
);
380391
if (!input_texture) {
381392
// Validation failures are logged in FlipBackdrop.
382393
return;
@@ -532,9 +543,9 @@ bool ExperimentalCanvas::Restore() {
532543
// to the render target texture so far need to execute before it's bound
533544
// for blending (otherwise the blend pass will end up executing before
534545
// all the previous commands in the active pass).
535-
auto input_texture =
536-
FlipBackdrop(render_passes_, GetGlobalPassPosition(),
537-
clip_coverage_stack_, renderer_);
546+
auto input_texture = FlipBackdrop(
547+
render_passes_, GetGlobalPassPosition(),
548+
element_entity.GetClipDepth(), clip_coverage_stack_, renderer_);
538549
if (!input_texture) {
539550
return false;
540551
}
@@ -712,8 +723,9 @@ void ExperimentalCanvas::AddRenderEntityToCurrentPass(Entity entity,
712723
// to the render target texture so far need to execute before it's bound
713724
// for blending (otherwise the blend pass will end up executing before
714725
// all the previous commands in the active pass).
715-
auto input_texture = FlipBackdrop(render_passes_, GetGlobalPassPosition(),
716-
clip_coverage_stack_, renderer_);
726+
auto input_texture =
727+
FlipBackdrop(render_passes_, GetGlobalPassPosition(),
728+
entity.GetClipDepth(), clip_coverage_stack_, renderer_);
717729
if (!input_texture) {
718730
return;
719731
}

impeller/entity/entity_pass.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,8 @@ bool EntityPass::RenderElement(Entity& element_entity,
852852
// If there are any pending clips to replay, render any that may affect
853853
// the entity we're about to render.
854854
while (const EntityPassClipStack::ReplayResult* next_replay_clip =
855-
clip_coverage_stack.GetNextReplayResult(element_entity)) {
855+
clip_coverage_stack.GetNextReplayResult(
856+
element_entity.GetClipDepth())) {
856857
auto& replay_entity = next_replay_clip->entity;
857858
SetClipScissor(next_replay_clip->clip_coverage, *result.pass,
858859
global_pass_position);

impeller/entity/entity_pass_clip_stack.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,15 @@ void EntityPassClipStack::ActivateClipReplay() {
178178
}
179179

180180
const EntityPassClipStack::ReplayResult*
181-
EntityPassClipStack::GetNextReplayResult(const Entity& entity) {
181+
EntityPassClipStack::GetNextReplayResult(size_t current_clip_depth) {
182182
if (next_replay_index_ >=
183183
subpass_state_.back().rendered_clip_entities.size()) {
184184
// No clips need to be replayed.
185185
return nullptr;
186186
}
187187
ReplayResult* next_replay =
188188
&subpass_state_.back().rendered_clip_entities[next_replay_index_];
189-
if (next_replay->entity.GetClipDepth() < entity.GetClipDepth()) {
189+
if (next_replay->entity.GetClipDepth() < current_clip_depth) {
190190
// The next replay clip doesn't affect the current entity, so don't replay
191191
// it yet.
192192
return nullptr;

impeller/entity/entity_pass_clip_stack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class EntityPassClipStack {
6868

6969
/// @brief Returns the next Entity that should be replayed. If there are no
7070
/// enities to replay, then nullptr is returned.
71-
const ReplayResult* GetNextReplayResult(const Entity& entity);
71+
const ReplayResult* GetNextReplayResult(size_t current_clip_depth);
7272

7373
// Visible for testing.
7474
const std::vector<ClipCoverageLayer> GetClipCoverageLayers() const;

0 commit comments

Comments
 (0)