Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: src/core/SkPixelRef.cpp

Issue 68973005: Expand pixelref to return SkImageInfo and rowbytes (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: add SK_SUPPORT_LEGACY_ONLOCKPIXELS so we can land in stages for Chrome Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkPixelRef.cpp
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp
index 972474ccc3357f301bda62da187def8f8b7c5db9..caae23f17147e4720177ca91594b222559a8484a 100644
--- a/src/core/SkPixelRef.cpp
+++ b/src/core/SkPixelRef.cpp
@@ -75,6 +75,16 @@ int32_t SkNextPixelRefGenerationID() {
///////////////////////////////////////////////////////////////////////////////
+static void mark_invalid(SkImageInfo* info) {
+ info->fWidth = -1;
+}
+
+static bool is_invalid(const SkImageInfo& info) {
+ return info.fWidth < 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
void SkPixelRef::setMutex(SkBaseMutex* mutex) {
if (NULL == mutex) {
mutex = get_default_mutex();
@@ -87,8 +97,8 @@ void SkPixelRef::setMutex(SkBaseMutex* mutex) {
SkPixelRef::SkPixelRef(SkBaseMutex* mutex) {
this->setMutex(mutex);
- fPixels = NULL;
- fColorTable = NULL; // we do not track ownership of this
+ mark_invalid(&fInfo);
+ fRec.zero();
fLockCount = 0;
this->needsNewGenID();
fIsImmutable = false;
@@ -98,8 +108,8 @@ SkPixelRef::SkPixelRef(SkBaseMutex* mutex) {
SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex)
: INHERITED(buffer) {
this->setMutex(mutex);
- fPixels = NULL;
- fColorTable = NULL; // we do not track ownership of this
+ mark_invalid(&fInfo);
+ fRec.zero();
fLockCount = 0;
fIsImmutable = buffer.readBool();
fGenerationID = buffer.readUInt();
@@ -123,12 +133,15 @@ void SkPixelRef::cloneGenID(const SkPixelRef& that) {
that.fUniqueGenerationID = false;
}
-void SkPixelRef::setPreLocked(void* pixels, SkColorTable* ctable) {
+void SkPixelRef::setPreLocked(const SkImageInfo& info, 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;
+ fInfo = info;
+ fRec.fPixels = pixels;
+ fRec.fColorTable = ctable;
+ fRec.fRowBytes = rowBytes;
fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT;
fPreLocked = true;
#endif
@@ -150,16 +163,49 @@ void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
}
}
-void SkPixelRef::lockPixels() {
- SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
+bool SkPixelRef::getInfo(SkImageInfo* info) {
+#ifdef SK_DEBUG
+ if (fPreLocked) {
+ SkASSERT(!is_invalid(fInfo));
scroggo 2013/12/04 22:47:38 This seems redundant.
reed1 2013/12/05 13:32:39 I don't think we assert elsewhere that prelocked m
scroggo 2013/12/05 13:45:34 Not directly, but just below this we assert that i
+ }
+#endif
+
+ if (is_invalid(fInfo)) {
+ SkASSERT(!fPreLocked);
- if (!fPreLocked) {
SkAutoMutexAcquire ac(*fMutex);
+
+ SkImageInfo tmpInfo;
scroggo 2013/12/04 22:47:38 This one is just in case the implementation of onG
reed1 2013/12/05 13:32:39 Exactly. Also, we are experimenting with making t
+ if (!this->onGetInfo(&tmpInfo)) {
+ return false;
+ }
+ fInfo = tmpInfo;
+ }
+ *info = fInfo;
+ return true;
+}
+bool SkPixelRef::lockPixels(LockRec* rec) {
+ SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
+
+ if (!fPreLocked) {
+ SkAutoMutexAcquire ac(*fMutex);
+
if (1 == ++fLockCount) {
- fPixels = this->onLockPixels(&fColorTable);
+ LockRec rec;
+ if (!this->onNewLockPixels(&rec)) {
+ return false;
+ }
+ fRec = rec;
}
}
+ *rec = fRec;
+ return true;
+}
+
+void SkPixelRef::lockPixels() {
+ LockRec rec;
+ (void)this->lockPixels(&rec);
}
void SkPixelRef::unlockPixels() {
@@ -171,8 +217,7 @@ void SkPixelRef::unlockPixels() {
SkASSERT(fLockCount > 0);
if (0 == --fLockCount) {
this->onUnlockPixels();
- fPixels = NULL;
- fColorTable = NULL;
+ fRec.zero();
}
}
}
@@ -249,6 +294,33 @@ SkData* SkPixelRef::onRefEncodedData() {
///////////////////////////////////////////////////////////////////////////////
+#ifdef SK_SUPPORT_LEGACY_ONLOCKPIXELS
+
+void* SkPixelRef::onLockPixels(SkColorTable** ctable) {
+ return NULL;
+}
+
+bool SkPixelRef::onGetInfo(SkImageInfo* info) {
+ return false;
+}
+
+bool SkPixelRef::onNewLockPixels(LockRec* rec) {
+ SkColorTable* ctable;
+ 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();

Powered by Google App Engine
This is Rietveld 408576698