|
21 | 21 | #include "impeller/display_list/dl_dispatcher.h"
|
22 | 22 | #include "impeller/display_list/dl_image_impeller.h"
|
23 | 23 | #include "impeller/display_list/dl_playground.h"
|
| 24 | +#include "impeller/entity/contents/clip_contents.h" |
24 | 25 | #include "impeller/entity/contents/solid_color_contents.h"
|
25 | 26 | #include "impeller/entity/contents/solid_rrect_blur_contents.h"
|
26 | 27 | #include "impeller/geometry/constants.h"
|
@@ -1681,6 +1682,65 @@ TEST_P(DisplayListTest, DrawVerticesBlendModes) {
|
1681 | 1682 | ASSERT_TRUE(OpenPlaygroundHere(callback));
|
1682 | 1683 | }
|
1683 | 1684 |
|
| 1685 | +template <typename Contents> |
| 1686 | +static std::optional<Rect> GetCoverageOfFirstEntity(const Picture& picture) { |
| 1687 | + std::optional<Rect> coverage; |
| 1688 | + picture.pass->IterateAllEntities([&coverage](Entity& entity) { |
| 1689 | + if (std::static_pointer_cast<Contents>(entity.GetContents())) { |
| 1690 | + auto contents = std::static_pointer_cast<Contents>(entity.GetContents()); |
| 1691 | + Entity entity; |
| 1692 | + coverage = contents->GetCoverage(entity); |
| 1693 | + return false; |
| 1694 | + } |
| 1695 | + return true; |
| 1696 | + }); |
| 1697 | + return coverage; |
| 1698 | +} |
| 1699 | + |
| 1700 | +TEST(DisplayListTest, RRectBoundsComputation) { |
| 1701 | + SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeLTRB(0, 0, 100, 100), 4, 4); |
| 1702 | + SkPath path = SkPath().addRRect(rrect); |
| 1703 | + |
| 1704 | + flutter::DlPaint paint; |
| 1705 | + flutter::DisplayListBuilder builder; |
| 1706 | + |
| 1707 | + builder.DrawPath(path, paint); |
| 1708 | + auto display_list = builder.Build(); |
| 1709 | + |
| 1710 | + DlDispatcher dispatcher; |
| 1711 | + display_list->Dispatch(dispatcher); |
| 1712 | + auto picture = dispatcher.EndRecordingAsPicture(); |
| 1713 | + |
| 1714 | + std::optional<Rect> coverage = |
| 1715 | + GetCoverageOfFirstEntity<SolidColorContents>(picture); |
| 1716 | + |
| 1717 | + // Validate that the RRect coverage is _exactly_ the same as the input rect. |
| 1718 | + ASSERT_TRUE(coverage.has_value()); |
| 1719 | + ASSERT_EQ(coverage.value_or(Rect::MakeMaximum()), |
| 1720 | + Rect::MakeLTRB(0, 0, 100, 100)); |
| 1721 | +} |
| 1722 | + |
| 1723 | +TEST(DisplayListTest, CircleBoundsComputation) { |
| 1724 | + SkPath path = SkPath().addCircle(0, 0, 5); |
| 1725 | + |
| 1726 | + flutter::DlPaint paint; |
| 1727 | + flutter::DisplayListBuilder builder; |
| 1728 | + |
| 1729 | + builder.DrawPath(path, paint); |
| 1730 | + auto display_list = builder.Build(); |
| 1731 | + |
| 1732 | + DlDispatcher dispatcher; |
| 1733 | + display_list->Dispatch(dispatcher); |
| 1734 | + auto picture = dispatcher.EndRecordingAsPicture(); |
| 1735 | + |
| 1736 | + std::optional<Rect> coverage = |
| 1737 | + GetCoverageOfFirstEntity<SolidColorContents>(picture); |
| 1738 | + |
| 1739 | + ASSERT_TRUE(coverage.has_value()); |
| 1740 | + ASSERT_EQ(coverage.value_or(Rect::MakeMaximum()), |
| 1741 | + Rect::MakeLTRB(-5, -5, 5, 5)); |
| 1742 | +} |
| 1743 | + |
1684 | 1744 | #ifdef IMPELLER_ENABLE_3D
|
1685 | 1745 | TEST_P(DisplayListTest, SceneColorSource) {
|
1686 | 1746 | // Load up the scene.
|
|
0 commit comments