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

[Impeller] Only set the stencil ref for StC draws. #52006

Merged
merged 4 commits into from
Apr 11, 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
45 changes: 23 additions & 22 deletions impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void Canvas::Save(bool create_subpass,
auto entry = CanvasStackEntry{};
entry.transform = transform_stack_.back().transform;
entry.cull_rect = transform_stack_.back().cull_rect;
entry.clip_depth = transform_stack_.back().clip_depth;
entry.clip_height = transform_stack_.back().clip_height;
if (create_subpass) {
entry.rendering_mode = Entity::RenderingMode::kSubpass;
auto subpass = std::make_unique<EntityPass>();
Expand All @@ -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_depth);
current_pass_->SetClipDepth(transform_stack_.back().clip_height);
}
transform_stack_.emplace_back(entry);
}
Expand Down Expand Up @@ -336,7 +336,7 @@ void Canvas::RestoreToCount(size_t count) {
void Canvas::DrawPath(const Path& path, const Paint& paint) {
Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetClipDepth(GetClipDepth());
entity.SetClipDepth(GetClipHeight());
entity.SetBlendMode(paint.blend_mode);
entity.SetContents(CreatePathContentsWithFilters(paint, path));

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

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

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

rrect_paint.mask_blur_descriptor = std::nullopt;
Expand All @@ -447,7 +447,7 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
// Then, draw the non-blurred RRect on top.
Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetClipDepth(GetClipDepth());
entity.SetClipDepth(GetClipHeight());
entity.SetBlendMode(rrect_paint.blend_mode);
entity.SetContents(CreateContentsForGeometryWithFilters(
rrect_paint, Geometry::MakeRoundRect(rect, corner_radii)));
Expand All @@ -474,7 +474,7 @@ 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(GetClipDepth());
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 +494,7 @@ void Canvas::DrawRect(const Rect& rect, const Paint& paint) {

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

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

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

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

++transform_stack_.back().clip_depth;
++transform_stack_.back().clip_height;
++transform_stack_.back().num_clips;
}

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

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

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

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

Expand Down Expand Up @@ -818,8 +819,8 @@ EntityPass& Canvas::GetCurrentPass() {
return *current_pass_;
}

size_t Canvas::GetClipDepth() const {
return transform_stack_.back().clip_depth;
size_t Canvas::GetClipHeight() const {
return transform_stack_.back().clip_height;
}

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

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

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions impeller/aiks/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct CanvasStackEntry {
Matrix transform;
// |cull_rect| is conservative screen-space bounds of the clipped output area
std::optional<Rect> cull_rect;
size_t clip_depth = 0u;
size_t clip_height = 0u;
// The number of clips tracked for this canvas stack entry.
size_t num_clips = 0u;
Entity::RenderingMode rendering_mode = Entity::RenderingMode::kDirect;
Expand Down Expand Up @@ -192,7 +192,7 @@ class Canvas {

EntityPass& GetCurrentPass();

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

void AddEntityToCurrentPass(Entity entity);

Expand Down
3 changes: 0 additions & 3 deletions impeller/entity/contents/atlas_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ bool AtlasContents::Render(const ContentContext& renderer,
SPrintF("DrawAtlas Blend (%s)", BlendModeToString(blend_mode_)));
#endif // IMPELLER_DEBUG
pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
pass.SetStencilReference(entity.GetClipDepth());
pass.SetPipeline(
renderer.GetPorterDuffBlendPipeline(OptionsFromPass(pass)));

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

auto options = OptionsFromPassAndEntity(pass, entity);
pass.SetPipeline(renderer.GetTexturePipeline(options));
pass.SetStencilReference(entity.GetClipDepth());
pass.SetVertexBuffer(vertex_builder.CreateVertexBuffer(host_buffer));
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
FS::BindTextureSampler(pass, texture,
Expand Down Expand Up @@ -498,7 +496,6 @@ bool AtlasColorContents::Render(const ContentContext& renderer,
auto opts = OptionsFromPassAndEntity(pass, entity);
opts.blend_mode = BlendMode::kSourceOver;
pass.SetPipeline(renderer.GetGeometryColorPipeline(opts));
pass.SetStencilReference(entity.GetClipDepth());
pass.SetVertexBuffer(vertex_builder.CreateVertexBuffer(host_buffer));
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
Expand Down
10 changes: 9 additions & 1 deletion impeller/entity/contents/clip_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ ClipRestoreContents::ClipRestoreContents() = default;

ClipRestoreContents::~ClipRestoreContents() = default;

void ClipRestoreContents::SetRestoreHeight(size_t clip_height) {
restore_height_ = clip_height;
}

size_t ClipRestoreContents::GetRestoreHeight() const {
return restore_height_;
}

void ClipRestoreContents::SetRestoreCoverage(
std::optional<Rect> restore_coverage) {
restore_coverage_ = restore_coverage;
Expand Down Expand Up @@ -230,7 +238,7 @@ bool ClipRestoreContents::Render(const ContentContext& renderer,
options.stencil_mode = ContentContextOptions::StencilMode::kLegacyClipRestore;
options.primitive_type = PrimitiveType::kTriangleStrip;
pass.SetPipeline(renderer.GetClipPipeline(options));
pass.SetStencilReference(entity.GetClipDepth());
pass.SetStencilReference(0);

// Create a rect that covers either the given restore area, or the whole
// render target texture.
Expand Down
5 changes: 5 additions & 0 deletions impeller/entity/contents/clip_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class ClipRestoreContents final : public Contents {

~ClipRestoreContents();

void SetRestoreHeight(size_t clip_height);

size_t GetRestoreHeight() const;

/// @brief The area on the pass texture where this clip restore will be
/// applied. If unset, the entire pass texture will be restored.
///
Expand Down Expand Up @@ -94,6 +98,7 @@ class ClipRestoreContents final : public Contents {

private:
std::optional<Rect> restore_coverage_;
size_t restore_height_ = 0;

ClipRestoreContents(const ClipRestoreContents&) = delete;

Expand Down
1 change: 0 additions & 1 deletion impeller/entity/contents/color_source_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ class ColorSourceContents : public Contents {
auto restore = ClipRestoreContents();
restore.SetRestoreCoverage(GetCoverage(entity));
Entity restore_entity = entity.Clone();
restore_entity.SetClipDepth(0);
return restore.Render(renderer, restore_entity, pass);
}
return true;
Expand Down
17 changes: 5 additions & 12 deletions impeller/entity/contents/filters/blend_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,14 @@ static std::optional<Entity> AdvancedBlend(
if (!dst_snapshot.has_value()) {
return std::nullopt;
}
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode(),
entity.GetClipDepth());
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode());
}
auto maybe_src_uvs = src_snapshot->GetCoverageUVs(coverage);
if (!maybe_src_uvs.has_value()) {
if (!dst_snapshot.has_value()) {
return std::nullopt;
}
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode(),
entity.GetClipDepth());
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode());
}
src_uvs = maybe_src_uvs.value();
}
Expand Down Expand Up @@ -253,7 +251,7 @@ static std::optional<Entity> AdvancedBlend(
? 1.0f
: dst_snapshot->opacity) *
alpha.value_or(1.0)},
entity.GetBlendMode(), entity.GetClipDepth());
entity.GetBlendMode());
}

std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
Expand Down Expand Up @@ -295,7 +293,6 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
BlendModeToString(blend_mode)));
#endif // IMPELLER_DEBUG
pass.SetVertexBuffer(std::move(vtx_buffer));
pass.SetStencilReference(entity.GetClipDepth());
auto options = OptionsFromPass(pass);
options.primitive_type = PrimitiveType::kTriangleStrip;

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

