Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add DlCanvas(SkCanvas) vs DlCanvas(Builder) variants to DL rendertests #39944

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,415 changes: 711 additions & 704 deletions display_list/display_list_canvas_unittests.cc

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions display_list/display_list_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ class DisplayListAttributeFlags : DisplayListFlagsBase {

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

constexpr bool operator==(DisplayListAttributeFlags const& other) const {
return flags_ == other.flags_;
}

private:
explicit constexpr DisplayListAttributeFlags(int flags)
: DisplayListFlagsBase(flags),
Expand Down
99 changes: 78 additions & 21 deletions display_list/display_list_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,13 @@ struct DrawVerticesOp final : DrawOpBase {
if (op_needed(ctx)) { \
ctx.dispatcher.drawImage(image, point, sampling, with_attributes); \
} \
} \
\
DisplayListCompare equals(const name##Op* other) const { \
return (point == other->point && sampling == other->sampling && \
image->Equals(other->image)) \
? DisplayListCompare::kEqual \
: DisplayListCompare::kNotEqual; \
} \
};
DEFINE_DRAW_IMAGE_OP(DrawImage, false)
Expand Down Expand Up @@ -868,30 +875,46 @@ struct DrawImageRectOp final : DrawOpBase {
render_with_attributes, constraint);
}
}

DisplayListCompare equals(const DrawImageRectOp* other) const {
return (src == other->src && dst == other->dst &&
sampling == other->sampling &&
render_with_attributes == other->render_with_attributes &&
constraint == other->constraint && image->Equals(other->image))
? DisplayListCompare::kEqual
: DisplayListCompare::kNotEqual;
}
};

// 4 byte header + 44 byte payload packs efficiently into 48 bytes
#define DEFINE_DRAW_IMAGE_NINE_OP(name, render_with_attributes) \
struct name##Op final : DrawOpBase { \
static const auto kType = DisplayListOpType::k##name; \
\
name##Op(const sk_sp<DlImage> image, \
const SkIRect& center, \
const SkRect& dst, \
DlFilterMode filter) \
: center(center), dst(dst), filter(filter), image(std::move(image)) {} \
\
const SkIRect center; \
const SkRect dst; \
const DlFilterMode filter; \
const sk_sp<DlImage> image; \
\
void dispatch(DispatchContext& ctx) const { \
if (op_needed(ctx)) { \
ctx.dispatcher.drawImageNine(image, center, dst, filter, \
render_with_attributes); \
} \
} \
#define DEFINE_DRAW_IMAGE_NINE_OP(name, render_with_attributes) \
struct name##Op final : DrawOpBase { \
static const auto kType = DisplayListOpType::k##name; \
\
name##Op(const sk_sp<DlImage> image, \
const SkIRect& center, \
const SkRect& dst, \
DlFilterMode mode) \
: center(center), dst(dst), mode(mode), image(std::move(image)) {} \
\
const SkIRect center; \
const SkRect dst; \
const DlFilterMode mode; \
const sk_sp<DlImage> image; \
\
void dispatch(DispatchContext& ctx) const { \
if (op_needed(ctx)) { \
ctx.dispatcher.drawImageNine(image, center, dst, mode, \
render_with_attributes); \
} \
} \
\
DisplayListCompare equals(const name##Op* other) const { \
return (center == other->center && dst == other->dst && \
mode == other->mode && image->Equals(other->image)) \
? DisplayListCompare::kEqual \
: DisplayListCompare::kNotEqual; \
} \
};
DEFINE_DRAW_IMAGE_NINE_OP(DrawImageNine, false)
DEFINE_DRAW_IMAGE_NINE_OP(DrawImageNineWithAttr, true)
Expand Down Expand Up @@ -924,6 +947,23 @@ struct DrawAtlasBaseOp : DrawOpBase {
const uint8_t render_with_attributes;
const DlImageSampling sampling;
const sk_sp<DlImage> atlas;

bool equals(const DrawAtlasBaseOp* other,
const void* pod_this,
const void* pod_other) const {
bool ret = (count == other->count && mode_index == other->mode_index &&
has_colors == other->has_colors &&
render_with_attributes == other->render_with_attributes &&
sampling == other->sampling && atlas->Equals(other->atlas));
if (ret) {
size_t bytes = count * (sizeof(SkRSXform) + sizeof(SkRect));
if (has_colors) {
bytes += count * sizeof(DlColor);
}
ret = (memcmp(pod_this, pod_other, bytes) == 0);
}
return ret;
}
};

