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 SkGrTexturePixelRef_DEFINED 12#define SkGrTexturePixelRef_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 */ 24class SK_API SkROLockPixelsPixelRef : public SkPixelRef { 25public: 26 SkROLockPixelsPixelRef(); 27 virtual ~SkROLockPixelsPixelRef(); 28 29protected: 30 // override from SkPixelRef 31 virtual void* onLockPixels(SkColorTable** ptr); 32 virtual void onUnlockPixels(); 33 virtual bool onLockPixelsAreWritable() const; // return false; 34 35private: 36 SkBitmap fBitmap; 37 typedef SkPixelRef INHERITED; 38}; 39 40/** 41 * PixelRef that wraps a GrTexture 42 */ 43class SK_API SkGrTexturePixelRef : public SkROLockPixelsPixelRef { 44public: 45 SkGrTexturePixelRef(GrTexture*); 46 virtual ~SkGrTexturePixelRef(); 47 48 // override from SkPixelRef 49 virtual SkGpuTexture* getTexture(); 50 51protected: 52 // override from SkPixelRef 53 virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset); 54 55 // override from SkPixelRef 56 virtual SkPixelRef* deepCopy(SkBitmap::Config dstConfig) SK_OVERRIDE; 57 58private: 59 GrTexture* fTexture; 60 typedef SkROLockPixelsPixelRef INHERITED; 61}; 62 63/** 64 * PixelRef that wraps a GrRenderTarget 65 */ 66class SK_API SkGrRenderTargetPixelRef : public SkROLockPixelsPixelRef { 67public: 68 SkGrRenderTargetPixelRef(GrRenderTarget* rt); 69 virtual ~SkGrRenderTargetPixelRef(); 70 71 // override from SkPixelRef 72 virtual SkGpuTexture* getTexture(); 73 74protected: 75 // override from SkPixelRef 76 virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset); 77 78 // override from SkPixelRef 79 virtual SkPixelRef* deepCopy(SkBitmap::Config dstConfig) SK_OVERRIDE; 80 81private: 82 GrRenderTarget* fRenderTarget; 83 typedef SkROLockPixelsPixelRef INHERITED; 84}; 85 86#endif 87 88