5#ifndef FLUTTER_IMPELLER_TESSELLATOR_TESSELLATOR_H_
6#define FLUTTER_IMPELLER_TESSELLATOR_TESSELLATOR_H_
53 size_t inline size()
const {
return trigs_.size(); }
54 std::vector<Trig>::iterator
inline begin()
const {
return trigs_.begin(); }
55 std::vector<Trig>::iterator
inline end()
const {
return trigs_.end(); }
58 size_t inline GetSteps()
const {
return trigs_.size() - 1u; }
63 explicit Trigs(std::vector<Trig>& trigs,
size_t divisions) : trigs_(trigs) {
69 explicit Trigs(
size_t divisions)
70 : local_storage_(
std::make_unique<
std::vector<
Trig>>()),
71 trigs_(*local_storage_) {
78 std::unique_ptr<std::vector<Trig>> local_storage_;
82 std::vector<Trig>& trigs_;
86 void init(
size_t divisions);
149 return trigs_.
size() * vertices_per_trig_;
154 impl_(trigs_, data_, proc);
165 const Point reference_centers[2];
173 typedef void GeneratorProc(
const Trigs& trigs,
177 GeneratorProc& impl_;
180 const size_t vertices_per_trig_;
185 size_t vertices_per_trig,
204 const Rect& oval_bounds,
206 bool supports_triangle_fans);
211 const Rect& oval_bounds,
214 std::unique_ptr<Trigs> round_cap_trigs);
221 const Rect oval_bounds_;
224 const bool use_center_;
225 const bool supports_triangle_fans_;
230 const std::unique_ptr<Trigs> round_cap_trigs_;
234 const Rect& oval_bounds,
236 bool supports_triangle_fans,
239 std::unique_ptr<Trigs> round_cap_trigs);
242 explicit Tessellator(
bool supports_32bit_primitive_indices =
true);
262 bool supports_primitive_restart =
false,
263 bool supports_triangle_fan =
false);
270 std::vector<Point>& point_buffer,
271 std::vector<uint16_t>& index_buffer,
326 bool supports_triangle_fans);
395 class ConvexTessellator {
397 virtual ~ConvexTessellator() =
default;
402 bool supports_primitive_restart,
403 bool supports_triangle_fan) = 0;
405 template <
typename IndexT>
409 std::unique_ptr<ConvexTessellator> convex_tessellator_;
412 std::vector<Point> stroke_points_;
417 static constexpr size_t kCachedTrigCount = 300;
418 std::vector<Trig> precomputed_trigs_[kCachedTrigCount];
420 Trigs GetTrigsForDivisions(
size_t divisions);
422 static void GenerateFilledCircle(
const Trigs& trigs,
423 const EllipticalVertexGenerator::Data&
data,
426 static void GenerateStrokedCircle(
const Trigs& trigs,
427 const EllipticalVertexGenerator::Data&
data,
430 static void GenerateFilledArcFan(
const Trigs& trigs,
432 const Rect& oval_bounds,
436 static void GenerateFilledArcStrip(
const Trigs& trigs,
438 const Rect& oval_bounds,
442 static void GenerateStrokedArc(
const Trigs& trigs,
444 const Rect& oval_bounds,
447 const std::unique_ptr<Trigs>& round_cap_trigs,
450 static void GenerateRoundCapLine(
const Trigs& trigs,
451 const EllipticalVertexGenerator::Data&
data,
454 static void GenerateFilledEllipse(
const Trigs& trigs,
455 const EllipticalVertexGenerator::Data&
data,
458 static void GenerateFilledRoundRect(
460 const EllipticalVertexGenerator::Data&
data,
477 static void GenerateStartRoundCap(
const Point& p,
495 static void GenerateEndRoundCap(
const Point& p,
The |VertexGenerator| implementation common to all shapes that are based on a polygonal representatio...
static ArcVertexGenerator MakeStroked(const Arc::Iteration &iteration, Trigs &&trigs, const Rect &oval_bounds, Scalar half_width, Cap cap, std::unique_ptr< Trigs > round_cap_trigs)
size_t GetVertexCount() const override
|VertexGenerator|
PrimitiveType GetTriangleType() const override
|VertexGenerator|
static ArcVertexGenerator MakeFilled(const Arc::Iteration &iteration, Trigs &&trigs, const Rect &oval_bounds, bool use_center, bool supports_triangle_fans)
void GenerateVertices(const TessellatedVertexProc &proc) const override
|VertexGenerator|
The |VertexGenerator| implementation common to all shapes that are based on a polygonal representatio...
PrimitiveType GetTriangleType() const override
|VertexGenerator|
size_t GetVertexCount() const override
|VertexGenerator|
void GenerateVertices(const TessellatedVertexProc &proc) const override
|VertexGenerator|
const Trig & operator[](size_t index) const
std::vector< Trig >::iterator begin() const
std::vector< Trig >::iterator end() const
An object which produces a list of vertices as |Point|s that tessellate a previously provided shape a...
virtual size_t GetVertexCount() const =0
Returns the number of vertices that the generator plans to produce, if known.
virtual PrimitiveType GetTriangleType() const =0
Returns the |PrimitiveType| that describes the relationship among the list of vertices produced by th...
virtual void GenerateVertices(const TessellatedVertexProc &proc) const =0
Generate the vertices and deliver them in the necessary order (as required by the PrimitiveType) to t...
A utility that generates triangles of the specified fill type given a polyline. This happens on the C...
Trigs GetTrigsForDeviceRadius(Scalar pixel_radius)
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 radi...
std::vector< Point > & GetStrokePointCache()
Retrieve a pre-allocated arena of kPointArenaSize points.
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 ...
static constexpr Scalar kCircleTolerance
The pixel tolerance used by the algorighm to determine how many divisions to create for a circle.
VertexBuffer TessellateConvex(const PathSource &path, HostBuffer &data_host_buffer, HostBuffer &indexes_host_buffer, Scalar tolerance, bool supports_primitive_restart=false, bool supports_triangle_fan=false)
Given a convex path, create a triangle fan structure.
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 t...
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 ova...
static void TessellateConvexInternal(const PathSource &path, std::vector< Point > &point_buffer, std::vector< uint16_t > &index_buffer, Scalar tolerance)
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 hal...
friend class ConvexTessellatorImpl
EllipticalVertexGenerator FilledEllipse(const Matrix &view_transform, const Rect &bounds)
Create a |VertexGenerator| that can produce vertices for a filled ellipse inscribed within the given ...
std::function< void(const Point &p)> TessellatedVertexProc
A callback function for a |VertexGenerator| to deliver the vertices it computes as |Point| objects.
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 ova...
#define FML_DCHECK(condition)
PrimitiveType
Decides how backend draws pixels based on input vertices.
Cap
An enum that describes ways to decorate the end of a path contour.
static constexpr size_t kPointArenaSize
The size of the point arena buffer stored on the tessellator.
A 4x4 matrix using column-major storage.
A structure to store the sine and cosine of an angle.
std::shared_ptr< const fml::Mapping > data