diff --git a/engine/src/flutter/display_list/benchmarking/dl_benchmarks.cc b/engine/src/flutter/display_list/benchmarking/dl_benchmarks.cc index d568186490..16a69d504a 100644 --- a/engine/src/flutter/display_list/benchmarking/dl_benchmarks.cc +++ b/engine/src/flutter/display_list/benchmarking/dl_benchmarks.cc @@ -806,7 +806,7 @@ void BM_DrawVertices(benchmark::State& state, std::shared_ptr vertices = GetTestVertices(p, radius, 50, mode, vertex_count); total_vertex_count += vertex_count; - builder.DrawVertices(vertices.get(), DlBlendMode::kSrc, paint); + builder.DrawVertices(vertices, DlBlendMode::kSrc, paint); } state.counters["VertexCount"] = total_vertex_count; diff --git a/engine/src/flutter/display_list/benchmarking/dl_complexity_gl.cc b/engine/src/flutter/display_list/benchmarking/dl_complexity_gl.cc index 81143c85b4..0f400f20c9 100644 --- a/engine/src/flutter/display_list/benchmarking/dl_complexity_gl.cc +++ b/engine/src/flutter/display_list/benchmarking/dl_complexity_gl.cc @@ -494,7 +494,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawPoints( } void DisplayListGLComplexityCalculator::GLHelper::drawVertices( - const DlVertices* vertices, + const std::shared_ptr& vertices, DlBlendMode mode) { // There is currently no way for us to get the VertexMode from the SkVertices // object, but for future reference: diff --git a/engine/src/flutter/display_list/benchmarking/dl_complexity_gl.h b/engine/src/flutter/display_list/benchmarking/dl_complexity_gl.h index 5cb53c96c4..119b47d2e3 100644 --- a/engine/src/flutter/display_list/benchmarking/dl_complexity_gl.h +++ b/engine/src/flutter/display_list/benchmarking/dl_complexity_gl.h @@ -57,7 +57,8 @@ class DisplayListGLComplexityCalculator void drawPoints(DlCanvas::PointMode mode, uint32_t count, const SkPoint points[]) override; - void drawVertices(const DlVertices* vertices, DlBlendMode mode) override; + void drawVertices(const std::shared_ptr& vertices, + DlBlendMode mode) override; void drawImage(const sk_sp image, const SkPoint point, DlImageSampling sampling, diff --git a/engine/src/flutter/display_list/benchmarking/dl_complexity_metal.cc b/engine/src/flutter/display_list/benchmarking/dl_complexity_metal.cc index a0e0440938..20a5af86a4 100644 --- a/engine/src/flutter/display_list/benchmarking/dl_complexity_metal.cc +++ b/engine/src/flutter/display_list/benchmarking/dl_complexity_metal.cc @@ -446,7 +446,7 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawPoints( } void DisplayListMetalComplexityCalculator::MetalHelper::drawVertices( - const DlVertices* vertices, + const std::shared_ptr& vertices, DlBlendMode mode) { // There is currently no way for us to get the VertexMode from the SkVertices // object, but for future reference: diff --git a/engine/src/flutter/display_list/benchmarking/dl_complexity_metal.h b/engine/src/flutter/display_list/benchmarking/dl_complexity_metal.h index d5a5b77007..2038001a18 100644 --- a/engine/src/flutter/display_list/benchmarking/dl_complexity_metal.h +++ b/engine/src/flutter/display_list/benchmarking/dl_complexity_metal.h @@ -57,7 +57,8 @@ class DisplayListMetalComplexityCalculator void drawPoints(DlCanvas::PointMode mode, uint32_t count, const SkPoint points[]) override; - void drawVertices(const DlVertices* vertices, DlBlendMode mode) override; + void drawVertices(const std::shared_ptr& vertices, + DlBlendMode mode) override; void drawImage(const sk_sp image, const SkPoint point, DlImageSampling sampling, diff --git a/engine/src/flutter/display_list/benchmarking/dl_complexity_unittests.cc b/engine/src/flutter/display_list/benchmarking/dl_complexity_unittests.cc index 511ba8b1f7..b83f8db1d2 100644 --- a/engine/src/flutter/display_list/benchmarking/dl_complexity_unittests.cc +++ b/engine/src/flutter/display_list/benchmarking/dl_complexity_unittests.cc @@ -295,7 +295,7 @@ TEST(DisplayListComplexity, DrawVertices) { auto vertices = DlVertices::Make(DlVertexMode::kTriangles, points.size(), points.data(), nullptr, nullptr); DisplayListBuilder builder; - builder.DrawVertices(vertices.get(), DlBlendMode::kSrc, DlPaint()); + builder.DrawVertices(vertices, DlBlendMode::kSrc, DlPaint()); auto display_list = builder.Build(); auto calculators = AccumulatorCalculators(); diff --git a/engine/src/flutter/display_list/display_list.cc b/engine/src/flutter/display_list/display_list.cc index 029e940419..0937c70f15 100644 --- a/engine/src/flutter/display_list/display_list.cc +++ b/engine/src/flutter/display_list/display_list.cc @@ -234,8 +234,7 @@ void DisplayList::DisposeOps(const uint8_t* ptr, const uint8_t* end) { #undef DL_OP_DISPOSE default: - FML_DCHECK(false); - return; + FML_UNREACHABLE(); } } } diff --git a/engine/src/flutter/display_list/display_list_unittests.cc b/engine/src/flutter/display_list/display_list_unittests.cc index 5c9397d4cc..635d38af7c 100644 --- a/engine/src/flutter/display_list/display_list_unittests.cc +++ b/engine/src/flutter/display_list/display_list_unittests.cc @@ -1155,8 +1155,7 @@ TEST_F(DisplayListTest, SingleOpsMightSupportGroupOpacityBlendMode) { RUN_TESTS2( receiver.drawPoints(PointMode::kPoints, TestPointCount, kTestPoints); , false); - RUN_TESTS2(receiver.drawVertices(TestVertices1.get(), DlBlendMode::kSrc); - , false); + RUN_TESTS2(receiver.drawVertices(kTestVertices1, DlBlendMode::kSrc);, false); RUN_TESTS(receiver.drawImage(TestImage1, {0, 0}, kLinearSampling, true);); RUN_TESTS2(receiver.drawImage(TestImage1, {0, 0}, kLinearSampling, false); , true); @@ -3270,7 +3269,7 @@ TEST_F(DisplayListTest, NopOperationsOmittedFromRecords) { builder.DrawArc({10, 10, 20, 20}, 45, 90, true, paint); SkPoint pts[] = {{10, 10}, {20, 20}}; builder.DrawPoints(PointMode::kLines, 2, pts, paint); - builder.DrawVertices(TestVertices1, DlBlendMode::kSrcOver, paint); + builder.DrawVertices(kTestVertices1, DlBlendMode::kSrcOver, paint); builder.DrawImage(TestImage1, {10, 10}, DlImageSampling::kLinear, &paint); builder.DrawImageRect(TestImage1, SkRect{0.0f, 0.0f, 10.0f, 10.0f}, @@ -4696,5 +4695,34 @@ TEST_F(DisplayListTest, ClipPathRRectNonCulling) { cull_dl->Dispatch(expector); } +TEST_F(DisplayListTest, RecordLargeVertices) { + constexpr size_t vertex_count = 2000000; + auto points = std::vector(); + points.reserve(vertex_count); + auto colors = std::vector(); + colors.reserve(vertex_count); + for (size_t i = 0; i < vertex_count; i++) { + colors.emplace_back(DlColor(-i)); + points.emplace_back(((i & 1) == 0) ? SkPoint::Make(-i, i) + : SkPoint::Make(i, i)); + } + ASSERT_EQ(points.size(), vertex_count); + ASSERT_EQ(colors.size(), vertex_count); + auto vertices = DlVertices::Make(DlVertexMode::kTriangleStrip, vertex_count, + points.data(), points.data(), colors.data()); + ASSERT_GT(vertices->size(), 1u << 24); + auto backdrop = DlBlurImageFilter::Make(5.0f, 5.0f, DlTileMode::kDecal); + + for (int i = 0; i < 1000; i++) { + DisplayListBuilder builder; + for (int j = 0; j < 16; j++) { + builder.SaveLayer(nullptr, nullptr, backdrop.get()); + builder.DrawVertices(vertices, DlBlendMode::kSrcOver, DlPaint()); + builder.Restore(); + } + auto dl = builder.Build(); + } +} + } // namespace testing } // namespace flutter diff --git a/engine/src/flutter/display_list/dl_builder.cc b/engine/src/flutter/display_list/dl_builder.cc index 2ed0e6e65c..98772c0d7a 100644 --- a/engine/src/flutter/display_list/dl_builder.cc +++ b/engine/src/flutter/display_list/dl_builder.cc @@ -42,17 +42,17 @@ static constexpr inline bool is_power_of_two(int value) { template void* DisplayListBuilder::Push(size_t pod, Args&&... args) { size_t size = SkAlignPtr(sizeof(T) + pod); - FML_DCHECK(size < (1 << 24)); + FML_CHECK(size < (1 << 24)); if (used_ + size > allocated_) { static_assert(is_power_of_two(DL_BUILDER_PAGE), "This math needs updating for non-pow2."); // Next greater multiple of DL_BUILDER_PAGE. allocated_ = (used_ + size + DL_BUILDER_PAGE) & ~(DL_BUILDER_PAGE - 1); storage_.realloc(allocated_); - FML_DCHECK(storage_.get()); + FML_CHECK(storage_.get()); memset(storage_.get() + used_, 0, allocated_ - used_); } - FML_DCHECK(used_ + size <= allocated_); + FML_CHECK(used_ + size <= allocated_); auto op = reinterpret_cast(storage_.get() + used_); used_ += size; new (op) T{std::forward(args)...}; @@ -1309,14 +1309,14 @@ void DisplayListBuilder::DrawPoints(PointMode mode, SetAttributesFromPaint(paint, FlagsForPointMode(mode)); drawPoints(mode, count, pts); } -void DisplayListBuilder::drawVertices(const DlVertices* vertices, - DlBlendMode mode) { +void DisplayListBuilder::drawVertices( + const std::shared_ptr& vertices, + DlBlendMode mode) { DisplayListAttributeFlags flags = kDrawVerticesFlags; OpResult result = PaintResult(current_, flags); if (result != OpResult::kNoEffect && AccumulateOpBounds(vertices->bounds(), flags)) { - void* pod = Push(vertices->size(), mode); - new (pod) DlVertices(vertices); + Push(0, vertices, mode); // DrawVertices applies its colors to the paint so we have no way // of controlling opacity using the current paint attributes. // Although, examination of the |mode| might find some predictable @@ -1334,9 +1334,10 @@ void DisplayListBuilder::drawVertices(const DlVertices* vertices, current_layer().layer_local_accumulator.record_overlapping_bounds(); } } -void DisplayListBuilder::DrawVertices(const DlVertices* vertices, - DlBlendMode mode, - const DlPaint& paint) { +void DisplayListBuilder::DrawVertices( + const std::shared_ptr& vertices, + DlBlendMode mode, + const DlPaint& paint) { SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawVerticesFlags); drawVertices(vertices, mode); } diff --git a/engine/src/flutter/display_list/dl_builder.h b/engine/src/flutter/display_list/dl_builder.h index 438162c071..b1a458f68e 100644 --- a/engine/src/flutter/display_list/dl_builder.h +++ b/engine/src/flutter/display_list/dl_builder.h @@ -188,10 +188,9 @@ class DisplayListBuilder final : public virtual DlCanvas, const SkPoint pts[], const DlPaint& paint) override; // |DlCanvas| - void DrawVertices(const DlVertices* vertices, + void DrawVertices(const std::shared_ptr& vertices, DlBlendMode mode, const DlPaint& paint) override; - using DlCanvas::DrawVertices; // |DlCanvas| void DrawImage(const sk_sp& image, const SkPoint point, @@ -442,7 +441,8 @@ class DisplayListBuilder final : public virtual DlCanvas, // |DlOpReceiver| void drawPoints(PointMode mode, uint32_t count, const SkPoint pts[]) override; // |DlOpReceiver| - void drawVertices(const DlVertices* vertices, DlBlendMode mode) override; + void drawVertices(const std::shared_ptr& vertices, + DlBlendMode mode) override; // |DlOpReceiver| void drawImage(const sk_sp image, diff --git a/engine/src/flutter/display_list/dl_canvas.h b/engine/src/flutter/display_list/dl_canvas.h index 769deb3f58..ab505777ae 100644 --- a/engine/src/flutter/display_list/dl_canvas.h +++ b/engine/src/flutter/display_list/dl_canvas.h @@ -157,14 +157,9 @@ class DlCanvas { uint32_t count, const SkPoint pts[], const DlPaint& paint) = 0; - virtual void DrawVertices(const DlVertices* vertices, + virtual void DrawVertices(const std::shared_ptr& vertices, DlBlendMode mode, const DlPaint& paint) = 0; - void DrawVertices(const std::shared_ptr& vertices, - DlBlendMode mode, - const DlPaint& paint) { - DrawVertices(vertices.get(), mode, paint); - } virtual void DrawImage(const sk_sp& image, const SkPoint point, DlImageSampling sampling, diff --git a/engine/src/flutter/display_list/dl_op_receiver.h b/engine/src/flutter/display_list/dl_op_receiver.h index 74c65e963c..8de5dae62c 100644 --- a/engine/src/flutter/display_list/dl_op_receiver.h +++ b/engine/src/flutter/display_list/dl_op_receiver.h @@ -358,7 +358,8 @@ class DlOpReceiver { virtual void drawPoints(PointMode mode, uint32_t count, const SkPoint points[]) = 0; - virtual void drawVertices(const DlVertices* vertices, DlBlendMode mode) = 0; + virtual void drawVertices(const std::shared_ptr& vertices, + DlBlendMode mode) = 0; virtual void drawImage(const sk_sp image, const SkPoint point, DlImageSampling sampling, diff --git a/engine/src/flutter/display_list/dl_op_records.h b/engine/src/flutter/display_list/dl_op_records.h index a8cf3063bb..3ad6eebe8f 100644 --- a/engine/src/flutter/display_list/dl_op_records.h +++ b/engine/src/flutter/display_list/dl_op_records.h @@ -802,24 +802,19 @@ DEFINE_DRAW_POINTS_OP(Lines, kLines); DEFINE_DRAW_POINTS_OP(Polygon, kPolygon); #undef DEFINE_DRAW_POINTS_OP -// 4 byte header + 4 byte payload packs efficiently into 8 bytes -// The DlVertices object will be pod-allocated after this structure -// and can take any number of bytes so the final efficiency will -// depend on the size of the DlVertices. -// Note that the DlVertices object ends with an array of 16-bit -// indices so the alignment can be up to 6 bytes off leading to -// up to 6 bytes of overhead +// 4 byte header + 20 byte payload packs efficiently into 24 bytes struct DrawVerticesOp final : DrawOpBase { static constexpr auto kType = DisplayListOpType::kDrawVertices; - explicit DrawVerticesOp(DlBlendMode mode) : mode(mode) {} + explicit DrawVerticesOp(const std::shared_ptr& vertices, + DlBlendMode mode) + : mode(mode), vertices(vertices) {} const DlBlendMode mode; + const std::shared_ptr vertices; void dispatch(DispatchContext& ctx) const { if (op_needed(ctx)) { - const DlVertices* vertices = - reinterpret_cast(this + 1); ctx.receiver.drawVertices(vertices, mode); } } diff --git a/engine/src/flutter/display_list/dl_vertices.h b/engine/src/flutter/display_list/dl_vertices.h index 6f7e6443ad..582c02f0bf 100644 --- a/engine/src/flutter/display_list/dl_vertices.h +++ b/engine/src/flutter/display_list/dl_vertices.h @@ -112,7 +112,7 @@ class DlVertices { Builder(DlVertexMode mode, int vertex_count, Flags flags, int index_count); /// Returns true iff the underlying object was successfully allocated. - bool is_valid() { return vertices_ != nullptr; } + bool is_valid() const { return vertices_ != nullptr; } /// @brief Copies the indicated list of points as vertices. /// diff --git a/engine/src/flutter/display_list/dl_vertices_unittests.cc b/engine/src/flutter/display_list/dl_vertices_unittests.cc index f30f473b1c..2fe46f812b 100644 --- a/engine/src/flutter/display_list/dl_vertices_unittests.cc +++ b/engine/src/flutter/display_list/dl_vertices_unittests.cc @@ -12,7 +12,7 @@ namespace flutter { namespace testing { TEST(DisplayListVertices, MakeWithZeroAndNegativeVerticesAndIndices) { - std::shared_ptr vertices1 = DlVertices::Make( + std::shared_ptr vertices1 = DlVertices::Make( DlVertexMode::kTriangles, 0, nullptr, nullptr, nullptr, 0, nullptr); EXPECT_NE(vertices1, nullptr); EXPECT_EQ(vertices1->vertex_count(), 0); @@ -22,7 +22,7 @@ TEST(DisplayListVertices, MakeWithZeroAndNegativeVerticesAndIndices) { EXPECT_EQ(vertices1->index_count(), 0); EXPECT_EQ(vertices1->indices(), nullptr); - std::shared_ptr vertices2 = DlVertices::Make( + std::shared_ptr vertices2 = DlVertices::Make( DlVertexMode::kTriangles, -1, nullptr, nullptr, nullptr, -1, nullptr); EXPECT_NE(vertices2, nullptr); EXPECT_EQ(vertices2->vertex_count(), 0); @@ -56,7 +56,7 @@ TEST(DisplayListVertices, MakeWithTexAndColorAndIndices) { 1, 2, 0, }; - std::shared_ptr vertices = DlVertices::Make( + std::shared_ptr vertices = DlVertices::Make( DlVertexMode::kTriangles, 3, coords, texture_coords, colors, 6, indices); ASSERT_NE(vertices, nullptr); @@ -96,7 +96,7 @@ TEST(DisplayListVertices, MakeWithTexAndColor) { DlColor::kGreen(), }; - std::shared_ptr vertices = DlVertices::Make( + std::shared_ptr vertices = DlVertices::Make( DlVertexMode::kTriangles, 3, coords, texture_coords, colors, 6, nullptr); ASSERT_NE(vertices, nullptr); @@ -132,7 +132,7 @@ TEST(DisplayListVertices, MakeWithTexAndIndices) { 1, 2, 0, }; - std::shared_ptr vertices = DlVertices::Make( + std::shared_ptr vertices = DlVertices::Make( DlVertexMode::kTriangles, 3, coords, texture_coords, nullptr, 6, indices); ASSERT_NE(vertices, nullptr); @@ -170,7 +170,7 @@ TEST(DisplayListVertices, MakeWithColorAndIndices) { 1, 2, 0, }; - std::shared_ptr vertices = DlVertices::Make( + std::shared_ptr vertices = DlVertices::Make( DlVertexMode::kTriangles, 3, coords, nullptr, colors, 6, indices); ASSERT_NE(vertices, nullptr); @@ -204,7 +204,7 @@ TEST(DisplayListVertices, MakeWithTex) { SkPoint::Make(115, 120), }; - std::shared_ptr vertices = DlVertices::Make( + std::shared_ptr vertices = DlVertices::Make( DlVertexMode::kTriangles, 3, coords, texture_coords, nullptr, 6, nullptr); ASSERT_NE(vertices, nullptr); @@ -235,7 +235,7 @@ TEST(DisplayListVertices, MakeWithColor) { DlColor::kGreen(), }; - std::shared_ptr vertices = DlVertices::Make( + std::shared_ptr vertices = DlVertices::Make( DlVertexMode::kTriangles, 3, coords, nullptr, colors, 6, nullptr); ASSERT_NE(vertices, nullptr); @@ -265,7 +265,7 @@ TEST(DisplayListVertices, MakeWithIndices) { 1, 2, 0, }; - std::shared_ptr vertices = DlVertices::Make( + std::shared_ptr vertices = DlVertices::Make( DlVertexMode::kTriangles, 3, coords, nullptr, nullptr, 6, indices); ASSERT_NE(vertices, nullptr); @@ -293,7 +293,7 @@ TEST(DisplayListVertices, MakeWithNoOptionalData) { SkPoint::Make(15, 20), }; - std::shared_ptr vertices = DlVertices::Make( + std::shared_ptr vertices = DlVertices::Make( DlVertexMode::kTriangles, 3, coords, nullptr, nullptr, 6, nullptr); ASSERT_NE(vertices, nullptr); @@ -322,7 +322,7 @@ TEST(DisplayListVertices, MakeWithIndicesButZeroIndexCount) { 1, 2, 0, }; - std::shared_ptr vertices = DlVertices::Make( + std::shared_ptr vertices = DlVertices::Make( DlVertexMode::kTriangles, 3, coords, nullptr, nullptr, 0, indices); ASSERT_NE(vertices, nullptr); @@ -351,7 +351,7 @@ TEST(DisplayListVertices, MakeWithIndicesButNegativeIndexCount) { 1, 2, 0, }; - std::shared_ptr vertices = DlVertices::Make( + std::shared_ptr vertices = DlVertices::Make( DlVertexMode::kTriangles, 3, coords, nullptr, nullptr, -5, indices); ASSERT_NE(vertices, nullptr); @@ -464,7 +464,7 @@ TEST(DisplayListVertices, BuildWithTexAndColorAndIndices) { builder.store_texture_coordinates(texture_coords); builder.store_colors(colors); builder.store_indices(indices); - std::shared_ptr vertices = builder.build(); + std::shared_ptr vertices = builder.build(); ASSERT_NE(vertices, nullptr); ASSERT_NE(vertices->vertices(), nullptr); @@ -491,11 +491,11 @@ TEST(DisplayListVertices, BuildWithTexAndColorAndIndices) { builder2.store_texture_coordinates(texture_coords); builder2.store_colors(colors); builder2.store_indices(indices); - std::shared_ptr vertices2 = builder2.build(); + std::shared_ptr vertices2 = builder2.build(); TestEquals(*vertices, *vertices2); - std::shared_ptr vertices3 = DlVertices::Make( + std::shared_ptr vertices3 = DlVertices::Make( DlVertexMode::kTriangles, 3, coords, texture_coords, colors, 6, indices); TestEquals(*vertices, *vertices3); @@ -523,7 +523,7 @@ TEST(DisplayListVertices, BuildWithTexAndColor) { builder.store_vertices(coords); builder.store_texture_coordinates(texture_coords); builder.store_colors(colors); - std::shared_ptr vertices = builder.build(); + std::shared_ptr vertices = builder.build(); ASSERT_NE(vertices, nullptr); ASSERT_NE(vertices->vertices(), nullptr); @@ -563,7 +563,7 @@ TEST(DisplayListVertices, BuildWithTexAndIndices) { builder.store_vertices(coords); builder.store_texture_coordinates(texture_coords); builder.store_indices(indices); - std::shared_ptr vertices = builder.build(); + std::shared_ptr vertices = builder.build(); ASSERT_NE(vertices, nullptr); ASSERT_NE(vertices->vertices(), nullptr); @@ -605,7 +605,7 @@ TEST(DisplayListVertices, BuildWithColorAndIndices) { builder.store_vertices(coords); builder.store_colors(colors); builder.store_indices(indices); - std::shared_ptr vertices = builder.build(); + std::shared_ptr vertices = builder.build(); ASSERT_NE(vertices, nullptr); ASSERT_NE(vertices->vertices(), nullptr); @@ -642,7 +642,7 @@ TEST(DisplayListVertices, BuildWithTexUsingPoints) { Builder::kHasTextureCoordinates, 0); builder.store_vertices(coords); builder.store_texture_coordinates(texture_coords); - std::shared_ptr vertices = builder.build(); + std::shared_ptr vertices = builder.build(); ASSERT_NE(vertices, nullptr); ASSERT_NE(vertices->vertices(), nullptr); @@ -676,7 +676,7 @@ TEST(DisplayListVertices, BuildWithTexUsingFloats) { Builder::kHasTextureCoordinates, 0); builder.store_vertices(coords); builder.store_texture_coordinates(texture_coords); - std::shared_ptr vertices = builder.build(); + std::shared_ptr vertices = builder.build(); ASSERT_NE(vertices, nullptr); ASSERT_NE(vertices->vertices(), nullptr); @@ -723,13 +723,13 @@ TEST(DisplayListVertices, BuildUsingFloatsSameAsPoints) { Builder::kHasTextureCoordinates, 0); builder_points.store_vertices(coord_points); builder_points.store_texture_coordinates(texture_coord_points); - std::shared_ptr vertices_points = builder_points.build(); + std::shared_ptr vertices_points = builder_points.build(); Builder builder_floats(DlVertexMode::kTriangles, 3, // Builder::kHasTextureCoordinates, 0); builder_floats.store_vertices(coord_floats); builder_floats.store_texture_coordinates(texture_coord_floats); - std::shared_ptr vertices_floats = builder_floats.build(); + std::shared_ptr vertices_floats = builder_floats.build(); TestEquals(*vertices_points, *vertices_floats); } @@ -750,7 +750,7 @@ TEST(DisplayListVertices, BuildWithColor) { Builder::kHasColors, 0); builder.store_vertices(coords); builder.store_colors(colors); - std::shared_ptr vertices = builder.build(); + std::shared_ptr vertices = builder.build(); ASSERT_NE(vertices, nullptr); ASSERT_NE(vertices->vertices(), nullptr); @@ -782,7 +782,7 @@ TEST(DisplayListVertices, BuildWithIndices) { Builder builder(DlVertexMode::kTriangles, 3, Builder::kNone, 6); builder.store_vertices(coords); builder.store_indices(indices); - std::shared_ptr vertices = builder.build(); + std::shared_ptr vertices = builder.build(); ASSERT_NE(vertices, nullptr); ASSERT_NE(vertices->vertices(), nullptr); @@ -811,7 +811,7 @@ TEST(DisplayListVertices, BuildWithNoOptionalData) { Builder builder(DlVertexMode::kTriangles, 3, Builder::kNone, 0); builder.store_vertices(coords); - std::shared_ptr vertices = builder.build(); + std::shared_ptr vertices = builder.build(); ASSERT_NE(vertices, nullptr); ASSERT_NE(vertices->vertices(), nullptr); @@ -837,7 +837,7 @@ TEST(DisplayListVertices, BuildWithNegativeIndexCount) { Builder builder(DlVertexMode::kTriangles, 3, Builder::kNone, -5); builder.store_vertices(coords); - std::shared_ptr vertices = builder.build(); + std::shared_ptr vertices = builder.build(); ASSERT_NE(vertices, nullptr); ASSERT_NE(vertices->vertices(), nullptr); @@ -875,9 +875,9 @@ TEST(DisplayListVertices, TestEquals) { 1, 2, 0, }; - std::shared_ptr vertices1 = DlVertices::Make( + std::shared_ptr vertices1 = DlVertices::Make( DlVertexMode::kTriangles, 3, coords, texture_coords, colors, 6, indices); - std::shared_ptr vertices2 = DlVertices::Make( + std::shared_ptr vertices2 = DlVertices::Make( DlVertexMode::kTriangles, 3, coords, texture_coords, colors, 6, indices); TestEquals(*vertices1, *vertices2); } @@ -930,47 +930,47 @@ TEST(DisplayListVertices, TestNotEquals) { 2, 3, 1, }; - std::shared_ptr vertices1 = DlVertices::Make( + std::shared_ptr vertices1 = DlVertices::Make( DlVertexMode::kTriangles, 4, coords, texture_coords, colors, 9, indices); { - std::shared_ptr vertices2 = + std::shared_ptr vertices2 = DlVertices::Make(DlVertexMode::kTriangleFan, 4, coords, // texture_coords, colors, 9, indices); TestNotEquals(*vertices1, *vertices2, "vertex mode differs"); } { - std::shared_ptr vertices2 = + std::shared_ptr vertices2 = DlVertices::Make(DlVertexMode::kTriangles, 3, coords, // texture_coords, colors, 9, indices); TestNotEquals(*vertices1, *vertices2, "vertex count differs"); } { - std::shared_ptr vertices2 = + std::shared_ptr vertices2 = DlVertices::Make(DlVertexMode::kTriangles, 4, wrong_coords, // texture_coords, colors, 9, indices); TestNotEquals(*vertices1, *vertices2, "vertex coordinates differ"); } { - std::shared_ptr vertices2 = + std::shared_ptr vertices2 = DlVertices::Make(DlVertexMode::kTriangles, 4, coords, // wrong_texture_coords, colors, 9, indices); TestNotEquals(*vertices1, *vertices2, "texture coordinates differ"); } { - std::shared_ptr vertices2 = + std::shared_ptr vertices2 = DlVertices::Make(DlVertexMode::kTriangles, 4, coords, // texture_coords, wrong_colors, 9, indices); TestNotEquals(*vertices1, *vertices2, "colors differ"); } { - std::shared_ptr vertices2 = + std::shared_ptr vertices2 = DlVertices::Make(DlVertexMode::kTriangles, 4, coords, // texture_coords, colors, 6, indices); TestNotEquals(*vertices1, *vertices2, "index count differs"); } { - std::shared_ptr vertices2 = + std::shared_ptr vertices2 = DlVertices::Make(DlVertexMode::kTriangles, 4, coords, // texture_coords, colors, 9, wrong_indices); TestNotEquals(*vertices1, *vertices2, "indices differ"); diff --git a/engine/src/flutter/display_list/skia/dl_sk_canvas.cc b/engine/src/flutter/display_list/skia/dl_sk_canvas.cc index a836360a0f..a7334f303e 100644 --- a/engine/src/flutter/display_list/skia/dl_sk_canvas.cc +++ b/engine/src/flutter/display_list/skia/dl_sk_canvas.cc @@ -254,9 +254,10 @@ void DlSkCanvasAdapter::DrawPoints(PointMode mode, delegate_->drawPoints(ToSk(mode), count, pts, ToStrokedSk(paint)); } -void DlSkCanvasAdapter::DrawVertices(const DlVertices* vertices, - DlBlendMode mode, - const DlPaint& paint) { +void DlSkCanvasAdapter::DrawVertices( + const std::shared_ptr& vertices, + DlBlendMode mode, + const DlPaint& paint) { delegate_->drawVertices(ToSk(vertices), ToSk(mode), ToSk(paint)); } diff --git a/engine/src/flutter/display_list/skia/dl_sk_canvas.h b/engine/src/flutter/display_list/skia/dl_sk_canvas.h index 9712a8acb1..c61f3f4654 100644 --- a/engine/src/flutter/display_list/skia/dl_sk_canvas.h +++ b/engine/src/flutter/display_list/skia/dl_sk_canvas.h @@ -118,7 +118,7 @@ class DlSkCanvasAdapter final : public virtual DlCanvas { uint32_t count, const SkPoint pts[], const DlPaint& paint) override; - void DrawVertices(const DlVertices* vertices, + void DrawVertices(const std::shared_ptr& vertices, DlBlendMode mode, const DlPaint& paint) override; void DrawImage(const sk_sp& image, diff --git a/engine/src/flutter/display_list/skia/dl_sk_conversions.cc b/engine/src/flutter/display_list/skia/dl_sk_conversions.cc index f61c3e06b2..a1747cfbb2 100644 --- a/engine/src/flutter/display_list/skia/dl_sk_conversions.cc +++ b/engine/src/flutter/display_list/skia/dl_sk_conversions.cc @@ -274,7 +274,7 @@ sk_sp ToSk(const DlMaskFilter* filter) { } } -sk_sp ToSk(const DlVertices* vertices) { +sk_sp ToSk(const std::shared_ptr& vertices) { const SkColor* sk_colors = reinterpret_cast(vertices->colors()); return SkVertices::MakeCopy(ToSk(vertices->mode()), vertices->vertex_count(), diff --git a/engine/src/flutter/display_list/skia/dl_sk_conversions.h b/engine/src/flutter/display_list/skia/dl_sk_conversions.h index 3d99401aae..ebe53882c9 100644 --- a/engine/src/flutter/display_list/skia/dl_sk_conversions.h +++ b/engine/src/flutter/display_list/skia/dl_sk_conversions.h @@ -114,14 +114,7 @@ inline sk_sp ToSk(const DlMaskFilter& filter) { return ToSk(&filter); } -extern sk_sp ToSk(const DlVertices* vertices); -inline sk_sp ToSk( - const std::shared_ptr& vertices) { - return ToSk(vertices.get()); -} -inline sk_sp ToSk(const DlVertices& vertices) { - return ToSk(&vertices); -} +extern sk_sp ToSk(const std::shared_ptr& vertices); } // namespace flutter diff --git a/engine/src/flutter/display_list/skia/dl_sk_conversions_unittests.cc b/engine/src/flutter/display_list/skia/dl_sk_conversions_unittests.cc index f5adf4d250..575113b9f6 100644 --- a/engine/src/flutter/display_list/skia/dl_sk_conversions_unittests.cc +++ b/engine/src/flutter/display_list/skia/dl_sk_conversions_unittests.cc @@ -194,12 +194,12 @@ TEST(DisplayListSkConversions, BlendColorFilterModifiesTransparency) { #undef FOR_EACH_BLEND_MODE_ENUM TEST(DisplayListSkConversions, ConvertWithZeroAndNegativeVerticesAndIndices) { - std::shared_ptr vertices1 = DlVertices::Make( + std::shared_ptr vertices1 = DlVertices::Make( DlVertexMode::kTriangles, 0, nullptr, nullptr, nullptr, 0, nullptr); EXPECT_NE(vertices1, nullptr); EXPECT_NE(ToSk(vertices1), nullptr); - std::shared_ptr vertices2 = DlVertices::Make( + std::shared_ptr vertices2 = DlVertices::Make( DlVertexMode::kTriangles, -1, nullptr, nullptr, nullptr, -1, nullptr); EXPECT_NE(vertices2, nullptr); EXPECT_NE(ToSk(vertices2), nullptr); diff --git a/engine/src/flutter/display_list/skia/dl_sk_dispatcher.cc b/engine/src/flutter/display_list/skia/dl_sk_dispatcher.cc index 733dbd40f3..84c7115fb5 100644 --- a/engine/src/flutter/display_list/skia/dl_sk_dispatcher.cc +++ b/engine/src/flutter/display_list/skia/dl_sk_dispatcher.cc @@ -192,8 +192,9 @@ void DlSkCanvasDispatcher::drawPoints(PointMode mode, const SkPoint pts[]) { canvas_->drawPoints(ToSk(mode), count, pts, paint()); } -void DlSkCanvasDispatcher::drawVertices(const DlVertices* vertices, - DlBlendMode mode) { +void DlSkCanvasDispatcher::drawVertices( + const std::shared_ptr& vertices, + DlBlendMode mode) { canvas_->drawVertices(ToSk(vertices), ToSk(mode), paint()); } void DlSkCanvasDispatcher::drawImage(const sk_sp image, diff --git a/engine/src/flutter/display_list/skia/dl_sk_dispatcher.h b/engine/src/flutter/display_list/skia/dl_sk_dispatcher.h index 17cb7440a7..ef15f8152e 100644 --- a/engine/src/flutter/display_list/skia/dl_sk_dispatcher.h +++ b/engine/src/flutter/display_list/skia/dl_sk_dispatcher.h @@ -72,7 +72,8 @@ class DlSkCanvasDispatcher : public virtual DlOpReceiver, SkScalar sweep, bool useCenter) override; void drawPoints(PointMode mode, uint32_t count, const SkPoint pts[]) override; - void drawVertices(const DlVertices* vertices, DlBlendMode mode) override; + void drawVertices(const std::shared_ptr& vertices, + DlBlendMode mode) override; void drawImage(const sk_sp image, const SkPoint point, DlImageSampling sampling, diff --git a/engine/src/flutter/display_list/testing/dl_test_snippets.cc b/engine/src/flutter/display_list/testing/dl_test_snippets.cc index 7c360d7df2..e5ad4b2f36 100644 --- a/engine/src/flutter/display_list/testing/dl_test_snippets.cc +++ b/engine/src/flutter/display_list/testing/dl_test_snippets.cc @@ -680,17 +680,17 @@ std::vector CreateAllRenderingOps() { }}, {"DrawVertices", { - {1, 112, 1, + {1, 24, 1, [](DlOpReceiver& r) { - r.drawVertices(TestVertices1.get(), DlBlendMode::kSrcIn); + r.drawVertices(kTestVertices1, DlBlendMode::kSrcIn); }}, - {1, 112, 1, + {1, 24, 1, [](DlOpReceiver& r) { - r.drawVertices(TestVertices1.get(), DlBlendMode::kDstIn); + r.drawVertices(kTestVertices1, DlBlendMode::kDstIn); }}, - {1, 112, 1, + {1, 24, 1, [](DlOpReceiver& r) { - r.drawVertices(TestVertices2.get(), DlBlendMode::kSrcIn); + r.drawVertices(kTestVertices2, DlBlendMode::kSrcIn); }}, }}, {"DrawImage", diff --git a/engine/src/flutter/display_list/testing/dl_test_snippets.h b/engine/src/flutter/display_list/testing/dl_test_snippets.h index 0c8c97e06b..16d740c2fb 100644 --- a/engine/src/flutter/display_list/testing/dl_test_snippets.h +++ b/engine/src/flutter/display_list/testing/dl_test_snippets.h @@ -192,13 +192,13 @@ static const SkPath kTestPath3 = static const SkMatrix kTestMatrix1 = SkMatrix::Scale(2, 2); static const SkMatrix kTestMatrix2 = SkMatrix::RotateDeg(45); -static std::shared_ptr TestVertices1 = +static const std::shared_ptr kTestVertices1 = DlVertices::Make(DlVertexMode::kTriangles, // 3, kTestPoints, nullptr, kColors); -static std::shared_ptr TestVertices2 = +static const std::shared_ptr kTestVertices2 = DlVertices::Make(DlVertexMode::kTriangleFan, // 3, kTestPoints, diff --git a/engine/src/flutter/display_list/utils/dl_receiver_utils.h b/engine/src/flutter/display_list/utils/dl_receiver_utils.h index a47178a36c..d50cb00cba 100644 --- a/engine/src/flutter/display_list/utils/dl_receiver_utils.h +++ b/engine/src/flutter/display_list/utils/dl_receiver_utils.h @@ -101,7 +101,8 @@ class IgnoreDrawDispatchHelper : public virtual DlOpReceiver { void drawPoints(DlCanvas::PointMode mode, uint32_t count, const SkPoint points[]) override {} - void drawVertices(const DlVertices* vertices, DlBlendMode mode) override {} + void drawVertices(const std::shared_ptr& vertices, + DlBlendMode mode) override {} void drawImage(const sk_sp image, const SkPoint point, DlImageSampling sampling, diff --git a/engine/src/flutter/impeller/display_list/dl_dispatcher.cc b/engine/src/flutter/impeller/display_list/dl_dispatcher.cc index 872c74f4cf..aaed5e44f6 100644 --- a/engine/src/flutter/impeller/display_list/dl_dispatcher.cc +++ b/engine/src/flutter/impeller/display_list/dl_dispatcher.cc @@ -957,8 +957,9 @@ void DlDispatcherBase::drawPoints(PointMode mode, } // |flutter::DlOpReceiver| -void DlDispatcherBase::drawVertices(const flutter::DlVertices* vertices, - flutter::DlBlendMode dl_mode) { +void DlDispatcherBase::drawVertices( + const std::shared_ptr& vertices, + flutter::DlBlendMode dl_mode) { GetCanvas().DrawVertices(MakeVertices(vertices), ToBlendMode(dl_mode), paint_); } diff --git a/engine/src/flutter/impeller/display_list/dl_dispatcher.h b/engine/src/flutter/impeller/display_list/dl_dispatcher.h index bb2c8624e6..7349ca7e4f 100644 --- a/engine/src/flutter/impeller/display_list/dl_dispatcher.h +++ b/engine/src/flutter/impeller/display_list/dl_dispatcher.h @@ -182,7 +182,7 @@ class DlDispatcherBase : public flutter::DlOpReceiver { const SkPoint points[]) override; // |flutter::DlOpReceiver| - void drawVertices(const flutter::DlVertices* vertices, + void drawVertices(const std::shared_ptr& vertices, flutter::DlBlendMode dl_mode) override; // |flutter::DlOpReceiver| diff --git a/engine/src/flutter/impeller/display_list/dl_vertices_geometry.cc b/engine/src/flutter/impeller/display_list/dl_vertices_geometry.cc index 279e590570..6a93757f3d 100644 --- a/engine/src/flutter/impeller/display_list/dl_vertices_geometry.cc +++ b/engine/src/flutter/impeller/display_list/dl_vertices_geometry.cc @@ -29,7 +29,7 @@ static VerticesGeometry::VertexMode ToVertexMode(flutter::DlVertexMode mode) { } std::shared_ptr MakeVertices( - const flutter::DlVertices* vertices) { + const std::shared_ptr& vertices) { auto bounds = ToRect(vertices->bounds()); auto mode = ToVertexMode(vertices->mode()); std::vector positions(vertices->vertex_count()); diff --git a/engine/src/flutter/impeller/display_list/dl_vertices_geometry.h b/engine/src/flutter/impeller/display_list/dl_vertices_geometry.h index e7502cdc83..96790af408 100644 --- a/engine/src/flutter/impeller/display_list/dl_vertices_geometry.h +++ b/engine/src/flutter/impeller/display_list/dl_vertices_geometry.h @@ -12,7 +12,7 @@ namespace impeller { std::shared_ptr MakeVertices( - const flutter::DlVertices* vertices); + const std::shared_ptr& vertices); } // namespace impeller diff --git a/engine/src/flutter/lib/ui/painting/vertices.h b/engine/src/flutter/lib/ui/painting/vertices.h index d0390dbc4c..6574cd8ca9 100644 --- a/engine/src/flutter/lib/ui/painting/vertices.h +++ b/engine/src/flutter/lib/ui/painting/vertices.h @@ -26,7 +26,7 @@ class Vertices : public RefCountedDartWrappable { Dart_Handle colors_handle, Dart_Handle indices_handle); - const DlVertices* vertices() const { return vertices_.get(); } + const std::shared_ptr& vertices() const { return vertices_; } void dispose(); diff --git a/engine/src/flutter/shell/common/dl_op_spy.cc b/engine/src/flutter/shell/common/dl_op_spy.cc index 78ce2a3ada..ba3b429756 100644 --- a/engine/src/flutter/shell/common/dl_op_spy.cc +++ b/engine/src/flutter/shell/common/dl_op_spy.cc @@ -79,7 +79,8 @@ void DlOpSpy::drawPoints(PointMode mode, const SkPoint points[]) { did_draw_ |= will_draw_; } -void DlOpSpy::drawVertices(const DlVertices* vertices, DlBlendMode mode) { +void DlOpSpy::drawVertices(const std::shared_ptr& vertices, + DlBlendMode mode) { did_draw_ |= will_draw_; } // In theory, below drawImage methods can produce a transparent screen when a diff --git a/engine/src/flutter/shell/common/dl_op_spy.h b/engine/src/flutter/shell/common/dl_op_spy.h index 2eeb6e66b5..490e09c60f 100644 --- a/engine/src/flutter/shell/common/dl_op_spy.h +++ b/engine/src/flutter/shell/common/dl_op_spy.h @@ -63,7 +63,8 @@ class DlOpSpy final : public virtual DlOpReceiver, void drawPoints(PointMode mode, uint32_t count, const SkPoint points[]) override; - void drawVertices(const DlVertices* vertices, DlBlendMode mode) override; + void drawVertices(const std::shared_ptr& vertices, + DlBlendMode mode) override; void drawImage(const sk_sp image, const SkPoint point, DlImageSampling sampling, diff --git a/engine/src/flutter/shell/common/dl_op_spy_unittests.cc b/engine/src/flutter/shell/common/dl_op_spy_unittests.cc index 90de2eed6e..b04c6d6f17 100644 --- a/engine/src/flutter/shell/common/dl_op_spy_unittests.cc +++ b/engine/src/flutter/shell/common/dl_op_spy_unittests.cc @@ -390,7 +390,7 @@ TEST(DlOpSpy, DrawVertices) { }; auto dl_vertices = DlVertices::Make(DlVertexMode::kTriangles, 3, vertices, texture_coordinates, colors, 0); - builder.DrawVertices(dl_vertices.get(), DlBlendMode::kSrc, paint); + builder.DrawVertices(dl_vertices, DlBlendMode::kSrc, paint); sk_sp dl = builder.Build(); DlOpSpy dl_op_spy; dl->Dispatch(dl_op_spy); @@ -416,7 +416,7 @@ TEST(DlOpSpy, DrawVertices) { }; auto dl_vertices = DlVertices::Make(DlVertexMode::kTriangles, 3, vertices, texture_coordinates, colors, 0); - builder.DrawVertices(dl_vertices.get(), DlBlendMode::kSrc, paint); + builder.DrawVertices(dl_vertices, DlBlendMode::kSrc, paint); sk_sp dl = builder.Build(); DlOpSpy dl_op_spy; dl->Dispatch(dl_op_spy); diff --git a/engine/src/flutter/testing/display_list_testing.cc b/engine/src/flutter/testing/display_list_testing.cc index fa1c575dab..8cf84bc270 100644 --- a/engine/src/flutter/testing/display_list_testing.cc +++ b/engine/src/flutter/testing/display_list_testing.cc @@ -823,7 +823,7 @@ void DisplayListStreamDispatcher::drawPoints(PointMode mode, out_array("points", count, points) << ");" << std::endl; } -void DisplayListStreamDispatcher::drawVertices(const DlVertices* vertices, +void DisplayListStreamDispatcher::drawVertices(const std::shared_ptr& vertices, DlBlendMode mode) { startl() << "drawVertices(" << "DlVertices(" diff --git a/engine/src/flutter/testing/display_list_testing.h b/engine/src/flutter/testing/display_list_testing.h index 1f65e1645e..b710e1e22a 100644 --- a/engine/src/flutter/testing/display_list_testing.h +++ b/engine/src/flutter/testing/display_list_testing.h @@ -141,7 +141,8 @@ class DisplayListStreamDispatcher final : public DlOpReceiver { void drawPoints(PointMode mode, uint32_t count, const SkPoint points[]) override; - void drawVertices(const DlVertices* vertices, DlBlendMode mode) override; + void drawVertices(const std::shared_ptr& vertices, + DlBlendMode mode) override; void drawImage(const sk_sp image, const SkPoint point, DlImageSampling sampling, diff --git a/engine/src/flutter/testing/mock_canvas.cc b/engine/src/flutter/testing/mock_canvas.cc index 65ab1bb96f..695678e23a 100644 --- a/engine/src/flutter/testing/mock_canvas.cc +++ b/engine/src/flutter/testing/mock_canvas.cc @@ -312,7 +312,9 @@ void MockCanvas::DrawImageNine(const sk_sp& image, FML_DCHECK(false); } -void MockCanvas::DrawVertices(const DlVertices*, DlBlendMode, const DlPaint&) { +void MockCanvas::DrawVertices(const std::shared_ptr&, + DlBlendMode, + const DlPaint&) { FML_DCHECK(false); } diff --git a/engine/src/flutter/testing/mock_canvas.h b/engine/src/flutter/testing/mock_canvas.h index 7d303d466a..f15e0ec54a 100644 --- a/engine/src/flutter/testing/mock_canvas.h +++ b/engine/src/flutter/testing/mock_canvas.h @@ -242,7 +242,7 @@ class MockCanvas final : public DlCanvas { uint32_t count, const SkPoint pts[], const DlPaint& paint) override; - void DrawVertices(const DlVertices* vertices, + void DrawVertices(const std::shared_ptr& vertices, DlBlendMode mode, const DlPaint& paint) override;