Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
impeller::Tessellator Class Reference

A utility that generates triangles of the specified fill type given a polyline. This happens on the CPU. More...

#include <tessellator.h>

Inheritance diagram for impeller::Tessellator:
impeller::TessellatorLibtess

Classes

class  EllipticalVertexGenerator
 The |VertexGenerator| implementation common to all shapes that are based on a polygonal representation of an ellipse. More...
 
class  VertexGenerator
 An object which produces a list of vertices as |Point|s that tessellate a previously provided shape and delivers the vertices through a |TessellatedVertexProc| callback. More...
 

Public Types

enum class  Result { kSuccess , kInputError , kTessellationError }
 
using TessellatedVertexProc = std::function< void(const Point &p)>
 A callback function for a |VertexGenerator| to deliver the vertices it computes as |Point| objects.
 

Public Member Functions

 Tessellator ()
 
virtual ~Tessellator ()
 
std::vector< PointTessellateConvex (const Path &path, Scalar tolerance)
 Given a convex path, create a triangle fan structure.
 
Path::Polyline CreateTempPolyline (const Path &path, Scalar tolerance)
 Create a temporary polyline. Only one per-process can exist at a time.
 
EllipticalVertexGenerator FilledCircle (const Matrix &view_transform, const Point &center, Scalar radius)
 Create a |VertexGenerator| that can produce vertices for a filled circle of the given radius around the given center with enough polygon sub-divisions to provide reasonable fidelity when viewed under the given view transform.
 
EllipticalVertexGenerator StrokedCircle (const Matrix &view_transform, const Point &center, Scalar radius, Scalar half_width)
 Create a |VertexGenerator| that can produce vertices for a stroked circle of the given radius and half_width around the given shared center with enough polygon sub-divisions to provide reasonable fidelity when viewed under the given view transform. The outer edge of the stroked circle is generated at (radius + half_width) and the inner edge is generated at (radius - half_width).
 
EllipticalVertexGenerator RoundCapLine (const Matrix &view_transform, const Point &p0, const Point &p1, Scalar radius)
 Create a |VertexGenerator| that can produce vertices for a line with round end caps of the given radius with enough polygon sub-divisions to provide reasonable fidelity when viewed under the given view transform.
 
EllipticalVertexGenerator FilledEllipse (const Matrix &view_transform, const Rect &bounds)
 Create a |VertexGenerator| that can produce vertices for a filled ellipse inscribed within the given bounds with enough polygon sub-divisions to provide reasonable fidelity when viewed under the given view transform.
 
EllipticalVertexGenerator FilledRoundRect (const Matrix &view_transform, const Rect &bounds, const Size &radii)
 Create a |VertexGenerator| that can produce vertices for a filled round rect within the given bounds and corner radii with enough polygon sub-divisions to provide reasonable fidelity when viewed under the given view transform.
 

Static Public Attributes

static constexpr Scalar kCircleTolerance = 0.1f
 The pixel tolerance used by the algorighm to determine how many divisions to create for a circle.
 

Protected Attributes

std::unique_ptr< std::vector< Point > > point_buffer_
 Used for polyline generation.
 

Detailed Description

A utility that generates triangles of the specified fill type given a polyline. This happens on the CPU.

Also contains functionality for optimized generation of circles and ellipses.

This object is not thread safe, and its methods must not be called from multiple threads.

Definition at line 29 of file tessellator.h.

Member Typedef Documentation

◆ TessellatedVertexProc

using impeller::Tessellator::TessellatedVertexProc = std::function<void(const Point& p)>

A callback function for a |VertexGenerator| to deliver the vertices it computes as |Point| objects.

Definition at line 76 of file tessellator.h.

Member Enumeration Documentation

◆ Result

enum class impeller::Tessellator::Result
strong
Enumerator
kSuccess 
kInputError 
kTessellationError 

Definition at line 68 of file tessellator.h.

Constructor & Destructor Documentation

◆ Tessellator()

impeller::Tessellator::Tessellator ( )

Definition at line 9 of file tessellator.cc.

10 : point_buffer_(std::make_unique<std::vector<Point>>()) {
11 point_buffer_->reserve(2048);
12}
std::unique_ptr< std::vector< Point > > point_buffer_
Used for polyline generation.

◆ ~Tessellator()

impeller::Tessellator::~Tessellator ( )
virtualdefault

Member Function Documentation

◆ CreateTempPolyline()

Path::Polyline impeller::Tessellator::CreateTempPolyline ( const Path path,
Scalar  tolerance 
)

Create a temporary polyline. Only one per-process can exist at a time.

The tessellator itself is not a thread safe class and should only be used from the raster thread.

Definition at line 16 of file tessellator.cc.

17 {
19 point_buffer_->clear();
20 auto polyline =
21 path.CreatePolyline(tolerance, std::move(point_buffer_),
22 [this](Path::Polyline::PointBufferPtr point_buffer) {
23 point_buffer_ = std::move(point_buffer);
24 });
25 return polyline;
26}
#define FML_DCHECK(condition)
Definition logging.h:103
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
const Path::Polyline & polyline
std::unique_ptr< std::vector< Point > > PointBufferPtr
Definition path.h:97

