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 SkGpuCanvas_DEFINED |
| 19 | #define SkGpuCanvas_DEFINED |
| 20 | |
| 21 | #include "SkCanvas.h" |
| 22 | |
| 23 | class GrContext; |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 24 | class GrRenderTarget; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Subclass of canvas that creates devices compatible with the GrContext pass |
| 28 | * to the canvas' constructor. |
| 29 | */ |
| 30 | class SkGpuCanvas : public SkCanvas { |
| 31 | public: |
| 32 | /** |
reed@google.com | 7b201d2 | 2011-01-11 18:59:23 +0000 | [diff] [blame] | 33 | * The GrContext object is reference counted. When passed to our |
| 34 | * constructor, its reference count is incremented. In our destructor, the |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 35 | * GrGpu's reference count will be decremented. |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 36 | * GrRenderTarget represents the rendering destination in the underlying |
| 37 | * 3D API. Its reference count is incremented in the constructor and |
| 38 | * decremented in the destructor. |
| 39 | * SkGpuDevice::Current3DApiRenderTarget() can be passed as a special |
| 40 | * value that will cause the factory to create a render target object |
| 41 | * that reflects the state of the underlying 3D API at the time of |
| 42 | * construction. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 43 | */ |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 44 | explicit SkGpuCanvas(GrContext*, GrRenderTarget*); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 45 | virtual ~SkGpuCanvas(); |
| 46 | |
| 47 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 48 | * Override from SkCanvas. Returns true, and if not-null, sets size to |
| 49 | * be the width/height of our viewport. |
| 50 | */ |
| 51 | virtual bool getViewport(SkIPoint* size) const; |
| 52 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 53 | #if 0 |
| 54 | virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 55 | SaveFlags flags = kARGB_ClipLayer_SaveFlag) { |
| 56 | return this->save(flags); |
| 57 | } |
| 58 | #endif |
reed@google.com | 7b201d2 | 2011-01-11 18:59:23 +0000 | [diff] [blame] | 59 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | private: |
| 61 | GrContext* fContext; |
| 62 | |
| 63 | typedef SkCanvas INHERITED; |
| 64 | }; |
| 65 | |
| 66 | #endif |
| 67 | |
| 68 | |