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

[Impeller] Remove old clip height tracking from Entity. #52178

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2959,10 +2959,10 @@ TEST_P(AiksTest, CorrectClipDepthAssignedToEntities) {

picture.pass->IterateAllElements([&](EntityPass::Element& element) -> bool {
if (auto* subpass = std::get_if<std::unique_ptr<EntityPass>>(&element)) {
actual.push_back(subpass->get()->GetNewClipDepth());
actual.push_back(subpass->get()->GetClipDepth());
}
if (Entity* entity = std::get_if<Entity>(&element)) {
actual.push_back(entity->GetNewClipDepth());
actual.push_back(entity->GetClipDepth());
}
return true;
});
Expand Down
23 changes: 4 additions & 19 deletions impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Canvas::~Canvas() = default;
void Canvas::Initialize(std::optional<Rect> cull_rect) {
initial_cull_rect_ = cull_rect;
base_pass_ = std::make_unique<EntityPass>();
base_pass_->SetNewClipDepth(++current_depth_);
base_pass_->SetClipDepth(++current_depth_);
current_pass_ = base_pass_.get();
transform_stack_.emplace_back(CanvasStackEntry{.cull_rect = cull_rect});
FML_DCHECK(GetSaveCount() == 1u);
Expand Down Expand Up @@ -244,7 +244,7 @@ void Canvas::Save(bool create_subpass,
subpass->SetBlendMode(blend_mode);
current_pass_ = GetCurrentPass().AddSubpass(std::move(subpass));
current_pass_->SetTransform(transform_stack_.back().transform);
current_pass_->SetClipDepth(transform_stack_.back().clip_height);
current_pass_->SetClipHeight(transform_stack_.back().clip_height);
}
transform_stack_.emplace_back(entry);
}
Expand All @@ -259,7 +259,7 @@ bool Canvas::Restore() {

if (transform_stack_.back().rendering_mode ==
Entity::RenderingMode::kSubpass) {
current_pass_->SetNewClipDepth(++current_depth_);
current_pass_->SetClipDepth(++current_depth_);
current_pass_ = GetCurrentPass().GetSuperpass();
FML_DCHECK(current_pass_);
}
Expand Down Expand Up @@ -336,7 +336,6 @@ void Canvas::RestoreToCount(size_t count) {
void Canvas::DrawPath(const Path& path, const Paint& paint) {
Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetClipDepth(GetClipHeight());
entity.SetBlendMode(paint.blend_mode);
entity.SetContents(CreatePathContentsWithFilters(paint, path));

Expand All @@ -346,7 +345,6 @@ void Canvas::DrawPath(const Path& path, const Paint& paint) {
void Canvas::DrawPaint(const Paint& paint) {
Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetClipDepth(GetClipHeight());
entity.SetBlendMode(paint.blend_mode);
entity.SetContents(CreateCoverContentsWithFilters(paint));

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

Entity blurred_rrect_entity;
blurred_rrect_entity.SetTransform(GetCurrentTransform());
blurred_rrect_entity.SetClipDepth(GetClipHeight());
blurred_rrect_entity.SetBlendMode(rrect_paint.blend_mode);

rrect_paint.mask_blur_descriptor = std::nullopt;
Expand All @@ -447,7 +444,6 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
// Then, draw the non-blurred RRect on top.
Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetClipDepth(GetClipHeight());
entity.SetBlendMode(rrect_paint.blend_mode);
entity.SetContents(CreateContentsForGeometryWithFilters(
rrect_paint, Geometry::MakeRoundRect(rect, corner_radii)));
Expand All @@ -474,7 +470,6 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
void Canvas::DrawLine(const Point& p0, const Point& p1, const Paint& paint) {
Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetClipDepth(GetClipHeight());
entity.SetBlendMode(paint.blend_mode);
entity.SetContents(CreateContentsForGeometryWithFilters(
paint, Geometry::MakeLine(p0, p1, paint.stroke_width, paint.stroke_cap)));
Expand All @@ -494,7 +489,6 @@ void Canvas::DrawRect(const Rect& rect, const Paint& paint) {

Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetClipDepth(GetClipHeight());
entity.SetBlendMode(paint.blend_mode);
entity.SetContents(
CreateContentsForGeometryWithFilters(paint, Geometry::MakeRect(rect)));
Expand All @@ -521,7 +515,6 @@ void Canvas::DrawOval(const Rect& rect, const Paint& paint) {

Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetClipDepth(GetClipHeight());
entity.SetBlendMode(paint.blend_mode);
entity.SetContents(
CreateContentsForGeometryWithFilters(paint, Geometry::MakeOval(rect)));
Expand All @@ -539,7 +532,6 @@ void Canvas::DrawRRect(const Rect& rect,
if (paint.style == Paint::Style::kFill) {
Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetClipDepth(GetClipHeight());
entity.SetBlendMode(paint.blend_mode);
entity.SetContents(CreateContentsForGeometryWithFilters(
paint, Geometry::MakeRoundRect(rect, corner_radii)));
Expand Down Expand Up @@ -568,7 +560,6 @@ void Canvas::DrawCircle(const Point& center,

Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetClipDepth(GetClipHeight());
entity.SetBlendMode(paint.blend_mode);
auto geometry =
paint.style == Paint::Style::kStroke
Expand Down Expand Up @@ -680,7 +671,6 @@ void Canvas::ClipGeometry(const std::shared_ptr<Geometry>& geometry,
Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetContents(std::move(contents));
entity.SetClipDepth(GetClipHeight());

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

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

Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetClipDepth(GetClipHeight());
entity.SetBlendMode(paint.blend_mode);
entity.SetContents(CreateContentsForGeometryWithFilters(
paint,
Expand Down Expand Up @@ -791,7 +780,6 @@ void Canvas::DrawImageRect(const std::shared_ptr<Image>& image,

Entity entity;
entity.SetBlendMode(paint.blend_mode);
entity.SetClipDepth(GetClipHeight());
entity.SetContents(paint.WithFilters(contents));
entity.SetTransform(GetCurrentTransform());

Expand Down Expand Up @@ -824,7 +812,7 @@ size_t Canvas::GetClipHeight() const {
}

void Canvas::AddEntityToCurrentPass(Entity entity) {
entity.SetNewClipDepth(++current_depth_);
entity.SetClipDepth(++current_depth_);
GetCurrentPass().AddEntity(std::move(entity));
}

Expand Down Expand Up @@ -867,7 +855,6 @@ void Canvas::DrawTextFrame(const std::shared_ptr<TextFrame>& text_frame,
Point position,
const Paint& paint) {
Entity entity;
entity.SetClipDepth(GetClipHeight());
entity.SetBlendMode(paint.blend_mode);

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

Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetClipDepth(GetClipHeight());
entity.SetBlendMode(paint.blend_mode);

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

Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetClipDepth(GetClipHeight());
entity.SetBlendMode(paint.blend_mode);
entity.SetContents(paint.WithFilters(contents));

Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/clip_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ static Scalar GetShaderClipDepth(const Entity& entity) {
// Draw the clip at the max of the clip entity's depth slice, so that other
// draw calls with this same depth value will be culled even if they have a
// perspective transform.
return std::nextafterf(
Entity::GetShaderClipDepth(entity.GetNewClipDepth() + 1), 0.0f);
return std::nextafterf(Entity::GetShaderClipDepth(entity.GetClipDepth() + 1),
0.0f);
}

/*******************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/filters/filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool FilterContents::Render(const ContentContext& renderer,
if (!maybe_entity.has_value()) {
return true;
}
maybe_entity->SetNewClipDepth(entity.GetNewClipDepth());
maybe_entity->SetClipDepth(entity.GetClipDepth());
return maybe_entity->Render(renderer, pass);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ Entity ApplyClippedBlurStyle(Entity::ClipOperation clip_operation,
blur_transform](const ContentContext& renderer, const Entity& entity,
RenderPass& pass) mutable {
bool result = true;
clipper.SetNewClipDepth(entity.GetNewClipDepth());
clipper.SetClipDepth(entity.GetClipDepth());
clipper.SetTransform(entity.GetTransform() * entity_transform);
result = clipper.Render(renderer, pass) && result;
blur_entity.SetNewClipDepth(entity.GetNewClipDepth());
blur_entity.SetClipDepth(entity.GetClipDepth());
blur_entity.SetTransform(entity.GetTransform() * blur_transform);
result = blur_entity.Render(renderer, pass) && result;
return result;
Expand Down Expand Up @@ -277,12 +277,12 @@ Entity ApplyBlurStyle(FilterContents::BlurStyle blur_style,
const Entity& entity,
RenderPass& pass) mutable {
bool result = true;
blur_entity.SetNewClipDepth(entity.GetNewClipDepth());
blur_entity.SetClipDepth(entity.GetClipDepth());
blur_entity.SetTransform(entity.GetTransform() * blurred_transform);
result = result && blur_entity.Render(renderer, pass);
snapshot_entity.SetTransform(entity.GetTransform() *
snapshot_transform);
snapshot_entity.SetNewClipDepth(entity.GetNewClipDepth());
snapshot_entity.SetClipDepth(entity.GetClipDepth());
result = result && snapshot_entity.Render(renderer, pass);
return result;
}),
Expand Down
14 changes: 1 addition & 13 deletions impeller/entity/entity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,15 @@ uint32_t Entity::GetClipDepth() const {
return clip_depth_;
}

void Entity::SetNewClipDepth(uint32_t clip_depth) {
new_clip_depth_ = clip_depth;
}

uint32_t Entity::GetNewClipDepth() const {
return new_clip_depth_;
}

Scalar Entity::GetShaderClipDepth() const {
return Entity::GetShaderClipDepth(new_clip_depth_);
return Entity::GetShaderClipDepth(clip_depth_);
}

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

void Entity::IncrementStencilDepth(uint32_t increment) {
clip_depth_ += increment;
}

void Entity::SetBlendMode(BlendMode blend_mode) {
blend_mode_ = blend_mode;
}
Expand Down
9 changes: 1 addition & 8 deletions impeller/entity/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,8 @@ class Entity {

void SetClipDepth(uint32_t clip_depth);

void IncrementStencilDepth(uint32_t increment);

uint32_t GetClipDepth() const;

void SetNewClipDepth(uint32_t clip_depth);

uint32_t GetNewClipDepth() const;

float GetShaderClipDepth() const;

static float GetShaderClipDepth(uint32_t clip_depth);
Expand Down Expand Up @@ -141,8 +135,7 @@ class Entity {
Matrix transform_;
std::shared_ptr<Contents> contents_;
BlendMode blend_mode_ = BlendMode::kSourceOver;
uint32_t clip_depth_ = 0u;
uint32_t new_clip_depth_ = 1u;
uint32_t clip_depth_ = 1u;
mutable Capture capture_;
};

Expand Down
32 changes: 15 additions & 17 deletions impeller/entity/entity_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void EntityPass::PopClips(size_t num_clips, uint64_t depth) {
FML_DCHECK(active_clips_.back() < elements_.size());
Entity* element = std::get_if<Entity>(&elements_[active_clips_.back()]);
FML_DCHECK(element);
element->SetNewClipDepth(depth);
element->SetClipDepth(depth);
active_clips_.pop_back();
}
}
Expand Down Expand Up @@ -591,7 +591,7 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
Point(), // local_pass_position
pass_depth, // pass_depth
clip_coverage_stack, // clip_coverage_stack
clip_depth_, // clip_height_floor
clip_height_, // clip_height_floor
nullptr, // backdrop_filter_contents
pass_context.GetRenderPass(pass_depth) // collapsed_parent_pass
)) {
Expand Down Expand Up @@ -690,7 +690,7 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
// save layers may transform the subpass texture after it's rendered,
// causing parent clip coverage to get misaligned with the actual area that
// the subpass will affect in the parent pass.
clip_coverage_stack.PushSubpass(subpass_coverage, subpass->clip_depth_);
clip_coverage_stack.PushSubpass(subpass_coverage, subpass->clip_height_);

// Stencil textures aren't shared between EntityPasses (as much of the
// time they are transient).
Expand All @@ -704,7 +704,7 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
global_pass_position, // local_pass_position
++pass_depth, // pass_depth
clip_coverage_stack, // clip_coverage_stack
subpass->clip_depth_, // clip_height_floor
subpass->clip_height_, // clip_height_floor
subpass_backdrop_filter_contents // backdrop_filter_contents
)) {
// Validation error messages are triggered for all `OnRender()` failure
Expand Down Expand Up @@ -738,10 +738,9 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
Entity element_entity;
Capture subpass_texture_capture =
capture.CreateChild("Entity (Subpass texture)");
element_entity.SetNewClipDepth(subpass->new_clip_depth_);
element_entity.SetClipDepth(subpass->clip_depth_);
element_entity.SetCapture(subpass_texture_capture);
element_entity.SetContents(std::move(offscreen_texture_contents));
element_entity.SetClipDepth(subpass->clip_depth_);
element_entity.SetBlendMode(subpass->blend_mode_);
element_entity.SetTransform(subpass_texture_capture.AddMatrix(
"Transform",
Expand Down Expand Up @@ -800,7 +799,7 @@ bool EntityPass::RenderElement(Entity& element_entity,
Entity msaa_backdrop_entity;
msaa_backdrop_entity.SetContents(std::move(msaa_backdrop_contents));
msaa_backdrop_entity.SetBlendMode(BlendMode::kSource);
msaa_backdrop_entity.SetNewClipDepth(std::numeric_limits<uint32_t>::max());
msaa_backdrop_entity.SetClipDepth(std::numeric_limits<uint32_t>::max());
if (!msaa_backdrop_entity.Render(renderer, *result.pass)) {
VALIDATION_LOG << "Failed to render MSAA backdrop filter entity.";
return false;
Expand Down Expand Up @@ -919,8 +918,7 @@ bool EntityPass::OnRender(
backdrop_entity.SetContents(std::move(backdrop_filter_contents));
backdrop_entity.SetTransform(
Matrix::MakeTranslation(Vector3(-local_pass_position)));
backdrop_entity.SetClipDepth(clip_height_floor);
backdrop_entity.SetNewClipDepth(std::numeric_limits<uint32_t>::max());
backdrop_entity.SetClipDepth(std::numeric_limits<uint32_t>::max());

RenderElement(backdrop_entity, clip_height_floor, pass_context, pass_depth,
renderer, clip_coverage_stack, global_pass_position);
Expand Down Expand Up @@ -1156,20 +1154,20 @@ void EntityPass::SetTransform(Matrix transform) {
transform_ = transform;
}

void EntityPass::SetClipDepth(size_t clip_depth) {
clip_depth_ = clip_depth;
void EntityPass::SetClipHeight(size_t clip_height) {
clip_height_ = clip_height;
}

size_t EntityPass::GetClipDepth() const {
return clip_depth_;
size_t EntityPass::GetClipHeight() const {
return clip_height_;
}

void EntityPass::SetNewClipDepth(size_t clip_depth) {
new_clip_depth_ = clip_depth;
void EntityPass::SetClipDepth(size_t clip_depth) {
clip_depth_ = clip_depth;
}

uint32_t EntityPass::GetNewClipDepth() const {
return new_clip_depth_;
uint32_t EntityPass::GetClipDepth() const {
return clip_depth_;
}

void EntityPass::SetBlendMode(BlendMode blend_mode) {
Expand Down
12 changes: 6 additions & 6 deletions impeller/entity/entity_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ class EntityPass {

void SetTransform(Matrix transform);

void SetClipDepth(size_t clip_depth);
void SetClipHeight(size_t clip_height);

size_t GetClipDepth() const;
size_t GetClipHeight() const;

void SetNewClipDepth(size_t clip_depth);
void SetClipDepth(size_t clip_depth);

uint32_t GetNewClipDepth() const;
uint32_t GetClipDepth() const;

void SetBlendMode(BlendMode blend_mode);

Expand Down Expand Up @@ -337,8 +337,8 @@ class EntityPass {

EntityPass* superpass_ = nullptr;
Matrix transform_;
size_t clip_depth_ = 0u;
uint32_t new_clip_depth_ = 1u;
size_t clip_height_ = 0u;
uint32_t clip_depth_ = 1u;
BlendMode blend_mode_ = BlendMode::kSourceOver;
bool flood_clip_ = false;
bool enable_offscreen_debug_checkerboard_ = false;
Expand Down
Loading