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

#include <GrBufferAllocPool.h>

Inheritance diagram for GrIndexBufferAllocPool:
GrBufferAllocPool SkNoncopyable

Public Member Functions

 GrIndexBufferAllocPool (GrGpu *gpu, sk_sp< CpuBufferCache > cpuBufferCache)
 
void * makeSpace (int indexCount, sk_sp< const GrBuffer > *buffer, int *startIndex)
 
void * makeSpaceAtLeast (int minIndexCount, int fallbackIndexCount, sk_sp< const GrBuffer > *buffer, int *startIndex, int *actualIndexCount)
 
- 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 index buffers

Definition at line 256 of file GrBufferAllocPool.h.

Constructor & Destructor Documentation

◆ GrIndexBufferAllocPool()

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

Constructor

Parameters
gpuThe GrGpu used to create the index 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 484 of file GrBufferAllocPool.cpp.

Member Function Documentation

◆ makeSpace()

void * GrIndexBufferAllocPool::makeSpace ( int  indexCount,
sk_sp< const GrBuffer > *  buffer,
int startIndex 
)

Returns a block of memory to hold indices. A buffer designated to hold the indices is 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 indices are guaranteed to be in the buffer at the offset indicated by startIndex. Until that time they may be in temporary storage and/or the buffer may be locked.

Parameters
indexCountnumber of indices to allocate space for
bufferreturns the index buffer that will hold the indices.
startIndexreturns the offset into buffer of the first index.
Returns
pointer to first index.

Definition at line 487 of file GrBufferAllocPool.cpp.

488 {
489 SkASSERT(indexCount >= 0);
491 SkASSERT(startIndex);
492
494 void* ptr = INHERITED::makeSpace(SkSafeMath::Mul(indexCount, sizeof(uint16_t)),
495 sizeof(uint16_t),
496 buffer,
497 &offset);
498
499 SkASSERT(0 == offset % sizeof(uint16_t));
500 *startIndex = static_cast<int>(offset / sizeof(uint16_t));
501 return ptr;
502}
#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 * GrIndexBufferAllocPool::makeSpaceAtLeast ( int  minIndexCount,
int  fallbackIndexCount,
sk_sp< const GrBuffer > *  buffer,
int startIndex,
int actualIndexCount 
)

Returns a block of memory to hold indices. A buffer designated to hold the indices is 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 indices are guaranteed to be in the buffer at the offset indicated by startIndex. Until that time they may be in temporary storage and/or the buffer may be locked.

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

Parameters
minIndexCountminimum number of indices to allocate space for
fallbackIndexCountnumber of indices to allocate space for if a new block is needed
bufferreturns the index buffer that will hold the indices.
startIndexreturns the offset into buffer of the first index.
actualIndexCountreturns the capacity of the block (in indices)
Returns
pointer to first index.

Definition at line 504 of file GrBufferAllocPool.cpp.

506 {
507 SkASSERT(minIndexCount >= 0);
508 SkASSERT(fallbackIndexCount >= minIndexCount);
510 SkASSERT(startIndex);
511 SkASSERT(actualIndexCount);
512
514 size_t actualSize SK_INIT_TO_AVOID_WARNING;
515 void* ptr = INHERITED::makeSpaceAtLeast(SkSafeMath::Mul(minIndexCount, sizeof(uint16_t)),
516 SkSafeMath::Mul(fallbackIndexCount, sizeof(uint16_t)),
517 sizeof(uint16_t),
518 buffer,
519 &offset,
520 &actualSize);
521
522 SkASSERT(0 == offset % sizeof(uint16_t));
523 *startIndex = static_cast<int>(offset / sizeof(uint16_t));
524
525 SkASSERT(0 == actualSize % sizeof(uint16_t));
526 SkASSERT(actualSize >= minIndexCount * sizeof(uint16_t));
527 *actualIndexCount = static_cast<int>(actualSize / sizeof(uint16_t));
528 return ptr;
529}
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: