Skip to content

Commit e039219

Browse files
authored
[Impeller] Migrate unit tests off of Skia geometry classes (flutter#161855)
Handles the impeller unittests line in flutter#161456 This PR is focused on the unit tests in Impeller. There are still some uses in other non-test areas which will be handled in a separate PR.
1 parent cc9c13e commit e039219

25 files changed

+1281
-1087
lines changed

engine/src/flutter/display_list/display_list_unittests.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,7 @@ TEST_F(DisplayListTest, FlutterSvgIssue661BoundsWereEmpty) {
17931793
{32.3f, 14.615f}, //
17941794
{32.3f, 19.34f});
17951795
path_builder1.Close();
1796-
DlPath dl_path1 = DlPath(path_builder1.TakePath(DlPathFillType::kNonZero));
1796+
DlPath dl_path1 = DlPath(path_builder1, DlPathFillType::kNonZero);
17971797

17981798
DlPathBuilder path_builder2;
17991799
path_builder2.MoveTo({37.5f, 19.33f});
@@ -1806,7 +1806,7 @@ TEST_F(DisplayListTest, FlutterSvgIssue661BoundsWereEmpty) {
18061806
{37.495f, 11.756f}, //
18071807
{37.5f, 19.33f});
18081808
path_builder2.Close();
1809-
DlPath dl_path2 = DlPath(path_builder2.TakePath(DlPathFillType::kNonZero));
1809+
DlPath dl_path2 = DlPath(path_builder2, DlPathFillType::kNonZero);
18101810

18111811
DisplayListBuilder builder;
18121812
DlPaint paint = DlPaint(DlColor::kWhite()).setAntiAlias(true);
@@ -4878,7 +4878,7 @@ TEST_F(DisplayListTest, ClipPathNonCulling) {
48784878
path_builder.LineTo({1000.0f, 0.0f});
48794879
path_builder.LineTo({0.0f, 1000.0f});
48804880
path_builder.Close();
4881-
DlPath path = DlPath(path_builder.TakePath());
4881+
DlPath path = DlPath(path_builder);
48824882

48834883
// Double checking that the path does indeed contain the clip. But,
48844884
// sadly, the Builder will not check paths for coverage to this level

engine/src/flutter/display_list/geometry/dl_path.cc

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,33 @@ DlPath DlPath::MakeRoundRectXY(const DlRect& rect,
6262
counter_clock_wise ? SkPathDirection::kCCW : SkPathDirection::kCW));
6363
}
6464

