Index: include/core/SkPixelRef.h |
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h |
index d90e58719bb0b87f5bd3b5ce9b0dc4c90e056259..0ca3407b857d63a0856c8b3374d8363cb5608b93 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 |
@@ -52,14 +55,22 @@ public: |
explicit SkPixelRef(SkBaseMutex* mutex = NULL); |
virtual ~SkPixelRef(); |
+ struct LockRec { |
scroggo
2013/12/04 22:47:38
Maybe add a comment that these are unowned pointer
|
+ void* fPixels; |
+ SkColorTable* fColorTable; |
+ size_t fRowBytes; |
+ |
+ void zero() { sk_bzero(this, sizeof(*this)); } |
+ }; |
+ |
/** 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; } |
/** |
* Returns true if the lockcount > 0 |
@@ -72,6 +83,13 @@ public: |
to unlockPixels(). |
*/ |
void 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. |
+ */ |
+ 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 |
@@ -87,6 +105,12 @@ public: |
*/ |
bool lockPixelsAreWritable() const; |
+ /** |
+ * On success, return true and return the ImageInfo. On failure, return |
+ * false and ignore the ImageInfo parameter. |
+ */ |
+ bool getInfo(SkImageInfo*); |
mtklein
2013/12/04 22:46:00
Don't forget how you, Hal, and I decided we should
reed1
2013/12/05 13:32:39
Working on it
|
+ |
/** Returns a non-zero, unique value corresponding to the pixels in this |
pixelref. Each time the pixels are changed (and notifyPixelsChanged is |
called), a different generation ID will be returned. |
@@ -228,14 +252,38 @@ 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; |
- /** 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. |
- */ |
+#ifdef SK_SUPPORT_LEGACY_ONLOCKPIXELS |
+ virtual void* onLockPixels(SkColorTable**); |
+ virtual bool onGetInfo(SkImageInfo*); |
+ virtual bool onNewLockPixels(LockRec*); |
+#else |
+ /** |
+ * Return the ImageInfo, returning true on success. On failure, return |
+ * false and ignore the info parameter. |
+ * |
+ * The caller will have already acquired a mutex for thread safety, so this |
+ * method need not do that. |
+ */ |
+ virtual bool onGetInfo(SkImageInfo*) = 0; |
+ |
+ /** |
+ * 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 |
+ |
+ /** |
+ * 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. |
+ * |
+ * The caller will have already acquired a mutex for thread safety, so this |
+ * method need not do that. |
+ */ |
virtual void onUnlockPixels() = 0; |
/** Default impl returns true */ |
@@ -269,12 +317,12 @@ 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(const SkImageInfo&, void*, size_t rowBytes, SkColorTable*); |
private: |
SkBaseMutex* fMutex; // must remain in scope for the life of this object |
- void* fPixels; |
- SkColorTable* fColorTable; // we do not track ownership, subclass does |
+ SkImageInfo fInfo; |
+ LockRec fRec; |
int fLockCount; |
mutable uint32_t fGenerationID; |