From 693f99ae009ff741d2ca120d799cb359040ac8f4 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 30 Oct 2024 17:40:18 -0700 Subject: [PATCH] [Impeller] expose reference to tessellator instead of shared_ptr. (flutter/engine#56244) All geometries were incrementing the shared_ptr usage count which shows up in profiles. Instead expose a Tessellator reference like we do with HostBuffer. --- .../src/flutter/impeller/entity/contents/content_context.cc | 4 ++-- .../src/flutter/impeller/entity/contents/content_context.h | 2 +- .../src/flutter/impeller/entity/geometry/circle_geometry.cc | 6 ++---- .../flutter/impeller/entity/geometry/ellipse_geometry.cc | 2 +- .../flutter/impeller/entity/geometry/fill_path_geometry.cc | 2 +- .../src/flutter/impeller/entity/geometry/line_geometry.cc | 4 ++-- .../impeller/entity/geometry/point_field_geometry.cc | 2 +- .../flutter/impeller/entity/geometry/round_rect_geometry.cc | 2 +- .../impeller/entity/geometry/stroke_path_geometry.cc | 2 +- 9 files changed, 12 insertions(+), 14 deletions(-) diff --git a/engine/src/flutter/impeller/entity/contents/content_context.cc b/engine/src/flutter/impeller/entity/contents/content_context.cc index e08670c59d..6748058270 100644 --- a/engine/src/flutter/impeller/entity/contents/content_context.cc +++ b/engine/src/flutter/impeller/entity/contents/content_context.cc @@ -543,8 +543,8 @@ fml::StatusOr ContentContext::MakeSubpass( return subpass_target; } -std::shared_ptr ContentContext::GetTessellator() const { - return tessellator_; +Tessellator& ContentContext::GetTessellator() const { + return *tessellator_; } std::shared_ptr ContentContext::GetContext() const { diff --git a/engine/src/flutter/impeller/entity/contents/content_context.h b/engine/src/flutter/impeller/entity/contents/content_context.h index 9abdc51ba9..9c7f4a7f2c 100644 --- a/engine/src/flutter/impeller/entity/contents/content_context.h +++ b/engine/src/flutter/impeller/entity/contents/content_context.h @@ -374,7 +374,7 @@ class ContentContext { bool IsValid() const; - std::shared_ptr GetTessellator() const; + Tessellator& GetTessellator() const; std::shared_ptr> GetFastGradientPipeline( ContentContextOptions opts) const { diff --git a/engine/src/flutter/impeller/entity/geometry/circle_geometry.cc b/engine/src/flutter/impeller/entity/geometry/circle_geometry.cc index f045f1f0ee..8565f0f0d8 100644 --- a/engine/src/flutter/impeller/entity/geometry/circle_geometry.cc +++ b/engine/src/flutter/impeller/entity/geometry/circle_geometry.cc @@ -46,12 +46,10 @@ GeometryResult CircleGeometry::GetPositionBuffer(const ContentContext& renderer, : LineGeometry::ComputePixelHalfWidth( transform, stroke_width_); - const std::shared_ptr& tessellator = renderer.GetTessellator(); - // We call the StrokedCircle method which will simplify to a // FilledCircleGenerator if the inner_radius is <= 0. - auto generator = - tessellator->StrokedCircle(transform, center_, radius_, half_width); + auto generator = renderer.GetTessellator().StrokedCircle(transform, center_, + radius_, half_width); return ComputePositionGeometry(renderer, generator, entity, pass); } diff --git a/engine/src/flutter/impeller/entity/geometry/ellipse_geometry.cc b/engine/src/flutter/impeller/entity/geometry/ellipse_geometry.cc index 76e457f201..71f3acec14 100644 --- a/engine/src/flutter/impeller/entity/geometry/ellipse_geometry.cc +++ b/engine/src/flutter/impeller/entity/geometry/ellipse_geometry.cc @@ -18,7 +18,7 @@ GeometryResult EllipseGeometry::GetPositionBuffer( RenderPass& pass) const { return ComputePositionGeometry( renderer, - renderer.GetTessellator()->FilledEllipse(entity.GetTransform(), bounds_), + renderer.GetTessellator().FilledEllipse(entity.GetTransform(), bounds_), entity, pass); } diff --git a/engine/src/flutter/impeller/entity/geometry/fill_path_geometry.cc b/engine/src/flutter/impeller/entity/geometry/fill_path_geometry.cc index 347aa3ed42..6ed0ec33e5 100644 --- a/engine/src/flutter/impeller/entity/geometry/fill_path_geometry.cc +++ b/engine/src/flutter/impeller/entity/geometry/fill_path_geometry.cc @@ -38,7 +38,7 @@ GeometryResult FillPathGeometry::GetPositionBuffer( }; } - VertexBuffer vertex_buffer = renderer.GetTessellator()->TessellateConvex( + VertexBuffer vertex_buffer = renderer.GetTessellator().TessellateConvex( path_, host_buffer, entity.GetTransform().GetMaxBasisLengthXY()); return GeometryResult{ diff --git a/engine/src/flutter/impeller/entity/geometry/line_geometry.cc b/engine/src/flutter/impeller/entity/geometry/line_geometry.cc index ed9306a214..56508b0377 100644 --- a/engine/src/flutter/impeller/entity/geometry/line_geometry.cc +++ b/engine/src/flutter/impeller/entity/geometry/line_geometry.cc @@ -80,8 +80,8 @@ GeometryResult LineGeometry::GetPositionBuffer(const ContentContext& renderer, auto radius = ComputePixelHalfWidth(transform, width_); if (cap_ == Cap::kRound) { - std::shared_ptr tessellator = renderer.GetTessellator(); - auto generator = tessellator->RoundCapLine(transform, p0_, p1_, radius); + auto generator = + renderer.GetTessellator().RoundCapLine(transform, p0_, p1_, radius); return ComputePositionGeometry(renderer, generator, entity, pass); } diff --git a/engine/src/flutter/impeller/entity/geometry/point_field_geometry.cc b/engine/src/flutter/impeller/entity/geometry/point_field_geometry.cc index e2ee046750..0548d61dbb 100644 --- a/engine/src/flutter/impeller/entity/geometry/point_field_geometry.cc +++ b/engine/src/flutter/impeller/entity/geometry/point_field_geometry.cc @@ -42,7 +42,7 @@ GeometryResult PointFieldGeometry::GetPositionBuffer( // Get triangulation relative to {0, 0} so we can translate it to each // point in turn. Tessellator::EllipticalVertexGenerator generator = - renderer.GetTessellator()->FilledCircle(transform, {}, radius); + renderer.GetTessellator().FilledCircle(transform, {}, radius); FML_DCHECK(generator.GetTriangleType() == PrimitiveType::kTriangleStrip); std::vector circle_vertices; diff --git a/engine/src/flutter/impeller/entity/geometry/round_rect_geometry.cc b/engine/src/flutter/impeller/entity/geometry/round_rect_geometry.cc index 1d673f53ad..060303c605 100644 --- a/engine/src/flutter/impeller/entity/geometry/round_rect_geometry.cc +++ b/engine/src/flutter/impeller/entity/geometry/round_rect_geometry.cc @@ -16,7 +16,7 @@ GeometryResult RoundRectGeometry::GetPositionBuffer( const Entity& entity, RenderPass& pass) const { return ComputePositionGeometry(renderer, - renderer.GetTessellator()->FilledRoundRect( + renderer.GetTessellator().FilledRoundRect( entity.GetTransform(), bounds_, radii_), entity, pass); } diff --git a/engine/src/flutter/impeller/entity/geometry/stroke_path_geometry.cc b/engine/src/flutter/impeller/entity/geometry/stroke_path_geometry.cc index 7358b0a5fb..a7020a87c3 100644 --- a/engine/src/flutter/impeller/entity/geometry/stroke_path_geometry.cc +++ b/engine/src/flutter/impeller/entity/geometry/stroke_path_geometry.cc @@ -581,7 +581,7 @@ GeometryResult StrokePathGeometry::GetPositionBuffer( auto scale = entity.GetTransform().GetMaxBasisLengthXY(); PositionWriter position_writer; - auto polyline = renderer.GetTessellator()->CreateTempPolyline(path_, scale); + auto polyline = renderer.GetTessellator().CreateTempPolyline(path_, scale); CreateSolidStrokeVertices(position_writer, polyline, stroke_width, miter_limit_ * stroke_width_ * 0.5f, GetJoinProc(stroke_join_),