65+
DlPath DlPath::MakeLine(const DlPoint& a, const DlPoint& b) {
66+
return DlPath(SkPath::Line(ToSkPoint(a), ToSkPoint(b)));
67+
}
68+
69+
DlPath DlPath::MakePoly(const DlPoint pts[],
70+
int count,
71+
bool close,
72+
DlPathFillType fill_type) {
73+
return DlPath(
74+
SkPath::Polygon(ToSkPoints(pts), count, close, ToSkFillType(fill_type)));
75+
}
76+
77+
DlPath DlPath::MakeArc(const DlRect& bounds,
78+
DlDegrees start,
79+
DlDegrees end,
80+
bool use_center) {
81+
SkPath path;
82+
if (use_center) {
83+
path.moveTo(ToSkPoint(bounds.GetCenter()));
84+
}
85+
path.arcTo(ToSkRect(bounds), start.degrees, end.degrees, !use_center);
86+
if (use_center) {
87+
path.close();
88+
}
89+
return DlPath(path);
90+
}
91+
6592
const SkPath& DlPath::GetSkPath() const {
6693
auto& sk_path = data_->sk_path;
6794
auto& path = data_->path;
@@ -207,16 +234,24 @@ bool DlPath::IsVolatile() const {
207234
return GetSkPath().isVolatile();
208235
}
209236

237+
bool DlPath::IsConvex() const {
238+
if (data_->sk_path_original) {
239+
auto& sk_path = data_->sk_path;
240+
FML_DCHECK(sk_path.has_value());
241+
return sk_path.has_value() && sk_path->isConvex();
242+
} else {
243+
auto& path = data_->path;
244+
FML_DCHECK(path.has_value());
245+
return path.has_value() && path->IsConvex();
246+
}
247+
}
248+
210249
DlPath DlPath::operator+(const DlPath& other) const {
211250
SkPath path = GetSkPath();
212251
path.addPath(other.GetSkPath());
213252
return DlPath(path);
214253
}
215254

216-
DlPath::Data::Data(const SkPath& path) : sk_path(path) {
217-
FML_DCHECK(!SkPathFillType_IsInverse(path.getFillType()));
218-
}
219-
220255
SkPath DlPath::ConvertToSkiaPath(const Path& path, const DlPoint& shift) {
221256
SkPath sk_path;
222257
sk_path.setFillType(ToSkFillType(path.GetFillType()));
@@ -338,26 +373,16 @@ Path DlPath::ConvertToImpellerPath(const SkPath& path, const DlPoint& shift) {
338373
}
339374
} while (verb != SkPath::Verb::kDone_Verb);
340375

341-
FillType fill_type;
342-
switch (path.getFillType()) {
343-
case SkPathFillType::kWinding:
344-
fill_type = FillType::kNonZero;
345-
break;
346-
case SkPathFillType::kEvenOdd:
347-
fill_type = FillType::kOdd;
348-
break;
349-
case SkPathFillType::kInverseWinding:
350-
case SkPathFillType::kInverseEvenOdd:
351-
FML_UNREACHABLE();
352-
}
353-
builder.SetConvexity(path.isConvex() ? Convexity::kConvex
354-
: Convexity::kUnknown);
376+
DlRect bounds = ToDlRect(path.getBounds());
355377
if (!shift.IsZero()) {
356378
builder.Shift(shift);
379+
bounds = bounds.Shift(shift);
357380
}
358-
auto sk_bounds = path.getBounds().makeOutset(shift.x, shift.y);
359-
builder.SetBounds(ToDlRect(sk_bounds));
360-
return builder.TakePath(fill_type);
381+
382+
builder.SetConvexity(path.isConvex() ? Convexity::kConvex
383+
: Convexity::kUnknown);
384+
builder.SetBounds(bounds);
385+
return builder.TakePath(ToDlFillType(path.getFillType()));
361386
}
362387

363388
} // namespace flutter

engine/src/flutter/display_list/geometry/dl_path.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,24 @@ class DlPath {
4343
DlScalar y_radius,
4444
bool counter_clock_wise = false);
4545

46+
static DlPath MakeLine(const DlPoint& a, const DlPoint& b);
47+
static DlPath MakePoly(const DlPoint pts[],
48+
int count,
49+
bool close,
50+
DlPathFillType fill_type = DlPathFillType::kNonZero);
51+
52+
static DlPath MakeArc(const DlRect& bounds,
53+
DlDegrees start,
54+
DlDegrees end,
55+
bool use_center);
56+
4657
DlPath() : data_(std::make_shared<Data>(SkPath())) {}
4758
explicit DlPath(const SkPath& path) : data_(std::make_shared<Data>(path)) {}
4859
explicit DlPath(const impeller::Path& path)
4960
: data_(std::make_shared<Data>(path)) {}
61+
explicit DlPath(DlPathBuilder& builder,
62+
DlPathFillType fill_type = DlPathFillType::kNonZero)
63+
: data_(std::make_shared<Data>(builder.TakePath(fill_type))) {}
5064

5165
DlPath(const DlPath& path) = default;
5266
DlPath(DlPath&& path) = default;
@@ -84,18 +98,22 @@ class DlPath {
8498

8599
bool IsConverted() const;
86100
bool IsVolatile() const;
87-
bool IsEvenOdd() const;
101+
bool IsConvex() const;
88102

89103
DlPath operator+(const DlPath& other) const;
90104

91105
private:
92106
struct Data {
93-
explicit Data(const SkPath& path);
94-
explicit Data(const impeller::Path& path) : path(path) {}
107+
explicit Data(const SkPath& path) : sk_path(path), sk_path_original(true) {
108+
FML_DCHECK(!SkPathFillType_IsInverse(path.getFillType()));
109+
}
110+
explicit Data(const impeller::Path& path)
111+
: path(path), sk_path_original(false) {}
95112

96113
std::optional<SkPath> sk_path;
97114
std::optional<impeller::Path> path;
98115
uint32_t render_count = 0u;
116+
const bool sk_path_original;
99117
};
100118

101119
inline constexpr static DlPathFillType ToDlFillType(SkPathFillType sk_type) {

0 commit comments

Comments
 (0)