Index: src/core/SkPixelRef.cpp |
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp |
index 20a8b34f067ff7eafc35759cb96b1b94de475a56..a1ea92382eee533dc66244ae248f274ea6491858 100644 |
--- a/src/core/SkPixelRef.cpp |
+++ b/src/core/SkPixelRef.cpp |
@@ -152,27 +152,33 @@ void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctabl |
#endif |
} |
+bool SkPixelRef::lockPixelsInsideMutex(LockRec* rec) { |
scroggo
2015/05/19 20:11:42
fMutex->assertHeld();
reed1
2015/05/21 20:59:35
Done.
|
+ if (1 == ++fLockCount) { |
+ 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) { |
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"); |
- |
- if (1 == ++fLockCount) { |
- SkASSERT(fRec.isZero()); |
- |
- LockRec rec; |
- if (!this->onNewLockPixels(&rec)) { |
- return false; |
- } |
- SkASSERT(!rec.isZero()); // else why did onNewLock return true? |
- fRec = rec; |
- } |
+ return this->lockPixelsInsideMutex(rec); |
} |
- *rec = fRec; |
- return true; |
} |
bool SkPixelRef::lockPixels() { |
@@ -199,6 +205,26 @@ void SkPixelRef::unlockPixels() { |
} |
} |
+bool SkPixelRef::requestLock(const LockRequest& request, LockResult* result) { |
+ SkASSERT(result); |
+ if (request.fSize.isEmpty()) { |
+ return false; |
+ } |
+ |
+ if (fPreLocked) { |
+ result->fUnlockProc = NULL; |
+ result->fUnlockContext = NULL; |
+ result->fCTable = fRec.fColorTable; |
+ result->fPixels = fRec.fPixels; |
+ result->fRowBytes = fRec.fRowBytes; |
+ result->fSize.set(fInfo.width(), fInfo.height()); |
+ return true; |
+ } else { |
+ SkAutoMutexAcquire ac(*fMutex); |
+ return this->onRequestLock(request, result); |
+ } |
+} |
+ |
bool SkPixelRef::lockPixelsAreWritable() const { |
return this->onLockPixelsAreWritable(); |
} |
@@ -271,6 +297,8 @@ bool SkPixelRef::readPixels(SkBitmap* dst, const SkIRect* subset) { |
return this->onReadPixels(dst, subset); |
} |
+/////////////////////////////////////////////////////////////////////////////////////////////////// |
+ |
bool SkPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { |
return false; |
} |
@@ -288,3 +316,22 @@ size_t SkPixelRef::getAllocatedSizeInBytes() const { |
return 0; |
} |
+static void unlock_legacy_result(void* ctx) { |
+ SkPixelRef* pr = (SkPixelRef*)ctx; |
+ pr->unlockPixels(); |
+} |
+ |
+bool SkPixelRef::onRequestLock(const LockRequest& request, LockResult* result) { |
+ LockRec rec; |
+ if (!this->lockPixelsInsideMutex(&rec)) { |
+ return false; |
+ } |
+ |
+ result->fUnlockProc = unlock_legacy_result; |
+ result->fUnlockContext = SkRef(this); |
+ result->fCTable = rec.fColorTable; |
+ result->fPixels = rec.fPixels; |
+ result->fRowBytes = rec.fRowBytes; |
+ result->fSize.set(fInfo.width(), fInfo.height()); |
+ return true; |
+} |