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

Commit 95339e2

Browse files
authored
[DisplayList] Create DlFoo type variants to start moving away from Skia types in API (#55812)
This is the beginning of the bulk of de-skia-fication work in the engine. All of the standard types in the DlCanvas API now have overloads that specify the corresponding Dl type, mainly for Dl*Rect and DlPoint types. This enables further work to switch from SkFoo types to DlFoo types in the various engine modules culminating in the elimination of the old methods that use the Sk types. All of the former methods that used the basic Sk types are now implemented as inlinable translation overloads and the underlying implementations of DlCanvas now implement only the newer style interfaces so that they don't need to be further modified as we eliminate the old Skia types from the interface. There are still a couple of Skia types remaining in the DlCanvas API without any DL type variants which will be handled in a future phase: - SkRRect - SkRSXform - SkTextBlob (will be hidden behind a common interface along with TextFrame) - SkImageInfo (only used in a few calling sites)
1 parent 2eedaf1 commit 95339e2

28 files changed

+881
-759
lines changed

display_list/display_list_unittests.cc

Lines changed: 170 additions & 161 deletions
Large diffs are not rendered by default.

display_list/dl_builder.cc

Lines changed: 56 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ DisplayListBuilder::~DisplayListBuilder() {
147147
}
148148
}
149149

