Skip to content

Commit

Permalink
add DlPaint object for optional use with DisplayListBuilder (flutter#…
Browse files Browse the repository at this point in the history
  • Loading branch information
flar authored Apr 22, 2022
1 parent 819ca4e commit e881225
Show file tree
Hide file tree
Showing 11 changed files with 655 additions and 8 deletions.
3 changes: 3 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ FILE: ../../../flutter/display_list/display_list_mask_filter.h
FILE: ../../../flutter/display_list/display_list_mask_filter_unittests.cc
FILE: ../../../flutter/display_list/display_list_ops.cc
FILE: ../../../flutter/display_list/display_list_ops.h
FILE: ../../../flutter/display_list/display_list_paint.cc
FILE: ../../../flutter/display_list/display_list_paint.h
FILE: ../../../flutter/display_list/display_list_paint_unittests.cc
FILE: ../../../flutter/display_list/display_list_test_utils.cc
FILE: ../../../flutter/display_list/display_list_test_utils.h
FILE: ../../../flutter/display_list/display_list_tile_mode.h
Expand Down
3 changes: 3 additions & 0 deletions display_list/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ source_set("display_list") {
"display_list_mask_filter.h",
"display_list_ops.cc",
"display_list_ops.h",
"display_list_paint.cc",
"display_list_paint.h",
"display_list_tile_mode.h",
"display_list_utils.cc",
"display_list_utils.h",
Expand Down Expand Up @@ -69,6 +71,7 @@ source_set("unittests") {
"display_list_enum_unittests.cc",
"display_list_image_filter_unittests.cc",
"display_list_mask_filter_unittests.cc",
"display_list_paint_unittests.cc",
"display_list_test_utils.cc",
"display_list_test_utils.h",
"display_list_unittests.cc",
Expand Down
4 changes: 2 additions & 2 deletions display_list/display_list_attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ class DlAttribute {
// Return an equivalent sk_sp<Skia> version of this object.
virtual sk_sp<S> skia_object() const = 0;

// Perform a content aware |==| comparison of the ColorFilter.
// Perform a content aware |==| comparison of the Attribute.
bool operator==(D const& other) const {
return type() == other.type() && equals_(other);
}
// Perform a content aware |!=| comparison of the ColorFilter.
// Perform a content aware |!=| comparison of the Attribute.
bool operator!=(D const& other) const { return !(*this == other); }

virtual ~DlAttribute() = default;
Expand Down
1 change: 1 addition & 0 deletions display_list/display_list_blend_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ enum class DlBlendMode {
kLastSeparableMode =
kMultiply, //!< last blend mode operating separately on components
kLastMode = kLuminosity, //!< last valid value
kDefaultMode = kSrcOver,
};

inline DlBlendMode ToDl(SkBlendMode mode) {
Expand Down
185 changes: 185 additions & 0 deletions display_list/display_list_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,49 @@ void DisplayListBuilder::onSetMaskFilter(const DlMaskFilter* filter) {
}
}

void DisplayListBuilder::setAttributesFromDlPaint(
const DlPaint& paint,
const DisplayListAttributeFlags flags) {
if (flags.applies_anti_alias()) {
setAntiAlias(paint.isAntiAlias());
}
if (flags.applies_dither()) {
setDither(paint.isDither());
}
if (flags.applies_alpha_or_color()) {
setColor(paint.getColor().argb);
}
if (flags.applies_blend()) {
setBlendMode(paint.getBlendMode());
}
if (flags.applies_style()) {
setStyle(ToSk(paint.getDrawStyle()));
}
if (flags.is_stroked(ToSk(paint.getDrawStyle()))) {
setStrokeWidth(paint.getStrokeWidth());
setStrokeMiter(paint.getStrokeMiter());
setStrokeCap(ToSk(paint.getStrokeCap()));
setStrokeJoin(ToSk(paint.getStrokeJoin()));
}
if (flags.applies_shader()) {
setColorSource(paint.getColorSource().get());
}
if (flags.applies_color_filter()) {
setInvertColors(paint.isInvertColors());
setColorFilter(paint.getColorFilter().get());
}
if (flags.applies_image_filter()) {
setImageFilter(paint.getImageFilter().get());
}
// Waiting for https://github.com/flutter/engine/pull/32159
// if (flags.applies_path_effect()) {
// setPathEffect(sk_ref_sp(paint.getPathEffect()));
// }
if (flags.applies_mask_filter()) {
setMaskFilter(paint.getMaskFilter().get());
}
}

void DisplayListBuilder::setAttributesFromPaint(
const SkPaint& paint,
const DisplayListAttributeFlags flags) {
Expand Down Expand Up @@ -406,6 +449,15 @@ void DisplayListBuilder::saveLayer(const SkRect* bounds,
}
}
}
void DisplayListBuilder::saveLayer(const SkRect* bounds, const DlPaint* paint) {
if (paint != nullptr) {
setAttributesFromDlPaint(*paint,
DisplayListOpFlags::kSaveLayerWithPaintFlags);
saveLayer(bounds, true);
} else {
saveLayer(bounds, false);
}
}

void DisplayListBuilder::translate(SkScalar tx, SkScalar ty) {
if (SkScalarIsFinite(tx) && SkScalarIsFinite(ty) &&
Expand Down Expand Up @@ -536,6 +588,10 @@ void DisplayListBuilder::drawPaint() {
Push<DrawPaintOp>(0, 1);
CheckLayerOpacityCompatibility();
}
void DisplayListBuilder::drawPaint(const DlPaint& paint) {
setAttributesFromDlPaint(paint, DisplayListOpFlags::kDrawPaintFlags);
drawPaint();
}
void DisplayListBuilder::drawColor(SkColor color, DlBlendMode mode) {
Push<DrawColorOp>(0, 1, color, mode);
CheckLayerOpacityCompatibility(mode);
Expand All @@ -544,18 +600,38 @@ void DisplayListBuilder::drawLine(const SkPoint& p0, const SkPoint& p1) {
Push<DrawLineOp>(0, 1, p0, p1);
CheckLayerOpacityCompatibility();
}
void DisplayListBuilder::drawLine(const SkPoint& p0,
const SkPoint& p1,
const DlPaint& paint) {
setAttributesFromDlPaint(paint, DisplayListOpFlags::kDrawLineFlags);
drawLine(p0, p1);
}
void DisplayListBuilder::drawRect(const SkRect& rect) {
Push<DrawRectOp>(0, 1, rect);
CheckLayerOpacityCompatibility();
}
void DisplayListBuilder::drawRect(const SkRect& rect, const DlPaint& paint) {
setAttributesFromDlPaint(paint, DisplayListOpFlags::kDrawRectFlags);
drawRect(rect);
}
void DisplayListBuilder::drawOval(const SkRect& bounds) {
Push<DrawOvalOp>(0, 1, bounds);
CheckLayerOpacityCompatibility();
}
void DisplayListBuilder::drawOval(const SkRect& bounds, const DlPaint& paint) {
setAttributesFromDlPaint(paint, DisplayListOpFlags::kDrawOvalFlags);
drawOval(bounds);
}
void DisplayListBuilder::drawCircle(const SkPoint& center, SkScalar radius) {
Push<DrawCircleOp>(0, 1, center, radius);
CheckLayerOpacityCompatibility();
}
void DisplayListBuilder::drawCircle(const SkPoint& center,
SkScalar radius,
const DlPaint& paint) {
setAttributesFromDlPaint(paint, DisplayListOpFlags::kDrawCircleFlags);
drawCircle(center, radius);
}
void DisplayListBuilder::drawRRect(const SkRRect& rrect) {
if (rrect.isRect()) {
drawRect(rrect.rect());
Expand All @@ -566,15 +642,29 @@ void DisplayListBuilder::drawRRect(const SkRRect& rrect) {
CheckLayerOpacityCompatibility();
}
}
void DisplayListBuilder::drawRRect(const SkRRect& rrect, const DlPaint& paint) {
setAttributesFromDlPaint(paint, DisplayListOpFlags::kDrawRRectFlags);
drawRRect(rrect);
}
void DisplayListBuilder::drawDRRect(const SkRRect& outer,
const SkRRect& inner) {
Push<DrawDRRectOp>(0, 1, outer, inner);
CheckLayerOpacityCompatibility();
}
void DisplayListBuilder::drawDRRect(const SkRRect& outer,
const SkRRect& inner,
const DlPaint& paint) {
setAttributesFromDlPaint(paint, DisplayListOpFlags::kDrawDRRectFlags);
drawDRRect(outer, inner);
}
void DisplayListBuilder::drawPath(const SkPath& path) {
Push<DrawPathOp>(0, 1, path);
CheckLayerOpacityHairlineCompatibility();
}
void DisplayListBuilder::drawPath(const SkPath& path, const DlPaint& paint) {
setAttributesFromDlPaint(paint, DisplayListOpFlags::kDrawPathFlags);
drawPath(path);
}

void DisplayListBuilder::drawArc(const SkRect& bounds,
SkScalar start,
Expand All @@ -587,6 +677,15 @@ void DisplayListBuilder::drawArc(const SkRect& bounds,
CheckLayerOpacityCompatibility();
}
}
void DisplayListBuilder::drawArc(const SkRect& bounds,
SkScalar start,
SkScalar sweep,
bool useCenter,
const DlPaint& paint) {
setAttributesFromDlPaint(
paint, useCenter ? kDrawArcWithCenterFlags : kDrawArcNoCenterFlags);
drawArc(bounds, start, sweep, useCenter);
}
void DisplayListBuilder::drawPoints(SkCanvas::PointMode mode,
uint32_t count,
const SkPoint pts[]) {
Expand Down Expand Up @@ -615,6 +714,28 @@ void DisplayListBuilder::drawPoints(SkCanvas::PointMode mode,
// See: https://fiddle.skia.org/c/228459001d2de8db117ce25ef5cedb0c
UpdateLayerOpacityCompatibility(false);
}
void DisplayListBuilder::drawPoints(SkCanvas::PointMode mode,
uint32_t count,
const SkPoint pts[],
const DlPaint& paint) {
const DisplayListAttributeFlags* flags;
switch (mode) {
case SkCanvas::PointMode::kPoints_PointMode:
flags = &DisplayListOpFlags::kDrawPointsAsPointsFlags;
break;
case SkCanvas::PointMode::kLines_PointMode:
flags = &DisplayListOpFlags::kDrawPointsAsLinesFlags;
break;
case SkCanvas::PointMode::kPolygon_PointMode:
flags = &DisplayListOpFlags::kDrawPointsAsPolygonFlags;
break;
default:
FML_DCHECK(false);
return;
}
setAttributesFromDlPaint(paint, *flags);
drawPoints(mode, count, pts);
}
void DisplayListBuilder::drawSkVertices(const sk_sp<SkVertices> vertices,
SkBlendMode mode) {
Push<DrawSkVerticesOp>(0, 1, std::move(vertices), mode);
Expand All @@ -634,6 +755,12 @@ void DisplayListBuilder::drawVertices(const DlVertices* vertices,
// cases.
UpdateLayerOpacityCompatibility(false);
}
void DisplayListBuilder::drawVertices(const DlVertices* vertices,
DlBlendMode mode,
const DlPaint& paint) {
setAttributesFromDlPaint(paint, DisplayListOpFlags::kDrawVerticesFlags);
drawVertices(vertices, mode);
}

void DisplayListBuilder::drawImage(const sk_sp<DlImage> image,
const SkPoint point,
Expand All @@ -644,6 +771,18 @@ void DisplayListBuilder::drawImage(const sk_sp<DlImage> image,
: Push<DrawImageOp>(0, 1, std::move(image), point, sampling);
CheckLayerOpacityCompatibility(render_with_attributes);
}
void DisplayListBuilder::drawImage(const sk_sp<DlImage> image,
const SkPoint point,
const SkSamplingOptions& sampling,
const DlPaint* paint) {
if (paint != nullptr) {
setAttributesFromDlPaint(*paint,
DisplayListOpFlags::kDrawImageWithPaintFlags);
drawImage(image, point, sampling, true);
} else {
drawImage(image, point, sampling, false);
}
}
void DisplayListBuilder::drawImageRect(const sk_sp<DlImage> image,
const SkRect& src,
const SkRect& dst,
Expand All @@ -654,6 +793,20 @@ void DisplayListBuilder::drawImageRect(const sk_sp<DlImage> image,
render_with_attributes, constraint);
CheckLayerOpacityCompatibility(render_with_attributes);
}
void DisplayListBuilder::drawImageRect(const sk_sp<DlImage> image,
const SkRect& src,
const SkRect& dst,
const SkSamplingOptions& sampling,
const DlPaint* paint,
SkCanvas::SrcRectConstraint constraint) {
if (paint != nullptr) {
setAttributesFromDlPaint(*paint,
DisplayListOpFlags::kDrawImageRectWithPaintFlags);
drawImageRect(image, src, dst, sampling, true, constraint);
} else {
drawImageRect(image, src, dst, sampling, false, constraint);
}
}
void DisplayListBuilder::drawImageNine(const sk_sp<DlImage> image,
const SkIRect& center,
const SkRect& dst,
Expand All @@ -665,6 +818,19 @@ void DisplayListBuilder::drawImageNine(const sk_sp<DlImage> image,
: Push<DrawImageNineOp>(0, 1, std::move(image), center, dst, filter);
CheckLayerOpacityCompatibility(render_with_attributes);
}
void DisplayListBuilder::drawImageNine(const sk_sp<DlImage> image,
const SkIRect& center,
const SkRect& dst,
SkFilterMode filter,
const DlPaint* paint) {
if (paint != nullptr) {
setAttributesFromDlPaint(*paint,
DisplayListOpFlags::kDrawImageNineWithPaintFlags);
drawImageNine(image, center, dst, filter, true);
} else {
drawImageNine(image, center, dst, filter, false);
}
}
void DisplayListBuilder::drawImageLattice(const sk_sp<DlImage> image,
const SkCanvas::Lattice& lattice,
const SkRect& dst,
Expand Down Expand Up @@ -725,6 +891,25 @@ void DisplayListBuilder::drawAtlas(const sk_sp<DlImage> atlas,
// of the transforms and texture rectangles.
UpdateLayerOpacityCompatibility(false);
}
void DisplayListBuilder::drawAtlas(const sk_sp<DlImage> atlas,
const SkRSXform xform[],
const SkRect tex[],
const SkColor colors[],
int count,
DlBlendMode mode,
const SkSamplingOptions& sampling,
const SkRect* cull_rect,
const DlPaint* paint) {
if (paint != nullptr) {
setAttributesFromDlPaint(*paint,
DisplayListOpFlags::kDrawAtlasWithPaintFlags);
drawAtlas(atlas, xform, tex, colors, count, mode, sampling, cull_rect,
true);
} else {
drawAtlas(atlas, xform, tex, colors, count, mode, sampling, cull_rect,
false);
}
}

void DisplayListBuilder::drawPicture(const sk_sp<SkPicture> picture,
const SkMatrix* matrix,
Expand Down
Loading

0 comments on commit e881225

Please sign in to comment.