| Index: include/core/SkPixelRef.h
 | 
| diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
 | 
| index d4c35323bbf3b713e22ac79d2ec7fb73026e2c9c..b096c3c057722e360a93fd92f0027a55596a33f7 100644
 | 
| --- a/include/core/SkPixelRef.h
 | 
| +++ b/include/core/SkPixelRef.h
 | 
| @@ -14,9 +14,12 @@
 | 
|  #include "SkRefCnt.h"
 | 
|  #include "SkString.h"
 | 
|  #include "SkFlattenable.h"
 | 
| +#include "SkImageInfo.h"
 | 
|  #include "SkTDArray.h"
 | 
|  
 | 
| -#define SK_SUPPORT_LEGACY_PIXELREF_CONSTRUCTOR
 | 
| +//#define SK_SUPPORT_LEGACY_PIXELREF_CONSTRUCTOR
 | 
| +
 | 
| +#define SK_SUPPORT_LEGACY_ONLOCKPIXELS
 | 
|  
 | 
|  #ifdef SK_DEBUG
 | 
|      /**
 | 
| @@ -67,23 +70,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
 | 
| @@ -240,18 +268,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
 | 
|      /**
 | 
| -     *  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.
 | 
| +     *  On success, returns true and fills out the LockRec for the pixels. On
 | 
| +     *  failure returns false and ignores the LockRec parameter.
 | 
|       *
 | 
| -     *  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 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;
 | 
|  
 | 
| @@ -296,16 +333,16 @@ 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
 | 
|      // FIXME: fInfo should be const once we remove old constructor that does
 | 
|      // not set it.
 | 
|      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;
 | 
| 
 |