Flutter Engine
The Flutter Engine
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. More...
 
bool is_valid ()
 Returns true iff the underlying object was successfully allocated. More...
 
void store_vertices (const SkPoint points[])
 Copies the indicated list of points as vertices. More...
 
void store_vertices (const float coordinates[])
 Copies the indicated list of float pairs as vertices. More...
 
void store_texture_coordinates (const SkPoint points[])
 Copies the indicated list of points as texture coordinates. More...
 
void store_texture_coordinates (const float coordinates[])
 Copies the indicated list of float pairs as texture coordinates. More...
 
void store_colors (const DlColor colors[])
 Copies the indicated list of colors as vertex colors. More...
 
void store_colors (const uint32_t colors[])
 Copies the indicated list of unsigned ints as vertex colors in the 32-bit RGBA format. More...
 
void store_indices (const uint16_t indices[])
 Copies the indicated list of 16-bit indices as vertex indices. More...
 
std::shared_ptr< DlVerticesbuild ()
 Finalizes and the constructed DlVertices object. More...
 

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) {
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
Definition: dl_vertices.h:202
DlVertexMode mode() const
Definition: dl_vertices.h:198
int index_count() const
Definition: dl_vertices.h:223
FlutterSemanticsFlag flags
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static void DlVerticesDeleter(void *p)
Definition: dl_vertices.cc:14
static size_t bytes_needed(int vertex_count, Flags flags, int index_count)
Definition: dl_vertices.cc:23

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.
Definition: dl_vertices.h:115
#define FML_CHECK(condition)
Definition: logging.h:85
static SkRect compute_bounds(const SkPoint *points, int count)
Definition: dl_vertices.cc:88

◆ 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
Definition: dl_vertices.h:217

◆ 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.
Definition: dl_vertices.cc:261
flutter::DlColor DlColor

◆ 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
Definition: dl_vertices.h:227

◆ 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)
Definition: dl_vertices.cc:218

◆ 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.
Definition: dl_vertices.h:205

◆ 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.

◆ kHasTextureCoordinates

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

Definition at line 97 of file dl_vertices.h.

◆ kNone

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

Definition at line 96 of file dl_vertices.h.


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