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