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

Commit ade5095

Browse files
authored
[Impeller] Remove old clip height tracking from Entity. (#52178)
And rename clip depth accessors and members. After this, I'm going to attempt to remove the need for tracking clip height altogether in EntityPass as well.
1 parent cc73c5c commit ade5095

11 files changed

+37
-76
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,10 +2959,10 @@ TEST_P(AiksTest, CorrectClipDepthAssignedToEntities) {
29592959

29602960
picture.pass->IterateAllElements([&](EntityPass::Element& element) -> bool {
29612961
if (auto* subpass = std::get_if<std::unique_ptr<EntityPass>>(&element)) {
2962-
actual.push_back(subpass->get()->GetNewClipDepth());
2962+
actual.push_back(subpass->get()->GetClipDepth());
29632963
}
29642964
if (Entity* entity = std::get_if<Entity>(&element)) {
2965-
actual.push_back(entity->GetNewClipDepth());
2965+
actual.push_back(entity->GetClipDepth());
29662966
}
29672967
return true;
29682968
});

impeller/aiks/canvas.cc

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Canvas::~Canvas() = default;
163163
void Canvas::Initialize(std::optional<Rect> cull_rect) {
164164
initial_cull_rect_ = cull_rect;
165165
base_pass_ = std::make_unique<EntityPass>();
166-
base_pass_->SetNewClipDepth(++current_depth_);
166+
base_pass_->SetClipDepth(++current_depth_);
167167
current_pass_ = base_pass_.get();
168168
transform_stack_.emplace_back(CanvasStackEntry{.cull_rect = cull_rect});
169169
FML_DCHECK(GetSaveCount() == 1u);
@@ -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_height);
247+
current_pass_->SetClipHeight(transform_stack_.back().clip_height);
248248
}
249249
transform_stack_.emplace_back(entry);
250250
}
@@ -259,7 +259,7 @@ bool Canvas::Restore() {
259259

260260
if (transform_stack_.back().rendering_mode ==
261261
Entity::RenderingMode::kSubpass) {
262-
current_pass_->SetNewClipDepth(++current_depth_);
262+
current_pass_->SetClipDepth(++current_depth_);
263263
current_pass_ = GetCurrentPass().GetSuperpass();
264264
FML_DCHECK(current_pass_);
265265
}
@@ -336,7 +336,6 @@ 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(GetClipHeight());
340339
entity.SetBlendMode(paint.blend_mode);
341340
entity.SetContents(CreatePathContentsWithFilters(paint, path));
342341

@@ -346,7 +345,6 @@ void Canvas::DrawPath(const Path& path, const Paint& paint) {
346345
void Canvas::DrawPaint(const Paint& paint) {
347346
Entity entity;
348347
entity.SetTransform(GetCurrentTransform());
349-
entity.SetClipDepth(GetClipHeight());
350348
entity.SetBlendMode(paint.blend_mode);
351349
entity.SetContents(CreateCoverContentsWithFilters(paint));
352350

@@ -427,7 +425,6 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
427425

428426
Entity blurred_rrect_entity;
429427
blurred_rrect_entity.SetTransform(GetCurrentTransform());
430-
blurred_rrect_entity.SetClipDepth(GetClipHeight());
431428
blurred_rrect_entity.SetBlendMode(rrect_paint.blend_mode);
432429

433430
rrect_paint.mask_blur_descriptor = std::nullopt;
@@ -447,7 +444,6 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
447444
// Then, draw the non-blurred RRect on top.
448445
Entity entity;
449446
entity.SetTransform(GetCurrentTransform());
450-
entity.SetClipDepth(GetClipHeight());
451447
entity.SetBlendMode(rrect_paint.blend_mode);
452448
entity.SetContents(CreateContentsForGeometryWithFilters(
453449
rrect_paint, Geometry::MakeRoundRect(rect, corner_radii)));
@@ -474,7 +470,6 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
474470
void Canvas::DrawLine(const Point& p0, const Point& p1, const Paint& paint) {
475471
Entity entity;
476472
entity.SetTransform(GetCurrentTransform());
477-
entity.SetClipDepth(GetClipHeight());
478473
entity.SetBlendMode(paint.blend_mode);
479474
entity.SetContents(CreateContentsForGeometryWithFilters(
480475
paint, Geometry::MakeLine(p0, p1, paint.stroke_width, paint.stroke_cap)));
@@ -494,7 +489,6 @@ void Canvas::DrawRect(const Rect& rect, const Paint& paint) {
494489

495490
Entity entity;
496491
entity.SetTransform(GetCurrentTransform());
497-
entity.SetClipDepth(GetClipHeight());
498492
entity.SetBlendMode(paint.blend_mode);
499493
entity.SetContents(
500494
CreateContentsForGeometryWithFilters(paint, Geometry::MakeRect(rect)));
@@ -521,7 +515,6 @@ void Canvas::DrawOval(const Rect& rect, const Paint& paint) {
521515

522516
Entity entity;
523517
entity.SetTransform(GetCurrentTransform());
524-
entity.SetClipDepth(GetClipHeight());
525518
entity.SetBlendMode(paint.blend_mode);
526519
entity.SetContents(
527520
CreateContentsForGeometryWithFilters(paint, Geometry::MakeOval(rect)));
@@ -539,7 +532,6 @@ void Canvas::DrawRRect(const Rect& rect,
539532
if (paint.style == Paint::Style::kFill) {
540533
Entity entity;
541534
entity.SetTransform(GetCurrentTransform());
542-
entity.SetClipDepth(GetClipHeight());
543535
entity.SetBlendMode(paint.blend_mode);
544536
entity.SetContents(CreateContentsForGeometryWithFilters(
545537
paint, Geometry::MakeRoundRect(rect, corner_radii)));
@@ -568,7 +560,6 @@ void Canvas::DrawCircle(const Point& center,
568560

569561
Entity entity;
570562
entity.SetTransform(GetCurrentTransform());
571-
entity.SetClipDepth(GetClipHeight());
572563
entity.SetBlendMode(paint.blend_mode);
573564
auto geometry =
574565
paint.style == Paint::Style::kStroke
@@ -680,7 +671,6 @@ void Canvas::ClipGeometry(const std::shared_ptr<Geometry>& geometry,
680671
Entity entity;
681672
entity.SetTransform(GetCurrentTransform());
682673
entity.SetContents(std::move(contents));
683-
entity.SetClipDepth(GetClipHeight());
684674

685675
GetCurrentPass().PushClip(std::move(entity));
686676

@@ -735,7 +725,6 @@ void Canvas::DrawPoints(std::vector<Point> points,
735725

736726
Entity entity;
737727
entity.SetTransform(GetCurrentTransform());
738-
entity.SetClipDepth(GetClipHeight());
739728
entity.SetBlendMode(paint.blend_mode);
740729
entity.SetContents(CreateContentsForGeometryWithFilters(
741730
paint,
@@ -791,7 +780,6 @@ void Canvas::DrawImageRect(const std::shared_ptr<Image>& image,
791780

792781
Entity entity;
793782
entity.SetBlendMode(paint.blend_mode);
794-
entity.SetClipDepth(GetClipHeight());
795783
entity.SetContents(paint.WithFilters(contents));
796784
entity.SetTransform(GetCurrentTransform());
797785

@@ -824,7 +812,7 @@ size_t Canvas::GetClipHeight() const {
824812
}
825813

826814
void Canvas::AddEntityToCurrentPass(Entity entity) {
827-
entity.SetNewClipDepth(++current_depth_);
815+
entity.SetClipDepth(++current_depth_);
828816
GetCurrentPass().AddEntity(std::move(entity));
829817
}
830818

@@ -867,7 +855,6 @@ void Canvas::DrawTextFrame(const std::shared_ptr<TextFrame>& text_frame,
867855
Point position,
868856
const Paint& paint) {
869857
Entity entity;
870-
entity.SetClipDepth(GetClipHeight());
871858
entity.SetBlendMode(paint.blend_mode);
872859

873860
auto text_contents = std::make_shared<TextContents>();
@@ -919,7 +906,6 @@ void Canvas::DrawVertices(const std::shared_ptr<VerticesGeometry>& vertices,
919906

920907
Entity entity;
921908
entity.SetTransform(GetCurrentTransform());
922-
entity.SetClipDepth(GetClipHeight());
923909
entity.SetBlendMode(paint.blend_mode);
924910

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

1013999
Entity entity;
10141000
entity.SetTransform(GetCurrentTransform());
1015-
entity.SetClipDepth(GetClipHeight());
10161001
entity.SetBlendMode(paint.blend_mode);
10171002
entity.SetContents(paint.WithFilters(contents));
10181003

impeller/entity/contents/clip_contents.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ static Scalar GetShaderClipDepth(const Entity& entity) {
1919
// Draw the clip at the max of the clip entity's depth slice, so that other
2020
// draw calls with this same depth value will be culled even if they have a
2121
// perspective transform.
22-
return std::nextafterf(
23-
Entity::GetShaderClipDepth(entity.GetNewClipDepth() + 1), 0.0f);
22+
return std::nextafterf(Entity::GetShaderClipDepth(entity.GetClipDepth() + 1),
23+
0.0f);
2424
}
2525

2626
/*******************************************************************************

impeller/entity/contents/filters/filter_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ bool FilterContents::Render(const ContentContext& renderer,
144144
if (!maybe_entity.has_value()) {
145145
return true;
146146
}
147-
maybe_entity->SetNewClipDepth(entity.GetNewClipDepth());
147+
maybe_entity->SetClipDepth(entity.GetClipDepth());
148148
return maybe_entity->Render(renderer, pass);
149149
}
150150

impeller/entity/contents/filters/gaussian_blur_filter_contents.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ Entity ApplyClippedBlurStyle(Entity::ClipOperation clip_operation,
226226
blur_transform](const ContentContext& renderer, const Entity& entity,
227227
RenderPass& pass) mutable {
228228
bool result = true;
229-
clipper.SetNewClipDepth(entity.GetNewClipDepth());
229+
clipper.SetClipDepth(entity.GetClipDepth());
230230
clipper.SetTransform(entity.GetTransform() * entity_transform);
231231
result = clipper.Render(renderer, pass) && result;
232-
blur_entity.SetNewClipDepth(entity.GetNewClipDepth());
232+
blur_entity.SetClipDepth(entity.GetClipDepth());
233233
blur_entity.SetTransform(entity.GetTransform() * blur_transform);
234234
result = blur_entity.Render(renderer, pass) && result;
235235
return result;
@@ -277,12 +277,12 @@ Entity ApplyBlurStyle(FilterContents::BlurStyle blur_style,
277277
const Entity& entity,
278278
RenderPass& pass) mutable {
279279
bool result = true;
280-
blur_entity.SetNewClipDepth(entity.GetNewClipDepth());
280+
blur_entity.SetClipDepth(entity.GetClipDepth());
281281
blur_entity.SetTransform(entity.GetTransform() * blurred_transform);
282282
result = result && blur_entity.Render(renderer, pass);
283283
snapshot_entity.SetTransform(entity.GetTransform() *
284284
snapshot_transform);
285-
snapshot_entity.SetNewClipDepth(entity.GetNewClipDepth());
285+
snapshot_entity.SetClipDepth(entity.GetClipDepth());
286286
result = result && snapshot_entity.Render(renderer, pass);
287287
return result;
288288
}),

impeller/entity/entity.cc

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,27 +103,15 @@ uint32_t Entity::GetClipDepth() const {
103103
return clip_depth_;
104104
}
105105

106-
void Entity::SetNewClipDepth(uint32_t clip_depth) {
107-
new_clip_depth_ = clip_depth;
108-
}
109-
110-
uint32_t Entity::GetNewClipDepth() const {
111-
return new_clip_depth_;
112-
}
113-
114106
Scalar Entity::GetShaderClipDepth() const {
115-
return Entity::GetShaderClipDepth(new_clip_depth_);
107+
return Entity::GetShaderClipDepth(clip_depth_);
116108
}
117109

118110
Scalar Entity::GetShaderClipDepth(uint32_t clip_depth) {
119111
Scalar result = std::clamp(clip_depth * kDepthEpsilon, 0.0f, 1.0f);
120112
return std::min(result, 1.0f - kDepthEpsilon);
121113
}
122114

123-
void Entity::IncrementStencilDepth(uint32_t increment) {
124-
clip_depth_ += increment;
125-
}
126-
127115
void Entity::SetBlendMode(BlendMode blend_mode) {
128116
blend_mode_ = blend_mode;
129117
}

impeller/entity/entity.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,8 @@ class Entity {
101101

102102
void SetClipDepth(uint32_t clip_depth);
103103

104-
void IncrementStencilDepth(uint32_t increment);
105-
106104
uint32_t GetClipDepth() const;
107105

108-
void SetNewClipDepth(uint32_t clip_depth);
109-
110-
uint32_t GetNewClipDepth() const;
111-
112106
float GetShaderClipDepth() const;
113107

114108
static float GetShaderClipDepth(uint32_t clip_depth);
@@ -141,8 +135,7 @@ class Entity {
141135
Matrix transform_;
142136
std::shared_ptr<Contents> contents_;
143137
BlendMode blend_mode_ = BlendMode::kSourceOver;
144-
uint32_t clip_depth_ = 0u;
145-
uint32_t new_clip_depth_ = 1u;
138+
uint32_t clip_depth_ = 1u;
146139
mutable Capture capture_;
147140
};
148141

impeller/entity/entity_pass.cc

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void EntityPass::PopClips(size_t num_clips, uint64_t depth) {
133133
FML_DCHECK(active_clips_.back() < elements_.size());
134134
Entity* element = std::get_if<Entity>(&elements_[active_clips_.back()]);
135135
FML_DCHECK(element);
136-
element->SetNewClipDepth(depth);
136+
element->SetClipDepth(depth);
137137
active_clips_.pop_back();
138138
}
139139
}
@@ -592,7 +592,7 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
592592
Point(), // local_pass_position
593593
pass_depth, // pass_depth
594594
clip_coverage_stack, // clip_coverage_stack
595-
clip_depth_, // clip_height_floor
595+
clip_height_, // clip_height_floor
596596
nullptr, // backdrop_filter_contents
597597
pass_context.GetRenderPass(pass_depth) // collapsed_parent_pass
598598
)) {
@@ -691,7 +691,7 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
691691
// save layers may transform the subpass texture after it's rendered,
692692
// causing parent clip coverage to get misaligned with the actual area that
693693
// the subpass will affect in the parent pass.
694-
clip_coverage_stack.PushSubpass(subpass_coverage, subpass->clip_depth_);
694+
clip_coverage_stack.PushSubpass(subpass_coverage, subpass->clip_height_);
695695

696696
// Stencil textures aren't shared between EntityPasses (as much of the
697697
// time they are transient).
@@ -705,7 +705,7 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
705705
global_pass_position, // local_pass_position
706706
++pass_depth, // pass_depth
707707
clip_coverage_stack, // clip_coverage_stack
708-
subpass->clip_depth_, // clip_height_floor
708+
subpass->clip_height_, // clip_height_floor
709709
subpass_backdrop_filter_contents // backdrop_filter_contents
710710
)) {
711711
// Validation error messages are triggered for all `OnRender()` failure
@@ -739,10 +739,9 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
739739
Entity element_entity;
740740
Capture subpass_texture_capture =
741741
capture.CreateChild("Entity (Subpass texture)");
742-
element_entity.SetNewClipDepth(subpass->new_clip_depth_);
742+
element_entity.SetClipDepth(subpass->clip_depth_);
743743
element_entity.SetCapture(subpass_texture_capture);
744744
element_entity.SetContents(std::move(offscreen_texture_contents));
745-
element_entity.SetClipDepth(subpass->clip_depth_);
746745
element_entity.SetBlendMode(subpass->blend_mode_);
747746
element_entity.SetTransform(subpass_texture_capture.AddMatrix(
748747
"Transform",
@@ -801,7 +800,7 @@ bool EntityPass::RenderElement(Entity& element_entity,
801800
Entity msaa_backdrop_entity;
802801
msaa_backdrop_entity.SetContents(std::move(msaa_backdrop_contents));
803802
msaa_backdrop_entity.SetBlendMode(BlendMode::kSource);
804-
msaa_backdrop_entity.SetNewClipDepth(std::numeric_limits<uint32_t>::max());
803+
msaa_backdrop_entity.SetClipDepth(std::numeric_limits<uint32_t>::max());
805804
if (!msaa_backdrop_entity.Render(renderer, *result.pass)) {
806805
VALIDATION_LOG << "Failed to render MSAA backdrop filter entity.";
807806
return false;
@@ -919,8 +918,7 @@ bool EntityPass::OnRender(
919918
backdrop_entity.SetContents(std::move(backdrop_filter_contents));
920919
backdrop_entity.SetTransform(
921920
Matrix::MakeTranslation(Vector3(-local_pass_position)));
922-
backdrop_entity.SetClipDepth(clip_height_floor);
923-
backdrop_entity.SetNewClipDepth(std::numeric_limits<uint32_t>::max());
921+
backdrop_entity.SetClipDepth(std::numeric_limits<uint32_t>::max());
924922

925923
RenderElement(backdrop_entity, clip_height_floor, pass_context, pass_depth,
926924
renderer, clip_coverage_stack, global_pass_position);
@@ -1156,20 +1154,20 @@ void EntityPass::SetTransform(Matrix transform) {
11561154
transform_ = transform;
11571155
}
11581156

1159-
void EntityPass::SetClipDepth(size_t clip_depth) {
1160-
clip_depth_ = clip_depth;
1157+
void EntityPass::SetClipHeight(size_t clip_height) {
1158+
clip_height_ = clip_height;
11611159
}
11621160

1163-
size_t EntityPass::GetClipDepth() const {
1164-
return clip_depth_;
1161+
size_t EntityPass::GetClipHeight() const {
1162+
return clip_height_;
11651163
}
11661164

1167-
void EntityPass::SetNewClipDepth(size_t clip_depth) {
1168-
new_clip_depth_ = clip_depth;
1165+
void EntityPass::SetClipDepth(size_t clip_depth) {
1166+
clip_depth_ = clip_depth;
11691167
}
11701168

1171-
uint32_t EntityPass::GetNewClipDepth() const {
1172-
return new_clip_depth_;
1169+
uint32_t EntityPass::GetClipDepth() const {
1170+
return clip_depth_;
11731171
}
11741172

11751173
void EntityPass::SetBlendMode(BlendMode blend_mode) {

impeller/entity/entity_pass.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ class EntityPass {
161161

162162
void SetTransform(Matrix transform);
163163

164-
void SetClipDepth(size_t clip_depth);
164+
void SetClipHeight(size_t clip_height);
165165

166-
size_t GetClipDepth() const;
166+
size_t GetClipHeight() const;
167167

168-
void SetNewClipDepth(size_t clip_depth);
168+
void SetClipDepth(size_t clip_depth);
169169

170-
uint32_t GetNewClipDepth() const;
170+
uint32_t GetClipDepth() const;
171171

172172
void SetBlendMode(BlendMode blend_mode);
173173

@@ -337,8 +337,8 @@ class EntityPass {
337337

338338
EntityPass* superpass_ = nullptr;
339339
Matrix transform_;
340-
size_t clip_depth_ = 0u;
341-
uint32_t new_clip_depth_ = 1u;
340+
size_t clip_height_ = 0u;
341+
uint32_t clip_depth_ = 1u;
342342
BlendMode blend_mode_ = BlendMode::kSourceOver;
343343
bool flood_clip_ = false;
344344
bool enable_offscreen_debug_checkerboard_ = false;

0 commit comments

Comments
 (0)