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

Commit 51d93f8

Browse files
authored
[DisplayList] use DlScalar, DlPoint, DlRect exclusively in DlOpReceiver methods (#54982)
Wean the DlOpReceiver interface and implementations off of using the SkScalar, Sk[I]Rect, and SkPoint objects in favor of our own DL/Impeller versions. The start of an ongoing effort to eventually compartmentalize all use of Skia interfaces into a single backend rendering module that is one of 2 semi-pluggable renderers.
1 parent f0bb98a commit 51d93f8

37 files changed

+1133
-972
lines changed

display_list/benchmarking/dl_complexity_gl.cc

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ unsigned int DisplayListGLComplexityCalculator::GLHelper::BatchedComplexity() {
4949
}
5050

5151
void DisplayListGLComplexityCalculator::GLHelper::saveLayer(
52-
const SkRect& bounds,
52+
const DlRect& bounds,
5353
const SaveLayerOptions options,
5454
const DlImageFilter* backdrop) {
5555
if (IsComplex()) {
@@ -64,8 +64,8 @@ void DisplayListGLComplexityCalculator::GLHelper::saveLayer(
6464
save_layer_count_++;
6565
}
6666

67-
void DisplayListGLComplexityCalculator::GLHelper::drawLine(const SkPoint& p0,
68-
const SkPoint& p1) {
67+
void DisplayListGLComplexityCalculator::GLHelper::drawLine(const DlPoint& p0,
68+
const DlPoint& p1) {
6969
if (IsComplex()) {
7070
return;
7171
}
@@ -89,7 +89,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawLine(const SkPoint& p0,
8989

9090
// Use an approximation for the distance to avoid floating point or
9191
// sqrt() calls.
92-
SkScalar distance = abs(p0.x() - p1.x()) + abs(p0.y() - p1.y());
92+
DlScalar distance = abs(p0.x - p1.x) + abs(p0.y - p1.y);
9393

9494
// The baseline complexity is for a hairline stroke with no AA.
9595
// m = 1/40
@@ -107,10 +107,10 @@ void DisplayListGLComplexityCalculator::GLHelper::drawDashedLine(
107107
DlScalar off_length) {
108108
// Dashing is slightly more complex than a regular drawLine, but this
109109
// op is so rare it is not worth measuring the difference.
110-
drawLine(ToSkPoint(p0), ToSkPoint(p1));
110+
drawLine(p0, p1);
111111
}
112112

113-
void DisplayListGLComplexityCalculator::GLHelper::drawRect(const SkRect& rect) {
113+
void DisplayListGLComplexityCalculator::GLHelper::drawRect(const DlRect& rect) {
114114
if (IsComplex()) {
115115
return;
116116
}
@@ -126,14 +126,14 @@ void DisplayListGLComplexityCalculator::GLHelper::drawRect(const SkRect& rect) {
126126
// currently use it anywhere in Flutter.
127127
if (DrawStyle() == DlDrawStyle::kFill) {
128128
// No real difference for AA with filled styles
129-
unsigned int area = rect.width() * rect.height();
129+
unsigned int area = rect.GetWidth() * rect.GetHeight();
130130

131131
// m = 1/3500
132132
// c = 0
133133
complexity = area * 2 / 175;
134134
} else {
135135
// Take the average of the width and height.
136-
unsigned int length = (rect.width() + rect.height()) / 2;
136+
unsigned int length = (rect.GetWidth() + rect.GetHeight()) / 2;
137137

138138
if (IsAntiAliased()) {
139139
// m = 1/30
@@ -160,7 +160,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawRect(const SkRect& rect) {
160160
}
161161

162162
void DisplayListGLComplexityCalculator::GLHelper::drawOval(
163-
const SkRect& bounds) {
163+
const DlRect& bounds) {
164164
if (IsComplex()) {
165165
return;
166166
}
@@ -169,7 +169,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawOval(
169169
//
170170
// Filled styles and stroked styles with AA scale linearly with the bounding
171171
// box area.
172-
unsigned int area = bounds.width() * bounds.height();
172+
unsigned int area = bounds.GetWidth() * bounds.GetHeight();
173173

174174
unsigned int complexity;
175175

@@ -187,7 +187,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawOval(
187187
complexity = area / 20;
188188
} else {
189189
// Take the average of the width and height.
190-
unsigned int length = (bounds.width() + bounds.height()) / 2;
190+
unsigned int length = (bounds.GetWidth() + bounds.GetHeight()) / 2;
191191

192192
// m = 1/75
193193
// c = 0
@@ -199,8 +199,8 @@ void DisplayListGLComplexityCalculator::GLHelper::drawOval(
199199
}
200200

201201
void DisplayListGLComplexityCalculator::GLHelper::drawCircle(
202-
const SkPoint& center,
203-
SkScalar radius) {
202+
const DlPoint& center,
203+
DlScalar radius) {
204204
if (IsComplex()) {
205205
return;
206206
}
@@ -372,9 +372,9 @@ void DisplayListGLComplexityCalculator::GLHelper::drawPath(const SkPath& path) {
372372
}
373373

374374
void DisplayListGLComplexityCalculator::GLHelper::drawArc(
375-
const SkRect& oval_bounds,
376-
SkScalar start_degrees,
377-
SkScalar sweep_degrees,
375+
const DlRect& oval_bounds,
376+
DlScalar start_degrees,
377+
DlScalar sweep_degrees,
378378
bool use_center) {
379379
if (IsComplex()) {
380380
return;
@@ -383,7 +383,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawArc(
383383
// Stroked styles without AA scale linearly with the log of the diameter.
384384
// Stroked styles with AA scale linearly with the area.
385385
// Filled styles scale lienarly with the area.
386-
unsigned int area = oval_bounds.width() * oval_bounds.height();
386+
unsigned int area = oval_bounds.GetWidth() * oval_bounds.GetHeight();
387387
unsigned int complexity;
388388

389389
// These values were worked out by creating a straight line graph (y=mx+c)
@@ -398,7 +398,8 @@ void DisplayListGLComplexityCalculator::GLHelper::drawArc(
398398
// c = 12
399399
complexity = (area + 45600) / 171;
400400
} else {
401-
unsigned int diameter = (oval_bounds.width() + oval_bounds.height()) / 2;
401+
unsigned int diameter =
402+
(oval_bounds.GetWidth() + oval_bounds.GetHeight()) / 2;
402403
// m = 15
403404
// c = -100
404405
// This should never go negative though, so use std::max to ensure
@@ -426,7 +427,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawArc(
426427
void DisplayListGLComplexityCalculator::GLHelper::drawPoints(
427428
DlCanvas::PointMode mode,
428429
uint32_t count,
429-
const SkPoint points[]) {
430+
const DlPoint points[]) {
430431
if (IsComplex()) {
431432
return;
432433
}
@@ -514,7 +515,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawVertices(
514515

515516
void DisplayListGLComplexityCalculator::GLHelper::drawImage(
516517
const sk_sp<DlImage> image,
517-
const SkPoint point,
518+
const DlPoint& point,
518519
DlImageSampling sampling,
519520
bool render_with_attributes) {
520521
if (IsComplex()) {
@@ -594,8 +595,8 @@ void DisplayListGLComplexityCalculator::GLHelper::ImageRect(
594595

595596
void DisplayListGLComplexityCalculator::GLHelper::drawImageNine(
596597
const sk_sp<DlImage> image,
597-
const SkIRect& center,
598-
const SkRect& dst,
598+
const DlIRect& center,
599+
const DlRect& dst,
599600
DlFilterMode filter,
600601
bool render_with_attributes) {
601602
if (IsComplex()) {
@@ -619,13 +620,13 @@ void DisplayListGLComplexityCalculator::GLHelper::drawImageNine(
619620

620621
void DisplayListGLComplexityCalculator::GLHelper::drawDisplayList(
621622
const sk_sp<DisplayList> display_list,
622-
SkScalar opacity) {
623+
DlScalar opacity) {
623624
if (IsComplex()) {
624625
return;
625626
}
626627
GLHelper helper(Ceiling() - CurrentComplexityScore());
627628
if (opacity < SK_Scalar1 && !display_list->can_apply_group_opacity()) {
628-
auto bounds = display_list->bounds();
629+
auto bounds = display_list->GetBounds();
629630
helper.saveLayer(bounds, SaveLayerOptions::kWithAttributes, nullptr);
630631
}
631632
display_list->Dispatch(helper);
@@ -634,8 +635,8 @@ void DisplayListGLComplexityCalculator::GLHelper::drawDisplayList(
634635

635636
void DisplayListGLComplexityCalculator::GLHelper::drawTextBlob(
636637
const sk_sp<SkTextBlob> blob,
637-
SkScalar x,
638-
SkScalar y) {
638+
DlScalar x,
639+
DlScalar y) {
639640
if (IsComplex()) {
640641
return;
641642
}
@@ -650,15 +651,15 @@ void DisplayListGLComplexityCalculator::GLHelper::drawTextBlob(
650651

651652
void DisplayListGLComplexityCalculator::GLHelper::drawTextFrame(
652653
const std::shared_ptr<impeller::TextFrame>& text_frame,
653-
SkScalar x,
654-
SkScalar y) {}
654+
DlScalar x,
655+
DlScalar y) {}
655656

656657
void DisplayListGLComplexityCalculator::GLHelper::drawShadow(
657658
const SkPath& path,
658659
const DlColor color,
659-
const SkScalar elevation,
660+
const DlScalar elevation,
660661
bool transparent_occluder,
661-
SkScalar dpr) {
662+
DlScalar dpr) {
662663
if (IsComplex()) {
663664
return;
664665
}

display_list/benchmarking/dl_complexity_gl.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,52 +35,52 @@ class DisplayListGLComplexityCalculator
3535
explicit GLHelper(unsigned int ceiling)
3636
: ComplexityCalculatorHelper(ceiling) {}
3737

38-
void saveLayer(const SkRect& bounds,
38+
void saveLayer(const DlRect& bounds,
3939
const SaveLayerOptions options,
4040
const DlImageFilter* backdrop) override;
4141

42-
void drawLine(const SkPoint& p0, const SkPoint& p1) override;
42+
void drawLine(const DlPoint& p0, const DlPoint& p1) override;
4343
void drawDashedLine(const DlPoint& p0,
4444
const DlPoint& p1,
4545
DlScalar on_length,
4646
DlScalar off_length) override;
47-
void drawRect(const SkRect& rect) override;
48-
void drawOval(const SkRect& bounds) override;
49-
void drawCircle(const SkPoint& center, SkScalar radius) override;
47+
void drawRect(const DlRect& rect) override;
48+
void drawOval(const DlRect& bounds) override;
49+
void drawCircle(const DlPoint& center, DlScalar radius) override;
5050
void drawRRect(const SkRRect& rrect) override;
5151
void drawDRRect(const SkRRect& outer, const SkRRect& inner) override;
5252
void drawPath(const SkPath& path) override;
53-
void drawArc(const SkRect& oval_bounds,
54-
SkScalar start_degrees,
55-
SkScalar sweep_degrees,
53+
void drawArc(const DlRect& oval_bounds,
54+
DlScalar start_degrees,
55+
DlScalar sweep_degrees,
5656
bool use_center) override;
5757
void drawPoints(DlCanvas::PointMode mode,
5858
uint32_t count,
59-
const SkPoint points[]) override;
59+
const DlPoint points[]) override;
6060
void drawVertices(const std::shared_ptr<DlVertices>& vertices,
6161
DlBlendMode mode) override;
6262
void drawImage(const sk_sp<DlImage> image,
63-
const SkPoint point,
63+
const DlPoint& point,
6464
DlImageSampling sampling,
6565
bool render_with_attributes) override;
6666
void drawImageNine(const sk_sp<DlImage> image,
67-
const SkIRect& center,
68-
const SkRect& dst,
67+
const DlIRect& center,
68+
const DlRect& dst,
6969
DlFilterMode filter,
7070
bool render_with_attributes) override;
7171
void drawDisplayList(const sk_sp<DisplayList> display_list,
72-
SkScalar opacity) override;
72+
DlScalar opacity) override;
7373
void drawTextBlob(const sk_sp<SkTextBlob> blob,
74-
SkScalar x,
75-
SkScalar y) override;
74+
DlScalar x,
75+
DlScalar y) override;
7676
void drawTextFrame(const std::shared_ptr<impeller::TextFrame>& text_frame,
77-
SkScalar x,
78-
SkScalar y) override;
77+
DlScalar x,
78+
DlScalar y) override;
7979
void drawShadow(const SkPath& path,
8080
const DlColor color,
81-
const SkScalar elevation,
81+
const DlScalar elevation,
8282
bool transparent_occluder,
83-
SkScalar dpr) override;
83+
DlScalar dpr) override;
8484

8585
protected:
8686
void ImageRect(const SkISize& size,

display_list/benchmarking/dl_complexity_helper.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ class ComplexityCalculatorHelper
145145

146146
void drawImageRect(
147147
const sk_sp<DlImage> image,
148-
const SkRect& src,
149-
const SkRect& dst,
148+
const DlRect& src,
149+
const DlRect& dst,
150150
DlImageSampling sampling,
151151
bool render_with_attributes,
152152
SrcRectConstraint constraint = SrcRectConstraint::kFast) override {
@@ -159,20 +159,20 @@ class ComplexityCalculatorHelper
159159

160160
void drawAtlas(const sk_sp<DlImage> atlas,
161161
const SkRSXform xform[],
162-
const SkRect tex[],
162+
const DlRect tex[],
163163
const DlColor colors[],
164164
int count,
165165
DlBlendMode mode,
166166
DlImageSampling sampling,
167-
const SkRect* cull_rect,
167+
const DlRect* cull_rect,
168168
bool render_with_attributes) override {
169169
if (IsComplex()) {
170170
return;
171171
}
172172
// This API just does a series of drawImage calls from the atlas
173173
// This is equivalent to calling drawImageRect lots of times
174174
for (int i = 0; i < count; i++) {
175-
ImageRect(SkISize::Make(tex[i].width(), tex[i].height()), true,
175+
ImageRect(SkISize::Make(tex[i].GetWidth(), tex[i].GetHeight()), true,
176176
render_with_attributes, true);
177177
}
178178
}

0 commit comments

Comments
 (0)