aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-03 16:22:48 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-03 16:22:48 +0000
commitf1ce05288a8fee6e691c3dff5db9dcd47818060f (patch)
tree935a2efe666716d19521786d0950a40153496842 /include
parent0bf919c89a5cd8d1779cdbd5d17536c2fbf534c8 (diff)
Add onNewLockPixels, that returns rowbytes and relies on info in pixelref
This reverts commit 890a6ec633c1f54891104a072a8964b4c2c81af9. BUG= R=scroggo@google.com Review URL: https://codereview.chromium.org/110593003 git-svn-id: http://skia.googlecode.com/svn/trunk@12883 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r--include/core/SkBitmapDevice.h2
-rw-r--r--include/core/SkMallocPixelRef.h10
-rw-r--r--include/core/SkPixelRef.h73
-rw-r--r--include/gpu/SkGrPixelRef.h7
-rw-r--r--include/images/SkImageRef.h4
5 files changed, 66 insertions, 30 deletions
diff --git a/include/core/SkBitmapDevice.h b/include/core/SkBitmapDevice.h
index 83f480c60c..f3d40d0ce8 100644
--- a/include/core/SkBitmapDevice.h
+++ b/include/core/SkBitmapDevice.h
@@ -258,6 +258,8 @@ private:
friend class SkSurface_Raster;
+ void init(SkBitmap::Config config, int width, int height, bool isOpaque);
+
// used to change the backend's pixels (and possibly config/rowbytes)
// but cannot change the width/height, so there should be no change to
// any clip information.
diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h
index 272dc21fd8..c40afc433a 100644
--- a/include/core/SkMallocPixelRef.h
+++ b/include/core/SkMallocPixelRef.h
@@ -32,11 +32,9 @@ public:
/**
* Return a new SkMallocPixelRef, automatically allocating storage for the
- * pixels.
- *
- * If rowBytes is 0, an optimal value will be chosen automatically.
- * If rowBytes is > 0, then it will be used, unless it is invald for the
- * specified info, in which case NULL will be returned (failure).
+ * pixels. If rowBytes are 0, an optimal value will be chosen automatically.
+ * If rowBytes is > 0, then it will be respected, or NULL will be returned
+ * if rowBytes is invalid for the specified info.
*
* This pixelref will ref() the specified colortable (if not NULL).
*
@@ -90,7 +88,7 @@ protected:
SkMallocPixelRef(SkFlattenableReadBuffer& buffer);
virtual ~SkMallocPixelRef();
- virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE;
+ virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
virtual void onUnlockPixels() SK_OVERRIDE;
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE;
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
index e611dc0ef8..a332b76a5d 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -14,8 +14,11 @@
#include "SkRefCnt.h"
#include "SkString.h"
#include "SkFlattenable.h"
+#include "SkImageInfo.h"
#include "SkTDArray.h"
+//#define SK_SUPPORT_LEGACY_ONLOCKPIXELS
+
#ifdef SK_DEBUG
/**
* Defining SK_IGNORE_PIXELREF_SETPRELOCKED will force all pixelref
@@ -60,23 +63,48 @@ public:
/** Return the pixel memory returned from lockPixels, or null if the
lockCount is 0.
*/
- void* pixels() const { return fPixels; }
+ void* pixels() const { return fRec.fPixels; }
/** Return the current colorTable (if any) if pixels are locked, or null.
*/
- SkColorTable* colorTable() const { return fColorTable; }
+ SkColorTable* colorTable() const { return fRec.fColorTable; }
/**
+ * To access the actual pixels of a pixelref, it must be "locked".
+ * Calling lockPixels returns a LockRec struct (on success).
+ */
+ struct LockRec {
+ void* fPixels;
+ SkColorTable* fColorTable;
+ size_t fRowBytes;
+
+ void zero() { sk_bzero(this, sizeof(*this)); }
+
+ bool isZero() const {
+ return NULL == fPixels && NULL == fColorTable && 0 == fRowBytes;
+ }
+ };
+
+ /**
* Returns true if the lockcount > 0
*/
bool isLocked() const { return fLockCount > 0; }
SkDEBUGCODE(int getLockCount() const { return fLockCount; })
- /** Call to access the pixel memory, which is returned. Balance with a call
- to unlockPixels().
- */
- void lockPixels();
+ /**
+ * Call to access the pixel memory. Return true on success. Balance this
+ * with a call to unlockPixels().
+ */
+ bool lockPixels();
+
+ /**
+ * Call to access the pixel memory. On success, return true and fill out
+ * the specified rec. On failure, return false and ignore the rec parameter.
+ * Balance this with a call to unlockPixels().
+ */
+ bool lockPixels(LockRec* rec);
+
/** Call to balanace a previous call to lockPixels(). Returns the pixels
(or null) after the unlock. NOTE: lock calls can be nested, but the
matching number of unlock calls must be made in order to free the
@@ -233,18 +261,27 @@ public:
void addGenIDChangeListener(GenIDChangeListener* listener);
protected:
- /** Called when the lockCount goes from 0 to 1. The caller will have already
- acquire a mutex for thread safety, so this method need not do that.
- */
- virtual void* onLockPixels(SkColorTable**) = 0;
+#ifdef SK_SUPPORT_LEGACY_ONLOCKPIXELS
+ virtual void* onLockPixels(SkColorTable**);
+ virtual bool onNewLockPixels(LockRec*);
+#else
+ /**
+ * On success, returns true and fills out the LockRec for the pixels. On
+ * failure returns false and ignores the LockRec parameter.
+ *
+ * The caller will have already acquired a mutex for thread safety, so this
+ * method need not do that.
+ */
+ virtual bool onNewLockPixels(LockRec*) = 0;
+#endif
/**
- * Called when the lock count goes from 1 to 0. The caller will have
- * already acquire a mutex for thread safety, so this method need not do
- * that.
+ * Balancing the previous successful call to onNewLockPixels. The locked
+ * pixel address will no longer be referenced, so the subclass is free to
+ * move or discard that memory.
*
- * If the previous call to onLockPixels failed (i.e. returned NULL), then
- * the onUnlockPixels will NOT be called.
+ * The caller will have already acquired a mutex for thread safety, so this
+ * method need not do that.
*/
virtual void onUnlockPixels() = 0;
@@ -289,15 +326,15 @@ protected:
// only call from constructor. Flags this to always be locked, removing
// the need to grab the mutex and call onLockPixels/onUnlockPixels.
// Performance tweak to avoid those calls (esp. in multi-thread use case).
- void setPreLocked(void* pixels, SkColorTable* ctable);
+ void setPreLocked(void*, size_t rowBytes, SkColorTable*);
private:
SkBaseMutex* fMutex; // must remain in scope for the life of this object
const SkImageInfo fInfo;
- void* fPixels;
- SkColorTable* fColorTable; // we do not track ownership, subclass does
+ // LockRec is only valid if we're in a locked state (isLocked())
+ LockRec fRec;
int fLockCount;
mutable uint32_t fGenerationID;
diff --git a/include/gpu/SkGrPixelRef.h b/include/gpu/SkGrPixelRef.h
index d8933724fb..63e975673f 100644
--- a/include/gpu/SkGrPixelRef.h
+++ b/include/gpu/SkGrPixelRef.h
@@ -24,10 +24,9 @@ public:
virtual ~SkROLockPixelsPixelRef();
protected:
- // override from SkPixelRef
- virtual void* onLockPixels(SkColorTable** ptr);
- virtual void onUnlockPixels();
- virtual bool onLockPixelsAreWritable() const; // return false;
+ virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
+ virtual void onUnlockPixels() SK_OVERRIDE;
+ virtual bool onLockPixelsAreWritable() const SK_OVERRIDE; // return false;
private:
SkBitmap fBitmap;
diff --git a/include/images/SkImageRef.h b/include/images/SkImageRef.h
index 30b1562c98..36f95e64b2 100644
--- a/include/images/SkImageRef.h
+++ b/include/images/SkImageRef.h
@@ -72,9 +72,9 @@ protected:
When these are called, we will have already acquired the mutex!
*/
- virtual void* onLockPixels(SkColorTable**);
+ virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
// override this in your subclass to clean up when we're unlocking pixels
- virtual void onUnlockPixels() {}
+ virtual void onUnlockPixels() SK_OVERRIDE {}
SkImageRef(SkFlattenableReadBuffer&, SkBaseMutex* mutex = NULL);
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;