diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkPicture.cpp | 4 | ||||
-rw-r--r-- | src/core/SkPictureRecord.cpp | 26 | ||||
-rw-r--r-- | src/core/SkPictureRecord.h | 30 | ||||
-rw-r--r-- | src/utils/SkDeferredCanvas.cpp | 3 |
4 files changed, 33 insertions, 30 deletions
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index 58098e7bfc..9f606f736d 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -168,10 +168,6 @@ bool SkPicture::hasRecorded() const { return NULL != fRecord && fRecord->writeStream().size() > 0; } -bool SkPicture::willFlattenPixelsOnRecord(const SkBitmap& bitmap) const { - return NULL != fRecord && fRecord->shouldFlattenPixels(bitmap); -} - SkCanvas* SkPicture::getRecordingCanvas() const { // will be null if we are not recording return fRecord; diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index 9f5a1c22dc..8b3e9fdab6 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -523,7 +523,7 @@ void SkPictureRecord::reset() { fPathHeap = NULL; fBitmaps.reset(); - fPixelRefDictionary.reset(); + fBitmapIndexCache.reset(); fMatrices.reset(); fPaints.reset(); fPictureRefs.unrefAll(); @@ -640,27 +640,23 @@ 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); + 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.fKey = bitmap.pixelRef()->getGenerationID(); + entry.fGenerationId = bitmap.getGenerationID(); + entry.fPixelOffset = bitmap.pixelRefOffset(); + entry.fWidth = bitmap.width(); + entry.fHeight = bitmap.height(); dictionaryIndex = - SkTSearch<const PixelRefDictionaryEntry>(fPixelRefDictionary.begin(), - fPixelRefDictionary.count(), entry, sizeof(entry)); + SkTSearch<const BitmapIndexCacheEntry>(fBitmapIndexCache.begin(), + fBitmapIndexCache.count(), entry, sizeof(entry)); if (dictionaryIndex >= 0) { - return fPixelRefDictionary[dictionaryIndex].fIndex; + return fBitmapIndexCache[dictionaryIndex].fIndex; } } @@ -671,7 +667,7 @@ int SkPictureRecord::find(const SkBitmap& bitmap) { if (flattenPixels) { entry.fIndex = index; dictionaryIndex = ~dictionaryIndex; - *fPixelRefDictionary.insert(dictionaryIndex) = entry; + *fBitmapIndexCache.insert(dictionaryIndex) = entry; } return index; } diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h index 23d0828b97..3dda39bfa9 100644 --- a/src/core/SkPictureRecord.h +++ b/src/core/SkPictureRecord.h @@ -96,18 +96,30 @@ public: return fWriter; } - bool shouldFlattenPixels(const SkBitmap&) const; - void endRecording(); private: - struct PixelRefDictionaryEntry { - uint32_t fKey; // SkPixelRef GenerationID. + struct BitmapIndexCacheEntry { + uint32_t fGenerationId; // SkPixelRef GenerationID. + size_t fPixelOffset; + uint32_t fWidth; + uint32_t fHeight; uint32_t fIndex; // Index of corresponding flattened bitmap in fBitmaps. - bool operator < (const PixelRefDictionaryEntry& other) const { - return this->fKey < other.fKey; + bool operator < (const BitmapIndexCacheEntry& other) const { + if (this->fGenerationId != other.fGenerationId) { + return this->fGenerationId < other.fGenerationId; + } else if(this->fPixelOffset != other.fPixelOffset) { + return this->fPixelOffset < other.fPixelOffset; + } else if(this->fWidth != other.fWidth) { + return this->fWidth < other.fWidth; + } else { + return this->fHeight < other.fHeight; + } } - bool operator != (const PixelRefDictionaryEntry& other) const { - return this->fKey != other.fKey; + bool operator != (const BitmapIndexCacheEntry& other) const { + return this->fGenerationId != other.fGenerationId + || this->fPixelOffset != other.fPixelOffset + || this->fWidth != other.fWidth + || this->fHeight != other.fHeight; } }; @@ -192,7 +204,7 @@ private: SkRefCntSet fRCSet; SkRefCntSet fTFSet; - SkTDArray<PixelRefDictionaryEntry> fPixelRefDictionary; + SkTDArray<BitmapIndexCacheEntry> fBitmapIndexCache; SkBitmapDictionary fBitmaps; SkMatrixDictionary fMatrices; SkPaintDictionary fPaints; diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp index c5a21831d4..47e551ef5d 100644 --- a/src/utils/SkDeferredCanvas.cpp +++ b/src/utils/SkDeferredCanvas.cpp @@ -576,8 +576,7 @@ void SkDeferredCanvas::DeferredDevice::beginRecording() { fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0); #else fRecordingCanvas = fPicture.beginRecording(fImmediateDevice->width(), - fImmediateDevice->height(), - SkPicture::kFlattenMutableNonTexturePixelRefs_RecordingFlag); + fImmediateDevice->height()); #endif } |