Index: src/core/SkPixelRef.cpp |
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp |
index 1fda14b0258ad99609571e179896e15dbc2b4544..90e2a40ea4fb92513d4ba351a366ec330ba2b207 100644 |
--- a/src/core/SkPixelRef.cpp |
+++ b/src/core/SkPixelRef.cpp |
@@ -160,18 +160,8 @@ |
SkASSERT(!that. genIDIsUnique()); |
} |
-static void validate_pixels_ctable(const void* pixels, const SkColorTable* ctable, SkColorType ct) { |
- SkASSERT(pixels); |
- if (kIndex_8_SkColorType == ct) { |
- SkASSERT(ctable); |
- } else { |
- SkASSERT(NULL == ctable); |
- } |
-} |
- |
void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctable) { |
#ifndef SK_IGNORE_PIXELREF_SETPRELOCKED |
- validate_pixels_ctable(pixels, ctable, fInfo.colorType()); |
// only call me in your constructor, otherwise fLockCount tracking can get |
// out of sync. |
fRec.fPixels = pixels; |
@@ -182,33 +172,38 @@ |
#endif |
} |
-// Increments fLockCount only on success |
-bool SkPixelRef::lockPixelsInsideMutex() { |
+bool SkPixelRef::lockPixelsInsideMutex(LockRec* rec) { |
fMutex->assertHeld(); |
+ // For historical reasons, we always inc fLockCount, even if we return false. |
+ // It would be nice to change this (it seems), and only inc if we actually succeed... |
if (1 == ++fLockCount) { |
SkASSERT(fRec.isZero()); |
- if (!this->onNewLockPixels(&fRec)) { |
- fRec.zero(); |
+ |
+ LockRec rec; |
+ if (!this->onNewLockPixels(&rec)) { |
fLockCount -= 1; // we return fLockCount unchanged if we fail. |
return false; |
} |
- } |
- validate_pixels_ctable(fRec.fPixels, fRec.fColorTable, fInfo.colorType()); |
+ SkASSERT(!rec.isZero()); // else why did onNewLock return true? |
+ fRec = rec; |
+ } |
+ *rec = fRec; |
return true; |
} |
-// For historical reasons, we always inc fLockCount, even if we return false. |
-// It would be nice to change this (it seems), and only inc if we actually succeed... |
-bool SkPixelRef::lockPixels() { |
+bool SkPixelRef::lockPixels(LockRec* rec) { |
SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); |
- if (!fPreLocked) { |
+ if (fPreLocked) { |
+ *rec = fRec; |
+ return true; |
+ } else { |
TRACE_EVENT_BEGIN0("skia", "SkPixelRef::lockPixelsMutex"); |
SkAutoMutexAcquire ac(*fMutex); |
TRACE_EVENT_END0("skia", "SkPixelRef::lockPixelsMutex"); |
SkDEBUGCODE(int oldCount = fLockCount;) |
- bool success = this->lockPixelsInsideMutex(); |
+ bool success = this->lockPixelsInsideMutex(rec); |
// lockPixelsInsideMutex only increments the count if it succeeds. |
SkASSERT(oldCount + (int)success == fLockCount); |
@@ -216,19 +211,14 @@ |
// For compatibility with SkBitmap calling lockPixels, we still want to increment |
// fLockCount even if we failed. If we updated SkBitmap we could remove this oddity. |
fLockCount += 1; |
- return false; |
- } |
- } |
- validate_pixels_ctable(fRec.fPixels, fRec.fColorTable, fInfo.colorType()); |
- return true; |
-} |
- |
-bool SkPixelRef::lockPixels(LockRec* rec) { |
- if (this->lockPixels()) { |
- *rec = fRec; |
- return true; |
- } |
- return false; |
+ } |
+ return success; |
+ } |
+} |
+ |
+bool SkPixelRef::lockPixels() { |
+ LockRec rec; |
+ return this->lockPixels(&rec); |
} |
void SkPixelRef::unlockPixels() { |
@@ -263,14 +253,11 @@ |
result->fPixels = fRec.fPixels; |
result->fRowBytes = fRec.fRowBytes; |
result->fSize.set(fInfo.width(), fInfo.height()); |
+ return true; |
} else { |
SkAutoMutexAcquire ac(*fMutex); |
- if (!this->onRequestLock(request, result)) { |
- return false; |
- } |
- } |
- validate_pixels_ctable(result->fPixels, result->fCTable, fInfo.colorType()); |
- return true; |
+ return this->onRequestLock(request, result); |
+ } |
} |
bool SkPixelRef::lockPixelsAreWritable() const { |
@@ -371,15 +358,16 @@ |
} |
bool SkPixelRef::onRequestLock(const LockRequest& request, LockResult* result) { |
- if (!this->lockPixelsInsideMutex()) { |
+ LockRec rec; |
+ if (!this->lockPixelsInsideMutex(&rec)) { |
return false; |
} |
result->fUnlockProc = unlock_legacy_result; |
result->fUnlockContext = SkRef(this); // this is balanced in our fUnlockProc |
- result->fCTable = fRec.fColorTable; |
- result->fPixels = fRec.fPixels; |
- result->fRowBytes = fRec.fRowBytes; |
+ result->fCTable = rec.fColorTable; |
+ result->fPixels = rec.fPixels; |
+ result->fRowBytes = rec.fRowBytes; |
result->fSize.set(fInfo.width(), fInfo.height()); |
return true; |
} |