Chromium Code Reviews| Index: src/core/SkPictureFlat.h |
| =================================================================== |
| --- src/core/SkPictureFlat.h (revision 12980) |
| +++ src/core/SkPictureFlat.h (working copy) |
| @@ -377,9 +377,9 @@ |
| explicit SkFlatDictionary(SkFlatController* controller) |
| : fController(SkRef(controller)) |
| , fScratchSize(kScratchSizeGuess) |
|
mtklein
2014/01/09 14:38:58
For consistency, let's make this fScratchSize(0) t
tomhudson
2014/01/09 14:49:32
Done.
|
| - , fScratch(AllocScratch(fScratchSize)) |
| + , fScratch(NULL) |
| , fWriteBuffer(kWriteBufferGrowthBytes) |
| - , fWriteBufferReady(false) { |
| + , fBuffersReady(false) { |
|
mtklein
2014/01/09 14:38:58
Suggestion: fReady and lazyInit() ?
tomhudson
2014/01/09 14:49:32
Done.
|
| this->reset(); |
| } |
| @@ -515,18 +515,23 @@ |
| } |
| // We have to delay fWriteBuffer's initialization until its first use; fController might not |
| - // be fully set up by the time we get it in the constructor. |
| - void lazyWriteBufferInit() { |
| - if (fWriteBufferReady) { |
| + // be fully set up by the time we get it in the constructor. We also delay fScratch to |
|
mtklein
2014/01/09 14:38:58
delay -> delay allocating?
tomhudson
2014/01/09 14:49:32
Done.
|
| + // avoid unnecessary heap allocations, since we're paying the price of the conditional |
| + // anyway. |
| + void lazyBufferInit() { |
| + if (fBuffersReady) { |
| return; |
| } |
| + |
| + fScratch = AllocScratch(fScratchSize); |
| + |
| // Without a bitmap heap, we'll flatten bitmaps into paints. That's never what you want. |
| SkASSERT(fController->getBitmapHeap() != NULL); |
| fWriteBuffer.setBitmapHeap(fController->getBitmapHeap()); |
| fWriteBuffer.setTypefaceRecorder(fController->getTypefaceSet()); |
| fWriteBuffer.setNamedFactoryRecorder(fController->getNamedFactorySet()); |
| fWriteBuffer.setFlags(fController->getWriteBufferFlags()); |
| - fWriteBufferReady = true; |
| + fBuffersReady = true; |
| } |
| // As findAndReturnFlat, but returns a mutable pointer for internal use. |
| @@ -546,7 +551,7 @@ |
| // This reference is valid only until the next call to resetScratch() or detachScratch(). |
| const SkFlatData& resetScratch(const T& element, int index) { |
| - this->lazyWriteBufferInit(); |
| + this->lazyBufferInit(); |
| // Flatten element into fWriteBuffer (using fScratch as storage). |
| fWriteBuffer.reset(fScratch->data(), fScratchSize); |
| @@ -577,6 +582,7 @@ |
| // Allocate a new SkFlatData exactly big enough to hold our current scratch. |
| // We use the controller for this allocation to extend the allocation's lifetime and allow |
| // the controller to do whatever memory management it wants. |
| + SkASSERT(fScratch); |
|
mtklein
2014/01/09 14:38:58
Suggestion: SkASSERT(fScratch != NULL); as a free
tomhudson
2014/01/09 14:49:32
Done.
|
| const size_t paddedSize = SizeWithPadding(fScratch->flatSize()); |
| SkFlatData* detached = (SkFlatData*)fController->allocThrow(paddedSize); |
| @@ -596,9 +602,9 @@ |
| // All SkFlatData* stored in fIndexedData and fHash are owned by the controller. |
| SkAutoTUnref<SkFlatController> fController; |
| size_t fScratchSize; // How many bytes fScratch has allocated for data itself. |
| - SkFlatData* fScratch; // Owned, must be freed with sk_free. |
| + SkFlatData* fScratch; // Owned, lazily allocated, must be freed with sk_free. |
| SkOrderedWriteBuffer fWriteBuffer; |
| - bool fWriteBufferReady; |
| + bool fBuffersReady; |
| // We map between SkFlatData and a 1-based integer index. |
| int fNextIndex; |