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

Commit bb96142

Browse files
committed
switch DL rendertests to DlCanvas(SkCanvas) and DlCanvas(Builder) operations
1 parent 623c935 commit bb96142

10 files changed

+866
-737
lines changed

display_list/display_list_canvas_unittests.cc

+711-704
Large diffs are not rendered by default.

display_list/display_list_flags.h

+4
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ class DisplayListAttributeFlags : DisplayListFlagsBase {
222222

223223
constexpr bool is_flood() const { return has_any(kFloodsSurface_); }
224224

225+
constexpr bool operator==(DisplayListAttributeFlags const& other) const {
226+
return flags_ == other.flags_;
227+
}
228+
225229
private:
226230
explicit constexpr DisplayListAttributeFlags(int flags)
227231
: DisplayListFlagsBase(flags),

display_list/display_list_ops.h

+78-21
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,13 @@ struct DrawVerticesOp final : DrawOpBase {
831831
if (op_needed(ctx)) { \
832832
ctx.dispatcher.drawImage(image, point, sampling, with_attributes); \
833833
} \
834+
} \
835+
\
836+
DisplayListCompare equals(const name##Op* other) const { \
837+
return (point == other->point && sampling == other->sampling && \
838+
image->Equals(other->image)) \
839+
? DisplayListCompare::kEqual \
840+
: DisplayListCompare::kNotEqual; \
834841
} \
835842
};
836843
DEFINE_DRAW_IMAGE_OP(DrawImage, false)
@@ -868,30 +875,46 @@ struct DrawImageRectOp final : DrawOpBase {
868875
render_with_attributes, constraint);
869876
}
870877
}
878+
879+
DisplayListCompare equals(const DrawImageRectOp* other) const {
880+
return (src == other->src && dst == other->dst &&
881+
sampling == other->sampling &&
882+
render_with_attributes == other->render_with_attributes &&
883+
constraint == other->constraint && image->Equals(other->image))
884+
? DisplayListCompare::kEqual
885+
: DisplayListCompare::kNotEqual;
886+
}
871887
};
872888

873889
// 4 byte header + 44 byte payload packs efficiently into 48 bytes
874-
#define DEFINE_DRAW_IMAGE_NINE_OP(name, render_with_attributes) \
875-
struct name##Op final : DrawOpBase { \
876-
static const auto kType = DisplayListOpType::k##name; \
877-
\
878-
name##Op(const sk_sp<DlImage> image, \
879-
const SkIRect& center, \
880-
const SkRect& dst, \
881-
DlFilterMode filter) \
882-
: center(center), dst(dst), filter(filter), image(std::move(image)) {} \
883-
\
884-
const SkIRect center; \
885-
const SkRect dst; \
886-
const DlFilterMode filter; \
887-
const sk_sp<DlImage> image; \
888-
\
889-
void dispatch(DispatchContext& ctx) const { \
890-
if (op_needed(ctx)) { \
891-
ctx.dispatcher.drawImageNine(image, center, dst, filter, \
892-
render_with_attributes); \
893-
} \
894-
} \
890+
#define DEFINE_DRAW_IMAGE_NINE_OP(name, render_with_attributes) \
891+
struct name##Op final : DrawOpBase { \
892+
static const auto kType = DisplayListOpType::k##name; \
893+
\
894+
name##Op(const sk_sp<DlImage> image, \
895+
const SkIRect& center, \
896+
const SkRect& dst, \
897+
DlFilterMode mode) \
898+
: center(center), dst(dst), mode(mode), image(std::move(image)) {} \
899+
\
900+
const SkIRect center; \
901+
const SkRect dst; \
902+
const DlFilterMode mode; \
903+
const sk_sp<DlImage> image; \
904+
\
905+
void dispatch(DispatchContext& ctx) const { \
906+
if (op_needed(ctx)) { \
907+
ctx.dispatcher.drawImageNine(image, center, dst, mode, \
908+
render_with_attributes); \
909+
} \
910+
} \
911+
\
912+
DisplayListCompare equals(const name##Op* other) const { \
913+
return (center == other->center && dst == other->dst && \
914+
mode == other->mode && image->Equals(other->image)) \
915+
? DisplayListCompare::kEqual \
916+
: DisplayListCompare::kNotEqual; \
917+
} \
895918
};
896919
DEFINE_DRAW_IMAGE_NINE_OP(DrawImageNine, false)
897920
DEFINE_DRAW_IMAGE_NINE_OP(DrawImageNineWithAttr, true)
@@ -924,6 +947,23 @@ struct DrawAtlasBaseOp : DrawOpBase {
924947
const uint8_t render_with_attributes;
925948
const DlImageSampling sampling;
926949
const sk_sp<DlImage> atlas;
950+
951+
bool equals(const DrawAtlasBaseOp* other,
952+
const void* pod_this,
953+
const void* pod_other) const {
954+
bool ret = (count == other->count && mode_index == other->mode_index &&
955+
has_colors == other->has_colors &&
956+
render_with_attributes == other->render_with_attributes &&
957+
sampling == other->sampling && atlas->Equals(other->atlas));
958+
if (ret) {
959+
size_t bytes = count * (sizeof(SkRSXform) + sizeof(SkRect));
960+
if (has_colors) {
961+
bytes += count * sizeof(DlColor);
962+
}
963+
ret = (memcmp(pod_this, pod_other, bytes) == 0);
964+
}
965+
return ret;
966+
}
927967
};
928968