Entity sub_entity;
sub_entity.SetContents(std::move(contents));
sub_entity.SetClipDepth(entity.GetClipDepth());

return sub_entity;
}
Expand All @@ -422,8 +418,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
}

if (blend_mode == BlendMode::kDestination) {
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode(),
entity.GetClipDepth());
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode());
}

RenderProc render_proc = [foreground_color, dst_snapshot, blend_mode,
Expand All @@ -450,7 +445,6 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
BlendModeToString(blend_mode)));
#endif // IMPELLER_DEBUG
pass.SetVertexBuffer(std::move(vtx_buffer));
pass.SetStencilReference(entity.GetClipDepth());
auto options = OptionsFromPass(pass);
options.primitive_type = PrimitiveType::kTriangleStrip;
pass.SetPipeline(renderer.GetPorterDuffBlendPipeline(options));
Expand Down Expand Up @@ -501,7 +495,6 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(

Entity sub_entity;
sub_entity.SetContents(std::move(contents));
sub_entity.SetClipDepth(entity.GetClipDepth());

return sub_entity;
}
Expand Down Expand Up @@ -667,7 +660,7 @@ static std::optional<Entity> PipelineBlend(
? 1.0f
: dst_snapshot->opacity) *
alpha.value_or(1.0)},
entity.GetBlendMode(), entity.GetClipDepth());
entity.GetBlendMode());
}

#define BLEND_CASE(mode) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ std::optional<Entity> BorderMaskBlurFilterContents::RenderFilter(
pass.SetCommandLabel("Border Mask Blur Filter");
pass.SetPipeline(renderer.GetBorderMaskBlurPipeline(options));
pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
pass.SetStencilReference(entity.GetClipDepth());

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

Entity sub_entity;
sub_entity.SetContents(std::move(contents));
sub_entity.SetClipDepth(entity.GetClipDepth());
sub_entity.SetBlendMode(entity.GetBlendMode());
return sub_entity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ std::optional<Entity> ColorMatrixFilterContents::RenderFilter(
const ContentContext& renderer,
const Entity& entity, RenderPass& pass) -> bool {
pass.SetCommandLabel("Color Matrix Filter");
pass.SetStencilReference(entity.GetClipDepth());

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

Entity sub_entity;
sub_entity.SetContents(std::move(contents));
sub_entity.SetClipDepth(entity.GetClipDepth());
sub_entity.SetBlendMode(entity.GetBlendMode());
return sub_entity;
}
Expand Down
Loading