Flutter Engine
 
Loading...
Searching...
No Matches
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 () const
 Returns true iff the underlying object was successfully allocated.
 
void store_vertices (const DlPoint vertices[])
 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 DlPoint 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.
 
void store_bounds (DlRect bounds)
 Overwrite the internal bounds with a precomputed bounding rect.
 
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 73 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 207 of file dl_vertices.cc.

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

References flutter::bytes_needed(), flutter::DlVerticesDeleter(), flutter::DlVertices::index_count(), flutter::DlVertices::mode(), and flutter::DlVertices::vertex_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 301 of file dl_vertices.cc.

301 {
303 if (vertices_->vertex_count() <= 0) {
304 // We set this to true in the constructor to make sure that they
305 // call store_vertices() only once, but if there are no vertices
306 // then we will not object to them never having stored any vertices
307 needs_vertices_ = false;
308 }
309 FML_DCHECK(!needs_vertices_);
310 FML_DCHECK(!needs_texture_coords_);
311 FML_DCHECK(!needs_colors_);
312 FML_DCHECK(!needs_indices_);
313
314 if (needs_bounds_) {
315 vertices_->bounds_ =
316 compute_bounds(vertices_->vertex_data(), vertices_->vertex_count_);
317 }
318
319 return std::move(vertices_);
320}
bool is_valid() const
Returns true iff the underlying object was successfully allocated.
#define FML_DCHECK(condition)
Definition logging.h:122
static DlRect compute_bounds(const DlPoint *points, int count)

References flutter::compute_bounds(), and FML_DCHECK.

Referenced by flutter::Vertices::init(), flutter::DlVertices::Make(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), impeller::testing::TEST_P(), and impeller::testing::TEST_P().

◆ is_valid()

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

Returns true iff the underlying object was successfully allocated.

Definition at line 113 of file dl_vertices.h.

113{ return vertices_ != nullptr; }

Referenced by flutter::Vertices::init(), flutter::testing::TEST(), and flutter::testing::TEST().

◆ store_bounds()

void flutter::DlVertices::Builder::store_bounds ( DlRect  bounds)

Overwrite the internal bounds with a precomputed bounding rect.

Definition at line 296 of file dl_vertices.cc.

296 {
297 vertices_->bounds_ = bounds;
298 needs_bounds_ = false;
299}

Referenced by flutter::DlVertices::Make().

◆ 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 266 of file dl_vertices.cc.

266 {
268 FML_DCHECK(needs_colors_);
269 char* pod = reinterpret_cast<char*>(vertices_.get());
270 size_t bytes = vertices_->vertex_count_ * sizeof(colors[0]);
271 memcpy(pod + vertices_->colors_offset_, colors, bytes);
272 needs_colors_ = false;
273}
const DlColor * colors() const

References flutter::DlVertices::colors(), and FML_DCHECK.

Referenced by flutter::Vertices::init(), flutter::DlVertices::Make(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().

◆ store_colors() [2/2]

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

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 275 of file dl_vertices.cc.

275 {
277 FML_DCHECK(needs_colors_);
278 char* pod = reinterpret_cast<char*>(vertices_.get());
279 DlColor* dlcolors_ptr =
280 reinterpret_cast<DlColor*>(pod + vertices_->colors_offset_);
281 for (int i = 0; i < vertices_->vertex_count_; ++i) {
282 *dlcolors_ptr++ = DlColor(colors[i]);
283 }
284 needs_colors_ = false;
285}
flutter::DlColor DlColor

References flutter::DlVertices::colors(), FML_DCHECK, and i.

◆ 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 287 of file dl_vertices.cc.

287 {
289 FML_DCHECK(needs_indices_);
290 char* pod = reinterpret_cast<char*>(vertices_.get());
291 size_t bytes = vertices_->index_count_ * sizeof(indices[0]);
292 memcpy(pod + vertices_->indices_offset_, indices, bytes);
293 needs_indices_ = false;
294}
const uint16_t * indices() const

References FML_DCHECK, and flutter::DlVertices::indices().

Referenced by flutter::Vertices::init(), flutter::DlVertices::Make(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), impeller::testing::TEST_P(), and impeller::testing::TEST_P().

◆ store_texture_coordinates() [1/2]

void flutter::DlVertices::Builder::store_texture_coordinates ( const DlPoint  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 248 of file dl_vertices.cc.

248 {
250 FML_DCHECK(needs_texture_coords_);
251 char* pod = reinterpret_cast<char*>(vertices_.get());
252 size_t bytes = vertices_->vertex_count_ * sizeof(coords[0]);
253 memcpy(pod + vertices_->texture_coordinates_offset_, coords, bytes);
254 needs_texture_coords_ = false;
255}

References FML_DCHECK.

Referenced by flutter::Vertices::init(), flutter::DlVertices::Make(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), impeller::testing::TEST_P(), and impeller::testing::TEST_P().

◆ store_texture_coordinates() [2/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 257 of file dl_vertices.cc.

257 {
259 FML_DCHECK(needs_texture_coords_);
260 char* pod = reinterpret_cast<char*>(vertices_.get());
261 store_points(pod, vertices_->texture_coordinates_offset_, coords,
262 vertices_->vertex_count_);
263 needs_texture_coords_ = false;
264}
static void store_points(char *dst, int offset, const float *src, int count)

References FML_DCHECK, and flutter::store_points().

◆ store_vertices() [1/2]

void flutter::DlVertices::Builder::store_vertices ( const DlPoint  vertices[])

Copies the indicated list of points as vertices.

fails if vertices have already been supplied.

Definition at line 230 of file dl_vertices.cc.

230 {
232 FML_DCHECK(needs_vertices_);
233 char* pod = reinterpret_cast<char*>(vertices_.get());
234 size_t bytes = vertices_->vertex_count_ * sizeof(vertices[0]);
235 memcpy(pod + vertices_->vertices_offset_, vertices, bytes);
236 needs_vertices_ = false;
237}

References FML_DCHECK.

Referenced by flutter::Vertices::init(), flutter::DlVertices::Make(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), impeller::testing::TEST_P(), and impeller::testing::TEST_P().

◆ store_vertices() [2/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 239 of file dl_vertices.cc.

239 {
241 FML_DCHECK(needs_vertices_);
242 char* pod = reinterpret_cast<char*>(vertices_.get());
243 store_points(pod, vertices_->vertices_offset_, vertices,
244 vertices_->vertex_count_);
245 needs_vertices_ = false;
246}

References FML_DCHECK, and flutter::store_points().

Member Data Documentation

◆ kHasColors

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

◆ kHasTextureCoordinates

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

◆ kNone

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

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