Skip to content

Commit 1c4e5e2

Browse files
authored
[DisplayList] Create DrawDashedLine for paragraph code (flutter#53411)
With this minor addition to the DlCanvas/DisplayList API the code in the paragraph builder no longer needs to worry about PathEffect objects and their varying support on the backends. At this point all PathEffect code in the engine is obsolete and can be deleted, but I'll leave that for a follow-on PR. The only PathEffect related thing I did delete was support for rendering primitives with a PathEffect in the DL Rendering tests, both because it is a vestigial attribute and also because it would interfere with the new DrawDashedLine rendering test (a PathEffect on top of a PathEffect...).
1 parent c5e0e55 commit 1c4e5e2

30 files changed

Lines changed: 408 additions & 118 deletions

display_list/benchmarking/dl_complexity_gl.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ void DisplayListGLComplexityCalculator::GLHelper::drawLine(const SkPoint& p0,
100100
AccumulateComplexity(complexity);
101101
}
102102

103+
void DisplayListGLComplexityCalculator::GLHelper::drawDashedLine(
104+
const DlPoint& p0,
105+
const DlPoint& p1,
106+
DlScalar on_length,
107+
DlScalar off_length) {
108+
// Dashing is slightly more complex than a regular drawLine, but this
109+
// op is so rare it is not worth measuring the difference.
110+
drawLine(ToSkPoint(p0), ToSkPoint(p1));
111+
}
112+
103113
void DisplayListGLComplexityCalculator::GLHelper::drawRect(const SkRect& rect) {
104114
if (IsComplex()) {
105115
return;

display_list/benchmarking/dl_complexity_gl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class DisplayListGLComplexityCalculator
4040
const DlImageFilter* backdrop) override;
4141

4242
void drawLine(const SkPoint& p0, const SkPoint& p1) override;
43+
void drawDashedLine(const DlPoint& p0,
44+
const DlPoint& p1,
45+
DlScalar on_length,
46+
DlScalar off_length) override;
4347
void drawRect(const SkRect& rect) override;
4448
void drawOval(const SkRect& bounds) override;
4549
void drawCircle(const SkPoint& center, SkScalar radius) override;

display_list/benchmarking/dl_complexity_metal.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawLine(
111111
AccumulateComplexity(complexity);
112112
}
113113

114+
void DisplayListMetalComplexityCalculator::MetalHelper::drawDashedLine(
115+
const DlPoint& p0,
116+
const DlPoint& p1,
117+
DlScalar on_length,
118+
DlScalar off_length) {
119+
// Dashing is slightly more complex than a regular drawLine, but this
120+
// op is so rare it is not worth measuring the difference.
121+
drawLine(ToSkPoint(p0), ToSkPoint(p1));
122+
}
123+
114124
void DisplayListMetalComplexityCalculator::MetalHelper::drawRect(
115125
const SkRect& rect) {
116126
if (IsComplex()) {

display_list/benchmarking/dl_complexity_metal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class DisplayListMetalComplexityCalculator
4040
const DlImageFilter* backdrop) override;
4141

4242
void drawLine(const SkPoint& p0, const SkPoint& p1) override;
43+
void drawDashedLine(const DlPoint& p0,
44+
const DlPoint& p1,
45+
DlScalar on_length,
46+
DlScalar off_length) override;
4347
void drawRect(const SkRect& rect) override;
4448
void drawOval(const SkRect& bounds) override;
4549
void drawCircle(const SkPoint& center, SkScalar radius) override;

display_list/display_list.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ namespace flutter {
111111
V(DrawColor) \
112112
\
113113
V(DrawLine) \
114+
V(DrawDashedLine) \
114115
V(DrawRect) \
115116
V(DrawOval) \
116117
V(DrawCircle) \

display_list/dl_builder.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,29 @@ void DisplayListBuilder::DrawLine(const SkPoint& p0,
10991099
SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawLineFlags);
11001100
drawLine(p0, p1);
11011101
}
1102+
void DisplayListBuilder::drawDashedLine(const DlPoint& p0,
1103+
const DlPoint& p1,
1104+
DlScalar on_length,
1105+
DlScalar off_length) {
1106+
SkRect bounds = SkRect::MakeLTRB(p0.x, p0.y, p1.x, p1.y).makeSorted();
1107+
DisplayListAttributeFlags flags =
1108+
(bounds.width() > 0.0f && bounds.height() > 0.0f) ? kDrawLineFlags
1109+
: kDrawHVLineFlags;
1110+
OpResult result = PaintResult(current_, flags);
1111+
if (result != OpResult::kNoEffect && AccumulateOpBounds(bounds, flags)) {
1112+
Push<DrawDashedLineOp>(0, p0, p1, on_length, off_length);
1113+
CheckLayerOpacityCompatibility();
1114+
UpdateLayerResult(result);
1115+
}
1116+
}
1117+
void DisplayListBuilder::DrawDashedLine(const DlPoint& p0,
1118+
const DlPoint& p1,
1119+
DlScalar on_length,
1120+
DlScalar off_length,
1121+
const DlPaint& paint) {
1122+
SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawLineFlags);
1123+
drawDashedLine(p0, p1, on_length, off_length);
1124+
}
11021125
void DisplayListBuilder::drawRect(const SkRect& rect) {
11031126
DisplayListAttributeFlags flags = kDrawRectFlags;
11041127
OpResult result = PaintResult(current_, flags);

display_list/dl_builder.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ class DisplayListBuilder final : public virtual DlCanvas,
156156
const SkPoint& p1,
157157
const DlPaint& paint) override;
158158
// |DlCanvas|
159+
void DrawDashedLine(const DlPoint& p0,
160+
const DlPoint& p1,
161+
DlScalar on_length,
162+
DlScalar off_length,
163+
const DlPaint& paint) override;
164+
// |DlCanvas|
159165
void DrawRect(const SkRect& rect, const DlPaint& paint) override;
160166
// |DlCanvas|
161167
void DrawOval(const SkRect& bounds, const DlPaint& paint) override;
@@ -419,6 +425,11 @@ class DisplayListBuilder final : public virtual DlCanvas,
419425
// |DlOpReceiver|
420426
void drawLine(const SkPoint& p0, const SkPoint& p1) override;
421427
// |DlOpReceiver|
428+
void drawDashedLine(const DlPoint& p0,
429+
const DlPoint& p1,
430+
DlScalar on_length,
431+
DlScalar off_length) override;
432+
// |DlOpReceiver|
422433
void drawRect(const SkRect& rect) override;
423434
// |DlOpReceiver|
424435
void drawOval(const SkRect& bounds) override;

display_list/dl_canvas.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "flutter/display_list/dl_blend_mode.h"
99
#include "flutter/display_list/dl_paint.h"
1010
#include "flutter/display_list/dl_vertices.h"
11+
#include "flutter/display_list/geometry/dl_geometry_types.h"
1112
#include "flutter/display_list/image/dl_image.h"
1213

1314
#include "third_party/skia/include/core/SkM44.h"
@@ -132,6 +133,11 @@ class DlCanvas {
132133
virtual void DrawLine(const SkPoint& p0,
133134
const SkPoint& p1,
134135
const DlPaint& paint) = 0;
136+
virtual void DrawDashedLine(const DlPoint& p0,
137+
const DlPoint& p1,
138+
DlScalar on_length,
139+
DlScalar off_length,
140+
const DlPaint& paint) = 0;
135141
virtual void DrawRect(const SkRect& rect, const DlPaint& paint) = 0;
136142
virtual void DrawOval(const SkRect& bounds, const DlPaint& paint) = 0;
137143
virtual void DrawCircle(const SkPoint& center,

display_list/dl_op_receiver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ class DlOpReceiver {
343343
virtual void drawColor(DlColor color, DlBlendMode mode) = 0;
344344
virtual void drawPaint() = 0;
345345
virtual void drawLine(const SkPoint& p0, const SkPoint& p1) = 0;
346+
virtual void drawDashedLine(const DlPoint& p0,
347+
const DlPoint& p1,
348+
DlScalar on_length,
349+
DlScalar off_length) = 0;
346350
virtual void drawRect(const SkRect& rect) = 0;
347351
virtual void drawOval(const SkRect& bounds) = 0;
348352
virtual void drawCircle(const SkPoint& center, SkScalar radius) = 0;

display_list/dl_op_records.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,28 @@ DEFINE_DRAW_2ARG_OP(Circle, SkPoint, center, SkScalar, radius)
736736
DEFINE_DRAW_2ARG_OP(DRRect, SkRRect, outer, SkRRect, inner)
737737
#undef DEFINE_DRAW_2ARG_OP
738738

739+
// 4 byte header + 24 byte payload packs into 32 bytes (4 bytes unused)
740+
struct DrawDashedLineOp final : DrawOpBase {
741+
static constexpr auto kType = DisplayListOpType::kDrawDashedLine;
742+
743+
DrawDashedLineOp(const DlPoint& p0,
744+
const DlPoint& p1,
745+
DlScalar on_length,
746+
DlScalar off_length)
747+
: p0(p0), p1(p1), on_length(on_length), off_length(off_length) {}
748+
749+
const DlPoint p0;
750+
const DlPoint p1;
751+
const SkScalar on_length;
752+
const SkScalar off_length;
753+
754+
void dispatch(DispatchContext& ctx) const {
755+
if (op_needed(ctx)) {
756+
ctx.receiver.drawDashedLine(p0, p1, on_length, off_length);
757+
}
758+
}
759+
};
760+
739761
// 4 byte header + 28 byte payload packs efficiently into 32 bytes
740762
struct DrawArcOp final : DrawOpBase {
741763
static constexpr auto kType = DisplayListOpType::kDrawArc;

0 commit comments

Comments
 (0)