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

Commit e18fdf0

Browse files
committed
New impeller round rect class
1 parent a9bd470 commit e18fdf0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1031
-426
lines changed

ci/licenses_golden/excluded_files

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
../../../flutter/impeller/geometry/matrix_unittests.cc
179179
../../../flutter/impeller/geometry/path_unittests.cc
180180
../../../flutter/impeller/geometry/rect_unittests.cc
181+
../../../flutter/impeller/geometry/round_rect_unittests.cc
181182
../../../flutter/impeller/geometry/saturated_math_unittests.cc
182183
../../../flutter/impeller/geometry/size_unittests.cc
183184
../../../flutter/impeller/geometry/trig_unittests.cc

ci/licenses_golden/licenses_flutter

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42931,6 +42931,8 @@ ORIGIN: ../../../flutter/impeller/geometry/quaternion.cc + ../../../flutter/LICE
4293142931
ORIGIN: ../../../flutter/impeller/geometry/quaternion.h + ../../../flutter/LICENSE
4293242932
ORIGIN: ../../../flutter/impeller/geometry/rect.cc + ../../../flutter/LICENSE
4293342933
ORIGIN: ../../../flutter/impeller/geometry/rect.h + ../../../flutter/LICENSE
42934+
ORIGIN: ../../../flutter/impeller/geometry/round_rect.cc + ../../../flutter/LICENSE
42935+
ORIGIN: ../../../flutter/impeller/geometry/round_rect.h + ../../../flutter/LICENSE
4293442936
ORIGIN: ../../../flutter/impeller/geometry/saturated_math.h + ../../../flutter/LICENSE
4293542937
ORIGIN: ../../../flutter/impeller/geometry/scalar.h + ../../../flutter/LICENSE
4293642938
ORIGIN: ../../../flutter/impeller/geometry/separated_vector.cc + ../../../flutter/LICENSE
@@ -45801,6 +45803,8 @@ FILE: ../../../flutter/impeller/geometry/quaternion.cc
4580145803
FILE: ../../../flutter/impeller/geometry/quaternion.h
4580245804
FILE: ../../../flutter/impeller/geometry/rect.cc
4580345805
FILE: ../../../flutter/impeller/geometry/rect.h
45806+
FILE: ../../../flutter/impeller/geometry/round_rect.cc
45807+
FILE: ../../../flutter/impeller/geometry/round_rect.h
4580445808
FILE: ../../../flutter/impeller/geometry/saturated_math.h
4580545809
FILE: ../../../flutter/impeller/geometry/scalar.h
4580645810
FILE: ../../../flutter/impeller/geometry/separated_vector.cc

display_list/benchmarking/dl_complexity_gl.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ void DisplayListGLComplexityCalculator::GLHelper::drawCircle(
236236
AccumulateComplexity(complexity);
237237
}
238238

