GrBufferAllocPool::GrBufferAllocPool(GrGpu* gpu,
BufferType bufferType,
size_t blockSize,
- int preallocBufferCnt) :
- fBlocks(SkTMax(8, 2*preallocBufferCnt)) {
+ int preallocBufferCnt)
+ : fBlocks(SkTMax(8, 2*preallocBufferCnt)) {
fGpu = SkRef(gpu);
}
}
while (!fBlocks.empty()) {
- destroyBlock();
+ this->destroyBlock();
}
fPreallocBuffers.unrefAll();
fGpu->unref();
// updateData() if the amount of data passed is less than the full buffer
// size.
- if (!createBlock(size)) {
+ if (!this->createBlock(size)) {
return NULL;
}
SkASSERT(fBufferPtr);
return fBufferPtr;
}
-int GrBufferAllocPool::currentBufferItems(size_t itemSize) const {
- VALIDATE();
- if (fBufferPtr) {
- const BufferBlock& back = fBlocks.back();
- size_t usedBytes = back.fBuffer->gpuMemorySize() - back.fBytesFree;
- size_t pad = GrSizeAlignUpPad(usedBytes, itemSize);
- return static_cast<int>((back.fBytesFree - pad) / itemSize);
- } else if (fPreallocBuffersInUse < fPreallocBuffers.count()) {
- return static_cast<int>(fMinBlockSize / itemSize);
- }
- return 0;
-}
-
-int GrBufferAllocPool::preallocatedBuffersRemaining() const {
- return fPreallocBuffers.count() - fPreallocBuffersInUse;
-}
-
-int GrBufferAllocPool::preallocatedBufferCount() const {
- return fPreallocBuffers.count();
-}
-
void GrBufferAllocPool::putBack(size_t bytes) {
VALIDATE();
int preallocBuffersInUse = fPreallocBuffersInUse;
while (bytes) {
- // caller shouldnt try to put back more than they've taken
+ // caller shouldn't try to put back more than they've taken
SkASSERT(!fBlocks.empty());
BufferBlock& block = fBlocks.back();
size_t bytesUsed = block.fBuffer->gpuMemorySize() - block.fBytesFree;
return ptr;
}
-int GrVertexBufferAllocPool::preallocatedBufferVertices(size_t vertexSize) const {
- return static_cast<int>(INHERITED::preallocatedBufferSize() / vertexSize);
-}
-
-int GrVertexBufferAllocPool::currentBufferVertices(size_t vertexSize) const {
- return currentBufferItems(vertexSize);
-}
-
////////////////////////////////////////////////////////////////////////////////
GrIndexBufferAllocPool::GrIndexBufferAllocPool(GrGpu* gpu,
return ptr;
}
-int GrIndexBufferAllocPool::preallocatedBufferIndices() const {
- return static_cast<int>(INHERITED::preallocatedBufferSize() / sizeof(uint16_t));
-}
-int GrIndexBufferAllocPool::currentBufferIndices() const {
- return currentBufferItems(sizeof(uint16_t));
-}
void reset();
/**
- * Gets the number of preallocated buffers that are yet to be used.
- */
- int preallocatedBuffersRemaining() const;
-
- /**
- * gets the number of preallocated buffers
- */
- int preallocatedBufferCount() const;
-
- /**
* Frees data from makeSpaces in LIFO order.
*/
void putBack(size_t bytes);
- /**
- * Gets the GrGpu that this pool is associated with.
- */
- GrGpu* getGpu() { return fGpu; }
-
protected:
/**
* Used to determine what type of buffers to create. We could make the
virtual ~GrBufferAllocPool();
/**
- * Gets the size of the preallocated buffers.
- *
- * @return the size of preallocated buffers.
- */
- size_t preallocatedBufferSize() const {
- return fPreallocBuffers.count() ? fMinBlockSize : 0;
- }
-
- /**
* Returns a block of memory to hold data. A buffer designated to hold the
* data is given to the caller. The buffer may or may not be locked. The
* returned ptr remains valid until any of the following:
const GrGeometryBuffer** buffer,
size_t* offset);
- /**
- * Gets the number of items of a size that can be added to the current
- * buffer without spilling to another buffer. If the pool has been reset, or
- * the previous makeSpace completely exhausted a buffer then the returned
- * size will be the size of the next available preallocated buffer, or zero
- * if no preallocated buffer remains available. It is assumed that items
- * should be itemSize-aligned from the start of a buffer.
- *
- * @return the number of items that would fit in the current buffer.
- */
- int currentBufferItems(size_t itemSize) const;
-
GrGeometryBuffer* createBuffer(size_t size);
private:
-
- // The GrGpu must be able to clear the ref of pools it creates as members
- friend class GrGpu;
-
struct BufferBlock {
size_t fBytesFree;
GrGeometryBuffer* fBuffer;
* Constructor
*
* @param gpu The GrGpu used to create the vertex buffers.
- * @param bufferSize The minimum size of created VBs This value
+ * @param bufferSize The minimum size of created VBs. This value
* will be clamped to some reasonable minimum.
* @param preallocBufferCnt The pool will allocate this number of VBs at
* bufferSize and keep them until it is
const GrVertexBuffer** buffer,
int* startVertex);
- /**
- * Gets the number of vertices that can be added to the current VB without
- * spilling to another VB. If the pool has been reset, or the previous
- * makeSpace completely exhausted a VB then the returned number of vertices
- * would fit in the next available preallocated buffer. If any makeSpace
- * would force a new VB to be created the return value will be zero.
- *
- * @param the size of a vertex to compute space for.
- * @return the number of vertices that would fit in the current buffer.
- */
- int currentBufferVertices(size_t vertexSize) const;
-
- /**
- * Gets the number of vertices that can fit in a preallocated vertex buffer.
- * Zero if no preallocated buffers.
- *
- * @param the size of a vertex to compute space for.
- *
- * @return number of vertices that fit in one of the preallocated vertex
- * buffers.
- */
- int preallocatedBufferVertices(size_t vertexSize) const;
-
private:
typedef GrBufferAllocPool INHERITED;
};
* Constructor
*
* @param gpu The GrGpu used to create the index buffers.
- * @param bufferSize The minimum size of created IBs This value
+ * @param bufferSize The minimum size of created IBs. This value
* will be clamped to some reasonable minimum.
* @param preallocBufferCnt The pool will allocate this number of VBs at
* bufferSize and keep them until it is
const GrIndexBuffer** buffer,
int* startIndex);
- /**
- * Gets the number of indices that can be added to the current IB without
- * spilling to another IB. If the pool has been reset, or the previous
- * makeSpace completely exhausted a IB then the returned number of indices
- * would fit in the next available preallocated buffer. If any makeSpace
- * would force a new IB to be created the return value will be zero.
- */
- int currentBufferIndices() const;
-
- /**
- * Gets the number of indices that can fit in a preallocated index buffer.
- * Zero if no preallocated buffers.
- *
- * @return number of indices that fit in one of the preallocated index
- * buffers.
- */
- int preallocatedBufferIndices() const;
-
private:
typedef GrBufferAllocPool INHERITED;
};