int GrBufferAllocPool::currentBufferItems(size_t itemSize) const { VALIDATE(); if (NULL != fBufferPtr) { const BufferBlock& back = fBlocks.back(); size_t usedBytes = back.fBuffer->sizeInBytes() - 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; }
void* GrBufferAllocPool::makeSpace(size_t size, size_t alignment, const GrGeometryBuffer** buffer, size_t* offset) { VALIDATE(); SkASSERT(buffer); SkASSERT(offset); if (fBufferPtr) { BufferBlock& back = fBlocks.back(); size_t usedBytes = back.fBuffer->gpuMemorySize() - back.fBytesFree; size_t pad = GrSizeAlignUpPad(usedBytes, alignment); if ((size + pad) <= back.fBytesFree) { memset((void*)(reinterpret_cast<intptr_t>(fBufferPtr) + usedBytes), 0, pad); usedBytes += pad; *offset = usedBytes; *buffer = back.fBuffer; back.fBytesFree -= size + pad; fBytesInUse += size + pad; VALIDATE(); return (void*)(reinterpret_cast<intptr_t>(fBufferPtr) + usedBytes); } } // We could honor the space request using by a partial update of the current // VB (if there is room). But we don't currently use draw calls to GL that // allow the driver to know that previously issued draws won't read from // the part of the buffer we update. Also, the GL buffer implementation // may be cheating on the actual buffer size by shrinking the buffer on // updateData() if the amount of data passed is less than the full buffer // size. if (!this->createBlock(size)) { return NULL; } SkASSERT(fBufferPtr); *offset = 0; BufferBlock& back = fBlocks.back(); *buffer = back.fBuffer; back.fBytesFree -= size; fBytesInUse += size; VALIDATE(); return fBufferPtr; }