aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPictureRecord.cpp
diff options
context:
space:
mode:
authorGravatar djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-27 15:58:23 +0000
committerGravatar djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-27 15:58:23 +0000
commit7dade42e6f2e35dd27b4090fd7894322d755d4db (patch)
tree0581859868d08ff07cbf44fb0a6477b445073373 /src/core/SkPictureRecord.cpp
parent1c6d64b78b24083ee9fd7411dac8a4a7e2d03a3c (diff)
Always store pixels of mutable bitmaps when recording a SkPicture.
Prior to this CL mutable bitmaps only saved a copy of their pixels if a flag was set at recording time. That flag has been removed and the default behavior when recording a mutable bitmap is to make a copy of it's pixels. This is the only way to ensure that the pixels are not manipulated before we playback their contents. However, enabling this behavior breaks the recording of extracted bitmaps in SkPicture. This is because we currently cache bitmaps within a picture based only on their pixelRef. This results in false positive cache hit when drawing an extracted bitmap as it shares a pixelRef with its orginating bitmap. Therefore we must update the index of the bitmap cache to be both the pixelRef AND the size and offset of the bitmap using those pixels. BUG= TEST=extractbitmap.cpp Review URL: https://codereview.appspot.com/6439043 git-svn-id: http://skia.googlecode.com/svn/trunk@4809 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkPictureRecord.cpp')
-rw-r--r--src/core/SkPictureRecord.cpp26
1 files changed, 11 insertions, 15 deletions
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;
}