Flutter Impeller
impeller::DlVerticesGeometry Class Referencefinal

A geometry that is created from a DlVertices object. More...

#include <dl_vertices_geometry.h>

Inheritance diagram for impeller::DlVerticesGeometry:
impeller::VerticesGeometry impeller::Geometry

Public Member Functions

 DlVerticesGeometry (const std::shared_ptr< const flutter::DlVertices > &vertices, const ContentContext &renderer)
 
 ~DlVerticesGeometry ()=default
 
GeometryResult GetPositionUVColorBuffer (Rect texture_coverage, Matrix effect_transform, const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
 
GeometryResult GetPositionBuffer (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
 
std::optional< RectGetCoverage (const Matrix &transform) const override
 
bool HasVertexColors () const override
 
bool HasTextureCoordinates () const override
 
bool CanApplyMaskFilter () const override
 
std::optional< RectGetTextureCoordinateCoverage () const override
 
- Public Member Functions inherited from impeller::Geometry
virtual ~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. More...
 
virtual bool IsAxisAlignedRect () const
 
virtual Scalar ComputeAlphaCoverage (const Matrix &transform) const
 

Additional Inherited Members

- Static Public Member Functions inherited from impeller::Geometry
static std::unique_ptr< GeometryMakeFillPath (const flutter::DlPath &path, std::optional< Rect > inner_rect=std::nullopt)
 
static std::unique_ptr< GeometryMakeStrokePath (const flutter::DlPath &path, const StrokeParameters &stroke={})
 
static std::unique_ptr< GeometryMakeCover ()
 
static std::unique_ptr< GeometryMakeRect (const Rect &rect)
 
static std::unique_ptr< GeometryMakeOval (const Rect &rect)
 
static std::unique_ptr< GeometryMakeLine (const Point &p0, const Point &p1, const StrokeParameters &stroke)
 
static std::unique_ptr< GeometryMakeCircle (const Point &center, Scalar radius)
 
static std::unique_ptr< GeometryMakeStrokedCircle (const Point &center, Scalar radius, Scalar stroke_width)
 
static std::unique_ptr< GeometryMakeFilledArc (const Rect &oval_bounds, Degrees start, Degrees sweep, bool include_center)
 
static std::unique_ptr< GeometryMakeStrokedArc (const Rect &oval_bounds, Degrees start, Degrees sweep, const StrokeParameters &stroke)
 
static std::unique_ptr< GeometryMakeRoundRect (const Rect &rect, const Size &radii)
 
static std::unique_ptr< GeometryMakeRoundSuperellipse (const Rect &rect, Scalar corner_radius)
 
static Scalar ComputeStrokeAlphaCoverage (const Matrix &entity, Scalar stroke_width)
 Compute an alpha value to simulate lower coverage of fractional pixel strokes. More...
 
static GeometryResult ComputePositionGeometry (const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
 

Detailed Description

A geometry that is created from a DlVertices object.

Definition at line 15 of file dl_vertices_geometry.h.

Constructor & Destructor Documentation

◆ DlVerticesGeometry()

impeller::DlVerticesGeometry::DlVerticesGeometry ( const std::shared_ptr< const flutter::DlVertices > &  vertices,
const ContentContext renderer 
)

Definition at line 60 of file dl_vertices_geometry.cc.

63  : vertices_(vertices) {
64  performed_normalization_ = MaybePerformIndexNormalization(renderer);
65  bounds_ = vertices_->GetBounds();
66 }

◆ ~DlVerticesGeometry()

impeller::DlVerticesGeometry::~DlVerticesGeometry ( )
default

Member Function Documentation

◆ CanApplyMaskFilter()

bool impeller::DlVerticesGeometry::CanApplyMaskFilter ( ) const
overridevirtual

Reimplemented from impeller::Geometry.

Definition at line 224 of file dl_vertices_geometry.cc.

224  {
225  return false;
226 }

◆ GetCoverage()

std::optional< Rect > impeller::DlVerticesGeometry::GetCoverage ( const Matrix transform) const
overridevirtual

Implements impeller::Geometry.

Definition at line 208 of file dl_vertices_geometry.cc.

209  {
210  return bounds_.TransformBounds(transform);
211 }
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:476

References transform, and impeller::TRect< T >::TransformBounds().

◆ GetPositionBuffer()

GeometryResult impeller::DlVerticesGeometry::GetPositionBuffer ( const ContentContext renderer,
const Entity entity,
RenderPass pass 
) const
overridevirtual

Implements impeller::Geometry.

Definition at line 115 of file dl_vertices_geometry.cc.

118  {
119  int vertex_count = vertices_->vertex_count();
120  BufferView vertex_buffer = renderer.GetTransientsBuffer().Emplace(
121  vertices_->vertex_data(), vertex_count * sizeof(Point), alignof(Point));
122 
123  BufferView index_buffer = {};
124  auto index_count =
125  performed_normalization_ ? indices_.size() : vertices_->index_count();
126  const uint16_t* indices_data =
127  performed_normalization_ ? indices_.data() : vertices_->indices();
128  if (index_count) {
129  index_buffer = renderer.GetTransientsBuffer().Emplace(
130  indices_data, index_count * sizeof(uint16_t), alignof(uint16_t));
131  }
132 
133  return GeometryResult{
134  .type = GetPrimitiveType(),
135  .vertex_buffer =
136  {
137  .vertex_buffer = vertex_buffer,
138  .index_buffer = index_buffer,
139  .vertex_count = index_count > 0 ? index_count : vertex_count,
140  .index_type =
141  index_count > 0 ? IndexType::k16bit : IndexType::kNone,
142  },
143  .transform = entity.GetShaderTransform(pass),
144  };
145 }
@ kNone
Does not use the index buffer.
TPoint< Scalar > Point
Definition: point.h:327

References impeller::HostBuffer::Emplace(), impeller::Entity::GetShaderTransform(), impeller::ContentContext::GetTransientsBuffer(), impeller::k16bit, impeller::kNone, and impeller::GeometryResult::type.

◆ GetPositionUVColorBuffer()

GeometryResult impeller::DlVerticesGeometry::GetPositionUVColorBuffer ( Rect  texture_coverage,
Matrix  effect_transform,
const ContentContext renderer,
const Entity entity,
RenderPass pass 
) const
overridevirtual

Implements impeller::VerticesGeometry.

Definition at line 147 of file dl_vertices_geometry.cc.

152  {
154 
155  int vertex_count = vertices_->vertex_count();
156  Matrix uv_transform =
157  texture_coverage.GetNormalizingTransform() * effect_transform;
158  bool has_texture_coordinates = HasTextureCoordinates();
159  bool has_colors = HasVertexColors();
160 
161  const Point* coordinates = has_texture_coordinates
162  ? vertices_->texture_coordinate_data()
163  : vertices_->vertex_data();
164  BufferView vertex_buffer = renderer.GetTransientsBuffer().Emplace(
165  vertex_count * sizeof(VS::PerVertexData), alignof(VS::PerVertexData),
166  [&](uint8_t* data) {
167  VS::PerVertexData* vtx_contents =
168  reinterpret_cast<VS::PerVertexData*>(data);
169  const Point* vertex_points = vertices_->vertex_data();
170  for (auto i = 0; i < vertex_count; i++) {
171  Point texture_coord = coordinates[i];
172  Point uv = uv_transform * texture_coord;
173  Color color = has_colors
174  ? skia_conversions::ToColor(vertices_->colors()[i])
175  .Premultiply()
177  VS::PerVertexData vertex_data = {.vertices = vertex_points[i],
178  .texture_coords = uv,
179  .color = color};
180  vtx_contents[i] = vertex_data;
181  }
182  });
183 
184  BufferView index_buffer = {};
185  auto index_count =
186  performed_normalization_ ? indices_.size() : vertices_->index_count();
187  const uint16_t* indices_data =
188  performed_normalization_ ? indices_.data() : vertices_->indices();
189  if (index_count) {
190  index_buffer = renderer.GetTransientsBuffer().Emplace(
191  indices_data, index_count * sizeof(uint16_t), alignof(uint16_t));
192  }
193 
194  return GeometryResult{
195  .type = GetPrimitiveType(),
196  .vertex_buffer =
197  {
198  .vertex_buffer = vertex_buffer,
199  .index_buffer = index_buffer,
200  .vertex_count = index_count > 0 ? index_count : vertex_count,
201  .index_type =
202  index_count > 0 ? IndexType::k16bit : IndexType::kNone,
203  },
204  .transform = entity.GetShaderTransform(pass),
205  };
206 }
bool HasTextureCoordinates() const override
bool HasVertexColors() const override
Color ToColor(const flutter::DlColor &color)
LinePipeline::VertexShader VS
static constexpr Color BlackTransparent()
Definition: color.h:270
constexpr Color Premultiply() const
Definition: color.h:212
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:68

References impeller::Color::BlackTransparent(), data, impeller::HostBuffer::Emplace(), impeller::TRect< T >::GetNormalizingTransform(), impeller::Entity::GetShaderTransform(), impeller::ContentContext::GetTransientsBuffer(), HasTextureCoordinates(), HasVertexColors(), impeller::k16bit, impeller::kNone, impeller::Color::Premultiply(), impeller::skia_conversions::ToColor(), and impeller::GeometryResult::type.

◆ GetTextureCoordinateCoverage()

std::optional< Rect > impeller::DlVerticesGeometry::GetTextureCoordinateCoverage ( ) const
overridevirtual

Implements impeller::VerticesGeometry.

Definition at line 91 of file dl_vertices_geometry.cc.

91  {
92  if (!HasTextureCoordinates()) {
93  return std::nullopt;
94  }
95  auto vertex_count = vertices_->vertex_count();
96  if (vertex_count == 0) {
97  return std::nullopt;
98  }
99 
100  auto first = vertices_->texture_coordinate_data();
101  auto left = first->x;
102  auto top = first->y;
103  auto right = first->x;
104  auto bottom = first->y;
105  int i = 1;
106  for (auto it = first + 1; i < vertex_count; ++it, i++) {
107  left = std::min(left, it->x);
108  top = std::min(top, it->y);
109  right = std::max(right, it->x);
110  bottom = std::max(bottom, it->y);
111  }
112  return Rect::MakeLTRB(left, top, right, bottom);
113 }
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129

References HasTextureCoordinates(), and impeller::TRect< Scalar >::MakeLTRB().

◆ HasTextureCoordinates()

bool impeller::DlVerticesGeometry::HasTextureCoordinates ( ) const
overridevirtual

Implements impeller::VerticesGeometry.

Definition at line 87 of file dl_vertices_geometry.cc.

87  {
88  return vertices_->texture_coordinate_data() != nullptr;
89 }

Referenced by GetPositionUVColorBuffer(), and GetTextureCoordinateCoverage().

◆ HasVertexColors()

bool impeller::DlVerticesGeometry::HasVertexColors ( ) const
overridevirtual

Implements impeller::VerticesGeometry.

Definition at line 83 of file dl_vertices_geometry.cc.

83  {
84  return vertices_->colors() != nullptr;
85 }

Referenced by GetPositionUVColorBuffer().


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