A utility that generates triangles of the specified fill type given a polyline. This happens on the CPU. More...
#include <tessellator.h>
Classes | |
class | ArcVertexGenerator |
The |VertexGenerator| implementation common to all shapes that are based on a polygonal representation of an ellipse. More... | |
class | EllipticalVertexGenerator |
The |VertexGenerator| implementation common to all shapes that are based on a polygonal representation of an ellipse. More... | |
class | Trigs |
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. More... | |
Public Member Functions | |
Tessellator () | |
virtual | ~Tessellator () |
VertexBuffer | TessellateConvex (const PathSource &path, HostBuffer &host_buffer, Scalar tolerance, bool supports_primitive_restart=false, bool supports_triangle_fan=false) |
Given a convex path, create a triangle fan structure. More... | |
EllipticalVertexGenerator | FilledCircle (const Matrix &view_transform, const Point ¢er, 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. More... | |
EllipticalVertexGenerator | StrokedCircle (const Matrix &view_transform, const Point ¢er, 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). More... | |
ArcVertexGenerator | FilledArc (const Matrix &view_transform, const Arc &arc, bool supports_triangle_fans) |
Create a |VertexGenerator| that can produce vertices for a stroked arc inscribed within the given oval_bounds with the given stroke half_width with enough polygon sub-divisions to provide reasonable fidelity when viewed under the given view transform. The outer edge of the stroked arc is generated at (radius + half_width) and the inner edge is generated at (radius - half_width). More... | |
ArcVertexGenerator | StrokedArc (const Matrix &view_transform, const Arc &arc, Cap cap, Scalar half_width) |
Create a |VertexGenerator| that can produce vertices for a stroked arc inscribed within the given oval_bounds with the given stroke half_width with enough polygon sub-divisions to provide reasonable fidelity when viewed under the given view transform. The outer edge of the stroked arc is generated at (radius + half_width) and the inner edge is generated at (radius - half_width). More... | |
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. More... | |
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. More... | |
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. More... | |
std::vector< Point > & | GetStrokePointCache () |
Retrieve a pre-allocated arena of kPointArenaSize points. More... | |
Trigs | GetTrigsForDeviceRadius (Scalar pixel_radius) |
Static Public Member Functions | |
static void | TessellateConvexInternal (const PathSource &path, std::vector< Point > &point_buffer, std::vector< uint16_t > &index_buffer, Scalar tolerance) |
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. More... | |
Protected Attributes | |
std::unique_ptr< std::vector< Point > > | point_buffer_ |
Used for polyline generation. More... | |
std::unique_ptr< std::vector< uint16_t > > | index_buffer_ |
std::vector< Point > | stroke_points_ |
Used for stroke path generation. More... | |
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 37 of file tessellator.h.
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 97 of file tessellator.h.
|
strong |
Enumerator | |
---|---|
kSuccess | |
kInputError | |
kTessellationError |
Definition at line 89 of file tessellator.h.
impeller::Tessellator::Tessellator | ( | ) |
Definition at line 296 of file tessellator.cc.
References index_buffer_, and point_buffer_.
|
virtualdefault |
ArcVertexGenerator impeller::Tessellator::FilledArc | ( | const Matrix & | view_transform, |
const Arc & | arc, | ||
bool | supports_triangle_fans | ||
) |
Create a |VertexGenerator| that can produce vertices for a stroked arc inscribed within the given oval_bounds with the given stroke half_width with enough polygon sub-divisions to provide reasonable fidelity when viewed under the given view transform. The outer edge of the stroked arc 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 oval bounds.
Definition at line 556 of file tessellator.cc.
References impeller::Arc::ComputeIterations(), impeller::Matrix::GetMaxBasisLengthXY(), impeller::Arc::GetOvalBounds(), impeller::Arc::GetOvalSize(), impeller::Arc::IncludeCenter(), and impeller::TSize< T >::MaxDimension().
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 452 of file tessellator.cc.
References impeller::Matrix::GetMaxBasisLengthXY().
Referenced by FilledEllipse(), and RoundCapLine().
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 606 of file tessellator.cc.
References FilledCircle(), impeller::TRect< T >::GetCenter(), impeller::Matrix::GetMaxBasisLengthXY(), impeller::TRect< T >::GetSize(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::IsSquare(), and impeller::kTriangleStrip.
Referenced by 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 627 of file tessellator.cc.
References FilledEllipse(), impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetLeftTop(), impeller::Matrix::GetMaxBasisLengthXY(), impeller::TRect< T >::GetRightBottom(), impeller::TRect< T >::GetWidth(), impeller::TSize< T >::height, impeller::kTriangleStrip, impeller::TSize< T >::MaxDimension(), and impeller::TSize< T >::width.
std::vector< Point > & impeller::Tessellator::GetStrokePointCache | ( | ) |
Retrieve a pre-allocated arena of kPointArenaSize points.
Definition at line 306 of file tessellator.cc.
References stroke_points_.
Tessellator::Trigs impeller::Tessellator::GetTrigsForDeviceRadius | ( | Scalar | pixel_radius | ) |
Return a vector of Trig (cos, sin pairs) structs for a 90 degree circle quadrant of the specified pixel radius
Definition at line 310 of file tessellator.cc.
Referenced by impeller::ArcStrokeGeometry::Dispatch(), impeller::StrokeRectGeometry::GetPositionBuffer(), impeller::StrokePathSegmentReceiver::RecordArc(), and impeller::testing::TEST().
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 583 of file tessellator.cc.
References FilledCircle(), impeller::TPoint< T >::GetLength(), impeller::Matrix::GetMaxBasisLengthXY(), impeller::kEhCloseEnough, and impeller::kTriangleStrip.
ArcVertexGenerator impeller::Tessellator::StrokedArc | ( | const Matrix & | view_transform, |
const Arc & | arc, | ||
Cap | cap, | ||
Scalar | half_width | ||
) |
Create a |VertexGenerator| that can produce vertices for a stroked arc inscribed within the given oval_bounds with the given stroke half_width with enough polygon sub-divisions to provide reasonable fidelity when viewed under the given view transform. The outer edge of the stroked arc is generated at (radius + half_width) and the inner edge is generated at (radius - half_width).
Note that the arc may not include the center and its bounds must be a perfect circle (width == height)
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 oval bounds.
Definition at line 567 of file tessellator.cc.
References impeller::Arc::ComputeIterations(), impeller::Matrix::GetMaxBasisLengthXY(), impeller::Arc::GetOvalBounds(), impeller::Arc::GetOvalSize(), impeller::Arc::IncludeCenter(), impeller::Arc::IsPerfectCircle(), and impeller::TSize< T >::MaxDimension().
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 468 of file tessellator.cc.
References impeller::Matrix::GetMaxBasisLengthXY().
VertexBuffer impeller::Tessellator::TessellateConvex | ( | const PathSource & | path, |
HostBuffer & | host_buffer, | ||
Scalar | tolerance, | ||
bool | supports_primitive_restart = false , |
||
bool | supports_triangle_fan = false |
||
) |
Given a convex path, create a triangle fan structure.
[in] | path | The path to tessellate. |
[in] | host_buffer | The host buffer for allocation of vertices/index data. |
[in] | tolerance | The tolerance value for conversion of the path to a polyline. This value is often derived from the Matrix::GetMaxBasisLengthXY of the CTM applied to the path for rendering. |
Definition at line 314 of file tessellator.cc.
References impeller::PathTessellator::CountFillStorage(), impeller::HostBuffer::Emplace(), impeller::DeviceBuffer::Flush(), impeller::BufferView::GetBuffer(), impeller::BufferView::GetRange(), index_buffer_, impeller::k16bit, impeller::Range::offset, impeller::DeviceBuffer::OnGetContents(), impeller::PathTessellator::PathToFilledVertices(), point_buffer_, TessellateConvexInternal(), and impeller::VertexBuffer::vertex_buffer.
|
static |
Visible for testing.
This method only exists for the ease of benchmarking without using the real allocator needed by the [host_buffer].
Definition at line 399 of file tessellator.cc.
References impeller::PathTessellator::PathToFilledVertices().
Referenced by impeller::BM_Convex(), TessellateConvex(), and impeller::testing::TEST().
|
protected |
Definition at line 380 of file tessellator.h.
Referenced by TessellateConvex(), and Tessellator().
|
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 263 of file tessellator.h.
Referenced by impeller::testing::TEST().
|
protected |
Used for polyline generation.
Definition at line 379 of file tessellator.h.
Referenced by TessellateConvex(), and Tessellator().
|
protected |
Used for stroke path generation.
Definition at line 382 of file tessellator.h.
Referenced by GetStrokePointCache().