const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const { if (NULL == fQuadIndexBuffer) { static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS; GrGpu* me = const_cast<GrGpu*>(this); fQuadIndexBuffer = me->createIndexBuffer(SIZE, false); if (NULL != fQuadIndexBuffer) { uint16_t* indices = (uint16_t*)fQuadIndexBuffer->lock(); if (NULL != indices) { fill_indices(indices, MAX_QUADS); fQuadIndexBuffer->unlock(); } else { indices = (uint16_t*)GrMalloc(SIZE); fill_indices(indices, MAX_QUADS); if (!fQuadIndexBuffer->updateData(indices, SIZE)) { fQuadIndexBuffer->unref(); fQuadIndexBuffer = NULL; GrCrash("Can't get indices into buffer!"); } GrFree(indices); } } } return fQuadIndexBuffer; }
GrMemoryPool::BlockHeader* GrMemoryPool::CreateBlock(size_t size) { BlockHeader* block = reinterpret_cast<BlockHeader*>(GrMalloc(size + kHeaderSize)); // we assume malloc gives us aligned memory GrAssert(!(reinterpret_cast<intptr_t>(block) % kAlignment)); block->fLiveCount = 0; block->fFreeSize = size; block->fCurrPtr = reinterpret_cast<intptr_t>(block) + kHeaderSize; return block; }
static Block* Create(size_t size, Block* next) { GrAssert(size >= GrAllocPool_MIN_BLOCK_SIZE); Block* block = (Block*)GrMalloc(sizeof(Block) + size); block->fNext = next; block->fPtr = (char*)block + sizeof(Block); block->fBytesFree = size; block->fBytesTotal = size; return block; }