OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrRenderTarget_DEFINED | 8 #ifndef GrRenderTarget_DEFINED |
9 #define GrRenderTarget_DEFINED | 9 #define GrRenderTarget_DEFINED |
10 | 10 |
11 #include "GrSurface.h" | 11 #include "GrSurface.h" |
12 #include "SkRect.h" | 12 #include "SkRect.h" |
13 | 13 |
14 class GrStencilBuffer; | 14 class GrStencilBuffer; |
15 class GrTexture; | |
16 | 15 |
17 /** | 16 /** |
18 * GrRenderTarget represents a 2D buffer of pixels that can be rendered to. | 17 * GrRenderTarget represents a 2D buffer of pixels that can be rendered to. |
19 * A context's render target is set by setRenderTarget(). Render targets are | 18 * A context's render target is set by setRenderTarget(). Render targets are |
20 * created by a createTexture with the kRenderTarget_TextureFlag flag. | 19 * created by a createTexture with the kRenderTarget_SurfaceFlag flag. |
21 * Additionally, GrContext provides methods for creating GrRenderTargets | 20 * Additionally, GrContext provides methods for creating GrRenderTargets |
22 * that wrap externally created render targets. | 21 * that wrap externally created render targets. |
23 */ | 22 */ |
24 class GrRenderTarget : public GrSurface { | 23 class GrRenderTarget : virtual public GrSurface { |
25 public: | 24 public: |
26 SK_DECLARE_INST_COUNT(GrRenderTarget) | 25 SK_DECLARE_INST_COUNT(GrRenderTarget) |
27 | 26 |
28 // GrResource overrides | |
29 virtual size_t gpuMemorySize() const SK_OVERRIDE; | |
30 | |
31 // GrSurface overrides | 27 // GrSurface overrides |
32 /** | |
33 * @return the texture associated with the render target, may be NULL. | |
34 */ | |
35 virtual GrTexture* asTexture() SK_OVERRIDE { return fTexture; } | |
36 virtual const GrTexture* asTexture() const SK_OVERRIDE { return fTexture; } | |
37 | |
38 /** | |
39 * @return this render target. | |
40 */ | |
41 virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return this; } | 28 virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return this; } |
42 virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { | 29 virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { return t
his; } |
43 return this; | |
44 } | |
45 | 30 |
46 // GrRenderTarget | 31 // GrRenderTarget |
47 /** | 32 /** |
48 * If this RT is multisampled, this is the multisample buffer | 33 * If this RT is multisampled, this is the multisample buffer |
49 * @return the 3D API's handle to this object (e.g. FBO ID in OpenGL) | 34 * @return the 3D API's handle to this object (e.g. FBO ID in OpenGL) |
50 */ | 35 */ |
51 virtual GrBackendObject getRenderTargetHandle() const = 0; | 36 virtual GrBackendObject getRenderTargetHandle() const = 0; |
52 | 37 |
53 /** | 38 /** |
54 * If this RT is multisampled, this is the buffer it is resolved to. | 39 * If this RT is multisampled, this is the buffer it is resolved to. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 112 |
128 /** | 113 /** |
129 * GrStencilBuffer is not part of the public API. | 114 * GrStencilBuffer is not part of the public API. |
130 */ | 115 */ |
131 GrStencilBuffer* getStencilBuffer() const { return fStencilBuffer; } | 116 GrStencilBuffer* getStencilBuffer() const { return fStencilBuffer; } |
132 void setStencilBuffer(GrStencilBuffer* stencilBuffer); | 117 void setStencilBuffer(GrStencilBuffer* stencilBuffer); |
133 | 118 |
134 protected: | 119 protected: |
135 GrRenderTarget(GrGpu* gpu, | 120 GrRenderTarget(GrGpu* gpu, |
136 bool isWrapped, | 121 bool isWrapped, |
137 GrTexture* texture, | |
138 const GrSurfaceDesc& desc) | 122 const GrSurfaceDesc& desc) |
139 : INHERITED(gpu, isWrapped, desc) | 123 : INHERITED(gpu, isWrapped, desc) |
140 , fStencilBuffer(NULL) | 124 , fStencilBuffer(NULL) { |
141 , fTexture(texture) { | |
142 fResolveRect.setLargestInverted(); | 125 fResolveRect.setLargestInverted(); |
143 } | 126 } |
144 | 127 |
145 // override of GrResource | 128 // override of GrResource |
146 virtual void onAbandon() SK_OVERRIDE; | 129 virtual void onAbandon() SK_OVERRIDE; |
147 virtual void onRelease() SK_OVERRIDE; | 130 virtual void onRelease() SK_OVERRIDE; |
148 | 131 |
149 private: | 132 private: |
150 friend class GrTexture; | |
151 // called by ~GrTexture to remove the non-ref'ed back ptr. | |
152 void owningTextureDestroyed() { | |
153 SkASSERT(fTexture); | |
154 fTexture = NULL; | |
155 } | |
156 | |
157 GrStencilBuffer* fStencilBuffer; | 133 GrStencilBuffer* fStencilBuffer; |
158 GrTexture* fTexture; // not ref'ed | |
159 | 134 |
160 SkIRect fResolveRect; | 135 SkIRect fResolveRect; |
161 | 136 |
162 typedef GrSurface INHERITED; | 137 typedef GrSurface INHERITED; |
163 }; | 138 }; |
164 | 139 |
165 #endif | 140 #endif |
OLD | NEW |