Index: src/lazy/SkCachingPixelRef.cpp |
diff --git a/src/lazy/SkCachingPixelRef.cpp b/src/lazy/SkCachingPixelRef.cpp |
index d12b7cf881cffa08e403a1073cdc7b9ace06a9a8..0c0dbb4fa883eb6bea53fb7703a357e15d4633d8 100644 |
--- a/src/lazy/SkCachingPixelRef.cpp |
+++ b/src/lazy/SkCachingPixelRef.cpp |
@@ -8,49 +8,25 @@ |
#include "SkCachingPixelRef.h" |
#include "SkScaledImageCache.h" |
-SkCachingPixelRef::SkCachingPixelRef() |
- : fErrorInDecoding(false) |
- , fScaledCacheId(NULL) { |
- memset(&fInfo, 0xFF, sizeof(fInfo)); |
+SkCachingPixelRef::SkCachingPixelRef(const SkImageInfo& info) |
+ : INHERITED(info) |
+ , fScaledCacheId(NULL) |
+ , fErrorInDecoding(false) |
+{ |
} |
+ |
SkCachingPixelRef::~SkCachingPixelRef() { |
SkASSERT(NULL == fScaledCacheId); |
// Assert always unlock before unref. |
} |
-bool SkCachingPixelRef::getInfo(SkImageInfo* info) { |
- SkASSERT(info != NULL); |
- if (fErrorInDecoding) { |
- return false; // Don't try again. |
- } |
- if (fInfo.fWidth < 0) { |
- SkImageInfo tmp; |
- if (!this->onDecodeInfo(&tmp)) { |
- fErrorInDecoding = true; |
- return false; |
- } |
- SkASSERT(tmp.fWidth >= 0); |
- fInfo = tmp; |
- } |
- *info = fInfo; |
- return true; |
-} |
- |
bool SkCachingPixelRef::configure(SkBitmap* bitmap) { |
SkASSERT(bitmap != NULL); |
- SkImageInfo info; |
- if (!this->getInfo(&info)) { |
- return false; |
- } |
- return bitmap->setConfig(info, 0); |
+ return bitmap->setConfig(this->info(), 0); |
} |
-void* SkCachingPixelRef::onLockPixels(SkColorTable** colorTable) { |
- (void)colorTable; |
- SkImageInfo info; |
- if (!this->getInfo(&info)) { |
- return NULL; |
- } |
+bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) { |
+ const SkImageInfo& info = this->info(); |
SkBitmap bitmap; |
fScaledCacheId = SkScaledImageCache::FindAndLock(this->getGenerationID(), |
@@ -60,7 +36,7 @@ void* SkCachingPixelRef::onLockPixels(SkColorTable** colorTable) { |
if (NULL == fScaledCacheId) { |
// Cache has been purged, must re-decode. |
if (!this->onDecodeInto(0, &bitmap)) { |
- return NULL; |
+ return false; |
} |
fScaledCacheId = SkScaledImageCache::AddAndLock(this->getGenerationID(), |
info.fWidth, |
@@ -73,6 +49,7 @@ void* SkCachingPixelRef::onLockPixels(SkColorTable** colorTable) { |
SkAutoLockPixels autoLockPixels(bitmap); |
void* pixels = bitmap.getPixels(); |
SkASSERT(pixels != NULL); |
+ |
// At this point, the autoLockPixels will unlockPixels() |
// to remove bitmap's lock on the pixels. We will then |
// destroy bitmap. The *only* guarantee that this pointer |
@@ -81,7 +58,10 @@ void* SkCachingPixelRef::onLockPixels(SkColorTable** colorTable) { |
// bitmap (SkScaledImageCache::Rec.fBitmap) that holds a |
// reference to the concrete PixelRef while this record is |
// locked. |
- return pixels; |
+ rec->fPixels = pixels; |
+ rec->fColorTable = NULL; |
+ rec->fRowBytes = bitmap.rowBytes(); |
+ return true; |
} |
void SkCachingPixelRef::onUnlockPixels() { |
@@ -95,14 +75,13 @@ void SkCachingPixelRef::onUnlockPixels() { |
bool SkCachingPixelRef::onDecodeInto(int pow2, SkBitmap* bitmap) { |
SkASSERT(bitmap != NULL); |
SkBitmap tmp; |
- SkImageInfo info; |
+ |
// TODO(halcanary) - Enable SkCachingPixelRef to use a custom |
// allocator. `tmp.allocPixels(fAllocator, NULL)` |
if (!(this->configure(&tmp) && tmp.allocPixels())) { |
return false; |
} |
- SkAssertResult(this->getInfo(&info)); // since configure() succeeded. |
- if (!this->onDecodePixels(info, tmp.getPixels(), tmp.rowBytes())) { |
+ if (!this->onDecodePixels(tmp.getPixels(), tmp.rowBytes())) { |
fErrorInDecoding = true; |
return false; |
} |