239-
void DisplayListGLComplexityCalculator::GLHelper::drawRRect(
240-
const SkRRect& rrect) {
239+
void DisplayListGLComplexityCalculator::GLHelper::drawRoundRect(
240+
const DlRoundRect& rrect) {
241241
if (IsComplex()) {
242242
return;
243243
}
@@ -256,14 +256,15 @@ void DisplayListGLComplexityCalculator::GLHelper::drawRRect(
256256
// approximately matching the measured data, normalising the data so that
257257
// 0.0005ms resulted in a score of 100 then simplifying down the formula.
258258
if (DrawStyle() == DlDrawStyle::kFill ||
259-
((rrect.getType() == SkRRect::Type::kSimple_Type) && IsAntiAliased())) {
260-
unsigned int area = rrect.width() * rrect.height();
259+
((rrect.GetRadii().AreAllSame()) && IsAntiAliased())) {
260+
unsigned int area = rrect.GetBounds().Area();
261261
// m = 1/3200
262262
// c = 0.5
263263
complexity = (area + 1600) / 80;
264264
} else {
265265
// Take the average of the width and height.
266-
unsigned int length = (rrect.width() + rrect.height()) / 2;
266+
unsigned int length =
267+
(rrect.GetBounds().GetWidth() + rrect.GetBounds().GetHeight()) / 2;
267268

268269
// There is some difference between hairline and non-hairline performance
269270
// but the spread is relatively inconsistent and it's pretty much a wash.
@@ -281,9 +282,9 @@ void DisplayListGLComplexityCalculator::GLHelper::drawRRect(
281282
AccumulateComplexity(complexity);
282283
}
283284

284-
void DisplayListGLComplexityCalculator::GLHelper::drawDRRect(
285-
const SkRRect& outer,
286-
const SkRRect& inner) {
285+
void DisplayListGLComplexityCalculator::GLHelper::drawDiffRoundRect(
286+
const DlRoundRect& outer,
287+
const DlRoundRect& inner) {
287288
if (IsComplex()) {
288289
return;
289290
}
@@ -306,8 +307,8 @@ void DisplayListGLComplexityCalculator::GLHelper::drawDRRect(
306307
// There is also a kStrokeAndFill_Style that Skia exposes, but we do not
307308
// currently use it anywhere in Flutter.
308309
if (DrawStyle() == DlDrawStyle::kFill) {
309-
unsigned int area = outer.width() * outer.height();
310-
if (outer.getType() == SkRRect::Type::kComplex_Type) {
310+
unsigned int area = outer.GetBounds().Area();
311+
if (!outer.GetRadii().AreAllSame()) {
311312
// m = 1/500
312313
// c = 0.5
313314
complexity = (area + 250) / 5;
@@ -317,7 +318,8 @@ void DisplayListGLComplexityCalculator::GLHelper::drawDRRect(
317318
complexity = (area + 3200) / 16;
318319
}
319320
} else {
320-
unsigned int length = (outer.width() + outer.height()) / 2;
321+
unsigned int length =
322+
(outer.GetBounds().GetWidth() + outer.GetBounds().GetHeight()) / 2;
321323
if (IsAntiAliased()) {
322324
// m = 1/15
323325
// c = 1

display_list/benchmarking/dl_complexity_gl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class DisplayListGLComplexityCalculator
4747
void drawRect(const DlRect& rect) override;
4848
void drawOval(const DlRect& bounds) override;
4949
void drawCircle(const DlPoint& center, DlScalar radius) override;
50-
void drawRRect(const SkRRect& rrect) override;
51-
void drawDRRect(const SkRRect& outer, const SkRRect& inner) override;
50+
void drawRoundRect(const DlRoundRect& rrect) override;
51+
void drawDiffRoundRect(const DlRoundRect& outer,
52+
const DlRoundRect& inner) override;
5253
void drawPath(const DlPath& path) override;
5354
void drawArc(const DlRect& oval_bounds,
5455
DlScalar start_degrees,

display_list/benchmarking/dl_complexity_metal.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,21 +241,20 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawCircle(
241241
AccumulateComplexity(complexity);
242242
}
243243

244-
void DisplayListMetalComplexityCalculator::MetalHelper::drawRRect(
245-
const SkRRect& rrect) {
244+
void DisplayListMetalComplexityCalculator::MetalHelper::drawRoundRect(
245+
const DlRoundRect& rrect) {
246246
if (IsComplex()) {
247247
return;
248248
}
249249
// RRects scale linearly with the area of the bounding rect.
250-
unsigned int area = rrect.width() * rrect.height();
250+
unsigned int area = rrect.GetBounds().Area();
251251

252252
// Drawing RRects is split into two performance tiers; an expensive
253253
// one and a less expensive one. Both scale linearly with area.
254254
//
255255
// Expensive: All filled style, symmetric w/AA.
256-
bool expensive =
257-
(DrawStyle() == DlDrawStyle::kFill) ||
258-
((rrect.getType() == SkRRect::Type::kSimple_Type) && IsAntiAliased());
256+
bool expensive = (DrawStyle() == DlDrawStyle::kFill) ||
257+
(rrect.GetRadii().AreAllSame() && IsAntiAliased());
259258

260259
unsigned int complexity;
261260

@@ -277,9 +276,9 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawRRect(
277276
AccumulateComplexity(complexity);
278277
}
279278

280-
void DisplayListMetalComplexityCalculator::MetalHelper::drawDRRect(
281-
const SkRRect& outer,
282-
const SkRRect& inner) {
279+
void DisplayListMetalComplexityCalculator::MetalHelper::drawDiffRoundRect(
280+
const DlRoundRect& outer,
281+
const DlRoundRect& inner) {
283282
if (IsComplex()) {
284283
return;
285284
}
@@ -292,7 +291,8 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawDRRect(
292291
// a) and c) scale linearly with the area, b) and d) scale linearly with
293292
// a single dimension (length). In all cases, the dimensions refer to
294293
// the outer RRect.
295-
unsigned int length = (outer.width() + outer.height()) / 2;
294+
unsigned int length =
295+
(outer.GetBounds().GetWidth() + outer.GetBounds().GetHeight()) / 2;
296296

297297
unsigned int complexity;
298298

@@ -303,8 +303,8 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawDRRect(
303303
// There is also a kStrokeAndFill_Style that Skia exposes, but we do not
304304
// currently use it anywhere in Flutter.
305305
if (DrawStyle() == DlDrawStyle::kFill) {
306-
unsigned int area = outer.width() * outer.height();
307-
if (outer.getType() == SkRRect::Type::kComplex_Type) {
306+
unsigned int area = outer.GetBounds().Area();
307+
if (!outer.GetRadii().AreAllSame()) {
308308
// m = 1/1000
309309
// c = 1
310310
complexity = (area + 1000) / 10;

display_list/benchmarking/dl_complexity_metal.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class DisplayListMetalComplexityCalculator
4747
void drawRect(const DlRect& rect) override;
4848
void drawOval(const DlRect& bounds) override;
4949
void drawCircle(const DlPoint& center, DlScalar radius) override;
50-
void drawRRect(const SkRRect& rrect) override;
51-
void drawDRRect(const SkRRect& outer, const SkRRect& inner) override;
50+
void drawRoundRect(const DlRoundRect& rrect) override;
51+
void drawDiffRoundRect(const DlRoundRect& outer,
52+
const DlRoundRect& inner) override;
5253
void drawPath(const DlPath& path) override;
5354
void drawArc(const DlRect& oval_bounds,
5455
DlScalar start_degrees,

display_list/display_list.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,11 @@ DisplayListOpCategory DisplayList::GetOpCategory(DisplayListOpType type) {
310310

311311
case DisplayListOpType::kClipIntersectRect:
312312
case DisplayListOpType::kClipIntersectOval:
313-
case DisplayListOpType::kClipIntersectRRect:
313+
case DisplayListOpType::kClipIntersectRoundRect:
314314
case DisplayListOpType::kClipIntersectPath:
315315
case DisplayListOpType::kClipDifferenceRect:
316316
case DisplayListOpType::kClipDifferenceOval:
317-
case DisplayListOpType::kClipDifferenceRRect:
317+
case DisplayListOpType::kClipDifferenceRoundRect:
318318
case DisplayListOpType::kClipDifferencePath:
319319
return DisplayListOpCategory::kClip;
320320

@@ -325,8 +325,8 @@ DisplayListOpCategory DisplayList::GetOpCategory(DisplayListOpType type) {
325325
case DisplayListOpType::kDrawRect:
326326
case DisplayListOpType::kDrawOval:
327327
case DisplayListOpType::kDrawCircle:
328-
case DisplayListOpType::kDrawRRect:
329-
case DisplayListOpType::kDrawDRRect:
328+
case DisplayListOpType::kDrawRoundRect:
329+
case DisplayListOpType::kDrawDiffRoundRect:
330330
case DisplayListOpType::kDrawArc:
331331
case DisplayListOpType::kDrawPath:
332332
case DisplayListOpType::kDrawPoints:

display_list/display_list.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ namespace flutter {
100100
\
101101
V(ClipIntersectRect) \
102102
V(ClipIntersectOval) \
103-
V(ClipIntersectRRect) \
103+
V(ClipIntersectRoundRect) \
104104
V(ClipIntersectPath) \
105105
V(ClipDifferenceRect) \
106106
V(ClipDifferenceOval) \
107-
V(ClipDifferenceRRect) \
107+
V(ClipDifferenceRoundRect) \
108108
V(ClipDifferencePath) \
109109
\
110110
V(DrawPaint) \
@@ -115,8 +115,8 @@ namespace flutter {
115115
V(DrawRect) \
116116
V(DrawOval) \
117117
V(DrawCircle) \
118-
V(DrawRRect) \
119-
V(DrawDRRect) \
118+
V(DrawRoundRect) \
119+
V(DrawDiffRoundRect) \
120120
V(DrawArc) \
121121
V(DrawPath) \
122122
\

display_list/display_list_unittests.cc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,7 +2945,7 @@ TEST_F(DisplayListTest, ClipRRectTriggersDeferredSave) {
29452945
{
29462946
builder1.Save();
29472947
{
2948-
builder1.ClipRRect(kTestRRect, ClipOp::kIntersect, true);
2948+
builder1.ClipRRect(kTestSkRRect, ClipOp::kIntersect, true);
29492949

29502950
builder1.DrawRect(SkRect{0, 0, 100, 100}, DlPaint());
29512951
}
@@ -2961,7 +2961,7 @@ TEST_F(DisplayListTest, ClipRRectTriggersDeferredSave) {
29612961

29622962
DisplayListBuilder builder2;
29632963
builder2.Save();
2964-
builder2.ClipRRect(kTestRRect, ClipOp::kIntersect, true);
2964+
builder2.ClipRRect(kTestSkRRect, ClipOp::kIntersect, true);
29652965

29662966
builder2.DrawRect(SkRect{0, 0, 100, 100}, DlPaint());
29672967
builder2.Restore();
@@ -4533,7 +4533,7 @@ TEST_F(DisplayListTest, DrawDisplayListForwardsBackdropFlag) {
45334533
#define CLIP_EXPECTOR(name) ClipExpector name(__FILE__, __LINE__)
45344534

45354535
struct ClipExpectation {
4536-
std::variant<DlRect, SkRRect, DlPath> shape;
4536+
std::variant<DlRect, DlRoundRect, DlPath> shape;
45374537
bool is_oval;
45384538
ClipOp clip_op;
45394539
bool is_aa;
@@ -4543,7 +4543,7 @@ struct ClipExpectation {
45434543
case 0:
45444544
return is_oval ? "SkOval" : "SkRect";
45454545
case 1:
4546-
return "SkRRect";
4546+
return "DlRoundRect";
45474547
case 2:
45484548
return "DlPath";
45494549
default:
@@ -4562,7 +4562,7 @@ ::std::ostream& operator<<(::std::ostream& os, const ClipExpectation& expect) {
45624562
}
45634563
break;
45644564
case 1:
4565-
os << std::get<SkRRect>(expect.shape);
4565+
os << std::get<DlRoundRect>(expect.shape);
45664566
break;
45674567
case 2:
45684568
os << std::get<DlPath>(expect.shape).GetSkPath();
@@ -4621,8 +4621,10 @@ class ClipExpector : public virtual DlOpReceiver,
46214621
ClipExpector& addExpectation(const SkRRect& rrect,
46224622
ClipOp clip_op = ClipOp::kIntersect,
46234623
bool is_aa = false) {
4624+
auto dl_rrect = ToDlRoundRect(rrect);
4625+
EXPECT_EQ(ToSkRRect(dl_rrect), rrect);
46244626
clip_expectations_.push_back({
4625-
.shape = rrect,
4627+
.shape = dl_rrect,
46264628
.is_oval = false,
46274629
.clip_op = clip_op,
46284630
.is_aa = is_aa,
@@ -4658,9 +4660,9 @@ class ClipExpector : public virtual DlOpReceiver,
46584660
bool is_aa) override {
46594661
check(bounds, clip_op, is_aa, true);
46604662
}
4661-
void clipRRect(const SkRRect& rrect,
4662-
DlCanvas::ClipOp clip_op,
4663-
bool is_aa) override {
4663+
void clipRoundRect(const DlRoundRect& rrect,
4664+
DlCanvas::ClipOp clip_op,
4665+
bool is_aa) override {
46644666
check(rrect, clip_op, is_aa);
46654667
}
46664668
void clipPath(const DlPath& path,

display_list/dl_builder.cc

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -992,15 +992,15 @@ void DisplayListBuilder::ClipOval(const DlRect& bounds,
992992
break;
993993
}
994994
}
995-
void DisplayListBuilder::ClipRRect(const SkRRect& rrect,
996-
ClipOp clip_op,
997-
bool is_aa) {
998-
if (rrect.isRect()) {
999-
ClipRect(ToDlRect(rrect.rect()), clip_op, is_aa);
995+
void DisplayListBuilder::ClipRoundRect(const DlRoundRect& rrect,
996+
ClipOp clip_op,
997+
bool is_aa) {
998+
if (rrect.IsRect()) {
999+
ClipRect(rrect.GetBounds(), clip_op, is_aa);
10001000
return;
10011001
}
1002-
if (rrect.isOval()) {
1003-
ClipOval(ToDlRect(rrect.rect()), clip_op, is_aa);
1002+
if (rrect.IsOval()) {
1003+
ClipOval(rrect.GetBounds(), clip_op, is_aa);
10041004
return;
10051005
}
10061006
if (current_info().is_nop) {
@@ -1022,10 +1022,10 @@ void DisplayListBuilder::ClipRRect(const SkRRect& rrect,
10221022
checkForDeferredSave();
10231023
switch (clip_op) {
10241024
case ClipOp::kIntersect:
1025-
Push<ClipIntersectRRectOp>(0, rrect, is_aa);
1025+
Push<ClipIntersectRoundRectOp>(0, rrect, is_aa);
10261026
break;
10271027
case ClipOp::kDifference:
1028-
Push<ClipDifferenceRRectOp>(0, rrect, is_aa);
1028+
Push<ClipDifferenceRoundRectOp>(0, rrect, is_aa);
10291029
break;
10301030
}
10311031
}
@@ -1182,42 +1182,43 @@ void DisplayListBuilder::DrawCircle(const DlPoint& center,
11821182
SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawCircleFlags);
11831183
drawCircle(center, radius);
11841184
}
1185-
void DisplayListBuilder::drawRRect(const SkRRect& rrect) {
1186-
if (rrect.isRect()) {
1187-
drawRect(ToDlRect(rrect.rect()));
1188-
} else if (rrect.isOval()) {
1189-
drawOval(ToDlRect(rrect.rect()));
1185+
void DisplayListBuilder::drawRoundRect(const DlRoundRect& rrect) {
1186+
if (rrect.IsRect()) {
1187+
drawRect(rrect.GetBounds());
1188+
} else if (rrect.IsOval()) {
1189+
drawOval(rrect.GetBounds());
11901190
} else {
11911191
DisplayListAttributeFlags flags = kDrawRRectFlags;
11921192
OpResult result = PaintResult(current_, flags);
11931193
if (result != OpResult::kNoEffect &&
1194-
AccumulateOpBounds(rrect.getBounds(), flags)) {
1195-
Push<DrawRRectOp>(0, rrect);
1194+
AccumulateOpBounds(ToSkRect(rrect.GetBounds()), flags)) {
1195+
Push<DrawRoundRectOp>(0, rrect);
11961196
CheckLayerOpacityCompatibility();
11971197
UpdateLayerResult(result);
11981198
}
11991199
}
12001200
}
1201-
void DisplayListBuilder::DrawRRect(const SkRRect& rrect, const DlPaint& paint) {
1201+
void DisplayListBuilder::DrawRoundRect(const DlRoundRect& rrect,
1202+
const DlPaint& paint) {
12021203
SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawRRectFlags);
1203-
drawRRect(rrect);
1204+
drawRoundRect(rrect);
12041205
}
1205-
void DisplayListBuilder::drawDRRect(const SkRRect& outer,
1206-
const SkRRect& inner) {
1206+
void DisplayListBuilder::drawDiffRoundRect(const DlRoundRect& outer,
1207+
const DlRoundRect& inner) {
12071208
DisplayListAttributeFlags flags = kDrawDRRectFlags;
12081209
OpResult result = PaintResult(current_, flags);
12091210
if (result != OpResult::kNoEffect &&
1210-
AccumulateOpBounds(outer.getBounds(), flags)) {
1211-
Push<DrawDRRectOp>(0, outer, inner);
1211+
AccumulateOpBounds(ToSkRect(outer.GetBounds()), flags)) {
1212+
Push<DrawDiffRoundRectOp>(0, outer, inner);
12121213
CheckLayerOpacityCompatibility();
12131214
UpdateLayerResult(result);
12141215
}
12151216
}
1216-
void DisplayListBuilder::DrawDRRect(const SkRRect& outer,
1217-
const SkRRect& inner,
1218-
const DlPaint& paint) {
1217+
void DisplayListBuilder::DrawDiffRoundRect(const DlRoundRect& outer,
1218+
const DlRoundRect& inner,
1219+
const DlPaint& paint) {
12191220
SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawDRRectFlags);
1220-
drawDRRect(outer, inner);
1221+
drawDiffRoundRect(outer, inner);
12211222
}
12221223
void DisplayListBuilder::drawPath(const DlPath& path) {
12231224
DisplayListAttributeFlags flags = kDrawPathFlags;

0 commit comments

Comments
 (0)