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 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
60 changes: 60 additions & 0 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,66 @@ 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(), /*typographer_context=*/nullptr);
Entity entity;

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

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

auto render_target = allocator.CreateOffscreen(
*content_context.GetContext(), /*size=*/{10, 10}, /*mip_count=*/1);
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));

std::vector<Point> expected = {
Point(1019.46, 1026.54), //
Point(1026.54, 1019.46), //
Point(1020.45, 1027.54), //
Point(1027.54, 1020.46), //
Point(1020.46, 1027.53) //
};

Point point = written_data[kPointArenaSize - 2];
EXPECT_NEAR(point.x, expected[0].x, 0.1);
EXPECT_NEAR(point.y, expected[0].y, 0.1);

point = written_data[kPointArenaSize - 1];
EXPECT_NEAR(point.x, expected[1].x, 0.1);
EXPECT_NEAR(point.y, expected[1].y, 0.1);

point = written_data[kPointArenaSize];
EXPECT_NEAR(point.x, expected[2].x, 0.1);
EXPECT_NEAR(point.y, expected[2].y, 0.1);

point = written_data[kPointArenaSize + 1];
EXPECT_NEAR(point.x, expected[3].x, 0.1);
EXPECT_NEAR(point.y, expected[3].y, 0.1);

point = written_data[kPointArenaSize + 2];
EXPECT_NEAR(point.x, expected[4].x, 0.1);
EXPECT_NEAR(point.y, expected[4].y, 0.1);
}

} // 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