Index: src/core/SkPixelRef.cpp |
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp |
index 8bf1f4eddf27d322fb51cbd7ba65f432846ffb67..10e1309c0b1af377268a0bdb30f4de2f9b61dee3 100644 |
--- a/src/core/SkPixelRef.cpp |
+++ b/src/core/SkPixelRef.cpp |
@@ -82,20 +82,19 @@ void SkPixelRef::setMutex(SkBaseMutex* mutex) { |
// just need a > 0 value, so pick a funny one to aid in debugging |
#define SKPIXELREF_PRELOCKED_LOCKCOUNT 123456789 |
-SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) : fInfo(info) { |
- this->setMutex(mutex); |
- fPixels = NULL; |
- fColorTable = NULL; // we do not track ownership of this |
+SkPixelRef::SkPixelRef(const SkImageInfo& info) : fInfo(info) { |
+ this->setMutex(NULL); |
+ fRec.zero(); |
fLockCount = 0; |
this->needsNewGenID(); |
fIsImmutable = false; |
fPreLocked = false; |
} |
-SkPixelRef::SkPixelRef(const SkImageInfo& info) : fInfo(info) { |
- this->setMutex(NULL); |
- fPixels = NULL; |
- fColorTable = NULL; // we do not track ownership of this |
+ |
+SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) : fInfo(info) { |
+ this->setMutex(mutex); |
+ fRec.zero(); |
fLockCount = 0; |
this->needsNewGenID(); |
fIsImmutable = false; |
@@ -113,8 +112,7 @@ SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex) |
, fInfo(read_info(buffer)) |
{ |
this->setMutex(mutex); |
- fPixels = NULL; |
- fColorTable = NULL; // we do not track ownership of this |
+ fRec.zero(); |
fLockCount = 0; |
fIsImmutable = buffer.readBool(); |
fGenerationID = buffer.readUInt(); |
@@ -138,13 +136,13 @@ void SkPixelRef::cloneGenID(const SkPixelRef& that) { |
that.fUniqueGenerationID = false; |
} |
-// rowBytes will be respected when we land the onNewLockPixels CL |
void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctable) { |
#ifndef SK_IGNORE_PIXELREF_SETPRELOCKED |
// only call me in your constructor, otherwise fLockCount tracking can get |
// out of sync. |
- fPixels = pixels; |
- fColorTable = ctable; |
+ fRec.fPixels = pixels; |
+ fRec.fColorTable = ctable; |
+ fRec.fRowBytes = rowBytes; |
fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT; |
fPreLocked = true; |
#endif |
@@ -167,20 +165,30 @@ void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { |
} |
} |
-void SkPixelRef::lockPixels() { |
+bool SkPixelRef::lockPixels(LockRec* rec) { |
SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); |
if (!fPreLocked) { |
SkAutoMutexAcquire ac(*fMutex); |
if (1 == ++fLockCount) { |
- fPixels = this->onLockPixels(&fColorTable); |
- // If onLockPixels failed, it will return NULL |
- if (NULL == fPixels) { |
- fColorTable = NULL; |
+ SkASSERT(fRec.isZero()); |
+ |
+ LockRec rec; |
+ if (!this->onNewLockPixels(&rec)) { |
+ return false; |
} |
+ SkASSERT(!rec.isZero()); // else why did onNewLock return true? |
+ fRec = rec; |
} |
} |
+ *rec = fRec; |
+ return true; |
+} |
+ |
+bool SkPixelRef::lockPixels() { |
+ LockRec rec; |
+ return this->lockPixels(&rec); |
} |
void SkPixelRef::unlockPixels() { |
@@ -192,12 +200,11 @@ void SkPixelRef::unlockPixels() { |
SkASSERT(fLockCount > 0); |
if (0 == --fLockCount) { |
// don't call onUnlockPixels unless onLockPixels succeeded |
- if (fPixels) { |
+ if (fRec.fPixels) { |
this->onUnlockPixels(); |
- fPixels = NULL; |
- fColorTable = NULL; |
+ fRec.zero(); |
} else { |
- SkASSERT(NULL == fColorTable); |
+ SkASSERT(fRec.isZero()); |
} |
} |
} |
@@ -279,6 +286,29 @@ size_t SkPixelRef::getAllocatedSizeInBytes() const { |
/////////////////////////////////////////////////////////////////////////////// |
+#ifdef SK_SUPPORT_LEGACY_ONLOCKPIXELS |
+ |
+void* SkPixelRef::onLockPixels(SkColorTable** ctable) { |
+ return NULL; |
+} |
+ |
+bool SkPixelRef::onNewLockPixels(LockRec* rec) { |
+ SkColorTable* ctable = NULL; // for legacy clients who forget to set this |
+ void* pixels = this->onLockPixels(&ctable); |
+ if (!pixels) { |
+ return false; |
+ } |
+ |
+ rec->fPixels = pixels; |
+ rec->fColorTable = ctable; |
+ rec->fRowBytes = 0; // callers don't currently need this (thank goodness) |
+ return true; |
+} |
+ |
+#endif |
+ |
+/////////////////////////////////////////////////////////////////////////////// |
+ |
#ifdef SK_BUILD_FOR_ANDROID |
void SkPixelRef::globalRef(void* data) { |
this->ref(); |