Fix cycling through buffers in buffer alloc pool
Review URL: http://codereview.appspot.com/5716050/ git-svn-id: http://skia.googlecode.com/svn/trunk@3296 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
9c88bafd28
commit
b665a6b148
@ -42,7 +42,7 @@ GrBufferAllocPool::GrBufferAllocPool(GrGpu* gpu,
|
||||
fBytesInUse = 0;
|
||||
|
||||
fPreallocBuffersInUse = 0;
|
||||
fFirstPreallocBuffer = 0;
|
||||
fPreallocBufferStartIdx = 0;
|
||||
for (int i = 0; i < preallocBufferCnt; ++i) {
|
||||
GrGeometryBuffer* buffer = this->createBuffer(fMinBlockSize);
|
||||
if (NULL != buffer) {
|
||||
@ -82,12 +82,15 @@ void GrBufferAllocPool::reset() {
|
||||
buffer->unlock();
|
||||
}
|
||||
}
|
||||
// fPreallocBuffersInUse will be decremented down to zero in the while loop
|
||||
int preallocBuffersInUse = fPreallocBuffersInUse;
|
||||
while (!fBlocks.empty()) {
|
||||
destroyBlock();
|
||||
this->destroyBlock();
|
||||
}
|
||||
if (fPreallocBuffers.count()) {
|
||||
// must set this after above loop.
|
||||
fFirstPreallocBuffer = (fFirstPreallocBuffer + fPreallocBuffersInUse) %
|
||||
fPreallocBufferStartIdx = (fPreallocBufferStartIdx +
|
||||
preallocBuffersInUse) %
|
||||
fPreallocBuffers.count();
|
||||
}
|
||||
// we may have created a large cpu mirror of a large VB. Reset the size
|
||||
@ -216,6 +219,12 @@ int GrBufferAllocPool::preallocatedBufferCount() const {
|
||||
void GrBufferAllocPool::putBack(size_t bytes) {
|
||||
VALIDATE();
|
||||
|
||||
// if the putBack unwinds all the preallocated buffers then we will
|
||||
// advance the starting index. As blocks are destroyed fPreallocBuffersInUse
|
||||
// will be decremented. I will reach zero if all blocks using preallocated
|
||||
// buffers are released.
|
||||
int preallocBuffersInUse = fPreallocBuffersInUse;
|
||||
|
||||
while (bytes) {
|
||||
// caller shouldnt try to put back more than they've taken
|
||||
GrAssert(!fBlocks.empty());
|
||||
@ -237,6 +246,11 @@ void GrBufferAllocPool::putBack(size_t bytes) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!fPreallocBuffersInUse && fPreallocBuffers.count()) {
|
||||
fPreallocBufferStartIdx = (fPreallocBufferStartIdx +
|
||||
preallocBuffersInUse) %
|
||||
fPreallocBuffers.count();
|
||||
}
|
||||
VALIDATE();
|
||||
}
|
||||
|
||||
@ -252,7 +266,8 @@ bool GrBufferAllocPool::createBlock(size_t requestSize) {
|
||||
if (size == fMinBlockSize &&
|
||||
fPreallocBuffersInUse < fPreallocBuffers.count()) {
|
||||
|
||||
uint32_t nextBuffer = (fPreallocBuffersInUse + fFirstPreallocBuffer) %
|
||||
uint32_t nextBuffer = (fPreallocBuffersInUse +
|
||||
fPreallocBufferStartIdx) %
|
||||
fPreallocBuffers.count();
|
||||
block.fBuffer = fPreallocBuffers[nextBuffer];
|
||||
block.fBuffer->ref();
|
||||
@ -301,7 +316,7 @@ void GrBufferAllocPool::destroyBlock() {
|
||||
BufferBlock& block = fBlocks.back();
|
||||
if (fPreallocBuffersInUse > 0) {
|
||||
uint32_t prevPreallocBuffer = (fPreallocBuffersInUse +
|
||||
fFirstPreallocBuffer +
|
||||
fPreallocBufferStartIdx +
|
||||
(fPreallocBuffers.count() - 1)) %
|
||||
fPreallocBuffers.count();
|
||||
if (block.fBuffer == fPreallocBuffers[prevPreallocBuffer]) {
|
||||
|
@ -176,7 +176,9 @@ private:
|
||||
|
||||
SkTArray<BufferBlock> fBlocks;
|
||||
int fPreallocBuffersInUse;
|
||||
int fFirstPreallocBuffer;
|
||||
// We attempt to cycle through the preallocated buffers rather than
|
||||
// always starting from the first.
|
||||
int fPreallocBufferStartIdx;
|
||||
SkAutoMalloc fCpuData;
|
||||
void* fBufferPtr;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user