1212
1313namespace impeller {
1414
15- PointFieldGeometry::PointFieldGeometry (std::vector<Point> points,
15+ PointFieldGeometry::PointFieldGeometry (const Point* points,
16+ size_t point_count,
1617 Scalar radius,
1718 bool round)
18- : points_(std::move(points)), radius_(radius), round_(round) {}
19+ : point_count_(point_count),
20+ radius_ (radius),
21+ round_(round),
22+ points_(points) {}
1923
2024PointFieldGeometry::~PointFieldGeometry () = default ;
2125
2226GeometryResult PointFieldGeometry::GetPositionBuffer (
2327 const ContentContext& renderer,
2428 const Entity& entity,
2529 RenderPass& pass) const {
26- if (radius_ < 0.0 || points_. empty () ) {
30+ if (radius_ < 0.0 || point_count_ == 0 ) {
2731 return {};
2832 }
2933 const Matrix& transform = entity.GetTransform ();
@@ -52,7 +56,7 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
5256 });
5357 FML_DCHECK (circle_vertices.size () == generator.GetVertexCount ());
5458
55- vertex_count = (circle_vertices.size () + 2 ) * points_. size () - 2 ;
59+ vertex_count = (circle_vertices.size () + 2 ) * point_count_ - 2 ;
5660 buffer_view = host_buffer.Emplace (
5761 vertex_count * sizeof (Point), alignof (Point), [&](uint8_t * data) {
5862 Point* output = reinterpret_cast <Point*>(data);
@@ -66,7 +70,7 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
6670 // the strip. This could be optimized out if we switched to using
6771 // primitive restart.
6872 Point last_point = circle_vertices.back () + center;
69- for (size_t i = 1 ; i < points_. size () ; i++) {
73+ for (size_t i = 1 ; i < point_count_ ; i++) {
7074 Point center = points_[i];
7175 output[offset++] = last_point;
7276 output[offset++] = Point (center + circle_vertices[0 ]);
@@ -77,7 +81,7 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
7781 }
7882 });
7983 } else {
80- vertex_count = 6 * points_. size () - 2 ;
84+ vertex_count = 6 * point_count_ - 2 ;
8185 buffer_view = host_buffer.Emplace (
8286 vertex_count * sizeof (Point), alignof (Point), [&](uint8_t * data) {
8387 Point* output = reinterpret_cast <Point*>(data);
@@ -97,7 +101,7 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
97101 // For all subequent points, insert a degenerate triangle to break
98102 // the strip. This could be optimized out if we switched to using
99103 // primitive restart.
100- for (size_t i = 1 ; i < points_. size () ; i++) {
104+ for (size_t i = 1 ; i < point_count_ ; i++) {
101105 Point point = points_[i];
102106 Point first = Point (point.x - radius, point.y - radius);
103107
@@ -129,22 +133,21 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
129133// |Geometry|
130134std::optional<Rect> PointFieldGeometry::GetCoverage (
131135 const Matrix& transform) const {
132- if (points_. size () > 0 ) {
136+ if (point_count_ > 0 ) {
133137 // Doesn't use MakePointBounds as this isn't resilient to points that
134138 // all lie along the same axis.
135- auto first = points_.begin ();
136- auto last = points_.end ();
137- auto left = first->x ;
138- auto top = first->y ;
139- auto right = first->x ;
140- auto bottom = first->y ;
141- for (auto it = first + 1 ; it < last; ++it) {
142- left = std::min (left, it->x );
143- top = std::min (top, it->y );
144- right = std::max (right, it->x );
145- bottom = std::max (bottom, it->y );
139+ Scalar left = points_[0 ].x ;
140+ Scalar top = points_[0 ].y ;
141+ Scalar right = points_[0 ].x ;
142+ Scalar bottom = points_[0 ].y ;
143+ for (auto i = 1u ; i < point_count_; i++) {
144+ const Point point = points_[i];
145+ left = std::min (left, point.x );
146+ top = std::min (top, point.y );
147+ right = std::max (right, point.x );
148+ bottom = std::max (bottom, point.y );
146149 }
147- auto coverage = Rect::MakeLTRB (left - radius_, top - radius_,
150+ Rect coverage = Rect::MakeLTRB (left - radius_, top - radius_,
148151 right + radius_, bottom + radius_);
149152 return coverage.TransformBounds (transform);
150153 }
0 commit comments