diff options
Diffstat (limited to 'src/lazy')
-rw-r--r-- | src/lazy/SkCachingPixelRef.cpp | 19 | ||||
-rw-r--r-- | src/lazy/SkCachingPixelRef.h | 2 | ||||
-rw-r--r-- | src/lazy/SkDiscardablePixelRef.cpp | 21 | ||||
-rw-r--r-- | src/lazy/SkDiscardablePixelRef.h | 6 |
4 files changed, 32 insertions, 16 deletions
diff --git a/src/lazy/SkCachingPixelRef.cpp b/src/lazy/SkCachingPixelRef.cpp index fb30d051e1..033a6b5ebb 100644 --- a/src/lazy/SkCachingPixelRef.cpp +++ b/src/lazy/SkCachingPixelRef.cpp @@ -8,7 +8,6 @@ #include "SkCachingPixelRef.h" #include "SkScaledImageCache.h" - bool SkCachingPixelRef::Install(SkImageGenerator* generator, SkBitmap* dst) { SkImageInfo info; @@ -41,12 +40,12 @@ SkCachingPixelRef::~SkCachingPixelRef() { // Assert always unlock before unref. } -void* SkCachingPixelRef::onLockPixels(SkColorTable**) { - const SkImageInfo& info = this->info(); - +bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) { if (fErrorInDecoding) { - return NULL; // don't try again. + return false; // don't try again. } + + const SkImageInfo& info = this->info(); SkBitmap bitmap; SkASSERT(NULL == fScaledCacheId); fScaledCacheId = SkScaledImageCache::FindAndLock(this->getGenerationID(), @@ -57,12 +56,12 @@ void* SkCachingPixelRef::onLockPixels(SkColorTable**) { // Cache has been purged, must re-decode. if ((!bitmap.setConfig(info, fRowBytes)) || !bitmap.allocPixels()) { fErrorInDecoding = true; - return NULL; + return false; } SkAutoLockPixels autoLockPixels(bitmap); if (!fImageGenerator->getPixels(info, bitmap.getPixels(), fRowBytes)) { fErrorInDecoding = true; - return NULL; + return false; } fScaledCacheId = SkScaledImageCache::AddAndLock(this->getGenerationID(), info.fWidth, @@ -76,6 +75,7 @@ void* SkCachingPixelRef::onLockPixels(SkColorTable**) { 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 @@ -84,7 +84,10 @@ void* SkCachingPixelRef::onLockPixels(SkColorTable**) { // 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() { diff --git a/src/lazy/SkCachingPixelRef.h b/src/lazy/SkCachingPixelRef.h index b1f2fcd669..905ee9bf0d 100644 --- a/src/lazy/SkCachingPixelRef.h +++ b/src/lazy/SkCachingPixelRef.h @@ -40,7 +40,7 @@ public: protected: virtual ~SkCachingPixelRef(); - virtual void* onLockPixels(SkColorTable** colorTable) SK_OVERRIDE; + virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE; virtual void onUnlockPixels() SK_OVERRIDE; virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } diff --git a/src/lazy/SkDiscardablePixelRef.cpp b/src/lazy/SkDiscardablePixelRef.cpp index 2886156102..3f960d3c47 100644 --- a/src/lazy/SkDiscardablePixelRef.cpp +++ b/src/lazy/SkDiscardablePixelRef.cpp @@ -36,15 +36,18 @@ SkDiscardablePixelRef::~SkDiscardablePixelRef() { SkDELETE(fGenerator); } -void* SkDiscardablePixelRef::onLockPixels(SkColorTable**) { +bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) { if (fDiscardableMemory != NULL) { if (fDiscardableMemory->lock()) { - return fDiscardableMemory->data(); + rec->fPixels = fDiscardableMemory->data(); + rec->fColorTable = NULL; + rec->fRowBytes = fRowBytes; + return true; } SkDELETE(fDiscardableMemory); fDiscardableMemory = NULL; } - + const size_t size = this->info().getSafeSize(fRowBytes); if (fDMFactory != NULL) { @@ -53,17 +56,23 @@ void* SkDiscardablePixelRef::onLockPixels(SkColorTable**) { fDiscardableMemory = SkDiscardableMemory::Create(size); } if (NULL == fDiscardableMemory) { - return NULL; // Memory allocation failed. + return false; // Memory allocation failed. } + void* pixels = fDiscardableMemory->data(); if (!fGenerator->getPixels(this->info(), pixels, fRowBytes)) { fDiscardableMemory->unlock(); SkDELETE(fDiscardableMemory); fDiscardableMemory = NULL; - return NULL; + return false; } - return pixels; + + rec->fPixels = pixels; + rec->fColorTable = NULL; + rec->fRowBytes = fRowBytes; + return true; } + void SkDiscardablePixelRef::onUnlockPixels() { fDiscardableMemory->unlock(); } diff --git a/src/lazy/SkDiscardablePixelRef.h b/src/lazy/SkDiscardablePixelRef.h index 3367096c26..4a013fda03 100644 --- a/src/lazy/SkDiscardablePixelRef.h +++ b/src/lazy/SkDiscardablePixelRef.h @@ -28,7 +28,8 @@ public: protected: ~SkDiscardablePixelRef(); - virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; + + virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE; virtual void onUnlockPixels() SK_OVERRIDE; virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } @@ -49,9 +50,12 @@ private: SkDiscardablePixelRef(const SkImageInfo&, SkImageGenerator*, size_t rowBytes, SkDiscardableMemory::Factory* factory); + friend bool SkInstallDiscardablePixelRef(SkImageGenerator*, SkBitmap*, SkDiscardableMemory::Factory*); + typedef SkPixelRef INHERITED; }; + #endif // SkDiscardablePixelRef_DEFINED |