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

[Impeller] generate stroke vertices into point arena. #56390

Merged
merged 7 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
39 changes: 39 additions & 0 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,45 @@ APPLY_COLOR_FILTER_GRADIENT_TEST(Radial);
APPLY_COLOR_FILTER_GRADIENT_TEST(Conical);
APPLY_COLOR_FILTER_GRADIENT_TEST(Sweep);

TEST_P(EntityTest, GiantStrokePathAllocation) {
PathBuilder builder{};
for (int i = 0; i < 10000; i++) {
builder.LineTo(Point(i, i));
}
Path path = builder.TakePath();
auto geom = Geometry::MakeStrokePath(path, /*stroke_width=*/10);

ContentContext content_context(GetContext(), nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ContentContext content_context(GetContext(), nullptr);
ContentContext content_context(GetContext(), /*typographer_context=*/nullptr);

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Entity entity;

auto cmd_buffer = content_context.GetContext()->CreateCommandBuffer();

RenderTargetAllocator allocator(
content_context.GetContext()->GetResourceAllocator());

auto render_target =
allocator.CreateOffscreen(*content_context.GetContext(), {10, 10}, 1);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
allocator.CreateOffscreen(*content_context.GetContext(), {10, 10}, 1);
allocator.CreateOffscreen(*content_context.GetContext(), /*size=*/{10, 10}, /*mip_count=*/1);

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

auto pass = cmd_buffer->CreateRenderPass(render_target);

GeometryResult result =
geom->GetPositionBuffer(content_context, entity, *pass);

// Validate the buffer data overflowed the small buffer
EXPECT_GT(result.vertex_buffer.vertex_count, kPointArenaSize);

// Validate that there are no uninitialized points near the gap.
Point* written_data = reinterpret_cast<Point*>(
(result.vertex_buffer.vertex_buffer.GetBuffer()->OnGetContents() +
result.vertex_buffer.vertex_buffer.GetRange().offset));

EXPECT_NE(*(written_data + kPointArenaSize - 2), Point(0, 0));
EXPECT_NE(*(written_data + kPointArenaSize - 1), Point(0, 0));
EXPECT_NE(*(written_data + kPointArenaSize), Point(0, 0));
EXPECT_NE(*(written_data + kPointArenaSize + 1), Point(0, 0));
EXPECT_NE(*(written_data + kPointArenaSize + 2), Point(0, 0));
EXPECT_NE(*(written_data + kPointArenaSize + 3), Point(0, 0));
Copy link
Member

Choose a reason for hiding this comment

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

Can we switch these to EXPECT_EQ assertions? Not being Point(0,0) leaves a lot of possibilities.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since this is stroke tessellation the generated points are floating point values like 43.22132 ...

I could do a CLOSE_TO or something like that though. As long as they are in the ballpark

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

}

} // namespace testing
} // namespace impeller

Expand Down
20 changes: 10 additions & 10 deletions impeller/entity/geometry/geometry_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
#include "impeller/renderer/testing/mocks.h"

inline ::testing::AssertionResult SolidVerticesNear(
std::vector<impeller::SolidFillVertexShader::PerVertexData> a,
std::vector<impeller::SolidFillVertexShader::PerVertexData> b) {
std::vector<impeller::Point> a,
std::vector<impeller::Point> b) {
if (a.size() != b.size()) {
return ::testing::AssertionFailure() << "Colors length does not match";
}
for (auto i = 0u; i < b.size(); i++) {
if (!PointNear(a[i].position, b[i].position)) {
if (!PointNear(a[i], b[i])) {
return ::testing::AssertionFailure() << "Positions are not equal.";
}
}
Expand Down Expand Up @@ -53,13 +53,13 @@ namespace impeller {

class ImpellerEntityUnitTestAccessor {
public:
static std::vector<SolidFillVertexShader::PerVertexData>
GenerateSolidStrokeVertices(const Path::Polyline& polyline,
Scalar stroke_width,
Scalar miter_limit,
Join stroke_join,
Cap stroke_cap,
Scalar scale) {
static std::vector<Point> GenerateSolidStrokeVertices(
const Path::Polyline& polyline,
Scalar stroke_width,
Scalar miter_limit,
Join stroke_join,
Cap stroke_cap,
Scalar scale) {
return StrokePathGeometry::GenerateSolidStrokeVertices(
polyline, stroke_width, miter_limit, stroke_join, stroke_cap, scale);
}
Expand Down
Loading