aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPictureRecord.cpp
diff options
context:
space:
mode:
authorGravatar junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-01 21:23:07 +0000
committerGravatar junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-01 21:23:07 +0000
commit4866cc0afb7571309d9fdecb221d919f663054c0 (patch)
tree3696433e73defaa1a3d8ec92da58b9877ba7fc91 /src/core/SkPictureRecord.cpp
parent898e7b568f535fc62a92acda3c22a68cb6e04dcc (diff)
Adding option to serialize mutable bitmaps in SkPicture
Diffstat (limited to 'src/core/SkPictureRecord.cpp')
-rw-r--r--src/core/SkPictureRecord.cpp40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index 422001bcea..a499ee1904 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -7,6 +7,7 @@
*/
#include "SkPictureRecord.h"
#include "SkTSearch.h"
+#include "SkPixelRef.h"
#define MIN_WRITER_SIZE 16384
#define HEAP_BLOCK_SIZE 4096
@@ -495,6 +496,7 @@ void SkPictureRecord::reset() {
fPathHeap = NULL;
fBitmaps.reset();
+ fPixelRefDictionary.reset();
fMatrices.reset();
fPaints.reset();
fPictureRefs.unrefAll();
@@ -510,7 +512,7 @@ void SkPictureRecord::reset() {
}
void SkPictureRecord::addBitmap(const SkBitmap& bitmap) {
- addInt(fBitmaps.find(&bitmap, &fRCSet));
+ addInt(find(bitmap));
}
void SkPictureRecord::addMatrix(const SkMatrix& matrix) {
@@ -611,6 +613,42 @@ void SkPictureRecord::addText(const void* text, size_t byteLength) {
///////////////////////////////////////////////////////////////////////////////
+bool SkPictureRecord::shouldFlattenPixels(const SkBitmap& bitmap) const {
+ return (fRecordFlags &
+ SkPicture::kFlattenMutableNonTexturePixelRefs_RecordingFlag)
+ && !bitmap.isImmutable() && bitmap.pixelRef()
+ && NULL == bitmap.getTexture();
+}
+
+int SkPictureRecord::find(const SkBitmap& bitmap) {
+ int dictionaryIndex = 0;
+ PixelRefDictionaryEntry entry;
+ bool flattenPixels = shouldFlattenPixels(bitmap);
+ 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.fKey = bitmap.pixelRef()->getGenerationID();
+ dictionaryIndex =
+ SkTSearch<const PixelRefDictionaryEntry>(fPixelRefDictionary.begin(),
+ fPixelRefDictionary.count(), entry, sizeof(entry));
+ if (dictionaryIndex >= 0) {
+ return fPixelRefDictionary[dictionaryIndex].fIndex;
+ }
+ }
+
+ uint32_t writeFlags = flattenPixels ?
+ SkFlattenableWriteBuffer::kForceFlattenBitmapPixels_Flag : 0;
+ int index = fBitmaps.find(&bitmap, &fRCSet, NULL, writeFlags);
+
+ if (flattenPixels) {
+ entry.fIndex = index;
+ dictionaryIndex = ~dictionaryIndex;
+ *fPixelRefDictionary.insert(dictionaryIndex) = entry;
+ }
+ return index;
+}
+
#ifdef SK_DEBUG_SIZE
size_t SkPictureRecord::size() const {
size_t result = 0;