// Packs into 48 bytes as per DrawAtlasBaseOp
Expand Down Expand Up @@ -955,6 +995,14 @@ struct DrawAtlasOp final : DrawAtlasBaseOp {
nullptr, render_with_attributes);
}
}

DisplayListCompare equals(const DrawAtlasOp* other) const {
const void* pod_this = reinterpret_cast<const void*>(this + 1);
const void* pod_other = reinterpret_cast<const void*>(other + 1);
return (DrawAtlasBaseOp::equals(other, pod_this, pod_other))
? DisplayListCompare::kEqual
: DisplayListCompare::kNotEqual;
}
};

// Packs into 48 bytes as per DrawAtlasBaseOp plus
Expand Down Expand Up @@ -992,6 +1040,15 @@ struct DrawAtlasCulledOp final : DrawAtlasBaseOp {
&cull_rect, render_with_attributes);
}
}

DisplayListCompare equals(const DrawAtlasCulledOp* other) const {
const void* pod_this = reinterpret_cast<const void*>(this + 1);
const void* pod_other = reinterpret_cast<const void*>(other + 1);
return (cull_rect == other->cull_rect &&
DrawAtlasBaseOp::equals(other, pod_this, pod_other))
? DisplayListCompare::kEqual
: DisplayListCompare::kNotEqual;
}
};

// 4 byte header + ptr aligned payload uses 12 bytes round up to 16
Expand Down
2 changes: 2 additions & 0 deletions display_list/display_list_paint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ bool DlPaint::operator==(DlPaint const& other) const {
Equals(maskFilter_, other.maskFilter_);
}

