Index: src/lazy/SkDiscardablePixelRef.cpp |
diff --git a/src/lazy/SkDiscardablePixelRef.cpp b/src/lazy/SkDiscardablePixelRef.cpp |
index 50988587a7c1030cf3fd56727e104011f31b4870..b6dec1b3a1129b85ccccbb65edf50255bdc1bad3 100644 |
--- a/src/lazy/SkDiscardablePixelRef.cpp |
+++ b/src/lazy/SkDiscardablePixelRef.cpp |
@@ -18,6 +18,7 @@ SkDiscardablePixelRef::SkDiscardablePixelRef(const SkImageInfo& info, |
, fDMFactory(fact) |
, fRowBytes(rowBytes) |
, fDiscardableMemory(NULL) |
+ , fDiscardableMemoryIsLocked(false) |
{ |
SkASSERT(fGenerator != NULL); |
SkASSERT(fRowBytes > 0); |
@@ -28,8 +29,9 @@ SkDiscardablePixelRef::SkDiscardablePixelRef(const SkImageInfo& info, |
} |
SkDiscardablePixelRef::~SkDiscardablePixelRef() { |
- if (this->isLocked()) { |
+ if (fDiscardableMemoryIsLocked) { |
fDiscardableMemory->unlock(); |
+ fDiscardableMemoryIsLocked = false; |
} |
SkDELETE(fDiscardableMemory); |
SkSafeUnref(fDMFactory); |
@@ -39,6 +41,7 @@ SkDiscardablePixelRef::~SkDiscardablePixelRef() { |
bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) { |
if (fDiscardableMemory != NULL) { |
if (fDiscardableMemory->lock()) { |
+ fDiscardableMemoryIsLocked = true; |
rec->fPixels = fDiscardableMemory->data(); |
rec->fColorTable = fCTable.get(); |
rec->fRowBytes = fRowBytes; |
@@ -46,16 +49,20 @@ bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) { |
} |
SkDELETE(fDiscardableMemory); |
fDiscardableMemory = NULL; |
+ fDiscardableMemoryIsLocked = false; |
} |
const size_t size = this->info().getSafeSize(fRowBytes); |
if (fDMFactory != NULL) { |
fDiscardableMemory = fDMFactory->create(size); |
+ fDiscardableMemoryIsLocked = true; |
} else { |
fDiscardableMemory = SkDiscardableMemory::Create(size); |
+ fDiscardableMemoryIsLocked = true; |
} |
if (NULL == fDiscardableMemory) { |
+ fDiscardableMemoryIsLocked = false; |
return false; // Memory allocation failed. |
} |
@@ -72,6 +79,7 @@ bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) { |
break; |
default: |
fDiscardableMemory->unlock(); |
+ fDiscardableMemoryIsLocked = false; |
SkDELETE(fDiscardableMemory); |
fDiscardableMemory = NULL; |
return false; |
@@ -96,6 +104,7 @@ bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) { |
void SkDiscardablePixelRef::onUnlockPixels() { |
fDiscardableMemory->unlock(); |
+ fDiscardableMemoryIsLocked = false; |
} |
bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst, |