| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2010 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #ifndef SkGrTexturePixelRef_DEFINED |
| 19 | #define SkGrTexturePixelRef_DEFINED |
| 20 | |
| reed@google.com | 9c49bc3 | 2011-07-07 13:42:37 +0000 | [diff] [blame] | 21 | #include "SkBitmap.h" |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 22 | #include "SkPixelRef.h" |
| 23 | #include "GrGpu.h" |
| 24 | |
| reed@google.com | 9c49bc3 | 2011-07-07 13:42:37 +0000 | [diff] [blame] | 25 | /** |
| 26 | * Common baseclass that implements onLockPixels() by calling onReadPixels(). |
| 27 | * Since it has a copy, it always returns false for onLockPixelsAreWritable(). |
| 28 | */ |
| 29 | class SkROLockPixelsPixelRef : public SkPixelRef { |
| 30 | public: |
| 31 | SkROLockPixelsPixelRef(); |
| 32 | virtual ~SkROLockPixelsPixelRef(); |
| 33 | |
| 34 | protected: |
| 35 | // override from SkPixelRef |
| 36 | virtual void* onLockPixels(SkColorTable** ptr); |
| 37 | virtual void onUnlockPixels(); |
| 38 | virtual bool onLockPixelsAreWritable() const; // return false; |
| 39 | |
| 40 | private: |
| 41 | SkBitmap fBitmap; |
| 42 | typedef SkPixelRef INHERITED; |
| 43 | }; |
| 44 | |
| 45 | /** |
| 46 | * PixelRef that wraps a GrTexture |
| 47 | */ |
| 48 | class SkGrTexturePixelRef : public SkROLockPixelsPixelRef { |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 49 | public: |
| 50 | SkGrTexturePixelRef(GrTexture*); |
| 51 | virtual ~SkGrTexturePixelRef(); |
| 52 | |
| 53 | // override from SkPixelRef |
| reed@google.com | 9c49bc3 | 2011-07-07 13:42:37 +0000 | [diff] [blame] | 54 | virtual SkGpuTexture* getTexture(); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 55 | |
| 56 | protected: |
| 57 | // override from SkPixelRef |
| reed@google.com | 50dfa01 | 2011-04-01 19:05:36 +0000 | [diff] [blame] | 58 | virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 59 | |
| 60 | private: |
| 61 | GrTexture* fTexture; |
| reed@google.com | 9c49bc3 | 2011-07-07 13:42:37 +0000 | [diff] [blame] | 62 | typedef SkROLockPixelsPixelRef INHERITED; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| reed@google.com | 9c49bc3 | 2011-07-07 13:42:37 +0000 | [diff] [blame] | 65 | /** |
| 66 | * PixelRef that wraps a GrRenderTarget |
| 67 | */ |
| 68 | class SkGrRenderTargetPixelRef : public SkROLockPixelsPixelRef { |
| bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 69 | public: |
| 70 | SkGrRenderTargetPixelRef(GrRenderTarget* rt); |
| 71 | virtual ~SkGrRenderTargetPixelRef(); |
| 72 | |
| 73 | // override from SkPixelRef |
| 74 | virtual SkGpuTexture* getTexture(); |
| 75 | |
| 76 | protected: |
| 77 | // override from SkPixelRef |
| bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 78 | virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset); |
| 79 | |
| 80 | private: |
| 81 | GrRenderTarget* fRenderTarget; |
| reed@google.com | 9c49bc3 | 2011-07-07 13:42:37 +0000 | [diff] [blame] | 82 | typedef SkROLockPixelsPixelRef INHERITED; |
| bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 85 | #endif |
| 86 | |