Skip to content

Commit 6f02b89

Browse files
bderodnfield
authored andcommitted
Wire up stroke cap/join/miter limit display list ops (flutter#105)
1 parent eb7b7d1 commit 6f02b89

File tree

4 files changed

+77
-7
lines changed

4 files changed

+77
-7
lines changed

impeller/aiks/paint.cc

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ std::shared_ptr<Contents> Paint::CreateContentsForEntity() const {
2323
auto solid_stroke = std::make_shared<SolidStrokeContents>();
2424
solid_stroke->SetColor(color.Premultiply());
2525
solid_stroke->SetStrokeSize(stroke_width);
26+
solid_stroke->SetStrokeMiter(stroke_miter);
27+
solid_stroke->SetStrokeCap(stroke_cap);
28+
solid_stroke->SetStrokeJoin(stroke_join);
2629
return solid_stroke;
2730
}
2831
}

impeller/aiks/paint.h

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "flutter/fml/macros.h"
1010
#include "impeller/entity/contents/contents.h"
11+
#include "impeller/entity/contents/solid_stroke_contents.h"
1112
#include "impeller/entity/entity.h"
1213
#include "impeller/geometry/color.h"
1314

@@ -21,6 +22,9 @@ struct Paint {
2122

2223
Color color = Color::Black();
2324
Scalar stroke_width = 0.0;
25+
SolidStrokeContents::Cap stroke_cap = SolidStrokeContents::Cap::kButt;
26+
SolidStrokeContents::Join stroke_join = SolidStrokeContents::Join::kMiter;
27+
Scalar stroke_miter = 4.0;
2428
Style style = Style::kFill;
2529
Entity::BlendMode blend_mode = Entity::BlendMode::kSourceOver;
2630
std::shared_ptr<Contents> contents;

impeller/display_list/display_list_dispatcher.cc

+24-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "flutter/fml/trace_event.h"
1010
#include "impeller/entity/contents/linear_gradient_contents.h"
11+
#include "impeller/entity/contents/solid_stroke_contents.h"
1112
#include "impeller/entity/entity.h"
1213
#include "impeller/geometry/path_builder.h"
1314
#include "impeller/typographer/backends/skia/text_frame_skia.h"
@@ -65,17 +66,37 @@ void DisplayListDispatcher::setStrokeWidth(SkScalar width) {
6566

6667
// |flutter::Dispatcher|
6768
void DisplayListDispatcher::setStrokeMiter(SkScalar limit) {
68-
UNIMPLEMENTED;
69+
paint_.stroke_miter = limit;
6970
}
7071

7172
// |flutter::Dispatcher|
7273
void DisplayListDispatcher::setStrokeCap(SkPaint::Cap cap) {
73-
UNIMPLEMENTED;
74+
switch (cap) {
75+
case SkPaint::kButt_Cap:
76+
paint_.stroke_cap = SolidStrokeContents::Cap::kButt;
77+
break;
78+
case SkPaint::kRound_Cap:
79+
paint_.stroke_cap = SolidStrokeContents::Cap::kRound;
80+
break;
81+
case SkPaint::kSquare_Cap:
82+
paint_.stroke_cap = SolidStrokeContents::Cap::kSquare;
83+
break;
84+
}
7485
}
7586

7687
// |flutter::Dispatcher|
7788
void DisplayListDispatcher::setStrokeJoin(SkPaint::Join join) {
78-
UNIMPLEMENTED;
89+
switch (join) {
90+
case SkPaint::kMiter_Join:
91+
paint_.stroke_join = SolidStrokeContents::Join::kMiter;
92+
break;
93+
case SkPaint::kRound_Join:
94+
paint_.stroke_join = SolidStrokeContents::Join::kRound;
95+
break;
96+
case SkPaint::kBevel_Join:
97+
paint_.stroke_join = SolidStrokeContents::Join::kBevel;
98+
break;
99+
}
79100
}
80101

81102
static Point ToPoint(const SkPoint& point) {
@@ -397,11 +418,9 @@ static Path ToPath(const SkPath& path) {
397418
builder.MoveTo(ToPoint(data.points[0]));
398419
break;
399420
case SkPath::kLine_Verb:
400-
builder.LineTo(ToPoint(data.points[0]));
401421
builder.LineTo(ToPoint(data.points[1]));
402422
break;
403423
case SkPath::kQuad_Verb:
404-
builder.LineTo(ToPoint(data.points[0]));
405424
builder.QuadraticCurveTo(ToPoint(data.points[1]),
406425
ToPoint(data.points[2]));
407426
break;
@@ -422,13 +441,11 @@ static Path ToPath(const SkPath& path) {
422441
curve_index < curve_count; //
423442
curve_index++, point_index += 2 //
424443
) {
425-
builder.LineTo(ToPoint(points[point_index + 0]));
426444
builder.QuadraticCurveTo(ToPoint(points[point_index + 1]),
427445
ToPoint(points[point_index + 2]));
428446
}
429447
} break;
430448
case SkPath::kCubic_Verb:
431-
builder.LineTo(ToPoint(data.points[0]));
432449
builder.CubicCurveTo(ToPoint(data.points[1]), ToPoint(data.points[2]),
433450
ToPoint(data.points[3]));
434451
break;

impeller/display_list/display_list_unittests.cc

+46
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "flutter/display_list/display_list_builder.h"
66
#include "flutter/testing/testing.h"
77
#include "impeller/display_list/display_list_playground.h"
8+
#include "third_party/skia/include/core/SkPathBuilder.h"
89

910
namespace impeller {
1011
namespace testing {
@@ -26,5 +27,50 @@ TEST_F(DisplayListTest, CanDrawTextBlob) {
2627
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2728
}
2829

30+
TEST_F(DisplayListTest, CapsAndJoins) {
31+
flutter::DisplayListBuilder builder;
32+
33+
builder.setStyle(SkPaint::Style::kStroke_Style);
34+
builder.setStrokeWidth(30);
35+
builder.setColor(SK_ColorRED);
36+
37+
auto path =
38+
SkPathBuilder{}.moveTo(-50, 0).lineTo(0, -50).lineTo(50, 0).snapshot();
39+
40+
builder.translate(100, 100);
41+
{
42+
builder.setStrokeCap(SkPaint::Cap::kButt_Cap);
43+
builder.setStrokeJoin(SkPaint::Join::kMiter_Join);
44+
builder.setStrokeMiter(4);
45+
builder.drawPath(path);
46+
}
47+
48+
{
49+
builder.save();
50+
builder.translate(0, 100);
51+
// The joint in the path is 45 degrees. A miter length of 1 convert to a
52+
// bevel in this case.
53+
builder.setStrokeMiter(1);
54+
builder.drawPath(path);
55+
builder.restore();
56+
}
57+
58+
builder.translate(150, 0);
59+
{
60+
builder.setStrokeCap(SkPaint::Cap::kSquare_Cap);
61+
builder.setStrokeJoin(SkPaint::Join::kBevel_Join);
62+
builder.drawPath(path);
63+
}
64+
65+
builder.translate(150, 0);
66+
{
67+
builder.setStrokeCap(SkPaint::Cap::kRound_Cap);
68+
builder.setStrokeJoin(SkPaint::Join::kRound_Join);
69+
builder.drawPath(path);
70+
}
71+
72+
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
73+
}
74+
2975
} // namespace testing
3076
} // namespace impeller

0 commit comments

Comments
 (0)