diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-07-07 13:42:37 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-07-07 13:42:37 +0000 |
commit | 9c49bc3e643c435677727c1c0904c4a7cb7a6907 (patch) | |
tree | 20d6cb41a7367fddcdd4a8c8c958934fcb2c7955 /include/gpu | |
parent | 63e5e34c4ef180ea0f2d7b2f1343d92063c7cc10 (diff) |
Allow texture-backed bitmaps to perform a read-back when lockPixels is called.
This means we have to be even more cautious about when we call lock, and we should
always check getTexture() first if we can handle a texture directly, rather than
forcing the read-back to get the bits.
git-svn-id: http://skia.googlecode.com/svn/trunk@1815 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/gpu')
-rw-r--r-- | include/gpu/SkGrTexturePixelRef.h | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/include/gpu/SkGrTexturePixelRef.h b/include/gpu/SkGrTexturePixelRef.h index 5bc64f532a..2de842e3b4 100644 --- a/include/gpu/SkGrTexturePixelRef.h +++ b/include/gpu/SkGrTexturePixelRef.h @@ -18,36 +18,54 @@ #ifndef SkGrTexturePixelRef_DEFINED #define SkGrTexturePixelRef_DEFINED +#include "SkBitmap.h" #include "SkPixelRef.h" #include "GrGpu.h" -class SkGrTexturePixelRef : public SkPixelRef { +/** + * Common baseclass that implements onLockPixels() by calling onReadPixels(). + * Since it has a copy, it always returns false for onLockPixelsAreWritable(). + */ +class SkROLockPixelsPixelRef : public SkPixelRef { +public: + SkROLockPixelsPixelRef(); + virtual ~SkROLockPixelsPixelRef(); + +protected: + // override from SkPixelRef + virtual void* onLockPixels(SkColorTable** ptr); + virtual void onUnlockPixels(); + virtual bool onLockPixelsAreWritable() const; // return false; + +private: + SkBitmap fBitmap; + typedef SkPixelRef INHERITED; +}; + +/** + * PixelRef that wraps a GrTexture + */ +class SkGrTexturePixelRef : public SkROLockPixelsPixelRef { public: SkGrTexturePixelRef(GrTexture*); virtual ~SkGrTexturePixelRef(); // override from SkPixelRef - virtual SkGpuTexture* getTexture() { return (SkGpuTexture*)fTexture; } + virtual SkGpuTexture* getTexture(); protected: // override from SkPixelRef - virtual void* onLockPixels(SkColorTable** ptr) { - if (ptr) { - *ptr = NULL; - } - return NULL; - } - - // override from SkPixelRef - virtual void onUnlockPixels() {} virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset); private: GrTexture* fTexture; - typedef SkPixelRef INHERITED; + typedef SkROLockPixelsPixelRef INHERITED; }; -class SkGrRenderTargetPixelRef : public SkPixelRef { +/** + * PixelRef that wraps a GrRenderTarget + */ +class SkGrRenderTargetPixelRef : public SkROLockPixelsPixelRef { public: SkGrRenderTargetPixelRef(GrRenderTarget* rt); virtual ~SkGrRenderTargetPixelRef(); @@ -57,20 +75,11 @@ public: protected: // override from SkPixelRef - virtual void* onLockPixels(SkColorTable** ptr) { - if (ptr) { - *ptr = NULL; - } - return NULL; - } - - // override from SkPixelRef - virtual void onUnlockPixels() {} virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset); private: GrRenderTarget* fRenderTarget; - typedef SkPixelRef INHERITED; + typedef SkROLockPixelsPixelRef INHERITED; }; #endif |