diff options
author | 2012-08-07 19:49:41 +0000 | |
---|---|---|
committer | 2012-08-07 19:49:41 +0000 | |
commit | 21830d90096d2dccc4168d99a427e78035ce942a (patch) | |
tree | 4dd555cade377ea06a9f4f826755ff6384b71699 /src/core/SkPictureRecord.cpp | |
parent | 44b67b2ed16ecb6fe001b785498e20b13fa42d0c (diff) |
Refactor Bitmap Storage for SkPicture using SkPipe's design.
Refactor Picture and Pipe bitmap storage into common data structure
Update SkFlattenable buffers to be more modular.
This CL is an effort to stage the conversion to named
parameters for all SkFlattenable commands. This particular
stage only does the following two things...
1. Move flattenable buffers from SkFlattenable.h into
their own header.
2. Update and Add new read write methods for better clarity
and convenience.
BUG=
Review URL: https://codereview.appspot.com/6445079
git-svn-id: http://skia.googlecode.com/svn/trunk@4994 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkPictureRecord.cpp')
-rw-r--r-- | src/core/SkPictureRecord.cpp | 65 |
1 files changed, 9 insertions, 56 deletions
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index c3f3ad12cf..fb4f991f51 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -17,11 +17,10 @@ enum { }; SkPictureRecord::SkPictureRecord(uint32_t flags) : - fHeap(HEAP_BLOCK_SIZE), - fBitmaps(&fHeap), - fMatrices(&fHeap), - fPaints(&fHeap), - fRegions(&fHeap), + fFlattenableHeap(HEAP_BLOCK_SIZE), + fMatrices(&fFlattenableHeap), + fPaints(&fFlattenableHeap), + fRegions(&fFlattenableHeap), fWriter(MIN_WRITER_SIZE), fRecordFlags(flags) { #ifdef SK_DEBUG_SIZE @@ -32,12 +31,15 @@ SkPictureRecord::SkPictureRecord(uint32_t flags) : fRestoreOffsetStack.setReserve(32); fInitialSaveCount = kNoInitialSave; + fFlattenableHeap.setBitmapStorage(&fBitmapHeap); fPathHeap = NULL; // lazy allocate fFirstSavedLayerIndex = kNoSavedLayerIndex; } SkPictureRecord::~SkPictureRecord() { - reset(); + SkSafeUnref(fPathHeap); + fFlattenableHeap.setBitmapStorage(NULL); + fPictureRefs.unrefAll(); } /////////////////////////////////////////////////////////////////////////////// @@ -518,25 +520,8 @@ void SkPictureRecord::drawData(const void* data, size_t length) { /////////////////////////////////////////////////////////////////////////////// -void SkPictureRecord::reset() { - SkSafeUnref(fPathHeap); - fPathHeap = NULL; - - fBitmaps.reset(); - fBitmapIndexCache.reset(); - fMatrices.reset(); - fPaints.reset(); - fPictureRefs.unrefAll(); - fRegions.reset(); - fWriter.reset(); - fHeap.reset(); - - fRestoreOffsetStack.setCount(1); - fRestoreOffsetStack.top() = 0; -} - void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { - addInt(find(bitmap)); + addInt(fBitmapHeap.insert(bitmap)); } void SkPictureRecord::addMatrix(const SkMatrix& matrix) { @@ -637,38 +622,6 @@ void SkPictureRecord::addText(const void* text, size_t byteLength) { /////////////////////////////////////////////////////////////////////////////// -int SkPictureRecord::find(const SkBitmap& bitmap) { - int dictionaryIndex = 0; - BitmapIndexCacheEntry entry; - const bool flattenPixels = !bitmap.isImmutable(); - if (flattenPixels) { - // Flattened bitmap may be very large. First attempt a fast lookup - // based on generation ID to avoid unnecessary flattening in - // fBitmaps.find() - entry.fGenerationId = bitmap.getGenerationID(); - entry.fPixelOffset = bitmap.pixelRefOffset(); - entry.fWidth = bitmap.width(); - entry.fHeight = bitmap.height(); - dictionaryIndex = - SkTSearch<const BitmapIndexCacheEntry>(fBitmapIndexCache.begin(), - fBitmapIndexCache.count(), entry, sizeof(entry)); - if (dictionaryIndex >= 0) { - return fBitmapIndexCache[dictionaryIndex].fIndex; - } - } - - uint32_t writeFlags = flattenPixels ? - SkFlattenableWriteBuffer::kForceFlattenBitmapPixels_Flag : 0; - int index = fBitmaps.find(bitmap, writeFlags); - - if (flattenPixels) { - entry.fIndex = index; - dictionaryIndex = ~dictionaryIndex; - *fBitmapIndexCache.insert(dictionaryIndex) = entry; - } - return index; -} - #ifdef SK_DEBUG_SIZE size_t SkPictureRecord::size() const { size_t result = 0; |