Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Attributes | List of all members
flutter::DlVertices::Builder Class Reference

A utility class to build up a |DlVertices| object one set of data at a time. More...

#include <dl_vertices.h>

Classes

union  Flags
 flags to indicate/promise which of the optional texture coordinates or colors will be supplied during the build phase. More...
 

Public Member Functions

 Builder (DlVertexMode mode, int vertex_count, Flags flags, int index_count)
 Constructs a Builder and prepares room for the required and optional data.
 
bool is_valid ()
 Returns true iff the underlying object was successfully allocated.
 
void store_vertices (const SkPoint points[])
 Copies the indicated list of points as vertices.
 
void store_vertices (const float coordinates[])
 Copies the indicated list of float pairs as vertices.
 
void store_texture_coordinates (const SkPoint points[])
 Copies the indicated list of points as texture coordinates.
 
void store_texture_coordinates (const float coordinates[])
 Copies the indicated list of float pairs as texture coordinates.
 
void store_colors (const DlColor colors[])
 Copies the indicated list of colors as vertex colors.
 
void store_colors (const uint32_t colors[])
 Copies the indicated list of unsigned ints as vertex colors in the 32-bit RGBA format.
 
void store_indices (const uint16_t indices[])
 Copies the indicated list of 16-bit indices as vertex indices.
 
std::shared_ptr< DlVerticesbuild ()
 Finalizes and the constructed DlVertices object.
 

Static Public Attributes

static constexpr Flags kNone = {{false, false}}
 
static constexpr Flags kHasTextureCoordinates = {{true, false}}
 
static constexpr Flags kHasColors = {{false, true}}
 

Detailed Description

A utility class to build up a |DlVertices| object one set of data at a time.

Definition at line 75 of file dl_vertices.h.

Constructor & Destructor Documentation

◆ Builder()

flutter::DlVertices::Builder::Builder ( DlVertexMode  mode,
int  vertex_count,
Flags  flags,
int  index_count 
)

Constructs a Builder and prepares room for the required and optional data.

Vertices are always required. Optional texture coordinates and optional colors are reserved depending on the |Flags|. Optional indices will be reserved if the index_count is positive (>0).

The caller must provide all data that is promised by the supplied |flags| and |index_count| parameters before calling the |build()| method.

Definition at line 202 of file dl_vertices.cc.

