Skip to content
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
26 changes: 26 additions & 0 deletions engine/src/flutter/impeller/display_list/aiks_dl_path_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,32 @@ TEST_P(AiksTest, TwoContourPathWithSinglePointContour) {
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

TEST_P(AiksTest, TwoContourPathWithConnectingLines) {
DisplayListBuilder builder;

DlPaint paint;
paint.setColor(DlColor::kRed());
paint.setDrawStyle(DlDrawStyle::kStroke);
paint.setStrokeWidth(15.0);

builder.Translate(100, 0);
for (auto join : std::vector<DlStrokeJoin>{
DlStrokeJoin::kMiter, DlStrokeJoin::kRound, DlStrokeJoin::kBevel}) {
builder.Translate(0, 100);
paint.setStrokeJoin(join);

DlPathBuilder path_builder;
path_builder.MoveTo(DlPoint(0, 0));
path_builder.LineTo(DlPoint(50, 50));
path_builder.MoveTo(DlPoint(50, 50));
path_builder.LineTo(DlPoint(100, 0));

builder.DrawPath(path_builder.TakePath(), paint);
}

ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

TEST_P(AiksTest, StrokeCapsAndJoins) {
DisplayListBuilder builder;
builder.Scale(GetContentScale().x, GetContentScale().y);
Expand Down
51 changes: 49 additions & 2 deletions engine/src/flutter/impeller/entity/geometry/geometry_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ TEST(EntityGeometryTest, TwoLineSegmentsRightTurnStrokeVerticesBevelJoin) {
Point(30, 25),
Point(30, 15),

// The points for the second segment (120, 20) -> (130, 20)
// The points for the second segment (30, 20) -> (30, 30)
Point(25, 20),
Point(35, 20),
Point(25, 30),
Expand Down Expand Up @@ -844,7 +844,7 @@ TEST(EntityGeometryTest, TwoLineSegmentsLeftTurnStrokeVerticesBevelJoin) {
Point(30, 25),
Point(30, 15),

// The points for the second segment (120, 20) -> (130, 20)
// The points for the second segment (30, 20) -> (30, 10)
Point(35, 20),
Point(25, 20),
Point(35, 10),
Expand All @@ -854,6 +854,53 @@ TEST(EntityGeometryTest, TwoLineSegmentsLeftTurnStrokeVerticesBevelJoin) {
EXPECT_EQ(points, expected);
}

TEST(EntityGeometryTest, TwoLineSegmentsInDifferentContoursAreNotJoined) {
flutter::DlPathBuilder path_builder;
// First contour with a single line.
path_builder.MoveTo({20, 20});
path_builder.LineTo({30, 20});
// Starts a new contour with a MoveTo command. The start of the new contour is
// specified to be the same as the end of the previous contour.
path_builder.MoveTo({30, 20});
// Add a line in the second contour.
path_builder.LineTo({30, 30});
flutter::DlPath path = path_builder.TakePath();

auto points = ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
path,
{
.width = 10.0f,
.cap = Cap::kButt,
.join = Join::kBevel,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do a golden test of this case with all 3 join types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added a golden test

Before:
Image

After:
Image

.miter_limit = 4.0f,
},
1.0f);

std::vector<Point> expected = {
// The points for the first segment (20, 20) -> (30, 20)
Point(20, 25),
Point(20, 15),
Point(30, 25),
Point(30, 15),

// The glue points that allow us to "pick up the pen" between segments.
// This prevents segments in different contours from being unintentionally
// joined with a bevel.
Point(30, 20),
Point(30, 20),
Point(30, 20),
Point(30, 20),

// The points for the second segment (30, 20) -> (30, 30)
Point(25, 20),
Point(35, 20),
Point(25, 30),
Point(35, 30),
};

EXPECT_EQ(points, expected);
}

TEST(EntityGeometryTest, TwoLineSegmentsRightTurnStrokeVerticesMiterJoin) {
flutter::DlPathBuilder path_builder;
path_builder.MoveTo({20, 20});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class StrokePathSegmentReceiver : public PathAndArcSegmentReceiver {
protected:
// |SegmentReceiver|
void BeginContour(Point origin, bool will_be_closed) override {
if (has_prior_contour_ && origin != last_point_) {
if (has_prior_contour_) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only question I would have is whether we need all 4 of these vertices if the 2 points are the same, but it shouldn't hurt anything I don't think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if the 2 points are the same, we only need 2 extra vertices instead of all 4. But like you said, I don't think it hurts to have 4. And I like that this keeps the code more consistent and simpler with no extra branching for the same vs different cases.

// We only append these extra points if we have had a prior contour.
vtx_builder_.AppendVertex(last_point_);
vtx_builder_.AppendVertex(last_point_);
Expand Down
Loading