diff --git a/src/gpu/GrInOrderDrawBuffer.h b/src/gpu/GrInOrderDrawBuffer.h index e86a5288d4..61bd51331b 100644 --- a/src/gpu/GrInOrderDrawBuffer.h +++ b/src/gpu/GrInOrderDrawBuffer.h @@ -301,7 +301,7 @@ private: // TODO: Use a single allocator for commands and records enum { - kCmdBufferInitialSizeInBytes = 64 * 1024, + kCmdBufferInitialSizeInBytes = 8 * 1024, kGeoPoolStatePreAllocCnt = 4, }; diff --git a/src/gpu/GrTRecorder.h b/src/gpu/GrTRecorder.h index 17c4213993..ab559e4a59 100644 --- a/src/gpu/GrTRecorder.h +++ b/src/gpu/GrTRecorder.h @@ -151,10 +151,12 @@ template TItem* GrTRecorder::alloc_back(int dataLength) { const int totalLength = length_of
::kValue + length_of::kValue + dataLength; - if (fTailBlock->fBack + totalLength > fTailBlock->fLength) { - SkASSERT(!fTailBlock->fNext); - fTailBlock->fNext = MemBlock::Alloc(SkTMax(2 * fTailBlock->fLength, totalLength)); + while (fTailBlock->fBack + totalLength > fTailBlock->fLength) { + if (!fTailBlock->fNext) { + fTailBlock->fNext = MemBlock::Alloc(SkTMax(2 * fTailBlock->fLength, totalLength)); + } fTailBlock = fTailBlock->fNext; + SkASSERT(0 == fTailBlock->fBack); } Header* header = reinterpret_cast(&(*fTailBlock)[fTailBlock->fBack]); @@ -183,12 +185,11 @@ public: Iter(GrTRecorder& recorder) : fBlock(recorder.fHeadBlock), fPosition(0), fItem(NULL) {} bool next() { - if (fPosition >= fBlock->fBack) { + while (fPosition >= fBlock->fBack) { SkASSERT(fPosition == fBlock->fBack); if (!fBlock->fNext) { return false; } - SkASSERT(0 != fBlock->fNext->fBack); fBlock = fBlock->fNext; fPosition = 0; } @@ -218,9 +219,22 @@ void GrTRecorder::reset() { while (iter.next()) { iter->~TBase(); } - fHeadBlock->fBack = 0; - MemBlock::Free(fHeadBlock->fNext); - fHeadBlock->fNext = NULL; + + // Assume the next time this recorder fills up it will use approximately the same + // amount of space as last time. Leave enough space for up to ~50% growth; free + // everything else. + if (fTailBlock->fBack <= fTailBlock->fLength / 2) { + MemBlock::Free(fTailBlock->fNext); + fTailBlock->fNext = NULL; + } else if (fTailBlock->fNext) { + MemBlock::Free(fTailBlock->fNext->fNext); + fTailBlock->fNext->fNext = NULL; + } + + for (MemBlock* block = fHeadBlock; block; block = block->fNext) { + block->fBack = 0; + } + fTailBlock = fHeadBlock; fLastItem = NULL; }