929969
// Packs into 48 bytes as per DrawAtlasBaseOp
@@ -955,6 +995,14 @@ struct DrawAtlasOp final : DrawAtlasBaseOp {
955995
nullptr, render_with_attributes);
956996
}
957997
}
998+
999+
DisplayListCompare equals(const DrawAtlasOp* other) const {
1000+
const void* pod_this = reinterpret_cast<const void*>(this + 1);
1001+
const void* pod_other = reinterpret_cast<const void*>(other + 1);
1002+
return (DrawAtlasBaseOp::equals(other, pod_this, pod_other))
1003+
? DisplayListCompare::kEqual
1004+
: DisplayListCompare::kNotEqual;
1005+
}
9581006
};
9591007

9601008
// Packs into 48 bytes as per DrawAtlasBaseOp plus
@@ -992,6 +1040,15 @@ struct DrawAtlasCulledOp final : DrawAtlasBaseOp {
9921040
&cull_rect, render_with_attributes);
9931041
}
9941042
}
1043+
1044+
DisplayListCompare equals(const DrawAtlasCulledOp* other) const {
1045+
const void* pod_this = reinterpret_cast<const void*>(this + 1);
1046+
const void* pod_other = reinterpret_cast<const void*>(other + 1);
1047+
return (cull_rect == other->cull_rect &&
1048+
DrawAtlasBaseOp::equals(other, pod_this, pod_other))
1049+
? DisplayListCompare::kEqual
1050+
: DisplayListCompare::kNotEqual;
1051+
}
9951052
};
9961053

9971054
// 4 byte header + ptr aligned payload uses 12 bytes round up to 16

display_list/display_list_paint.cc

+2
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ bool DlPaint::operator==(DlPaint const& other) const {
3535
Equals(maskFilter_, other.maskFilter_);
3636
}
3737

38+
const DlPaint DlPaint::kDefault;
39+
3840
} // namespace flutter

