Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
impeller::PointFieldGeometry Class Referencefinal

#include <point_field_geometry.h>

Inheritance diagram for impeller::PointFieldGeometry:
impeller::Geometry

Public Member Functions

 PointFieldGeometry (std::vector< Point > points, Scalar radius, bool round)
 
 ~PointFieldGeometry ()=default
 
- Public Member Functions inherited from impeller::Geometry
virtual GeometryResult::Mode GetResultMode () const
 
virtual bool CoversArea (const Matrix &transform, const Rect &rect) const
 Determines if this geometry, transformed by the given transform, will completely cover all surface area of the given rect.
 
virtual bool IsAxisAlignedRect () const
 
virtual bool CanApplyMaskFilter () const
 

Private Member Functions

GeometryResult GetPositionBuffer (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
 
std::optional< RectGetCoverage (const Matrix &transform) const override
 

Additional Inherited Members

- Static Public Member Functions inherited from impeller::Geometry
static std::shared_ptr< GeometryMakeFillPath (const Path &path, std::optional< Rect > inner_rect=std::nullopt)
 
static std::shared_ptr< GeometryMakeStrokePath (const Path &path, Scalar stroke_width=0.0, Scalar miter_limit=4.0, Cap stroke_cap=Cap::kButt, Join stroke_join=Join::kMiter)
 
static std::shared_ptr< GeometryMakeCover ()
 
static std::shared_ptr< GeometryMakeRect (const Rect &rect)
 
static std::shared_ptr< GeometryMakeOval (const Rect &rect)
 
static std::shared_ptr< GeometryMakeLine (const Point &p0, const Point &p1, Scalar width, Cap cap)
 
static std::shared_ptr< GeometryMakeCircle (const Point &center, Scalar radius)
 
static std::shared_ptr< GeometryMakeStrokedCircle (const Point &center, Scalar radius, Scalar stroke_width)
 
static std::shared_ptr< GeometryMakeRoundRect (const Rect &rect, const Size &radii)
 
static std::shared_ptr< GeometryMakePointField (std::vector< Point > points, Scalar radius, bool round)
 
- Static Protected Member Functions inherited from impeller::Geometry
static GeometryResult ComputePositionGeometry (const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
 

Detailed Description

Definition at line 12 of file point_field_geometry.h.

Constructor & Destructor Documentation

◆ PointFieldGeometry()

impeller::PointFieldGeometry::PointFieldGeometry ( std::vector< Point points,
Scalar  radius,
bool  round 
)

Definition at line 13 of file point_field_geometry.cc.

16 : points_(std::move(points)), radius_(radius), round_(round) {}
static void round(SkPoint *p)
static const int points[]

◆ ~PointFieldGeometry()

impeller::PointFieldGeometry::~PointFieldGeometry ( )
default

Member Function Documentation

◆ GetCoverage()

std::optional< Rect > impeller::PointFieldGeometry::GetCoverage ( const Matrix transform) const
overrideprivatevirtual

Implements impeller::Geometry.

Definition at line 87 of file point_field_geometry.cc.

88 {
89 if (points_.size() > 0) {
90 // Doesn't use MakePointBounds as this isn't resilient to points that
91 // all lie along the same axis.
92 auto first = points_.begin();
93 auto last = points_.end();
94 auto left = first->x;
95 auto top = first->y;
96 auto right = first->x;
97 auto bottom = first->y;
98 for (auto it = first + 1; it < last; ++it) {
99 left = std::min(left, it->x);
100 top = std::min(top, it->y);
101 right = std::max(right, it->x);
102 bottom = std::max(bottom, it->y);
103 }
104 auto coverage = Rect::MakeLTRB(left - radius_, top - radius_,
105 right + radius_, bottom + radius_);
106 return coverage.TransformBounds(transform);
107 }
108 return std::nullopt;
109}
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129

◆ GetPositionBuffer()

GeometryResult impeller::PointFieldGeometry::GetPositionBuffer ( const ContentContext renderer,
const Entity entity,
RenderPass pass 
) const
overrideprivatevirtual

Implements impeller::Geometry.

Definition at line 18 of file point_field_geometry.cc.

21 {
22 if (radius_ < 0.0) {
23 return {};
24 }
25 Matrix transform = entity.GetTransform();
26 Scalar determinant = transform.GetDeterminant();
27 if (determinant == 0) {
28 return {};
29 }
30
31 Scalar min_size = 1.0f / sqrt(std::abs(determinant));
32 Scalar radius = std::max(radius_, min_size);
33
34 HostBuffer& host_buffer = renderer.GetTransientsBuffer();
35 VertexBufferBuilder<SolidFillVertexShader::PerVertexData> vtx_builder;
36
37 if (round_) {
38 // Get triangulation relative to {0, 0} so we can translate it to each
39 // point in turn.
40 auto generator =
41 renderer.GetTessellator()->FilledCircle(transform, {}, radius);
42 FML_DCHECK(generator.GetTriangleType() == PrimitiveType::kTriangleStrip);
43 std::vector<Point> circle_vertices;
44 circle_vertices.reserve(generator.GetVertexCount());
45 generator.GenerateVertices([&circle_vertices](const Point& p) { //
46 circle_vertices.push_back(p);
47 });
48 FML_DCHECK(circle_vertices.size() == generator.GetVertexCount());
49
50 vtx_builder.Reserve((circle_vertices.size() + 2) * points_.size() - 2);
51 for (auto& center : points_) {
52 if (vtx_builder.HasVertices()) {
53 vtx_builder.AppendVertex(vtx_builder.Last());
54 vtx_builder.AppendVertex({center + circle_vertices[0]});
55 }
56
57 for (auto& vertex : circle_vertices) {
58 vtx_builder.AppendVertex({center + vertex});
59 }
60 }
61 } else {
62 vtx_builder.Reserve(6 * points_.size() - 2);
63 for (auto& point : points_) {
64 auto first = Point(point.x - radius, point.y - radius);
65
66 if (vtx_builder.HasVertices()) {
67 vtx_builder.AppendVertex(vtx_builder.Last());
68 vtx_builder.AppendVertex({first});
69 }
70
71 // Z pattern from UL -> UR -> LL -> LR
72 vtx_builder.AppendVertex({first});
73 vtx_builder.AppendVertex({{point.x + radius, point.y - radius}});
74 vtx_builder.AppendVertex({{point.x - radius, point.y + radius}});
75 vtx_builder.AppendVertex({{point.x + radius, point.y + radius}});
76 }
77 }
78
79 return GeometryResult{
81 .vertex_buffer = vtx_builder.CreateVertexBuffer(host_buffer),
82 .transform = entity.GetShaderTransform(pass),
83 };
84}
static SkScalar center(float pos0, float pos1)
#define FML_DCHECK(condition)
Definition logging.h:103
float Scalar
Definition scalar.h:18
TPoint< Scalar > Point
Definition point.h:316
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
Definition SkVx.h:706

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