Skip to content

Commit

Permalink
aaron review.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahwilliams committed Nov 6, 2024
1 parent b03c4e5 commit dd2bf07
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 25 deletions.
39 changes: 30 additions & 9 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2372,16 +2372,16 @@ TEST_P(EntityTest, GiantStrokePathAllocation) {
Path path = builder.TakePath();
auto geom = Geometry::MakeStrokePath(path, /*stroke_width=*/10);

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

GeometryResult result =
Expand All @@ -2395,12 +2395,33 @@ TEST_P(EntityTest, GiantStrokePathAllocation) {
(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));
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
Expand Down
38 changes: 22 additions & 16 deletions impeller/entity/geometry/stroke_path_geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "impeller/core/buffer_view.h"
#include "impeller/core/formats.h"
#include "impeller/core/host_buffer.h"
#include "impeller/entity/geometry/geometry.h"
#include "impeller/geometry/constants.h"
#include "impeller/geometry/path_builder.h"
Expand All @@ -20,7 +21,9 @@ namespace {
class PositionWriter {
public:
explicit PositionWriter(std::vector<Point>& points)
: points_(points), oversized_(0) {}
: points_(points), oversized_() {
FML_DCHECK(points_.size() == kPointArenaSize);
}

void AppendVertex(const Point& point) {
if (offset_ >= kPointArenaSize) {
Expand All @@ -30,7 +33,11 @@ class PositionWriter {
}
}

size_t GetUsedSize() const { return offset_; }
/// @brief Return the number of points used in the arena, followed by
/// the number of points allocated in the overized buffer.
std::pair<size_t, size_t> GetUsedSize() const {
return std::make_pair(offset_, oversized_.size());
}

bool HasOversizedBuffer() const { return !oversized_.empty(); }

Expand Down Expand Up @@ -594,47 +601,46 @@ GeometryResult StrokePathGeometry::GetPositionBuffer(
GetJoinProc(stroke_join_), GetCapProc(stroke_cap_),
scale);

const auto [arena_length, oversized_length] = position_writer.GetUsedSize();
if (!position_writer.HasOversizedBuffer()) {
BufferView buffer_view = host_buffer.Emplace(
renderer.GetTessellator().GetStrokePointCache().data(),
position_writer.GetUsedSize() * sizeof(Point), alignof(Point));
arena_length * sizeof(Point), alignof(Point));

return GeometryResult{.type = PrimitiveType::kTriangleStrip,
.vertex_buffer =
{
.vertex_buffer = buffer_view,
.vertex_count = position_writer.GetUsedSize(),
.vertex_count = arena_length,
.index_type = IndexType::kNone,
},
.transform = entity.GetShaderTransform(pass),
.mode = GeometryResult::Mode::kPreventOverdraw};
}
FML_LOG(ERROR) << "Oversized";
const std::vector<Point>& oversized_data =
position_writer.GetOveriszedBuffer();
BufferView buffer_view = host_buffer.Emplace(
nullptr,
(position_writer.GetUsedSize() + oversized_data.size()) * sizeof(Point),
alignof(Point));
/*buffer=*/nullptr, //
(arena_length + oversized_length) * sizeof(Point), //
alignof(Point) //
);
memcpy(buffer_view.GetBuffer()->OnGetContents() +
buffer_view.GetRange().offset, //
renderer.GetTessellator().GetStrokePointCache().data(), //
position_writer.GetUsedSize() * sizeof(Point) //
arena_length * sizeof(Point) //
);
memcpy(
buffer_view.GetBuffer()->OnGetContents() + buffer_view.GetRange().offset +
position_writer.GetUsedSize() * sizeof(Point), //
oversized_data.data(), //
oversized_data.size() * sizeof(Point) //
memcpy(buffer_view.GetBuffer()->OnGetContents() +
buffer_view.GetRange().offset + arena_length * sizeof(Point), //
oversized_data.data(), //
oversized_data.size() * sizeof(Point) //
);
buffer_view.GetBuffer()->Flush(buffer_view.GetRange());

return GeometryResult{.type = PrimitiveType::kTriangleStrip,
.vertex_buffer =
{
.vertex_buffer = buffer_view,
.vertex_count = position_writer.GetUsedSize() +
oversized_data.size(),
.vertex_count = arena_length + oversized_length,
.index_type = IndexType::kNone,
},
.transform = entity.GetShaderTransform(pass),
Expand Down

0 comments on commit dd2bf07

Please sign in to comment.