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

Commit a042fa0

Browse files
authored
Merge branch 'flutter-3.7-candidate.1' into dl-opacity-inheritance-cp
2 parents b4f76c6 + 0f35906 commit a042fa0

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

impeller/entity/contents/clip_contents.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,18 @@ Contents::StencilCoverage ClipContents::GetStencilCoverage(
4747
return {.type = StencilCoverage::Type::kAppend,
4848
.coverage = current_stencil_coverage};
4949
case Entity::ClipOperation::kIntersect:
50+
if (!geometry_) {
51+
return {.type = StencilCoverage::Type::kAppend,
52+
.coverage = std::nullopt};
53+
}
54+
auto coverage = geometry_->GetCoverage(entity.GetTransformation());
55+
if (!coverage.has_value() || !current_stencil_coverage.has_value()) {
56+
return {.type = StencilCoverage::Type::kAppend,
57+
.coverage = std::nullopt};
58+
}
5059
return {
5160
.type = StencilCoverage::Type::kAppend,
52-
.coverage = current_stencil_coverage->Intersection(
53-
geometry_->GetCoverage(entity.GetTransformation()).value()),
61+
.coverage = current_stencil_coverage->Intersection(coverage.value()),
5462
};
5563
}
5664
FML_UNREACHABLE();

impeller/entity/entity_unittests.cc

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,66 @@ TEST_P(EntityTest, ClipContentsShouldRenderIsCorrect) {
14631463
}
14641464
}
14651465

1466+
TEST_P(EntityTest, ClipContentsGetStencilCoverageIsCorrect) {
1467+
// Intersection: No stencil coverage, no geometry.
1468+
{
1469+
auto clip = std::make_shared<ClipContents>();
1470+
clip->SetClipOperation(Entity::ClipOperation::kIntersect);
1471+
auto result = clip->GetStencilCoverage(Entity{}, Rect{});
1472+
1473+
ASSERT_FALSE(result.coverage.has_value());
1474+
}
1475+
1476+
// Intersection: No stencil coverage, with geometry.
1477+
{
1478+
auto clip = std::make_shared<ClipContents>();
1479+
clip->SetClipOperation(Entity::ClipOperation::kIntersect);
1480+
clip->SetGeometry(Geometry::MakeFillPath(
1481+
PathBuilder{}.AddRect(Rect::MakeLTRB(0, 0, 100, 100)).TakePath()));
1482+
auto result = clip->GetStencilCoverage(Entity{}, Rect{});
1483+
1484+
ASSERT_FALSE(result.coverage.has_value());
1485+
}
1486+
1487+
// Intersection: With stencil coverage, no geometry.
1488+
{
1489+
auto clip = std::make_shared<ClipContents>();
1490+
clip->SetClipOperation(Entity::ClipOperation::kIntersect);
1491+
auto result =
1492+
clip->GetStencilCoverage(Entity{}, Rect::MakeLTRB(0, 0, 100, 100));
1493+
1494+
ASSERT_FALSE(result.coverage.has_value());
1495+
}
1496+
1497+
// Intersection: With stencil coverage, with geometry.
1498+
{
1499+
auto clip = std::make_shared<ClipContents>();
1500+
clip->SetClipOperation(Entity::ClipOperation::kIntersect);
1501+
clip->SetGeometry(Geometry::MakeFillPath(
1502+
PathBuilder{}.AddRect(Rect::MakeLTRB(0, 0, 50, 50)).TakePath()));
1503+
auto result =
1504+
clip->GetStencilCoverage(Entity{}, Rect::MakeLTRB(0, 0, 100, 100));
1505+
1506+
ASSERT_TRUE(result.coverage.has_value());
1507+
ASSERT_RECT_NEAR(result.coverage.value(), Rect::MakeLTRB(0, 0, 50, 50));
1508+
ASSERT_EQ(result.type, Contents::StencilCoverage::Type::kAppend);
1509+
}
1510+
1511+
// Difference: With stencil coverage, with geometry.
1512+
{
1513+
auto clip = std::make_shared<ClipContents>();
1514+
clip->SetClipOperation(Entity::ClipOperation::kDifference);
1515+
clip->SetGeometry(Geometry::MakeFillPath(
1516+
PathBuilder{}.AddRect(Rect::MakeLTRB(0, 0, 50, 50)).TakePath()));
1517+
auto result =
1518+
clip->GetStencilCoverage(Entity{}, Rect::MakeLTRB(0, 0, 100, 100));
1519+
1520+
ASSERT_TRUE(result.coverage.has_value());
1521+
ASSERT_RECT_NEAR(result.coverage.value(), Rect::MakeLTRB(0, 0, 100, 100));
1522+
ASSERT_EQ(result.type, Contents::StencilCoverage::Type::kAppend);
1523+
}
1524+
}
1525+
14661526
TEST_P(EntityTest, RRectShadowTest) {
14671527
auto callback = [&](ContentContext& context, RenderPass& pass) {
14681528
static Color color = Color::Red();

0 commit comments

Comments
 (0)