display_list/display_list_paint.h

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class DlPaint {
7373
static constexpr float kDefaultWidth = 0.0;
7474
static constexpr float kDefaultMiter = 4.0;
7575

76+
static const DlPaint kDefault;
77+
7678
DlPaint() : DlPaint(DlColor::kBlack()) {}
7779
DlPaint(DlColor color);
7880

@@ -215,6 +217,8 @@ class DlPaint {
215217
return *this;
216218
}
217219

220+
bool isDefault() const { return *this == kDefault; }
221+
218222
bool operator==(DlPaint const& other) const;
219223
bool operator!=(DlPaint const& other) const { return !(*this == other); }
220224

display_list/display_list_paint_unittests.cc

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ TEST(DisplayListPaint, ConstructorDefaults) {
2727
EXPECT_EQ(paint.getColorFilter(), nullptr);
2828
EXPECT_EQ(paint.getImageFilter(), nullptr);
2929
EXPECT_EQ(paint.getMaskFilter(), nullptr);
30+
EXPECT_TRUE(paint.isDefault());
31+
EXPECT_EQ(paint, DlPaint::kDefault);
3032

3133
EXPECT_EQ(DlBlendMode::kDefaultMode, DlBlendMode::kSrcOver);
3234
EXPECT_EQ(DlDrawStyle::kDefaultStyle, DlDrawStyle::kFill);

display_list/dl_canvas.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ class DlCanvas {
109109
virtual bool QuickReject(const SkRect& bounds) const = 0;
110110

111111
virtual void DrawPaint(const DlPaint& paint) = 0;
112-
virtual void DrawColor(DlColor color, DlBlendMode mode) = 0;
112+
virtual void DrawColor(DlColor color,
113+
DlBlendMode mode = DlBlendMode::kSrcOver) = 0;
113114
void Clear(DlColor color) { DrawColor(color, DlBlendMode::kSrc); }
114115
virtual void DrawLine(const SkPoint& p0,
115116
const SkPoint& p1,

display_list/skia/dl_sk_canvas.cc

+32-11
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,41 @@ static SkCanvas::PointMode ToSk(DlCanvas::PointMode mode) {
4141
return static_cast<SkCanvas::PointMode>(mode);
4242
}
4343

44-
static SkPaint ToSk(const DlPaint& paint) {
44+
// clang-format off
45+
constexpr float kInvertColorMatrix[20] = {
46+
-1.0, 0, 0, 1.0, 0,
47+
0, -1.0, 0, 1.0, 0,
48+
0, 0, -1.0, 1.0, 0,
49+
1.0, 1.0, 1.0, 1.0, 0
50+
};
51+
// clang-format on
52+
53+
static SkPaint ToSk(const DlPaint& paint, bool force_stroke = false) {
4554
SkPaint sk_paint;
4655

56+
sk_paint.setAntiAlias(paint.isAntiAlias());
57+
sk_paint.setDither(paint.isDither());
58+
4759
sk_paint.setColor(paint.getColor());
4860
sk_paint.setBlendMode(ToSk(paint.getBlendMode()));
49-
sk_paint.setStyle(ToSk(paint.getDrawStyle()));
61+
sk_paint.setStyle(force_stroke ? SkPaint::kStroke_Style
62+
: ToSk(paint.getDrawStyle()));
5063
sk_paint.setStrokeWidth(paint.getStrokeWidth());
5164
sk_paint.setStrokeMiter(paint.getStrokeMiter());
5265
sk_paint.setStrokeCap(ToSk(paint.getStrokeCap()));
5366
sk_paint.setStrokeJoin(ToSk(paint.getStrokeJoin()));
5467

5568
sk_paint.setShader(ToSk(paint.getColorSourcePtr()));
5669
sk_paint.setImageFilter(ToSk(paint.getImageFilterPtr()));
57-
sk_paint.setColorFilter(ToSk(paint.getColorFilterPtr()));
70+
auto color_filter = ToSk(paint.getColorFilterPtr());
71+
if (paint.isInvertColors()) {
72+
auto invert_filter = SkColorFilters::Matrix(kInvertColorMatrix);
73+
if (color_filter) {
74+
invert_filter = invert_filter->makeComposed(color_filter);
75+
}
76+
color_filter = invert_filter;
77+
}
78+
sk_paint.setColorFilter(color_filter);
5879
sk_paint.setMaskFilter(ToSk(paint.getMaskFilterPtr()));
5980
sk_paint.setPathEffect(ToSk(paint.getPathEffectPtr()));
6081

@@ -63,10 +84,10 @@ static SkPaint ToSk(const DlPaint& paint) {
6384

6485
class SkOptionalPaint {
6586
public:
66-
explicit SkOptionalPaint(const DlPaint* paint) {
67-
if (paint) {
68-
paint_ = ToSk(*paint);
69-
ptr_ = &paint_;
87+
explicit SkOptionalPaint(const DlPaint* dl_paint) {
88+
if (dl_paint && !dl_paint->isDefault()) {
89+
sk_paint_ = ToSk(*dl_paint);
90+
ptr_ = &sk_paint_;
7091
} else {
7192
ptr_ = nullptr;
7293
}
@@ -75,7 +96,7 @@ class SkOptionalPaint {
7596
SkPaint* operator()() { return ptr_; }
7697

7798
private:
78-
SkPaint paint_;
99+
SkPaint sk_paint_;
79100
SkPaint* ptr_;
80101
};
81102

@@ -239,7 +260,7 @@ void DlSkCanvasAdapter::DrawColor(DlColor color, DlBlendMode mode) {
239260
void DlSkCanvasAdapter::DrawLine(const SkPoint& p0,
240261
const SkPoint& p1,
241262
const DlPaint& paint) {
242-
delegate_->drawLine(p0, p1, ToSk(paint));
263+
delegate_->drawLine(p0, p1, ToSk(paint, true));
243264
}
244265

245266
void DlSkCanvasAdapter::DrawRect(const SkRect& rect, const DlPaint& paint) {
@@ -282,7 +303,7 @@ void DlSkCanvasAdapter::DrawPoints(PointMode mode,
282303
uint32_t count,
283304
const SkPoint pts[],
284305
const DlPaint& paint) {
285-
delegate_->drawPoints(ToSk(mode), count, pts, ToSk(paint));
306+
delegate_->drawPoints(ToSk(mode), count, pts, ToSk(paint, true));
286307
}
287308

288309
void DlSkCanvasAdapter::DrawVertices(const DlVertices* vertices,
@@ -358,7 +379,7 @@ void DlSkCanvasAdapter::DrawShadow(const SkPath& path,
358379
bool transparent_occluder,
359380
SkScalar dpr) {
360381
DisplayListCanvasDispatcher::DrawShadow(delegate_, path, color, elevation,
361-
SkColorGetA(color) != 0xff, dpr);
382+
transparent_occluder, dpr);
362383
}
363384

364385
void DlSkCanvasAdapter::Flush() {

display_list/testing/dl_test_snippets.cc

+30
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,11 @@ std::vector<DisplayListInvocationGroup> CreateAllRenderingOps() {
769769
[](DisplayListBuilder& b) {
770770
b.drawImage(TestImage2, {10, 10}, kNearestSampling, false);
771771
}},
772+
{1, 24, -1, 48,
773+
[](DisplayListBuilder& b) {
774+
auto dl_image = DlImage::Make(TestSkImage);
775+
b.drawImage(dl_image, {10, 10}, kNearestSampling, false);
776+
}},
772777
}},
773778
{"DrawImageRect",
774779
{
@@ -809,6 +814,12 @@ std::vector<DisplayListInvocationGroup> CreateAllRenderingOps() {
809814
b.drawImageRect(TestImage2, {10, 10, 15, 15}, {10, 10, 80, 80},
810815
kNearestSampling, false);
811816
}},
817+
{1, 56, -1, 80,
818+
[](DisplayListBuilder& b) {
819+
auto dl_image = DlImage::Make(TestSkImage);
820+
b.drawImageRect(dl_image, {10, 10, 15, 15}, {10, 10, 80, 80},
821+
kNearestSampling, false);
822+
}},
812823
}},
813824
{"DrawImageNine",
814825
{
@@ -844,6 +855,12 @@ std::vector<DisplayListInvocationGroup> CreateAllRenderingOps() {
844855
b.drawImageNine(TestImage2, {10, 10, 15, 15}, {10, 10, 80, 80},
845856
DlFilterMode::kNearest, false);
846857
}},
858+
{1, 48, -1, 80,
859+
[](DisplayListBuilder& b) {
860+
auto dl_image = DlImage::Make(TestSkImage);
861+
b.drawImageNine(dl_image, {10, 10, 15, 15}, {10, 10, 80, 80},
862+
DlFilterMode::kNearest, false);
863+
}},
847864
}},
848865
{"DrawAtlas",
849866
{
@@ -921,6 +938,15 @@ std::vector<DisplayListInvocationGroup> CreateAllRenderingOps() {
921938
DlBlendMode::kSrcIn, kNearestSampling, &cull_rect,
922939
false);
923940
}},
941+
{1, 48 + 32 + 8, -1, 48 + 32 + 32,
942+
[](DisplayListBuilder& b) {
943+
auto dl_image = DlImage::Make(TestSkImage);
944+
static SkRSXform xforms[] = {{1, 0, 0, 0}, {0, 1, 0, 0}};
945+
static SkRect texs[] = {{10, 10, 20, 20}, {20, 20, 30, 30}};
946+
b.drawAtlas(dl_image, xforms, texs, nullptr, 2,
947+
DlBlendMode::kSrcIn, kNearestSampling, nullptr,
948+
false);
949+
}},
924950
}},
925951
{"DrawDisplayList",
926952
{
@@ -929,6 +955,10 @@ std::vector<DisplayListInvocationGroup> CreateAllRenderingOps() {
929955
[](DisplayListBuilder& b) { b.drawDisplayList(TestDisplayList1); }},
930956
{1, 16, -1, 16,
931957
[](DisplayListBuilder& b) { b.drawDisplayList(TestDisplayList2); }},
958+
{1, 16, -1, 16,
959+
[](DisplayListBuilder& b) {
960+
b.drawDisplayList(MakeTestDisplayList(10, 10, SK_ColorRED));
961+
}},
932962
}},
933963
{"DrawTextBlob",
934964
{

display_list/testing/dl_test_snippets.h

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static sk_sp<DlImage> MakeTestImage(int w, int h, int checker_size) {
8989

9090
static auto TestImage1 = MakeTestImage(40, 40, 5);
9191
static auto TestImage2 = MakeTestImage(50, 50, 5);
92+
static auto TestSkImage = MakeTestImage(30, 30, 5) -> skia_image();
9293

9394
static const DlImageColorSource kTestSource1(TestImage1,
9495
DlTileMode::kClamp,

0 commit comments

Comments
 (0)