◆ FilledCircle()

EllipticalVertexGenerator impeller::Tessellator::FilledCircle ( const Matrix view_transform,
const Point center,
Scalar  radius 
)

Create a |VertexGenerator| that can produce vertices for a filled circle of the given radius around the given center with enough polygon sub-divisions to provide reasonable fidelity when viewed under the given view transform.

Note that the view transform is only used to choose the number of sample points to use per quarter circle and the returned points are not transformed by it, instead they are relative to the coordinate space of the center point.

Definition at line 254 of file tessellator.cc.

257 {
258 auto divisions =
259 ComputeQuadrantDivisions(view_transform.GetMaxBasisLength() * radius);
260 return EllipticalVertexGenerator(Tessellator::GenerateFilledCircle,
261 GetTrigsForDivisions(divisions),
263 {
264 .reference_centers = {center, center},
265 .radii = {radius, radius},
266 .half_width = -1.0f,
267 });
268}
static SkScalar center(float pos0, float pos1)
static size_t ComputeQuadrantDivisions(Scalar pixel_radius)
Tessellator::EllipticalVertexGenerator EllipticalVertexGenerator

◆ FilledEllipse()

EllipticalVertexGenerator impeller::Tessellator::FilledEllipse ( const Matrix view_transform,
const Rect bounds 
)

Create a |VertexGenerator| that can produce vertices for a filled ellipse inscribed within the given bounds with enough polygon sub-divisions to provide reasonable fidelity when viewed under the given view transform.

Note that the view transform is only used to choose the number of sample points to use per quarter circle and the returned points are not transformed by it, instead they are relative to the coordinate space of the bounds.

Definition at line 314 of file tessellator.cc.

316 {
317 if (bounds.IsSquare()) {
318 return FilledCircle(view_transform, bounds.GetCenter(),
319 bounds.GetWidth() * 0.5f);
320 }
321 auto max_radius = bounds.GetSize().MaxDimension();
322 auto divisions =
323 ComputeQuadrantDivisions(view_transform.GetMaxBasisLength() * max_radius);
324 auto center = bounds.GetCenter();
325 return EllipticalVertexGenerator(Tessellator::GenerateFilledEllipse,
326 GetTrigsForDivisions(divisions),
328 {
329 .reference_centers = {center, center},
330 .radii = bounds.GetSize() * 0.5f,
331 .half_width = -1.0f,
332 });
333}
EllipticalVertexGenerator FilledCircle(const Matrix &view_transform, const Point &center, Scalar radius)
Create a |VertexGenerator| that can produce vertices for a filled circle of the given radius around t...
Optional< SkRect > bounds
Definition SkRecords.h:189

◆ FilledRoundRect()

EllipticalVertexGenerator impeller::Tessellator::FilledRoundRect ( const Matrix view_transform,
const Rect bounds,
const Size radii 
)

Create a |VertexGenerator| that can produce vertices for a filled round rect within the given bounds and corner radii with enough polygon sub-divisions to provide reasonable fidelity when viewed under the given view transform.

Note that the view transform is only used to choose the number of sample points to use per quarter circle and the returned points are not transformed by it, instead they are relative to the coordinate space of the bounds.

Definition at line 335 of file tessellator.cc.

338 {
339 if (radii.width * 2 < bounds.GetWidth() ||
340 radii.height * 2 < bounds.GetHeight()) {
341 auto max_radius = radii.MaxDimension();
342 auto divisions = ComputeQuadrantDivisions(
343 view_transform.GetMaxBasisLength() * max_radius);
344 auto upper_left = bounds.GetLeftTop() + radii;
345 auto lower_right = bounds.GetRightBottom() - radii;
346 return EllipticalVertexGenerator(Tessellator::GenerateFilledRoundRect,
347 GetTrigsForDivisions(divisions),
349 {
350 .reference_centers =
351 {
352 upper_left,
353 lower_right,
354 },
355 .radii = radii,
356 .half_width = -1.0f,
357 });
358 } else {
359 return FilledEllipse(view_transform, bounds);
360 }
361}
EllipticalVertexGenerator FilledEllipse(const Matrix &view_transform, const Rect &bounds)
Create a |VertexGenerator| that can produce vertices for a filled ellipse inscribed within the given ...

◆ RoundCapLine()

EllipticalVertexGenerator impeller::Tessellator::RoundCapLine ( const Matrix view_transform,
const Point p0,
const Point p1,
Scalar  radius 
)

Create a |VertexGenerator| that can produce vertices for a line with round end caps of the given radius with enough polygon sub-divisions to provide reasonable fidelity when viewed under the given view transform.

Note that the view transform is only used to choose the number of sample points to use per quarter circle and the returned points are not transformed by it, instead they are relative to the coordinate space of the two points.