150-
SkISize DisplayListBuilder::GetBaseLayerSize() const {
151-
return ToSkISize(DlIRect::RoundOut(original_cull_rect_).GetSize());
150+
DlISize DisplayListBuilder::GetBaseLayerDimensions() const {
151+
return DlIRect::RoundOut(original_cull_rect_).GetSize();
152152
}
153153

154154
SkImageInfo DisplayListBuilder::GetImageInfo() const {
@@ -540,14 +540,14 @@ void DisplayListBuilder::saveLayer(const DlRect& bounds,
540540
}
541541
}
542542
}
543-
void DisplayListBuilder::SaveLayer(const SkRect* bounds,
543+
void DisplayListBuilder::SaveLayer(std::optional<const DlRect>& bounds,
544544
const DlPaint* paint,
545545
const DlImageFilter* backdrop) {
546546
SaveLayerOptions options;
547547
DlRect temp_bounds;
548-
if (bounds) {
548+
if (bounds.has_value()) {
549549
options = options.with_bounds_from_caller();
550-
temp_bounds = ToDlRect(*bounds);
550+
temp_bounds = *bounds;
551551
} else {
552552
FML_DCHECK(temp_bounds.IsEmpty());
553553
}
@@ -867,7 +867,7 @@ void DisplayListBuilder::TransformFullPerspective(
867867
myz == 0 &&
868868
mzx == 0 && mzy == 0 && mzz == 1 && mzt == 0 &&
869869
mwx == 0 && mwy == 0 && mwz == 0 && mwt == 1) {
870-
Transform2DAffine(mxx, mxy, mxt,
870+
transform2DAffine(mxx, mxy, mxt,
871871
myx, myy, myt);
872872
} else if (std::isfinite(mxx) && std::isfinite(mxy) &&
873873
std::isfinite(mxz) && std::isfinite(mxt) &&
@@ -920,25 +920,18 @@ void DisplayListBuilder::TransformReset() {
920920

921921
global_state().setIdentity();
922922
}
923-
void DisplayListBuilder::Transform(const SkMatrix* matrix) {
924-
if (matrix != nullptr) {
925-
Transform(SkM44(*matrix));
926-
}
927-
}
928-
void DisplayListBuilder::Transform(const SkM44* m44) {
929-
if (m44 != nullptr) {
930-
transformFullPerspective(
931-
m44->rc(0, 0), m44->rc(0, 1), m44->rc(0, 2), m44->rc(0, 3),
932-
m44->rc(1, 0), m44->rc(1, 1), m44->rc(1, 2), m44->rc(1, 3),
933-
m44->rc(2, 0), m44->rc(2, 1), m44->rc(2, 2), m44->rc(2, 3),
934-
m44->rc(3, 0), m44->rc(3, 1), m44->rc(3, 2), m44->rc(3, 3));
935-
}
923+
void DisplayListBuilder::Transform(const DlMatrix& matrix) {
924+
TransformFullPerspective(
925+
matrix.e[0][0], matrix.e[1][0], matrix.e[2][0], matrix.e[3][0],
926+
matrix.e[0][1], matrix.e[1][1], matrix.e[2][1], matrix.e[3][1],
927+
matrix.e[0][2], matrix.e[1][2], matrix.e[2][2], matrix.e[3][2],
928+
matrix.e[0][3], matrix.e[1][3], matrix.e[2][3], matrix.e[3][3]);
936929
}
937930

938-
void DisplayListBuilder::ClipRect(const SkRect& rect,
931+
void DisplayListBuilder::ClipRect(const DlRect& rect,
939932
ClipOp clip_op,
940933
bool is_aa) {
941-
if (!rect.isFinite()) {
934+
if (!rect.IsFinite()) {
942935
return;
943936
}
944937
if (current_info().is_nop) {
@@ -960,17 +953,17 @@ void DisplayListBuilder::ClipRect(const SkRect& rect,
960953
checkForDeferredSave();
961954
switch (clip_op) {
962955
case ClipOp::kIntersect:
963-
Push<ClipIntersectRectOp>(0, ToDlRect(rect), is_aa);
956+
Push<ClipIntersectRectOp>(0, rect, is_aa);
964957
break;
965958
case ClipOp::kDifference:
966-
Push<ClipDifferenceRectOp>(0, ToDlRect(rect), is_aa);
959+
Push<ClipDifferenceRectOp>(0, rect, is_aa);
967960
break;
968961
}
969962
}
970-
void DisplayListBuilder::ClipOval(const SkRect& bounds,
963+
void DisplayListBuilder::ClipOval(const DlRect& bounds,
971964
ClipOp clip_op,
972965
bool is_aa) {
973-
if (!bounds.isFinite()) {
966+
if (!bounds.IsFinite()) {
974967
return;
975968
}
976969
if (current_info().is_nop) {
@@ -992,22 +985,22 @@ void DisplayListBuilder::ClipOval(const SkRect& bounds,
992985
checkForDeferredSave();
993986
switch (clip_op) {
994987
case ClipOp::kIntersect:
995-
Push<ClipIntersectOvalOp>(0, ToDlRect(bounds), is_aa);
988+
Push<ClipIntersectOvalOp>(0, bounds, is_aa);
996989
break;
997990
case ClipOp::kDifference:
998-
Push<ClipDifferenceOvalOp>(0, ToDlRect(bounds), is_aa);
991+
Push<ClipDifferenceOvalOp>(0, bounds, is_aa);
999992
break;
1000993
}
1001994
}
1002995
void DisplayListBuilder::ClipRRect(const SkRRect& rrect,
1003996
ClipOp clip_op,
1004997
bool is_aa) {
1005998
if (rrect.isRect()) {
1006-
ClipRect(rrect.rect(), clip_op, is_aa);
999+
ClipRect(ToDlRect(rrect.rect()), clip_op, is_aa);
10071000
return;
10081001
}
10091002
if (rrect.isOval()) {
1010-
ClipOval(rrect.rect(), clip_op, is_aa);
1003+
ClipOval(ToDlRect(rrect.rect()), clip_op, is_aa);
10111004
return;
10121005
}
10131006
if (current_info().is_nop) {
@@ -1043,12 +1036,12 @@ void DisplayListBuilder::ClipPath(const DlPath& path,
10431036
return;
10441037
}
10451038
if (!path.IsInverseFillType()) {
1046-
SkRect rect;
1047-
if (path.IsSkRect(&rect)) {
1039+
DlRect rect;
1040+
if (path.IsRect(&rect)) {
10481041
ClipRect(rect, clip_op, is_aa);
10491042
return;
10501043
}
1051-
if (path.IsSkOval(&rect)) {
1044+
if (path.IsOval(&rect)) {
10521045
ClipOval(rect, clip_op, is_aa);
10531046
return;
10541047
}
@@ -1077,7 +1070,7 @@ void DisplayListBuilder::ClipPath(const DlPath& path,
10771070
}
10781071
}
10791072

1080-
bool DisplayListBuilder::QuickReject(const SkRect& bounds) const {
1073+
bool DisplayListBuilder::QuickReject(const DlRect& bounds) const {
10811074
return global_state().content_culled(bounds);
10821075
}
10831076

@@ -1113,11 +1106,11 @@ void DisplayListBuilder::drawLine(const DlPoint& p0, const DlPoint& p1) {
11131106
UpdateLayerResult(result);
11141107
}
11151108
}
1116-
void DisplayListBuilder::DrawLine(const SkPoint& p0,
1117-
const SkPoint& p1,
1109+
void DisplayListBuilder::DrawLine(const DlPoint& p0,
1110+
const DlPoint& p1,
11181111
const DlPaint& paint) {
11191112
SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawLineFlags);
1120-
drawLine(ToDlPoint(p0), ToDlPoint(p1));
1113+
drawLine(p0, p1);
11211114
}
11221115
void DisplayListBuilder::drawDashedLine(const DlPoint& p0,
11231116
const DlPoint& p1,
@@ -1152,9 +1145,9 @@ void DisplayListBuilder::drawRect(const DlRect& rect) {
11521145
UpdateLayerResult(result);
11531146
}
11541147
}
1155-
void DisplayListBuilder::DrawRect(const SkRect& rect, const DlPaint& paint) {
1148+
void DisplayListBuilder::DrawRect(const DlRect& rect, const DlPaint& paint) {
11561149
SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawRectFlags);
1157-
drawRect(ToDlRect(rect));
1150+
drawRect(rect);
11581151
}
11591152
void DisplayListBuilder::drawOval(const DlRect& bounds) {
11601153
DisplayListAttributeFlags flags = kDrawOvalFlags;
@@ -1166,9 +1159,9 @@ void DisplayListBuilder::drawOval(const DlRect& bounds) {
11661159
UpdateLayerResult(result);
11671160
}
11681161
}
1169-
void DisplayListBuilder::DrawOval(const SkRect& bounds, const DlPaint& paint) {
1162+
void DisplayListBuilder::DrawOval(const DlRect& bounds, const DlPaint& paint) {
11701163
SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawOvalFlags);
1171-
drawOval(ToDlRect(bounds));
1164+
drawOval(bounds);
11721165
}
11731166
void DisplayListBuilder::drawCircle(const DlPoint& center, DlScalar radius) {
11741167
DisplayListAttributeFlags flags = kDrawCircleFlags;
@@ -1183,11 +1176,11 @@ void DisplayListBuilder::drawCircle(const DlPoint& center, DlScalar radius) {
11831176
}
11841177
}
11851178
}
1186-
void DisplayListBuilder::DrawCircle(const SkPoint& center,
1179+
void DisplayListBuilder::DrawCircle(const DlPoint& center,
11871180
DlScalar radius,
11881181
const DlPaint& paint) {
11891182
SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawCircleFlags);
1190-
drawCircle(ToDlPoint(center), radius);
1183+
drawCircle(center, radius);
11911184
}
11921185
void DisplayListBuilder::drawRRect(const SkRRect& rrect) {
11931186
if (rrect.isRect()) {
@@ -1241,11 +1234,6 @@ void DisplayListBuilder::drawPath(const DlPath& path) {
12411234
}
12421235
}
12431236
}
1244-
void DisplayListBuilder::DrawPath(const SkPath& path, const DlPaint& paint) {
1245-
SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawPathFlags);
1246-
DlPath dl_path(path);
1247-
drawPath(dl_path);
1248-
}
12491237
void DisplayListBuilder::DrawPath(const DlPath& path, const DlPaint& paint) {
12501238
SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawPathFlags);
12511239
drawPath(path);
@@ -1274,14 +1262,14 @@ void DisplayListBuilder::drawArc(const DlRect& bounds,
12741262
UpdateLayerResult(result);
12751263
}
12761264
}
1277-
void DisplayListBuilder::DrawArc(const SkRect& bounds,
1265+
void DisplayListBuilder::DrawArc(const DlRect& bounds,
12781266
DlScalar start,
12791267
DlScalar sweep,
12801268
bool useCenter,
12811269
const DlPaint& paint) {
12821270
SetAttributesFromPaint(
12831271
paint, useCenter ? kDrawArcWithCenterFlags : kDrawArcNoCenterFlags);
1284-
drawArc(ToDlRect(bounds), start, sweep, useCenter);
1272+
drawArc(bounds, start, sweep, useCenter);
12851273
}
12861274

12871275
DisplayListAttributeFlags DisplayListBuilder::FlagsForPointMode(
@@ -1350,10 +1338,10 @@ void DisplayListBuilder::drawPoints(PointMode mode,
13501338
}
13511339
void DisplayListBuilder::DrawPoints(PointMode mode,
13521340
uint32_t count,
1353-
const SkPoint pts[],
1341+
const DlPoint pts[],
13541342
const DlPaint& paint) {
13551343
SetAttributesFromPaint(paint, FlagsForPointMode(mode));
1356-
drawPoints(mode, count, ToDlPoints(pts));
1344+
drawPoints(mode, count, pts);
13571345
}
13581346
void DisplayListBuilder::drawVertices(
13591347
const std::shared_ptr<DlVertices>& vertices,
@@ -1411,15 +1399,15 @@ void DisplayListBuilder::drawImage(const sk_sp<DlImage> image,
14111399
}
14121400
}
14131401
void DisplayListBuilder::DrawImage(const sk_sp<DlImage>& image,
1414-
const SkPoint& point,
1402+
const DlPoint& point,
14151403
DlImageSampling sampling,
14161404
const DlPaint* paint) {
14171405
if (paint != nullptr) {
14181406
SetAttributesFromPaint(*paint,
14191407
DisplayListOpFlags::kDrawImageWithPaintFlags);
1420-
drawImage(image, ToDlPoint(point), sampling, true);
1408+
drawImage(image, point, sampling, true);
14211409
} else {
1422-
drawImage(image, ToDlPoint(point), sampling, false);
1410+
drawImage(image, point, sampling, false);
14231411
}
14241412
}
14251413
void DisplayListBuilder::drawImageRect(const sk_sp<DlImage> image,
@@ -1442,19 +1430,17 @@ void DisplayListBuilder::drawImageRect(const sk_sp<DlImage> image,
14421430
}
14431431
}
14441432
void DisplayListBuilder::DrawImageRect(const sk_sp<DlImage>& image,
1445-
const SkRect& src,
1446-
const SkRect& dst,
1433+
const DlRect& src,
1434+
const DlRect& dst,
14471435
DlImageSampling sampling,
14481436
const DlPaint* paint,
14491437
SrcRectConstraint constraint) {
14501438
if (paint != nullptr) {
14511439
SetAttributesFromPaint(*paint,
14521440
DisplayListOpFlags::kDrawImageRectWithPaintFlags);
1453-
drawImageRect(image, ToDlRect(src), ToDlRect(dst), sampling, true,
1454-
constraint);
1441+
drawImageRect(image, src, dst, sampling, true, constraint);
14551442
} else {
1456-
drawImageRect(image, ToDlRect(src), ToDlRect(dst), sampling, false,
1457-
constraint);
1443+
drawImageRect(image, src, dst, sampling, false, constraint);
14581444
}
14591445
}
14601446
void DisplayListBuilder::drawImageNine(const sk_sp<DlImage> image,
@@ -1477,16 +1463,16 @@ void DisplayListBuilder::drawImageNine(const sk_sp<DlImage> image,
14771463
}
14781464
}
14791465
void DisplayListBuilder::DrawImageNine(const sk_sp<DlImage>& image,
1480-
const SkIRect& center,
1481-
const SkRect& dst,
1466+
const DlIRect& center,
1467+
const DlRect& dst,
14821468
DlFilterMode filter,
14831469
const DlPaint* paint) {
14841470
if (paint != nullptr) {
14851471
SetAttributesFromPaint(*paint,
14861472
DisplayListOpFlags::kDrawImageNineWithPaintFlags);
1487-
drawImageNine(image, ToDlIRect(center), ToDlRect(dst), filter, true);
1473+
drawImageNine(image, center, dst, filter, true);
14881474
} else {
1489-
drawImageNine(image, ToDlIRect(center), ToDlRect(dst), filter, false);
1475+
drawImageNine(image, center, dst, filter, false);
14901476
}
14911477
}
14921478
void DisplayListBuilder::drawAtlas(const sk_sp<DlImage> atlas,
@@ -1565,21 +1551,21 @@ void DisplayListBuilder::drawAtlas(const sk_sp<DlImage> atlas,
15651551
}
15661552
void DisplayListBuilder::DrawAtlas(const sk_sp<DlImage>& atlas,
15671553
const SkRSXform xform[],
1568-
const SkRect tex[],
1554+
const DlRect tex[],
15691555
const DlColor colors[],
15701556
int count,
15711557
DlBlendMode mode,
15721558
DlImageSampling sampling,
1573-
const SkRect* cull_rect,
1559+
const DlRect* cull_rect,
15741560
const DlPaint* paint) {
15751561
if (paint != nullptr) {
15761562
SetAttributesFromPaint(*paint,
15771563
DisplayListOpFlags::kDrawAtlasWithPaintFlags);
1578-
drawAtlas(atlas, xform, ToDlRects(tex), colors, count, mode, sampling,
1579-
ToDlRect(cull_rect), true);
1564+
drawAtlas(atlas, xform, tex, colors, count, mode, sampling, cull_rect,
1565+
true);
15801566
} else {
1581-
drawAtlas(atlas, xform, ToDlRects(tex), colors, count, mode, sampling,
1582-
ToDlRect(cull_rect), false);
1567+
drawAtlas(atlas, xform, tex, colors, count, mode, sampling, cull_rect,
1568+
false);
15831569
}
15841570
}
15851571

0 commit comments

Comments
 (0)