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

Commit 1fb2a7a

Browse files
authored
[Impeller] Only set the stencil ref for StC draws. (#52006)
Another clean-up patch following #51992. Also, don't rely on Entity tracked stencil height for clip coverage tracking.
1 parent d9013ba commit 1fb2a7a

28 files changed

+112
-113
lines changed

impeller/aiks/canvas.cc

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void Canvas::Save(bool create_subpass,
218218
auto entry = CanvasStackEntry{};
219219
entry.transform = transform_stack_.back().transform;
220220
entry.cull_rect = transform_stack_.back().cull_rect;
221-
entry.clip_depth = transform_stack_.back().clip_depth;
221+
entry.clip_height = transform_stack_.back().clip_height;
222222
if (create_subpass) {
223223
entry.rendering_mode = Entity::RenderingMode::kSubpass;
224224
auto subpass = std::make_unique<EntityPass>();
@@ -244,7 +244,7 @@ void Canvas::Save(bool create_subpass,
244244
subpass->SetBlendMode(blend_mode);
245245
current_pass_ = GetCurrentPass().AddSubpass(std::move(subpass));
246246
current_pass_->SetTransform(transform_stack_.back().transform);
247-
current_pass_->SetClipDepth(transform_stack_.back().clip_depth);
247+
current_pass_->SetClipDepth(transform_stack_.back().clip_height);
248248
}
249249
transform_stack_.emplace_back(entry);
250250
}
@@ -336,7 +336,7 @@ void Canvas::RestoreToCount(size_t count) {
336336
void Canvas::DrawPath(const Path& path, const Paint& paint) {
337337
Entity entity;
338338
entity.SetTransform(GetCurrentTransform());
339-
entity.SetClipDepth(GetClipDepth());
339+
entity.SetClipDepth(GetClipHeight());
340340
entity.SetBlendMode(paint.blend_mode);
341341
entity.SetContents(CreatePathContentsWithFilters(paint, path));
342342

@@ -346,7 +346,7 @@ void Canvas::DrawPath(const Path& path, const Paint& paint) {
346346
void Canvas::DrawPaint(const Paint& paint) {
347347
Entity entity;
348348
entity.SetTransform(GetCurrentTransform());
349-
entity.SetClipDepth(GetClipDepth());
349+
entity.SetClipDepth(GetClipHeight());
350350
entity.SetBlendMode(paint.blend_mode);
351351
entity.SetContents(CreateCoverContentsWithFilters(paint));
352352

@@ -427,7 +427,7 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
427427

428428
Entity blurred_rrect_entity;
429429
blurred_rrect_entity.SetTransform(GetCurrentTransform());
430-
blurred_rrect_entity.SetClipDepth(GetClipDepth());
430+
blurred_rrect_entity.SetClipDepth(GetClipHeight());
431431
blurred_rrect_entity.SetBlendMode(rrect_paint.blend_mode);
432432

433433
rrect_paint.mask_blur_descriptor = std::nullopt;
@@ -447,7 +447,7 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
447447
// Then, draw the non-blurred RRect on top.
448448
Entity entity;
449449
entity.SetTransform(GetCurrentTransform());
450-
entity.SetClipDepth(GetClipDepth());
450+
entity.SetClipDepth(GetClipHeight());
451451
entity.SetBlendMode(rrect_paint.blend_mode);
452452
entity.SetContents(CreateContentsForGeometryWithFilters(
453453
rrect_paint, Geometry::MakeRoundRect(rect, corner_radii)));
@@ -474,7 +474,7 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
474474
void Canvas::DrawLine(const Point& p0, const Point& p1, const Paint& paint) {
475475
Entity entity;
476476
entity.SetTransform(GetCurrentTransform());
477-
entity.SetClipDepth(GetClipDepth());
477+
entity.SetClipDepth(GetClipHeight());
478478
entity.SetBlendMode(paint.blend_mode);
479479
entity.SetContents(CreateContentsForGeometryWithFilters(
480480
paint, Geometry::MakeLine(p0, p1, paint.stroke_width, paint.stroke_cap)));
@@ -494,7 +494,7 @@ void Canvas::DrawRect(const Rect& rect, const Paint& paint) {
494494

495495
Entity entity;
496496
entity.SetTransform(GetCurrentTransform());
497-
entity.SetClipDepth(GetClipDepth());
497+
entity.SetClipDepth(GetClipHeight());
498498
entity.SetBlendMode(paint.blend_mode);
499499
entity.SetContents(
500500
CreateContentsForGeometryWithFilters(paint, Geometry::MakeRect(rect)));
@@ -521,7 +521,7 @@ void Canvas::DrawOval(const Rect& rect, const Paint& paint) {
521521

522522
Entity entity;
523523
entity.SetTransform(GetCurrentTransform());
524-
entity.SetClipDepth(GetClipDepth());
524+
entity.SetClipDepth(GetClipHeight());
525525
entity.SetBlendMode(paint.blend_mode);
526526
entity.SetContents(
527527
CreateContentsForGeometryWithFilters(paint, Geometry::MakeOval(rect)));
@@ -539,7 +539,7 @@ void Canvas::DrawRRect(const Rect& rect,
539539
if (paint.style == Paint::Style::kFill) {
540540
Entity entity;
541541
entity.SetTransform(GetCurrentTransform());
542-
entity.SetClipDepth(GetClipDepth());
542+
entity.SetClipDepth(GetClipHeight());
543543
entity.SetBlendMode(paint.blend_mode);
544544
entity.SetContents(CreateContentsForGeometryWithFilters(
545545
paint, Geometry::MakeRoundRect(rect, corner_radii)));
@@ -568,7 +568,7 @@ void Canvas::DrawCircle(const Point& center,
568568

569569
Entity entity;
570570
entity.SetTransform(GetCurrentTransform());
571-
entity.SetClipDepth(GetClipDepth());
571+
entity.SetClipDepth(GetClipHeight());
572572
entity.SetBlendMode(paint.blend_mode);
573573
auto geometry =
574574
paint.style == Paint::Style::kStroke
@@ -680,11 +680,11 @@ void Canvas::ClipGeometry(const std::shared_ptr<Geometry>& geometry,
680680
Entity entity;
681681
entity.SetTransform(GetCurrentTransform());
682682
entity.SetContents(std::move(contents));
683-
entity.SetClipDepth(GetClipDepth());
683+
entity.SetClipDepth(GetClipHeight());
684684

685685
GetCurrentPass().PushClip(std::move(entity));
686686

687-
++transform_stack_.back().clip_depth;
687+
++transform_stack_.back().clip_height;
688688
++transform_stack_.back().num_clips;
689689
}
690690

@@ -718,8 +718,9 @@ void Canvas::RestoreClip() {
718718
entity.SetTransform(GetCurrentTransform());
719719
// This path is empty because ClipRestoreContents just generates a quad that
720720
// takes up the full render target.
721-
entity.SetContents(std::make_shared<ClipRestoreContents>());
722-
entity.SetClipDepth(GetClipDepth());
721+
auto clip_restore = std::make_shared<ClipRestoreContents>();
722+
clip_restore->SetRestoreHeight(GetClipHeight());
723+
entity.SetContents(std::move(clip_restore));
723724

724725
AddEntityToCurrentPass(std::move(entity));
725726
}
@@ -734,7 +735,7 @@ void Canvas::DrawPoints(std::vector<Point> points,
734735

735736
Entity entity;
736737
entity.SetTransform(GetCurrentTransform());
737-
entity.SetClipDepth(GetClipDepth());
738+
entity.SetClipDepth(GetClipHeight());
738739
entity.SetBlendMode(paint.blend_mode);
739740
entity.SetContents(CreateContentsForGeometryWithFilters(
740741
paint,
@@ -790,7 +791,7 @@ void Canvas::DrawImageRect(const std::shared_ptr<Image>& image,
790791

791792
Entity entity;
792793
entity.SetBlendMode(paint.blend_mode);
793-
entity.SetClipDepth(GetClipDepth());
794+
entity.SetClipDepth(GetClipHeight());
794795
entity.SetContents(paint.WithFilters(contents));
795796
entity.SetTransform(GetCurrentTransform());
796797

@@ -818,8 +819,8 @@ EntityPass& Canvas::GetCurrentPass() {
818819
return *current_pass_;
819820
}
820821

821-
size_t Canvas::GetClipDepth() const {
822-
return transform_stack_.back().clip_depth;
822+
size_t Canvas::GetClipHeight() const {
823+
return transform_stack_.back().clip_height;
823824
}
824825

825826
void Canvas::AddEntityToCurrentPass(Entity entity) {
@@ -866,7 +867,7 @@ void Canvas::DrawTextFrame(const std::shared_ptr<TextFrame>& text_frame,
866867
Point position,
867868
const Paint& paint) {
868869
Entity entity;
869-
entity.SetClipDepth(GetClipDepth());
870+
entity.SetClipDepth(GetClipHeight());
870871
entity.SetBlendMode(paint.blend_mode);
871872

872873
auto text_contents = std::make_shared<TextContents>();
@@ -918,7 +919,7 @@ void Canvas::DrawVertices(const std::shared_ptr<VerticesGeometry>& vertices,
918919

919920
Entity entity;
920921
entity.SetTransform(GetCurrentTransform());
921-
entity.SetClipDepth(GetClipDepth());
922+
entity.SetClipDepth(GetClipHeight());
922923
entity.SetBlendMode(paint.blend_mode);
923924

924925
// If there are no vertex color or texture coordinates. Or if there
@@ -1011,7 +1012,7 @@ void Canvas::DrawAtlas(const std::shared_ptr<Image>& atlas,
10111012

10121013
Entity entity;
10131014
entity.SetTransform(GetCurrentTransform());
1014-
entity.SetClipDepth(GetClipDepth());
1015+
entity.SetClipDepth(GetClipHeight());
10151016
entity.SetBlendMode(paint.blend_mode);
10161017
entity.SetContents(paint.WithFilters(contents));
10171018

impeller/aiks/canvas.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct CanvasStackEntry {
3232
Matrix transform;
3333
// |cull_rect| is conservative screen-space bounds of the clipped output area
3434
std::optional<Rect> cull_rect;
35-
size_t clip_depth = 0u;
35+
size_t clip_height = 0u;
3636
// The number of clips tracked for this canvas stack entry.
3737
size_t num_clips = 0u;
3838
Entity::RenderingMode rendering_mode = Entity::RenderingMode::kDirect;
@@ -192,7 +192,7 @@ class Canvas {
192192

193193
EntityPass& GetCurrentPass();
194194

195-
size_t GetClipDepth() const;
195+
size_t GetClipHeight() const;
196196

197197
void AddEntityToCurrentPass(Entity entity);
198198

impeller/entity/contents/atlas_contents.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ bool AtlasContents::Render(const ContentContext& renderer,
240240
SPrintF("DrawAtlas Blend (%s)", BlendModeToString(blend_mode_)));
241241
#endif // IMPELLER_DEBUG
242242
pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
243-
pass.SetStencilReference(entity.GetClipDepth());
244243
pass.SetPipeline(
245244
renderer.GetPorterDuffBlendPipeline(OptionsFromPass(pass)));
246245

@@ -410,7 +409,6 @@ bool AtlasTextureContents::Render(const ContentContext& renderer,
410409

411410
auto options = OptionsFromPassAndEntity(pass, entity);
412411
pass.SetPipeline(renderer.GetTexturePipeline(options));
413-
pass.SetStencilReference(entity.GetClipDepth());
414412
pass.SetVertexBuffer(vertex_builder.CreateVertexBuffer(host_buffer));
415413
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
416414
FS::BindTextureSampler(pass, texture,
@@ -498,7 +496,6 @@ bool AtlasColorContents::Render(const ContentContext& renderer,
498496
auto opts = OptionsFromPassAndEntity(pass, entity);
499497
opts.blend_mode = BlendMode::kSourceOver;
500498
pass.SetPipeline(renderer.GetGeometryColorPipeline(opts));
501-
pass.SetStencilReference(entity.GetClipDepth());
502499
pass.SetVertexBuffer(vertex_builder.CreateVertexBuffer(host_buffer));
503500
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
504501
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));

impeller/entity/contents/clip_contents.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ ClipRestoreContents::ClipRestoreContents() = default;
191191

192192
ClipRestoreContents::~ClipRestoreContents() = default;
193193

194+
void ClipRestoreContents::SetRestoreHeight(size_t clip_height) {
195+
restore_height_ = clip_height;
196+
}
197+
198+
size_t ClipRestoreContents::GetRestoreHeight() const {
199+
return restore_height_;
200+
}
201+
194202
void ClipRestoreContents::SetRestoreCoverage(
195203
std::optional<Rect> restore_coverage) {
196204
restore_coverage_ = restore_coverage;
@@ -230,7 +238,7 @@ bool ClipRestoreContents::Render(const ContentContext& renderer,
230238
options.stencil_mode = ContentContextOptions::StencilMode::kLegacyClipRestore;
231239
options.primitive_type = PrimitiveType::kTriangleStrip;
232240
pass.SetPipeline(renderer.GetClipPipeline(options));
233-
pass.SetStencilReference(entity.GetClipDepth());
241+
pass.SetStencilReference(0);
234242

235243
// Create a rect that covers either the given restore area, or the whole
236244
// render target texture.

impeller/entity/contents/clip_contents.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class ClipRestoreContents final : public Contents {
6363

6464
~ClipRestoreContents();
6565

66+
void SetRestoreHeight(size_t clip_height);
67+
68+
size_t GetRestoreHeight() const;
69+
6670
/// @brief The area on the pass texture where this clip restore will be
6771
/// applied. If unset, the entire pass texture will be restored.
6872
///
@@ -94,6 +98,7 @@ class ClipRestoreContents final : public Contents {
9498

9599
private:
96100
std::optional<Rect> restore_coverage_;
101+
size_t restore_height_ = 0;
97102

98103
ClipRestoreContents(const ClipRestoreContents&) = delete;
99104

impeller/entity/contents/color_source_contents.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ class ColorSourceContents : public Contents {
229229
auto restore = ClipRestoreContents();
230230
restore.SetRestoreCoverage(GetCoverage(entity));
231231
Entity restore_entity = entity.Clone();
232-
restore_entity.SetClipDepth(0);
233232
return restore.Render(renderer, restore_entity, pass);
234233
}
235234
return true;

impeller/entity/contents/filters/blend_filter_contents.cc

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,14 @@ static std::optional<Entity> AdvancedBlend(
111111
if (!dst_snapshot.has_value()) {
112112
return std::nullopt;
113113
}
114-
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode(),
115-
entity.GetClipDepth());
114+
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode());
116115
}
117116
auto maybe_src_uvs = src_snapshot->GetCoverageUVs(coverage);
118117
if (!maybe_src_uvs.has_value()) {
119118
if (!dst_snapshot.has_value()) {
120119
return std::nullopt;
121120
}
122-
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode(),
123-
entity.GetClipDepth());
121+
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode());
124122
}
125123
src_uvs = maybe_src_uvs.value();
126124
}
@@ -253,7 +251,7 @@ static std::optional<Entity> AdvancedBlend(
253251
? 1.0f
254252
: dst_snapshot->opacity) *
255253
alpha.value_or(1.0)},
256-
entity.GetBlendMode(), entity.GetClipDepth());
254+
entity.GetBlendMode());
257255
}
258256

259257
std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
@@ -295,7 +293,6 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
295293
BlendModeToString(blend_mode)));
296294
#endif // IMPELLER_DEBUG
297295
pass.SetVertexBuffer(std::move(vtx_buffer));
298-
pass.SetStencilReference(entity.GetClipDepth());
299296
auto options = OptionsFromPass(pass);
300297
options.primitive_type = PrimitiveType::kTriangleStrip;
301298

@@ -397,7 +394,6 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
397394

398395
Entity sub_entity;
399396
sub_entity.SetContents(std::move(contents));
400-
sub_entity.SetClipDepth(entity.GetClipDepth());
401397

402398
return sub_entity;
403399
}
@@ -422,8 +418,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
422418
}
423419

424420
if (blend_mode == BlendMode::kDestination) {
425-
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode(),
426-
entity.GetClipDepth());
421+
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode());
427422
}
428423

429424
RenderProc render_proc = [foreground_color, dst_snapshot, blend_mode,
@@ -450,7 +445,6 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
450445
BlendModeToString(blend_mode)));
451446
#endif // IMPELLER_DEBUG
452447
pass.SetVertexBuffer(std::move(vtx_buffer));
453-
pass.SetStencilReference(entity.GetClipDepth());
454448
auto options = OptionsFromPass(pass);
455449
options.primitive_type = PrimitiveType::kTriangleStrip;
456450
pass.SetPipeline(renderer.GetPorterDuffBlendPipeline(options));
@@ -501,7 +495,6 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
501495

502496
Entity sub_entity;
503497
sub_entity.SetContents(std::move(contents));
504-
sub_entity.SetClipDepth(entity.GetClipDepth());
505498

506499
return sub_entity;
507500
}
@@ -667,7 +660,7 @@ static std::optional<Entity> PipelineBlend(
667660
? 1.0f
668661
: dst_snapshot->opacity) *
669662
alpha.value_or(1.0)},
670-
entity.GetBlendMode(), entity.GetClipDepth());
663+
entity.GetBlendMode());
671664
}
672665

673666
#define BLEND_CASE(mode) \

impeller/entity/contents/filters/border_mask_blur_filter_contents.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ std::optional<Entity> BorderMaskBlurFilterContents::RenderFilter(
118118
pass.SetCommandLabel("Border Mask Blur Filter");
119119
pass.SetPipeline(renderer.GetBorderMaskBlurPipeline(options));
120120
pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
121-
pass.SetStencilReference(entity.GetClipDepth());
122121

123122
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
124123
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
@@ -139,7 +138,6 @@ std::optional<Entity> BorderMaskBlurFilterContents::RenderFilter(
139138

140139
Entity sub_entity;
141140
sub_entity.SetContents(std::move(contents));
142-
sub_entity.SetClipDepth(entity.GetClipDepth());
143141
sub_entity.SetBlendMode(entity.GetBlendMode());
144142
return sub_entity;
145143
}

impeller/entity/contents/filters/color_matrix_filter_contents.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ std::optional<Entity> ColorMatrixFilterContents::RenderFilter(
5656
const ContentContext& renderer,
5757
const Entity& entity, RenderPass& pass) -> bool {
5858
pass.SetCommandLabel("Color Matrix Filter");
59-
pass.SetStencilReference(entity.GetClipDepth());
6059

6160
auto options = OptionsFromPassAndEntity(pass, entity);
6261
options.primitive_type = PrimitiveType::kTriangleStrip;
@@ -116,7 +115,6 @@ std::optional<Entity> ColorMatrixFilterContents::RenderFilter(
116115

117116
Entity sub_entity;
118117
sub_entity.SetContents(std::move(contents));
119-
sub_entity.SetClipDepth(entity.GetClipDepth());
120118
sub_entity.SetBlendMode(entity.GetBlendMode());
121119
return sub_entity;
122120
}

0 commit comments

Comments
 (0)