switch DL rendertests to DlCanvas(SkCanvas) and DlCanvas(Builder) operations (flutter/engine#39944)

add DlCanvas(SkCanvas) vs DlCanvas(Builder) variants to DL rendertests
This commit is contained in:
Jim Graham
2023-03-01 13:33:24 -08:00
committed by GitHub
parent 56dfdf8fbf
commit 713de45bb4
10 changed files with 870 additions and 741 deletions

View File

@@ -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),

View File

@@ -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)
@@ -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)
@@ -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
@@ -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
@@ -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

View File

@@ -35,4 +35,6 @@ bool DlPaint::operator==(DlPaint const& other) const {
Equals(maskFilter_, other.maskFilter_);
}
const DlPaint DlPaint::kDefault;
} // namespace flutter

View File

@@ -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);
@@ -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); }

View File

@@ -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);

View File

@@ -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,

View File

@@ -41,12 +41,25 @@ 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()));
@@ -54,7 +67,15 @@ static SkPaint ToSk(const DlPaint& paint) {
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()));
@@ -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;
}
@@ -75,7 +96,7 @@ class SkOptionalPaint {
SkPaint* operator()() { return ptr_; }
private:
SkPaint paint_;
SkPaint sk_paint_;
SkPaint* ptr_;
};
@@ -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) {
@@ -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,
@@ -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() {

View File

@@ -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",
{
@@ -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",
{
@@ -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",
{
@@ -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",
{
@@ -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",
{

View File

@@ -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,