@@ -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+
14661526TEST_P (EntityTest, RRectShadowTest) {
14671527 auto callback = [&](ContentContext& context, RenderPass& pass) {
14681528 static Color color = Color::Red ();
0 commit comments