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

Commit 1783fc8

Browse files
author
jonahwilliams
committed
++
1 parent df63862 commit 1783fc8

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

impeller/aiks/experimental_canvas.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,7 @@ void ExperimentalCanvas::AddClipEntityToCurrentPass(Entity entity) {
785785

786786
// Skip rendering the clip if it is fully contained by the current render
787787
// target.
788-
const std::shared_ptr<ClipContents>& clip_contents =
789-
std::static_pointer_cast<ClipContents>(entity.GetContents());
790-
if (clip_contents->CanSkip(
788+
if (entity.GetContents()->CanSkip(
791789
render_passes_.back().inline_pass_context->GetTexture()->GetSize(),
792790
entity.GetTransform())) {
793791
return;

impeller/entity/contents/clip_contents.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ClipContents final : public Contents {
2525

2626
void SetClipOperation(Entity::ClipOperation clip_op);
2727

28-
bool CanSkip(ISize render_pass_size, const Matrix& ctm) const;
28+
bool CanSkip(ISize render_pass_size, const Matrix& transform) const override;
2929

3030
// |Contents|
3131
std::optional<Rect> GetCoverage(const Entity& entity) const override;

impeller/entity/contents/contents.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,8 @@ void Contents::SetColorSourceSize(Size size) {
182182
color_source_size_ = size;
183183
}
184184

185+
bool Contents::CanSkip(ISize render_pass_size, const Matrix& transform) const {
186+
return false;
187+
}
188+
185189
} // namespace impeller

impeller/entity/contents/contents.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ class Contents {
8383
///
8484
void SetCoverageHint(std::optional<Rect> coverage_hint);
8585

86+
//----------------------------------------------------------------------------
87+
/// @brief Whether this entity can be entirely skipped during rendering.
88+
///
89+
/// TODO(jonahwilliams): remove this method which was only added for clipping
90+
/// once experimental canvas lands.
91+
virtual bool CanSkip(ISize render_pass_size, const Matrix& transform) const;
92+
8693
const std::optional<Rect>& GetCoverageHint() const;
8794

8895
//----------------------------------------------------------------------------

impeller/entity/entity_unittests.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,35 @@ TEST_P(EntityTest, ClipContentsShouldRenderIsCorrect) {
15321532
}
15331533
}
15341534

1535+
TEST_P(EntityTest, ClipContentsCanSkip) {
1536+
// Intersect Clips can be skipped if the render target coverage is fully
1537+
// inside of them.
1538+
1539+
auto clip = std::make_shared<ClipContents>();
1540+
clip->SetGeometry(Geometry::MakeRect(Rect::MakeLTRB(0, 0, 100, 100)));
1541+
clip->SetClipOperation(Entity::ClipOperation::kIntersect);
1542+
1543+
// Fully Contained
1544+
EXPECT_TRUE(clip->CanSkip(ISize::MakeWH(50, 50), {}));
1545+
1546+
// Not Intersect
1547+
clip->SetClipOperation(Entity::ClipOperation::kDifference);
1548+
EXPECT_FALSE(clip->CanSkip(ISize::MakeWH(50, 50), {}));
1549+
1550+
// Not Contained
1551+
clip->SetClipOperation(Entity::ClipOperation::kIntersect);
1552+
EXPECT_FALSE(clip->CanSkip(ISize::MakeWH(200, 200), {}));
1553+
1554+
// Not Scale Translate
1555+
clip->SetClipOperation(Entity::ClipOperation::kIntersect);
1556+
EXPECT_FALSE(
1557+
clip->CanSkip(ISize::MakeWH(50, 50), Matrix::MakeRotationX(Radians(2))));
1558+
1559+
// Not Axis Aligned Rectangle.
1560+
clip->SetGeometry(Geometry::MakeOval(Rect::MakeLTRB(0, 0, 50, 50)));
1561+
EXPECT_FALSE(clip->CanSkip(ISize::MakeWH(50, 50), {}));
1562+
}
1563+
15351564
TEST_P(EntityTest, ClipContentsGetClipCoverageIsCorrect) {
15361565
// Intersection: No stencil coverage, no geometry.
15371566
{

0 commit comments

Comments
 (0)