Definition at line 291 of file tessellator.cc.

295 {
296 auto along = p1 - p0;
297 auto length = along.GetLength();
298 if (length > kEhCloseEnough) {
299 auto divisions =
300 ComputeQuadrantDivisions(view_transform.GetMaxBasisLength() * radius);
301 return EllipticalVertexGenerator(Tessellator::GenerateRoundCapLine,
302 GetTrigsForDivisions(divisions),
304 {
305 .reference_centers = {p0, p1},
306 .radii = {radius, radius},
307 .half_width = -1.0f,
308 });
309 } else {
310 return FilledCircle(view_transform, p0, radius);
311 }
312}
size_t length
constexpr float kEhCloseEnough
Definition constants.h:56

◆ StrokedCircle()

EllipticalVertexGenerator impeller::Tessellator::StrokedCircle ( const Matrix view_transform,
const Point center,
Scalar  radius,
Scalar  half_width 
)

Create a |VertexGenerator| that can produce vertices for a stroked circle of the given radius and half_width around the given shared center with enough polygon sub-divisions to provide reasonable fidelity when viewed under the given view transform. The outer edge of the stroked circle is generated at (radius + half_width) and the inner edge is generated at (radius - half_width).

Note that the view transform is only used to choose the number of sample points to use per quarter circle and the returned points are not transformed by it, instead they are relative to the coordinate space of the center point.

Definition at line 270 of file tessellator.cc.

274 {
275 if (half_width > 0) {
276 auto divisions = ComputeQuadrantDivisions(
277 view_transform.GetMaxBasisLength() * radius + half_width);
278 return EllipticalVertexGenerator(Tessellator::GenerateStrokedCircle,
279 GetTrigsForDivisions(divisions),
281 {
282 .reference_centers = {center, center},
283 .radii = {radius, radius},
284 .half_width = half_width,
285 });
286 } else {
287 return FilledCircle(view_transform, center, radius);
288 }
289}

◆ TessellateConvex()

std::vector< Point > impeller::Tessellator::TessellateConvex ( const Path path,
Scalar  tolerance 
)

Given a convex path, create a triangle fan structure.

Parameters
[in]pathThe path to tessellate.
[in]toleranceThe tolerance value for conversion of the path to a polyline. This value is often derived from the Matrix::GetMaxBasisLength of the CTM applied to the path for rendering.
Returns
A point vector containing the vertices in triangle strip format.

Definition at line 28 of file tessellator.cc.

29 {
31
32 std::vector<Point> output;
33 point_buffer_->clear();
34 auto polyline =
35 path.CreatePolyline(tolerance, std::move(point_buffer_),
36 [this](Path::Polyline::PointBufferPtr point_buffer) {
37 point_buffer_ = std::move(point_buffer);
38 });
39 if (polyline.points->size() == 0) {
40 return output;
41 }
42
43 output.reserve(polyline.points->size() +
44 (4 * (polyline.contours.size() - 1)));
45 bool previous_contour_odd_points = false;
46 for (auto j = 0u; j < polyline.contours.size(); j++) {
47 auto [start, end] = polyline.GetContourPointBounds(j);
48 auto first_point = polyline.GetPoint(start);
49
50 // Some polygons will not self close and an additional triangle
51 // must be inserted, others will self close and we need to avoid
52 // inserting an extra triangle.
53 if (polyline.GetPoint(end - 1) == first_point) {
54 end--;
55 }
56
57 if (j > 0) {
58 // Triangle strip break.
59 output.emplace_back(output.back());
60 output.emplace_back(first_point);
61 output.emplace_back(first_point);
62
63 // If the contour has an odd number of points, insert an extra point when
64 // bridging to the next contour to preserve the correct triangle winding
65 // order.
66 if (previous_contour_odd_points) {
67 output.emplace_back(first_point);
68 }
69 } else {
70 output.emplace_back(first_point);
71 }
72
73 size_t a = start + 1;
74 size_t b = end - 1;
75 while (a < b) {
76 output.emplace_back(polyline.GetPoint(a));
77 output.emplace_back(polyline.GetPoint(b));
78 a++;
79 b--;
80 }
81 if (a == b) {
82 previous_contour_odd_points = false;
83 output.emplace_back(polyline.GetPoint(a));
84 } else {
85 previous_contour_odd_points = true;
86 }
87 }
88 return output;
89}
static bool b
struct MyStruct a[10]
glong glong end

Member Data Documentation

◆ kCircleTolerance

constexpr Scalar impeller::Tessellator::kCircleTolerance = 0.1f
staticconstexpr

The pixel tolerance used by the algorighm to determine how many divisions to create for a circle.

No point on the polygon of vertices should deviate from the true circle by more than this tolerance.

Definition at line 198 of file tessellator.h.

◆ point_buffer_

std::unique_ptr<std::vector<Point> > impeller::Tessellator::point_buffer_
protected

Used for polyline generation.

Definition at line 271 of file tessellator.h.


The documentation for this class was generated from the following files: