Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DisplayList] Optimize draws of simple shapes expressed as paths #55376

Closed
wants to merge 1 commit into from
Closed
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
173 changes: 159 additions & 14 deletions display_list/display_list_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5094,11 +5094,164 @@ TEST_F(DisplayListTest, DrawRectPathPromoteToDrawRect) {
expected.DrawRect(rect, DlPaint());
auto expect_dl = expected.Build();

// Support for this will be re-added soon, until then verify that we
// do not promote.
ASSERT_TRUE(DisplayListsEQ_Verbose(dl, expect_dl));
}

TEST_F(DisplayListTest, FillCompleteUnclosedRectPathPromoteToDrawRect) {
DlPaint paint = DlPaint().setDrawStyle(DlDrawStyle::kFill);

SkPath path;
path.moveTo(10.0f, 10.0f);
path.lineTo(20.0f, 10.0f);
path.lineTo(20.0f, 20.0f);
path.lineTo(10.0f, 20.0f);
path.lineTo(10.0f, 10.0f);
// No explicit close
// path.close();

DisplayListBuilder builder;
builder.DrawPath(path, paint);
auto dl = builder.Build();

DisplayListBuilder expected;
expected.DrawRect(path.getBounds(), paint);
auto expect_dl = expected.Build();

ASSERT_TRUE(DisplayListsEQ_Verbose(dl, expect_dl));
}

TEST_F(DisplayListTest, FillIncompleteUnclosedRectPathPromoteToDrawRect) {
DlPaint paint = DlPaint().setDrawStyle(DlDrawStyle::kFill);

SkPath path;
path.moveTo(10.0f, 10.0f);
path.lineTo(20.0f, 10.0f);
path.lineTo(20.0f, 20.0f);
path.lineTo(10.0f, 20.0f);
// Leave last segment for fill operation to infer
// path.lineTo(10.0f, 10.0f);
// No explicit close
// path.close();

DisplayListBuilder builder;
builder.DrawPath(path, paint);
auto dl = builder.Build();

DisplayListBuilder expected;
expected.DrawRect(path.getBounds(), paint);
auto expect_dl = expected.Build();

ASSERT_TRUE(DisplayListsEQ_Verbose(dl, expect_dl));
}

TEST_F(DisplayListTest, FillBarelyUnclosedRectPathPromoteToDrawPath) {
DlPaint paint = DlPaint().setDrawStyle(DlDrawStyle::kFill);

SkPath path;
path.moveTo(10.0f, 10.0f);
path.lineTo(20.0f, 10.0f);
path.lineTo(20.0f, 20.0f);
path.lineTo(10.0f, 20.0f);
path.lineTo(10.0f, 11.0f); // One pixel short of closed

DisplayListBuilder builder;
builder.DrawPath(path, paint);
auto dl = builder.Build();

DisplayListBuilder expected;
expected.DrawRect(path.getBounds(), paint);
auto expect_dl = expected.Build();

ASSERT_TRUE(DisplayListsEQ_Verbose(dl, expect_dl));
}

TEST_F(DisplayListTest, StrokeBarelyUnclosedRectPathPromoteToDrawPath) {
DlPaint paint = DlPaint().setDrawStyle(DlDrawStyle::kStroke);

SkPath path;
path.moveTo(10.0f, 10.0f);
path.lineTo(20.0f, 10.0f);
path.lineTo(20.0f, 20.0f);
path.lineTo(10.0f, 20.0f);
path.lineTo(10.0f, 11.0f); // One pixel short of closed

DisplayListBuilder builder;
builder.DrawPath(path, paint);
auto dl = builder.Build();

DisplayListBuilder expected;
expected.DrawRect(path.getBounds(), paint);
auto expect_dl = expected.Build();

ASSERT_TRUE(DisplayListsNE_Verbose(dl, expect_dl));
}

TEST_F(DisplayListTest, StrokeCompleteUnclosedRectPathNotPromoteToDrawPath) {
DlPaint paint = DlPaint().setDrawStyle(DlDrawStyle::kStroke);

SkPath path;
path.moveTo(10.0f, 10.0f);
path.lineTo(20.0f, 10.0f);
path.lineTo(20.0f, 20.0f);
path.lineTo(10.0f, 20.0f);
path.lineTo(10.0f, 10.0f);

DisplayListBuilder builder;
builder.DrawPath(path, paint);
auto dl = builder.Build();

DisplayListBuilder expected;
expected.DrawRect(path.getBounds(), paint);
auto expect_dl = expected.Build();

ASSERT_TRUE(DisplayListsNE_Verbose(dl, expect_dl));
}

TEST_F(DisplayListTest, StrokeIncompleteClosedRectPathPromoteToDrawRect) {
DlPaint paint = DlPaint().setDrawStyle(DlDrawStyle::kStroke);

SkPath path;
path.moveTo(10.0f, 10.0f);
path.lineTo(20.0f, 10.0f);
path.lineTo(20.0f, 20.0f);
path.lineTo(10.0f, 20.0f);
// Leave last segment for close to fill in
// path.lineTo(10.0f, 10.0f);
path.close();

DisplayListBuilder builder;
builder.DrawPath(path, paint);
auto dl = builder.Build();

DisplayListBuilder expected;
expected.DrawRect(path.getBounds(), paint);
auto expect_dl = expected.Build();

ASSERT_TRUE(DisplayListsEQ_Verbose(dl, expect_dl));
}

TEST_F(DisplayListTest, StrokeCompleteClosedRectPathPromoteToDrawRect) {
DlPaint paint = DlPaint().setDrawStyle(DlDrawStyle::kStroke);

SkPath path;
path.moveTo(10.0f, 10.0f);
path.lineTo(20.0f, 10.0f);
path.lineTo(20.0f, 20.0f);
path.lineTo(10.0f, 20.0f);
path.lineTo(10.0f, 10.0f);
path.close();

DisplayListBuilder builder;
builder.DrawPath(path, paint);
auto dl = builder.Build();

DisplayListBuilder expected;
expected.DrawRect(path.getBounds(), paint);
auto expect_dl = expected.Build();

ASSERT_TRUE(DisplayListsEQ_Verbose(dl, expect_dl));
}

TEST_F(DisplayListTest, DrawOvalPathPromoteToDrawOval) {
SkRect rect = SkRect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f);

Expand All @@ -5110,9 +5263,7 @@ TEST_F(DisplayListTest, DrawOvalPathPromoteToDrawOval) {
expected.DrawOval(rect, DlPaint());
auto expect_dl = expected.Build();

// Support for this will be re-added soon, until then verify that we
// do not promote.
ASSERT_TRUE(DisplayListsNE_Verbose(dl, expect_dl));
ASSERT_TRUE(DisplayListsEQ_Verbose(dl, expect_dl));
}

TEST_F(DisplayListTest, DrawRRectPathPromoteToDrawRRect) {
Expand All @@ -5127,9 +5278,7 @@ TEST_F(DisplayListTest, DrawRRectPathPromoteToDrawRRect) {
expected.DrawRRect(rrect, DlPaint());
auto expect_dl = expected.Build();

// Support for this will be re-added soon, until then verify that we
// do not promote.
ASSERT_TRUE(DisplayListsNE_Verbose(dl, expect_dl));
ASSERT_TRUE(DisplayListsEQ_Verbose(dl, expect_dl));
}

TEST_F(DisplayListTest, DrawRectRRectPathPromoteToDrawRect) {
Expand All @@ -5144,9 +5293,7 @@ TEST_F(DisplayListTest, DrawRectRRectPathPromoteToDrawRect) {
expected.DrawRect(rect, DlPaint());
auto expect_dl = expected.Build();

// Support for this will be re-added soon, until then verify that we
// do not promote.
ASSERT_TRUE(DisplayListsNE_Verbose(dl, expect_dl));
ASSERT_TRUE(DisplayListsEQ_Verbose(dl, expect_dl));
}

TEST_F(DisplayListTest, DrawOvalRRectPathPromoteToDrawOval) {
Expand All @@ -5161,9 +5308,7 @@ TEST_F(DisplayListTest, DrawOvalRRectPathPromoteToDrawOval) {
expected.DrawOval(rect, DlPaint());
auto expect_dl = expected.Build();

// Support for this will be re-added soon, until then verify that we
// do not promote.
ASSERT_TRUE(DisplayListsNE_Verbose(dl, expect_dl));
ASSERT_TRUE(DisplayListsEQ_Verbose(dl, expect_dl));
}

TEST_F(DisplayListTest, ClipRectRRectPromoteToClipRect) {
Expand Down
18 changes: 18 additions & 0 deletions display_list/dl_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,24 @@ void DisplayListBuilder::DrawDRRect(const SkRRect& outer,
drawDRRect(outer, inner);
}
void DisplayListBuilder::drawPath(const DlPath& path) {
if (!path.IsInverseFillType()) {
SkRect rect;
bool is_closed;
if (path.IsSkRect(&rect, &is_closed) &&
(is_closed || current_.getDrawStyle() == DlDrawStyle::kFill)) {
drawRect(ToDlRect(rect));
return;
}
if (path.IsSkOval(&rect)) {
drawOval(ToDlRect(rect));
return;
}
SkRRect rrect;
if (path.IsSkRRect(&rrect)) {
drawRRect(rrect);
return;
}
}
DisplayListAttributeFlags flags = kDrawPathFlags;
OpResult result = PaintResult(current_, flags);
if (result != OpResult::kNoEffect) {
Expand Down
5 changes: 3 additions & 2 deletions display_list/testing/dl_test_snippets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,11 @@ std::vector<DisplayListInvocationGroup> CreateAllRenderingOps() {
{1, 24, 1, [](DlOpReceiver& r) { r.drawPath(kTestPath1); }},
{1, 24, 1, [](DlOpReceiver& r) { r.drawPath(kTestPath2); }},
{1, 24, 1, [](DlOpReceiver& r) { r.drawPath(kTestPath3); }},
// oval, rect and rrect paths are left as drawPath
// oval and rect paths are redirected to drawRect and drawOval
{1, 24, 1, [](DlOpReceiver& r) { r.drawPath(kTestPathRect); }},
{1, 24, 1, [](DlOpReceiver& r) { r.drawPath(kTestPathOval); }},
{1, 24, 1, [](DlOpReceiver& r) { r.drawPath(kTestPathRRect); }},
// rrect path is redirected to drawRRect
{1, 56, 1, [](DlOpReceiver& r) { r.drawPath(kTestPathRRect); }},
}},
{"DrawArc",
{
Expand Down