const DlPaint DlPaint::kDefault;

} // namespace flutter
4 changes: 4 additions & 0 deletions display_list/display_list_paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class DlPaint {
static constexpr float kDefaultWidth = 0.0;
static constexpr float kDefaultMiter = 4.0;

static const DlPaint kDefault;

DlPaint() : DlPaint(DlColor::kBlack()) {}
DlPaint(DlColor color);

Expand Down Expand Up @@ -215,6 +217,8 @@ class DlPaint {
return *this;
}

bool isDefault() const { return *this == kDefault; }

bool operator==(DlPaint const& other) const;
bool operator!=(DlPaint const& other) const { return !(*this == other); }

Expand Down
2 changes: 2 additions & 0 deletions display_list/display_list_paint_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ TEST(DisplayListPaint, ConstructorDefaults) {
EXPECT_EQ(paint.getColorFilter(), nullptr);
EXPECT_EQ(paint.getImageFilter(), nullptr);
EXPECT_EQ(paint.getMaskFilter(), nullptr);
EXPECT_TRUE(paint.isDefault());
EXPECT_EQ(paint, DlPaint::kDefault);

EXPECT_EQ(DlBlendMode::kDefaultMode, DlBlendMode::kSrcOver);
EXPECT_EQ(DlDrawStyle::kDefaultStyle, DlDrawStyle::kFill);
Expand Down
3 changes: 2 additions & 1 deletion display_list/dl_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ class DlCanvas {
virtual bool QuickReject(const SkRect& bounds) const = 0;

virtual void DrawPaint(const DlPaint& paint) = 0;
virtual void DrawColor(DlColor color, DlBlendMode mode) = 0;
virtual void DrawColor(DlColor color,
DlBlendMode mode = DlBlendMode::kSrcOver) = 0;
void Clear(DlColor color) { DrawColor(color, DlBlendMode::kSrc); }
virtual void DrawLine(const SkPoint& p0,
const SkPoint& p1,
Expand Down
43 changes: 32 additions & 11 deletions display_list/skia/dl_sk_canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,41 @@ static SkCanvas::PointMode ToSk(DlCanvas::PointMode mode) {
return static_cast<SkCanvas::PointMode>(mode);
}

static SkPaint ToSk(const DlPaint& paint) {
// clang-format off
constexpr float kInvertColorMatrix[20] = {
-1.0, 0, 0, 1.0, 0,
0, -1.0, 0, 1.0, 0,
0, 0, -1.0, 1.0, 0,
1.0, 1.0, 1.0, 1.0, 0
};
// clang-format on

static SkPaint ToSk(const DlPaint& paint, bool force_stroke = false) {
SkPaint sk_paint;

sk_paint.setAntiAlias(paint.isAntiAlias());
sk_paint.setDither(paint.isDither());

sk_paint.setColor(paint.getColor());
sk_paint.setBlendMode(ToSk(paint.getBlendMode()));
sk_paint.setStyle(ToSk(paint.getDrawStyle()));
sk_paint.setStyle(force_stroke ? SkPaint::kStroke_Style
: ToSk(paint.getDrawStyle()));
sk_paint.setStrokeWidth(paint.getStrokeWidth());
sk_paint.setStrokeMiter(paint.getStrokeMiter());
sk_paint.setStrokeCap(ToSk(paint.getStrokeCap()));
sk_paint.setStrokeJoin(ToSk(paint.getStrokeJoin()));

sk_paint.setShader(ToSk(paint.getColorSourcePtr()));
sk_paint.setImageFilter(ToSk(paint.getImageFilterPtr()));
sk_paint.setColorFilter(ToSk(paint.getColorFilterPtr()));
auto color_filter = ToSk(paint.getColorFilterPtr());
if (paint.isInvertColors()) {
auto invert_filter = SkColorFilters::Matrix(kInvertColorMatrix);
if (color_filter) {
invert_filter = invert_filter->makeComposed(color_filter);
}
color_filter = invert_filter;
}
sk_paint.setColorFilter(color_filter);
sk_paint.setMaskFilter(ToSk(paint.getMaskFilterPtr()));
sk_paint.setPathEffect(ToSk(paint.getPathEffectPtr()));

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

class SkOptionalPaint {
public:
explicit SkOptionalPaint(const DlPaint* paint) {
if (paint) {
paint_ = ToSk(*paint);
ptr_ = &paint_;
explicit SkOptionalPaint(const DlPaint* dl_paint) {
if (dl_paint && !dl_paint->isDefault()) {
sk_paint_ = ToSk(*dl_paint);
ptr_ = &sk_paint_;
} else {
ptr_ = nullptr;
}
Expand All @@ -75,7 +96,7 @@ class SkOptionalPaint {
SkPaint* operator()() { return ptr_; }

private:
SkPaint paint_;
SkPaint sk_paint_;
SkPaint* ptr_;
};

Expand Down Expand Up @@ -239,7 +260,7 @@ void DlSkCanvasAdapter::DrawColor(DlColor color, DlBlendMode mode) {
void DlSkCanvasAdapter::DrawLine(const SkPoint& p0,
const SkPoint& p1,
const DlPaint& paint) {
delegate_->drawLine(p0, p1, ToSk(paint));
delegate_->drawLine(p0, p1, ToSk(paint, true));
}

void DlSkCanvasAdapter::DrawRect(const SkRect& rect, const DlPaint& paint) {
Expand Down Expand Up @@ -282,7 +303,7 @@ void DlSkCanvasAdapter::DrawPoints(PointMode mode,
uint32_t count,
const SkPoint pts[],
const DlPaint& paint) {
delegate_->drawPoints(ToSk(mode), count, pts, ToSk(paint));
delegate_->drawPoints(ToSk(mode), count, pts, ToSk(paint, true));
}

void DlSkCanvasAdapter::DrawVertices(const DlVertices* vertices,
Expand Down Expand Up @@ -358,7 +379,7 @@ void DlSkCanvasAdapter::DrawShadow(const SkPath& path,
bool transparent_occluder,
SkScalar dpr) {
DisplayListCanvasDispatcher::DrawShadow(delegate_, path, color, elevation,
SkColorGetA(color) != 0xff, dpr);
transparent_occluder, dpr);
}

void DlSkCanvasAdapter::Flush() {
Expand Down
30 changes: 30 additions & 0 deletions display_list/testing/dl_test_snippets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,11 @@ std::vector<DisplayListInvocationGroup> CreateAllRenderingOps() {
[](DisplayListBuilder& b) {
b.drawImage(TestImage2, {10, 10}, kNearestSampling, false);
}},
{1, 24, -1, 48,
[](DisplayListBuilder& b) {
auto dl_image = DlImage::Make(TestSkImage);
b.drawImage(dl_image, {10, 10}, kNearestSampling, false);
}},
}},
{"DrawImageRect",
{
Expand Down Expand Up @@ -809,6 +814,12 @@ std::vector<DisplayListInvocationGroup> CreateAllRenderingOps() {
b.drawImageRect(TestImage2, {10, 10, 15, 15}, {10, 10, 80, 80},
kNearestSampling, false);
}},
{1, 56, -1, 80,
[](DisplayListBuilder& b) {
auto dl_image = DlImage::Make(TestSkImage);
b.drawImageRect(dl_image, {10, 10, 15, 15}, {10, 10, 80, 80},
kNearestSampling, false);
}},
}},
{"DrawImageNine",
{
Expand Down Expand Up @@ -844,6 +855,12 @@ std::vector<DisplayListInvocationGroup> CreateAllRenderingOps() {
b.drawImageNine(TestImage2, {10, 10, 15, 15}, {10, 10, 80, 80},
DlFilterMode::kNearest, false);
}},
{1, 48, -1, 80,
[](DisplayListBuilder& b) {
auto dl_image = DlImage::Make(TestSkImage);
b.drawImageNine(dl_image, {10, 10, 15, 15}, {10, 10, 80, 80},
DlFilterMode::kNearest, false);
}},
}},
{"DrawAtlas",
{
Expand Down Expand Up @@ -921,6 +938,15 @@ std::vector<DisplayListInvocationGroup> CreateAllRenderingOps() {
DlBlendMode::kSrcIn, kNearestSampling, &cull_rect,
false);
}},
{1, 48 + 32 + 8, -1, 48 + 32 + 32,
[](DisplayListBuilder& b) {
auto dl_image = DlImage::Make(TestSkImage);
static SkRSXform xforms[] = {{1, 0, 0, 0}, {0, 1, 0, 0}};
static SkRect texs[] = {{10, 10, 20, 20}, {20, 20, 30, 30}};
b.drawAtlas(dl_image, xforms, texs, nullptr, 2,
DlBlendMode::kSrcIn, kNearestSampling, nullptr,
false);
}},
}},
{"DrawDisplayList",
{
Expand All @@ -929,6 +955,10 @@ std::vector<DisplayListInvocationGroup> CreateAllRenderingOps() {
[](DisplayListBuilder& b) { b.drawDisplayList(TestDisplayList1); }},
{1, 16, -1, 16,
[](DisplayListBuilder& b) { b.drawDisplayList(TestDisplayList2); }},
{1, 16, -1, 16,
[](DisplayListBuilder& b) {
b.drawDisplayList(MakeTestDisplayList(10, 10, SK_ColorRED));
}},
}},
{"DrawTextBlob",
{
Expand Down
1 change: 1 addition & 0 deletions display_list/testing/dl_test_snippets.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ static sk_sp<DlImage> MakeTestImage(int w, int h, int checker_size) {

static auto TestImage1 = MakeTestImage(40, 40, 5);
static auto TestImage2 = MakeTestImage(50, 50, 5);
static auto TestSkImage = MakeTestImage(30, 30, 5) -> skia_image();

static const DlImageColorSource kTestSource1(TestImage1,
DlTileMode::kClamp,
Expand Down