| Index: src/lazy/SkLazyPixelRef.cpp
|
| diff --git a/src/lazy/SkLazyPixelRef.cpp b/src/lazy/SkLazyPixelRef.cpp
|
| index c2ca041b41da71e372be13cbc9c0cc4591440046..a9943c478a2375973fde91deed2e5bf8f05218c1 100644
|
| --- a/src/lazy/SkLazyPixelRef.cpp
|
| +++ b/src/lazy/SkLazyPixelRef.cpp
|
| @@ -118,23 +118,25 @@ static void* decode_into_bitmap(SkImageInfo* info,
|
| return target.fAddr;
|
| }
|
|
|
| -void* SkLazyPixelRef::lockScaledImageCachePixels() {
|
| +bool SkLazyPixelRef::lockScaledImageCachePixels(LockRec* rec) {
|
| SkASSERT(!fErrorInDecoding);
|
| SkASSERT(NULL == fImageCache);
|
| SkBitmap bitmap;
|
| const SkImageInfo* info = this->getCachedInfo();
|
| - if (info == NULL) {
|
| - return NULL;
|
| + if (NULL == info) {
|
| + return false;
|
| }
|
| +
|
| // If this is the first time though, this is guaranteed to fail.
|
| // Maybe we should have a flag that says "don't even bother looking"
|
| fScaledCacheId = SkScaledImageCache::FindAndLock(this->getGenerationID(),
|
| info->fWidth,
|
| info->fHeight,
|
| &bitmap);
|
| + void* pixels;
|
| if (fScaledCacheId != NULL) {
|
| SkAutoLockPixels autoLockPixels(bitmap);
|
| - void* pixels = bitmap.getPixels();
|
| + pixels = bitmap.getPixels();
|
| SkASSERT(NULL != pixels);
|
| // At this point, the autoLockPixels will unlockPixels()
|
| // to remove bitmap's lock on the pixels. We will then
|
| @@ -144,12 +146,10 @@ void* SkLazyPixelRef::lockScaledImageCachePixels() {
|
| // bitmap (SkScaledImageCache::Rec.fBitmap) that holds a
|
| // reference to the concrete PixelRef while this record is
|
| // locked.
|
| - return pixels;
|
| } else {
|
| // Cache has been purged, must re-decode.
|
| - void* pixels = decode_into_bitmap(const_cast<SkImageInfo*>(info),
|
| - fDecodeProc, &fRowBytes, fData,
|
| - &bitmap);
|
| + pixels = decode_into_bitmap(const_cast<SkImageInfo*>(info), fDecodeProc,
|
| + &fRowBytes, fData, &bitmap);
|
| if (NULL == pixels) {
|
| fErrorInDecoding = true;
|
| return NULL;
|
| @@ -159,22 +159,15 @@ void* SkLazyPixelRef::lockScaledImageCachePixels() {
|
| info->fHeight,
|
| bitmap);
|
| SkASSERT(fScaledCacheId != NULL);
|
| - return pixels;
|
| }
|
| -}
|
|
|
| -void* SkLazyPixelRef::onLockPixels(SkColorTable**) {
|
| - if (fErrorInDecoding) {
|
| - return NULL;
|
| - }
|
| - if (NULL == fImageCache) {
|
| - return this->lockScaledImageCachePixels();
|
| - } else {
|
| - return this->lockImageCachePixels();
|
| - }
|
| + rec->fPixels = pixels;
|
| + rec->fColorTable = NULL;
|
| + rec->fRowBytes = bitmap.rowBytes();
|
| + return true;
|
| }
|
|
|
| -void* SkLazyPixelRef::lockImageCachePixels() {
|
| +bool SkLazyPixelRef::lockImageCachePixels(LockRec* rec) {
|
| SkASSERT(fImageCache != NULL);
|
| SkASSERT(!fErrorInDecoding);
|
| SkBitmapFactory::Target target;
|
| @@ -207,7 +200,7 @@ void* SkLazyPixelRef::lockImageCachePixels() {
|
| const SkImageInfo* info = this->getCachedInfo();
|
| if (NULL == info) {
|
| SkASSERT(SkImageCache::UNINITIALIZED_ID == fCacheId);
|
| - return NULL;
|
| + return false;
|
| }
|
| size_t bytes = ComputeMinRowBytesAndSize(*info, &target.fRowBytes);
|
| target.fAddr = fImageCache->allocAndPinCache(bytes, &fCacheId);
|
| @@ -215,7 +208,7 @@ void* SkLazyPixelRef::lockImageCachePixels() {
|
| // Space could not be allocated.
|
| // Just like the last assert, fCacheId must be UNINITIALIZED_ID.
|
| SkASSERT(SkImageCache::UNINITIALIZED_ID == fCacheId);
|
| - return NULL;
|
| + return false;
|
| }
|
| } else {
|
| // pinCache returned purged memory to which target.fAddr already points. Set
|
| @@ -234,7 +227,33 @@ void* SkLazyPixelRef::lockImageCachePixels() {
|
| }
|
| // Upon success, store fRowBytes so it can be used in case pinCache later returns purged memory.
|
| fRowBytes = target.fRowBytes;
|
| - return target.fAddr;
|
| +
|
| + rec->fPixels = target.fAddr;
|
| + rec->fColorTable = NULL;
|
| + rec->fRowBytes = target.fRowBytes;
|
| + return true;
|
| +}
|
| +
|
| +///////////////////////////////////////////////////////////////////////////////
|
| +
|
| +bool SkLazyPixelRef::onGetInfo(SkImageInfo* info) {
|
| + const SkImageInfo* cachedInfo = this->getCachedInfo();
|
| + if (NULL == cachedInfo) {
|
| + return false;
|
| + }
|
| + *info = *cachedInfo;
|
| + return true;
|
| +}
|
| +
|
| +bool SkLazyPixelRef::onNewLockPixels(LockRec* rec) {
|
| + if (fErrorInDecoding) {
|
| + return false;
|
| + }
|
| + if (NULL == fImageCache) {
|
| + return this->lockScaledImageCachePixels(rec);
|
| + } else {
|
| + return this->lockImageCachePixels(rec);
|
| + }
|
| }
|
|
|
| void SkLazyPixelRef::onUnlockPixels() {
|
|
|