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

Commit 680af3c

Browse files
committed
finish off unit tests
1 parent 7b57bf6 commit 680af3c

File tree

10 files changed

+242
-115
lines changed

10 files changed

+242
-115
lines changed

display_list/benchmarking/dl_complexity_gl.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawRoundRect(
257257
// approximately matching the measured data, normalising the data so that
258258
// 0.0005ms resulted in a score of 100 then simplifying down the formula.
259259
if (DrawStyle() == DlDrawStyle::kFill ||
260-
((rrect.GetRadii().AreAllSame()) && IsAntiAliased())) {
260+
((rrect.GetRadii().AreAllCornersSame()) && IsAntiAliased())) {
261261
unsigned int area = rrect.GetBounds().Area();
262262
// m = 1/3200
263263
// c = 0.5
@@ -309,7 +309,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawDiffRoundRect(
309309
// currently use it anywhere in Flutter.
310310
if (DrawStyle() == DlDrawStyle::kFill) {
311311
unsigned int area = outer.GetBounds().Area();
312-
if (!outer.GetRadii().AreAllSame()) {
312+
if (!outer.GetRadii().AreAllCornersSame()) {
313313
// m = 1/500
314314
// c = 0.5
315315
complexity = (area + 250) / 5;

display_list/benchmarking/dl_complexity_metal.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawRoundRect(
255255
//
256256
// Expensive: All filled style, symmetric w/AA.
257257
bool expensive = (DrawStyle() == DlDrawStyle::kFill) ||
258-
(rrect.GetRadii().AreAllSame() && IsAntiAliased());
258+
(rrect.GetRadii().AreAllCornersSame() && IsAntiAliased());
259259

260260
unsigned int complexity;
261261

@@ -305,7 +305,7 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawDiffRoundRect(
305305
// currently use it anywhere in Flutter.
306306
if (DrawStyle() == DlDrawStyle::kFill) {
307307
unsigned int area = outer.GetBounds().Area();
308-
if (!outer.GetRadii().AreAllSame()) {
308+
if (!outer.GetRadii().AreAllCornersSame()) {
309309
// m = 1/1000
310310
// c = 1
311311
complexity = (area + 1000) / 10;

display_list/utils/dl_matrix_clip_tracker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ bool DisplayListMatrixClipState::rrect_covers_cull(
312312
if (content.IsOval()) {
313313
return oval_covers_cull(content.GetBounds());
314314
}
315-
if (!content.GetRadii().AreAllSame()) {
315+
if (!content.GetRadii().AreAllCornersSame()) {
316316
return false;
317317
}
318318
DlPoint corners[4];

display_list/utils/dl_matrix_clip_tracker_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ TEST(DisplayListMatrixClipState, RRectCoverage) {
938938
// Expanded by 2.0 and then with a corner of 2.0 obviously still covers
939939
EXPECT_TRUE(state.rrect_covers_cull(SkRRect::MakeRectXY(test, 2.0f, 2.0f)));
940940
// The corner point of the cull rect is at (c-2, c-2) relative to the
941-
// corner of the rrect bounds so we compute its disance to the center
941+
// corner of the rrect bounds so we compute its distance to the center
942942
// of the circular part and compare it to the radius of the corner (c)
943943
// to find the corner radius where it will start to leave the rounded
944944
// rectangle:

impeller/display_list/canvas.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ void Canvas::DrawOval(const Rect& rect, const Paint& paint) {
612612
void Canvas::DrawRoundRect(const RoundRect& round_rect, const Paint& paint) {
613613
auto& rect = round_rect.GetBounds();
614614
auto& radii = round_rect.GetRadii();
615-
if (radii.AreAllSame()) {
615+
if (radii.AreAllCornersSame()) {
616616
if (AttemptDrawBlurredRRect(rect, radii.top_left, paint)) {
617617
return;
618618
}

impeller/display_list/dl_dispatcher.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ void DlDispatcherBase::clipRoundRect(const DlRoundRect& rrect,
458458
GetCanvas().ClipGeometry(Geometry::MakeRect(rrect.GetBounds()), clip_op);
459459
} else if (rrect.IsOval()) {
460460
GetCanvas().ClipGeometry(Geometry::MakeOval(rrect.GetBounds()), clip_op);
461-
} else if (rrect.GetRadii().AreAllSame()) {
461+
} else if (rrect.GetRadii().AreAllCornersSame()) {
462462
GetCanvas().ClipGeometry(
463463
Geometry::MakeRoundRect(rrect.GetBounds(), rrect.GetRadii().top_left),
464464
clip_op);
@@ -585,13 +585,7 @@ void DlDispatcherBase::drawCircle(const DlPoint& center, DlScalar radius) {
585585
void DlDispatcherBase::drawRoundRect(const DlRoundRect& rrect) {
586586
AUTO_DEPTH_WATCHER(1u);
587587

588-
if (rrect.GetRadii().AreAllSame()) {
589-
GetCanvas().DrawRoundRect(rrect, paint_);
590-
} else {
591-
PathBuilder builder;
592-
builder.AddRoundRect(rrect);
593-
GetCanvas().DrawPath(builder.TakePath(), paint_);
594-
}
588+
GetCanvas().DrawRoundRect(rrect, paint_);
595589
}
596590

597591
// |flutter::DlOpReceiver|

impeller/geometry/path_builder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ PathBuilder& PathBuilder::AddCircle(const Point& c, Scalar r) {
142142
PathBuilder& PathBuilder::AddRoundRect(RoundRect round_rect) {
143143
auto rect = round_rect.GetBounds();
144144
auto radii = round_rect.GetRadii();
145-
if (radii.AreAllEmpty()) {
145+
if (radii.AreAllCornersEmpty()) {
146146
return AddRect(rect);
147147
}
148148

impeller/geometry/round_rect.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ static inline void AdjustScale(Scalar& radius1,
2525

2626
RoundRect RoundRect::MakeRectRadii(const Rect& bounds,
2727
const RoundingRadii& in_radii) {
28-
if (bounds.IsEmpty() || !bounds.IsFinite()) {
29-
return RoundRect();
30-
}
31-
if (in_radii.AreAllEmpty() || !in_radii.IsFinite()) {
28+
if (bounds.IsEmpty() || !bounds.IsFinite() || //
29+
in_radii.AreAllCornersEmpty() || !in_radii.IsFinite()) {
30+
// preserve the empty bounds as they might be strokable
3231
return RoundRect(bounds, RoundingRadii());
3332
}
3433

impeller/geometry/round_rect.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,20 @@ struct RoundingRadii {
3232
bottom_right.IsFinite();
3333
}
3434

35-
constexpr bool AreAllEmpty() const {
35+
constexpr bool AreAllCornersEmpty() const {
3636
return top_left.IsEmpty() && //
3737
top_right.IsEmpty() && //
3838
bottom_left.IsEmpty() && //
3939
bottom_right.IsEmpty();
4040
}
4141

42-
constexpr bool AreAllSame() const {
43-
return top_left == top_right && //
44-
top_left == bottom_left && //
45-
top_left == bottom_right;
42+
constexpr bool AreAllCornersSame(Scalar tolerance = kEhCloseEnough) const {
43+
return ScalarNearlyEqual(top_left.width, top_right.width, tolerance) &&
44+
ScalarNearlyEqual(top_left.width, bottom_right.width, tolerance) &&
45+
ScalarNearlyEqual(top_left.width, bottom_left.width, tolerance) &&
46+
ScalarNearlyEqual(top_left.height, top_right.height, tolerance) &&
47+
ScalarNearlyEqual(top_left.height, bottom_right.height, tolerance) &&
48+
ScalarNearlyEqual(top_left.height, bottom_left.height, tolerance);
4649
}
4750

4851
constexpr inline RoundingRadii operator*(Scalar scale) {
@@ -108,11 +111,11 @@ struct RoundRect {
108111
[[nodiscard]] constexpr bool IsEmpty() const { return bounds_.IsEmpty(); }
109112

110113
[[nodiscard]] constexpr bool IsRect() const {
111-
return !bounds_.IsEmpty() && radii_.AreAllEmpty();
114+
return !bounds_.IsEmpty() && radii_.AreAllCornersEmpty();
112115
}
113116

114117
[[nodiscard]] constexpr bool IsOval() const {
115-
return !bounds_.IsEmpty() && radii_.AreAllSame() &&
118+
return !bounds_.IsEmpty() && radii_.AreAllCornersSame() &&
116119
ScalarNearlyEqual(radii_.top_left.width,
117120
bounds_.GetWidth() * 0.5f) &&
118121
ScalarNearlyEqual(radii_.top_left.height,

0 commit comments

Comments
 (0)