Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
GrVertexBufferAllocPool Class Reference

#include <GrBufferAllocPool.h>

Inheritance diagram for GrVertexBufferAllocPool:
GrBufferAllocPool SkNoncopyable

Public Member Functions

 GrVertexBufferAllocPool (GrGpu *gpu, sk_sp< CpuBufferCache > cpuBufferCache)
 
void * makeSpace (size_t vertexSize, int vertexCount, sk_sp< const GrBuffer > *buffer, int *startVertex)
 
void * makeSpaceAtLeast (size_t vertexSize, int minVertexCount, int fallbackVertexCount, sk_sp< const GrBuffer > *buffer, int *startVertex, int *actualVertexCount)
 
- Public Member Functions inherited from GrBufferAllocPool
void unmap ()
 
void reset ()
 
void putBack (size_t bytes)
 

Additional Inherited Members

- Static Public Attributes inherited from GrBufferAllocPool
static constexpr size_t kDefaultBufferSize = 1 << 15
 
- Protected Member Functions inherited from GrBufferAllocPool
 GrBufferAllocPool (GrGpu *gpu, GrGpuBufferType bufferType, sk_sp< CpuBufferCache > cpuBufferCache)
 
virtual ~GrBufferAllocPool ()
 
void * makeSpace (size_t size, size_t alignment, sk_sp< const GrBuffer > *buffer, size_t *offset)
 
void * makeSpaceAtLeast (size_t minSize, size_t fallbackSize, size_t alignment, sk_sp< const GrBuffer > *buffer, size_t *offset, size_t *actualSize)
 
sk_sp< GrBuffergetBuffer (size_t size)
 

Detailed Description

A GrBufferAllocPool of vertex buffers

Definition at line 177 of file GrBufferAllocPool.h.

Constructor & Destructor Documentation

◆ GrVertexBufferAllocPool()

GrVertexBufferAllocPool::GrVertexBufferAllocPool ( GrGpu gpu,
sk_sp< CpuBufferCache cpuBufferCache 
)

Constructor

Parameters
gpuThe GrGpu used to create the vertex buffers.
cpuBufferCacheIf non-null a cache for client side array buffers or staging buffers used before data is uploaded to GPU buffer objects.

Definition at line 431 of file GrBufferAllocPool.cpp.

Member Function Documentation

◆ makeSpace()

void * GrVertexBufferAllocPool::makeSpace ( size_t  vertexSize,
int  vertexCount,
sk_sp< const GrBuffer > *  buffer,
int startVertex 
)

Returns a block of memory to hold vertices. A buffer designated to hold the vertices given to the caller. The buffer may or may not be locked. The returned ptr remains valid until any of the following: *makeSpace is called again. *unmap is called. *reset is called. *this object is destroyed.

Once unmap on the pool is called the vertices are guaranteed to be in the buffer at the offset indicated by startVertex. Until that time they may be in temporary storage and/or the buffer may be locked.

Parameters
vertexSizespecifies size of a vertex to allocate space for
vertexCountnumber of vertices to allocate space for
bufferreturns the vertex buffer that will hold the vertices.
startVertexreturns the offset into buffer of the first vertex. In units of the size of a vertex from layout param.
Returns
pointer to first vertex.

Definition at line 434 of file GrBufferAllocPool.cpp.

437 {
438 SkASSERT(vertexCount >= 0);
440 SkASSERT(startVertex);
441
443 void* ptr = INHERITED::makeSpace(SkSafeMath::Mul(vertexSize, vertexCount),
444 vertexSize,
445 buffer,
446 &offset);
447
448 SkASSERT(0 == offset % vertexSize);
449 *startVertex = static_cast<int>(offset / vertexSize);
450 return ptr;
451}
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SK_INIT_TO_AVOID_WARNING
Definition SkMacros.h:58
void * makeSpace(size_t size, size_t alignment, sk_sp< const GrBuffer > *buffer, size_t *offset)
static size_t Mul(size_t x, size_t y)
static const uint8_t buffer[]
Point offset

◆ makeSpaceAtLeast()

void * GrVertexBufferAllocPool::makeSpaceAtLeast ( size_t  vertexSize,
int  minVertexCount,
int  fallbackVertexCount,
sk_sp< const GrBuffer > *  buffer,
int startVertex,
int actualVertexCount 
)

Returns a block of memory to hold vertices. A buffer designated to hold the vertices given to the caller. The buffer may or may not be locked. The returned ptr remains valid until any of the following: *makeSpace is called again. *unmap is called. *reset is called. *this object is destroyed.

Once unmap on the pool is called the vertices are guaranteed to be in the buffer at the offset indicated by startVertex. Until that time they may be in temporary storage and/or the buffer may be locked.

The caller requests a minimum number of vertices, but the block may be (much) larger. Assuming that a new block must be allocated, it will be sized to hold fallbackVertexCount vertices. The actual block size (in vertices) is returned in actualVertexCount.

Parameters
vertexSizespecifies size of a vertex to allocate space for
minVertexCountminimum number of vertices to allocate space for
fallbackVertexCountnumber of vertices to allocate space for if a new block is needed
bufferreturns the vertex buffer that will hold the vertices.
startVertexreturns the offset into buffer of the first vertex. In units of the size of a vertex from layout param.
actualVertexCountreturns the capacity of the block (in vertices)
Returns
pointer to first vertex.

Definition at line 453 of file GrBufferAllocPool.cpp.

456 {
457 SkASSERT(minVertexCount >= 0);
458 SkASSERT(fallbackVertexCount >= minVertexCount);
460 SkASSERT(startVertex);
461 SkASSERT(actualVertexCount);
462
464 size_t actualSize SK_INIT_TO_AVOID_WARNING;
465 void* ptr = INHERITED::makeSpaceAtLeast(SkSafeMath::Mul(vertexSize, minVertexCount),
466 SkSafeMath::Mul(vertexSize, fallbackVertexCount),
467 vertexSize,
468 buffer,
469 &offset,
470 &actualSize);
471
472 SkASSERT(0 == offset % vertexSize);
473 *startVertex = static_cast<int>(offset / vertexSize);
474
475 SkASSERT(0 == actualSize % vertexSize);
476 SkASSERT(actualSize >= vertexSize * minVertexCount);
477 *actualVertexCount = static_cast<int>(actualSize / vertexSize);
478
479 return ptr;
480}
void * makeSpaceAtLeast(size_t minSize, size_t fallbackSize, size_t alignment, sk_sp< const GrBuffer > *buffer, size_t *offset, size_t *actualSize)

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