| Index: include/core/SkPixelRef.h
|
| diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
|
| index d90e58719bb0b87f5bd3b5ce9b0dc4c90e056259..7a3fd302b887ee24122090362fb880c345fdf9af 100644
|
| --- a/include/core/SkPixelRef.h
|
| +++ b/include/core/SkPixelRef.h
|
| @@ -14,6 +14,7 @@
|
| #include "SkRefCnt.h"
|
| #include "SkString.h"
|
| #include "SkFlattenable.h"
|
| +#include "SkImageInfo.h"
|
| #include "SkTDArray.h"
|
|
|
| #ifdef SK_DEBUG
|
| @@ -52,14 +53,27 @@ public:
|
| explicit SkPixelRef(SkBaseMutex* mutex = NULL);
|
| virtual ~SkPixelRef();
|
|
|
| + struct LockRec {
|
| + void* fPixels;
|
| + SkColorTable* fColorTable;
|
| + size_t fRowBytes;
|
| +
|
| + void zero() { sk_bzero(this, sizeof(*this)); }
|
| + };
|
| +
|
| + /**
|
| + * Return the data's rowbytes. Will be 0 if the the lockCount is 0.
|
| + */
|
| + size_t rowBytes() const { return fRec.fRowBytes; }
|
| +
|
| /** 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 +86,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 +108,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*);
|
| +
|
| /** 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 +255,32 @@ 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.
|
| - */
|
| + /**
|
| + * 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;
|
| +
|
| + /**
|
| + * 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 +314,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;
|
|
|