Home | History | Annotate | Download | only in gpu
      1 /*
      2  * Copyright 2010 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef SkGrPixelRef_DEFINED
      9 #define SkGrPixelRef_DEFINED
     10 
     11 #include "SkBitmap.h"
     12 #include "SkPixelRef.h"
     13 #include "GrTexture.h"
     14 #include "GrRenderTarget.h"
     15 
     16 
     17 /**
     18  *  Common baseclass that implements onLockPixels() by calling onReadPixels().
     19  *  Since it has a copy, it always returns false for onLockPixelsAreWritable().
     20  */
     21 class SK_API SkROLockPixelsPixelRef : public SkPixelRef {
     22 public:
     23     SkROLockPixelsPixelRef(const SkImageInfo&);
     24     virtual ~SkROLockPixelsPixelRef();
     25 
     26 protected:
     27     // override from SkPixelRef
     28     virtual void* onLockPixels(SkColorTable** ptr);
     29     virtual void onUnlockPixels();
     30     virtual bool onLockPixelsAreWritable() const;   // return false;
     31 
     32 private:
     33     SkBitmap    fBitmap;
     34     typedef SkPixelRef INHERITED;
     35 };
     36 
     37 /**
     38  *  PixelRef that wraps a GrSurface
     39  */
     40 class SK_API SkGrPixelRef : public SkROLockPixelsPixelRef {
     41 public:
     42     /**
     43      * Constructs a pixel ref around a GrSurface. If the caller has locked the GrSurface in the
     44      * cache and would like the pixel ref to unlock it in its destructor then transferCacheLock
     45      * should be set to true.
     46      */
     47     SkGrPixelRef(const SkImageInfo&, GrSurface*, bool transferCacheLock = false);
     48     virtual ~SkGrPixelRef();
     49 
     50     // override from SkPixelRef
     51     virtual GrTexture* getTexture() SK_OVERRIDE;
     52 
     53     SK_DECLARE_UNFLATTENABLE_OBJECT()
     54 
     55 protected:
     56     // overrides from SkPixelRef
     57     virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset) SK_OVERRIDE;
     58     virtual SkPixelRef* deepCopy(SkBitmap::Config dstConfig, const SkIRect* subset) SK_OVERRIDE;
     59 
     60 private:
     61     GrSurface*  fSurface;
     62     bool        fUnlock;   // if true the pixel ref owns a texture cache lock on fSurface
     63 
     64     typedef SkROLockPixelsPixelRef INHERITED;
     65 };
     66 
     67 #endif
     68