206 : needs_texture_coords_(flags.has_texture_coordinates),
207 needs_colors_(flags.has_colors),
208 needs_indices_(index_count > 0) {
209 vertex_count = std::max(vertex_count, 0);
210 index_count = std::max(index_count, 0);
211 void* storage =
212 ::operator new(bytes_needed(vertex_count, flags, index_count));
213 vertices_.reset(new (storage)
214 DlVertices(mode, vertex_count, flags, index_count),
216}
int vertex_count() const
DlVertexMode mode() const
int index_count() const
FlutterSemanticsFlag flags
static void DlVerticesDeleter(void *p)
static size_t bytes_needed(int vertex_count, Flags flags, int index_count)

Member Function Documentation

◆ build()

std::shared_ptr< DlVertices > flutter::DlVertices::Builder::build ( )

Finalizes and the constructed DlVertices object.

fails if any of the optional data promised in the constructor is missing.

Definition at line 279 of file dl_vertices.cc.

279 {
281 if (vertices_->vertex_count() <= 0) {
282 // We set this to true in the constructor to make sure that they
283 // call store_vertices() only once, but if there are no vertices
284 // then we will not object to them never having stored any vertices
285 needs_vertices_ = false;
286 }
287 FML_CHECK(!needs_vertices_);
288 FML_CHECK(!needs_texture_coords_);
289 FML_CHECK(!needs_colors_);
290 FML_CHECK(!needs_indices_);
291
292 vertices_->bounds_ =
293 compute_bounds(vertices_->vertices(), vertices_->vertex_count_);
294
295 return std::move(vertices_);
296}
bool is_valid()
Returns true iff the underlying object was successfully allocated.
#define FML_CHECK(condition)
Definition logging.h:85
static SkRect compute_bounds(const SkPoint *points, int count)

◆ is_valid()

bool flutter::DlVertices::Builder::is_valid ( )
inline

Returns true iff the underlying object was successfully allocated.

Definition at line 115 of file dl_vertices.h.

115{ return vertices_ != nullptr; }

◆ store_colors() [1/2]

void flutter::DlVertices::Builder::store_colors ( const DlColor  colors[])

Copies the indicated list of colors as vertex colors.

fails if colors have already been supplied or if they were not promised by the flags.has_colors.

Definition at line 261 of file dl_vertices.cc.

261 {
263 FML_CHECK(needs_colors_);
264 char* pod = reinterpret_cast<char*>(vertices_.get());
265 size_t bytes = vertices_->vertex_count_ * sizeof(colors[0]);
266 memcpy(pod + vertices_->colors_offset_, colors, bytes);
267 needs_colors_ = false;
268}
const DlColor * colors() const

◆ store_colors() [2/2]

void flutter::DlVertices::Builder::store_colors ( const uint32_t  colors[])
inline

Copies the indicated list of unsigned ints as vertex colors in the 32-bit RGBA format.

fails if colors have already been supplied or if they were not promised by the flags.has_colors.

Definition at line 150 of file dl_vertices.h.

150 {
151 store_colors(reinterpret_cast<const DlColor*>(colors));
152 }
void store_colors(const DlColor colors[])
Copies the indicated list of colors as vertex colors.

◆ store_indices()

void flutter::DlVertices::Builder::store_indices ( const uint16_t  indices[])

Copies the indicated list of 16-bit indices as vertex indices.

fails if indices have already been supplied or if they were not promised by (index_count > 0).

Definition at line 270 of file dl_vertices.cc.

270 {
272 FML_CHECK(needs_indices_);
273 char* pod = reinterpret_cast<char*>(vertices_.get());
274 size_t bytes = vertices_->index_count_ * sizeof(indices[0]);
275 memcpy(pod + vertices_->indices_offset_, indices, bytes);
276 needs_indices_ = false;
277}
const uint16_t * indices() const

◆ store_texture_coordinates() [1/2]

void flutter::DlVertices::Builder::store_texture_coordinates ( const float  coordinates[])

Copies the indicated list of float pairs as texture coordinates.

fails if texture coordinates have already been supplied or if they were not promised by the flags.has_texture_coordinates.

Definition at line 252 of file dl_vertices.cc.

252 {
254 FML_CHECK(needs_texture_coords_);
255 char* pod = reinterpret_cast<char*>(vertices_.get());
256 store_points(pod, vertices_->texture_coordinates_offset_, coords,
257 vertices_->vertex_count_);
258 needs_texture_coords_ = false;
259}
static void store_points(char *dst, int offset, const float *src, int count)

◆ store_texture_coordinates() [2/2]

void flutter::DlVertices::Builder::store_texture_coordinates ( const SkPoint  points[])

Copies the indicated list of points as texture coordinates.

fails if texture coordinates have already been supplied or if they were not promised by the flags.has_texture_coordinates.

Definition at line 243 of file dl_vertices.cc.

243 {
245 FML_CHECK(needs_texture_coords_);
246 char* pod = reinterpret_cast<char*>(vertices_.get());
247 size_t bytes = vertices_->vertex_count_ * sizeof(coords[0]);
248 memcpy(pod + vertices_->texture_coordinates_offset_, coords, bytes);
249 needs_texture_coords_ = false;
250}

◆ store_vertices() [1/2]

void flutter::DlVertices::Builder::store_vertices ( const float  coordinates[])

Copies the indicated list of float pairs as vertices.

fails if vertices have already been supplied.

Definition at line 234 of file dl_vertices.cc.

234 {
236 FML_CHECK(needs_vertices_);
237 char* pod = reinterpret_cast<char*>(vertices_.get());
238 store_points(pod, vertices_->vertices_offset_, vertices,
239 vertices_->vertex_count_);
240 needs_vertices_ = false;
241}
const SkPoint * vertices() const
Returns a pointer to the vertex information. Should be non-null.

◆ store_vertices() [2/2]

void flutter::DlVertices::Builder::store_vertices ( const SkPoint  points[])

Copies the indicated list of points as vertices.

fails if vertices have already been supplied.

Definition at line 225 of file dl_vertices.cc.

225 {
227 FML_CHECK(needs_vertices_);
228 char* pod = reinterpret_cast<char*>(vertices_.get());
229 size_t bytes = vertices_->vertex_count_ * sizeof(vertices[0]);
230 memcpy(pod + vertices_->vertices_offset_, vertices, bytes);
231 needs_vertices_ = false;
232}

Member Data Documentation

◆ kHasColors

constexpr Flags flutter::DlVertices::Builder::kHasColors = {{false, true}}
staticconstexpr

Definition at line 98 of file dl_vertices.h.

98{{false, true}};

◆ kHasTextureCoordinates

constexpr Flags flutter::DlVertices::Builder::kHasTextureCoordinates = {{true, false}}
staticconstexpr

Definition at line 97 of file dl_vertices.h.

97{{true, false}};

◆ kNone

constexpr Flags flutter::DlVertices::Builder::kNone = {{false, false}}
staticconstexpr

Definition at line 96 of file dl_vertices.h.

96{{false, false}};

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