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

Unified Diff: src/core/SkPixelRef.cpp

Issue 111323005: Remvoe duplicate impl for SkImageInfo flattening (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: 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
« no previous file with comments | « src/core/SkMaskFilter.cpp ('k') | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPixelRef.cpp
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp
index da88ca5c71ae6ff6bf1a3dc9ab0a1e67b641779e..5d394d56cd3cc3a61ae24a45d897da46bf7be3ba 100644
--- a/src/core/SkPixelRef.cpp
+++ b/src/core/SkPixelRef.cpp
@@ -82,48 +82,32 @@ 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) {
- this->setMutex(mutex);
- fInfo = info;
- fPixels = NULL;
- fColorTable = NULL; // we do not track ownership of this
- fLockCount = 0;
- this->needsNewGenID();
- fIsImmutable = false;
- fPreLocked = false;
-}
-
SkPixelRef::SkPixelRef(const SkImageInfo& info) {
this->setMutex(NULL);
fInfo = info;
- fPixels = NULL;
- fColorTable = NULL; // we do not track ownership of this
+ fRec.zero();
fLockCount = 0;
this->needsNewGenID();
fIsImmutable = false;
fPreLocked = false;
}
-#ifdef SK_SUPPORT_LEGACY_PIXELREF_CONSTRUCTOR
-// THIS GUY IS DEPRECATED -- don't use me!
-SkPixelRef::SkPixelRef(SkBaseMutex* mutex) {
+SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) {
this->setMutex(mutex);
- // Fill with dummy values.
- sk_bzero(&fInfo, sizeof(fInfo));
- fPixels = NULL;
- fColorTable = NULL; // we do not track ownership of this
+ fInfo = info;
+ fRec.zero();
fLockCount = 0;
this->needsNewGenID();
fIsImmutable = false;
fPreLocked = false;
}
-#endif
SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex)
: INHERITED(buffer) {
this->setMutex(mutex);
- fPixels = NULL;
- fColorTable = NULL; // we do not track ownership of this
+
+ fInfo.unflatten(buffer);
+ fRec.zero();
fLockCount = 0;
fIsImmutable = buffer.readBool();
fGenerationID = buffer.readUInt();
@@ -147,12 +131,13 @@ void SkPixelRef::cloneGenID(const SkPixelRef& that) {
that.fUniqueGenerationID = false;
}
-void SkPixelRef::setPreLocked(void* pixels, SkColorTable* ctable) {
+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
@@ -160,6 +145,8 @@ void SkPixelRef::setPreLocked(void* pixels, SkColorTable* ctable) {
void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
+
+ fInfo.flatten(buffer);
buffer.writeBool(fIsImmutable);
// We write the gen ID into the picture for within-process recording. This
// is safe since the same genID will never refer to two different sets of
@@ -174,20 +161,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() {
@@ -199,12 +196,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());
}
}
}
@@ -286,6 +282,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;
+ 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();
« no previous file with comments | « src/core/SkMaskFilter.cpp ('k') | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698