epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef SkGrTexturePixelRef_DEFINED |
| 12 | #define SkGrTexturePixelRef_DEFINED |
| 13 | |
reed@google.com | 9c49bc3 | 2011-07-07 13:42:37 +0000 | [diff] [blame] | 14 | #include "SkBitmap.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 15 | #include "SkPixelRef.h" |
| 16 | #include "GrGpu.h" |
| 17 | |
reed@google.com | 9c49bc3 | 2011-07-07 13:42:37 +0000 | [diff] [blame] | 18 | /** |
| 19 | * Common baseclass that implements onLockPixels() by calling onReadPixels(). |
| 20 | * Since it has a copy, it always returns false for onLockPixelsAreWritable(). |
| 21 | */ |
| 22 | class SkROLockPixelsPixelRef : public SkPixelRef { |
| 23 | public: |
| 24 | SkROLockPixelsPixelRef(); |
| 25 | virtual ~SkROLockPixelsPixelRef(); |
| 26 | |
| 27 | protected: |
| 28 | // override from SkPixelRef |
| 29 | virtual void* onLockPixels(SkColorTable** ptr); |
| 30 | virtual void onUnlockPixels(); |
| 31 | virtual bool onLockPixelsAreWritable() const; // return false; |
| 32 | |
| 33 | private: |
| 34 | SkBitmap fBitmap; |
| 35 | typedef SkPixelRef INHERITED; |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * PixelRef that wraps a GrTexture |
| 40 | */ |
| 41 | class SkGrTexturePixelRef : public SkROLockPixelsPixelRef { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 42 | public: |
| 43 | SkGrTexturePixelRef(GrTexture*); |
| 44 | virtual ~SkGrTexturePixelRef(); |
| 45 | |
| 46 | // override from SkPixelRef |
reed@google.com | 9c49bc3 | 2011-07-07 13:42:37 +0000 | [diff] [blame] | 47 | virtual SkGpuTexture* getTexture(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 48 | |
| 49 | protected: |
| 50 | // override from SkPixelRef |
reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 51 | virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 52 | |
| 53 | private: |
| 54 | GrTexture* fTexture; |
reed@google.com | 9c49bc3 | 2011-07-07 13:42:37 +0000 | [diff] [blame] | 55 | typedef SkROLockPixelsPixelRef INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
reed@google.com | 9c49bc3 | 2011-07-07 13:42:37 +0000 | [diff] [blame] | 58 | /** |
| 59 | * PixelRef that wraps a GrRenderTarget |
| 60 | */ |
| 61 | class SkGrRenderTargetPixelRef : public SkROLockPixelsPixelRef { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 62 | public: |
| 63 | SkGrRenderTargetPixelRef(GrRenderTarget* rt); |
| 64 | virtual ~SkGrRenderTargetPixelRef(); |
| 65 | |
| 66 | // override from SkPixelRef |
| 67 | virtual SkGpuTexture* getTexture(); |
| 68 | |
| 69 | protected: |
| 70 | // override from SkPixelRef |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 71 | virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset); |
| 72 | |
| 73 | private: |
| 74 | GrRenderTarget* fRenderTarget; |
reed@google.com | 9c49bc3 | 2011-07-07 13:42:37 +0000 | [diff] [blame] | 75 | typedef SkROLockPixelsPixelRef INHERITED; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 78 | #endif |
| 79 | |