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 #include "GrGLRenderTarget.h" | 8 #include "GrGLRenderTarget.h" |
9 | 9 |
10 #include "GrRenderTargetPriv.h" | |
11 #include "GrGLGpu.h" | 10 #include "GrGLGpu.h" |
12 #include "GrGLUtil.h" | 11 #include "GrGLUtil.h" |
| 12 #include "GrGpuResourcePriv.h" |
| 13 #include "GrRenderTargetPriv.h" |
13 #include "SkTraceMemoryDump.h" | 14 #include "SkTraceMemoryDump.h" |
14 | 15 |
15 #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) | 16 #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) |
16 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) | 17 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
17 | 18 |
18 // Because this class is virtually derived from GrSurface we must explicitly cal
l its constructor. | 19 // Because this class is virtually derived from GrSurface we must explicitly cal
l its constructor. |
| 20 // Constructor for wrapped render targets. |
19 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, | 21 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, |
20 const GrSurfaceDesc& desc, | 22 const GrSurfaceDesc& desc, |
21 const IDDesc& idDesc, | 23 const IDDesc& idDesc, |
22 GrGLStencilAttachment* stencil) | 24 GrGLStencilAttachment* stencil) |
23 : GrSurface(gpu, idDesc.fLifeCycle, desc) | 25 : GrSurface(gpu, desc) |
24 , INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig, stencil) { | 26 , INHERITED(gpu, desc, idDesc.fSampleConfig, stencil) { |
25 this->init(desc, idDesc); | 27 this->init(desc, idDesc); |
26 this->registerWithCache(); | 28 this->registerWithCacheWrapped(); |
27 } | 29 } |
28 | 30 |
29 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, cons
t IDDesc& idDesc, | 31 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, |
30 Derived) | 32 const IDDesc& idDesc) |
31 : GrSurface(gpu, idDesc.fLifeCycle, desc) | 33 : GrSurface(gpu, desc) |
32 , INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig) { | 34 , INHERITED(gpu, desc, idDesc.fSampleConfig) { |
33 this->init(desc, idDesc); | 35 this->init(desc, idDesc); |
34 } | 36 } |
35 | 37 |
36 void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { | 38 void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { |
37 fRTFBOID = idDesc.fRTFBOID; | 39 fRTFBOID = idDesc.fRTFBOID; |
38 fTexFBOID = idDesc.fTexFBOID; | 40 fTexFBOID = idDesc.fTexFBOID; |
39 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID; | 41 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID; |
40 fRTLifecycle = idDesc.fLifeCycle; | 42 fRTFBOOwnership = idDesc.fRTFBOOwnership; |
41 | 43 |
42 fViewport.fLeft = 0; | 44 fViewport.fLeft = 0; |
43 fViewport.fBottom = 0; | 45 fViewport.fBottom = 0; |
44 fViewport.fWidth = desc.fWidth; | 46 fViewport.fWidth = desc.fWidth; |
45 fViewport.fHeight = desc.fHeight; | 47 fViewport.fHeight = desc.fHeight; |
46 | 48 |
47 fGpuMemorySize = this->totalSamples() * this->totalBytesPerSample(); | 49 fGpuMemorySize = this->totalSamples() * this->totalBytesPerSample(); |
48 | 50 |
49 SkASSERT(fGpuMemorySize <= WorseCaseSize(desc)); | 51 SkASSERT(fGpuMemorySize <= WorseCaseSize(desc)); |
50 } | 52 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 #ifdef SK_DEBUG | 114 #ifdef SK_DEBUG |
113 GrGLenum status; | 115 GrGLenum status; |
114 GR_GL_CALL_RET(interface, status, CheckFramebufferStatus(GR_GL_FRAMEBUFF
ER)); | 116 GR_GL_CALL_RET(interface, status, CheckFramebufferStatus(GR_GL_FRAMEBUFF
ER)); |
115 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); | 117 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); |
116 #endif | 118 #endif |
117 return true; | 119 return true; |
118 } | 120 } |
119 } | 121 } |
120 | 122 |
121 void GrGLRenderTarget::onRelease() { | 123 void GrGLRenderTarget::onRelease() { |
122 if (kBorrowed_LifeCycle != fRTLifecycle) { | 124 if (GrBackendObjectOwnership::kBorrowed != fRTFBOOwnership) { |
123 if (fTexFBOID) { | 125 if (fTexFBOID) { |
124 GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); | 126 GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); |
125 } | 127 } |
126 if (fRTFBOID && fRTFBOID != fTexFBOID) { | 128 if (fRTFBOID && fRTFBOID != fTexFBOID) { |
127 GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); | 129 GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); |
128 } | 130 } |
129 if (fMSColorRenderbufferID) { | 131 if (fMSColorRenderbufferID) { |
130 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); | 132 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
131 } | 133 } |
132 } | 134 } |
133 fRTFBOID = 0; | 135 fRTFBOID = 0; |
134 fTexFBOID = 0; | 136 fTexFBOID = 0; |
135 fMSColorRenderbufferID = 0; | 137 fMSColorRenderbufferID = 0; |
136 INHERITED::onRelease(); | 138 INHERITED::onRelease(); |
137 } | 139 } |
138 | 140 |
139 void GrGLRenderTarget::onAbandon() { | 141 void GrGLRenderTarget::onAbandon() { |
140 fRTFBOID = 0; | 142 fRTFBOID = 0; |
141 fTexFBOID = 0; | 143 fTexFBOID = 0; |
142 fMSColorRenderbufferID = 0; | 144 fMSColorRenderbufferID = 0; |
143 INHERITED::onAbandon(); | 145 INHERITED::onAbandon(); |
144 } | 146 } |
145 | 147 |
146 GrGLGpu* GrGLRenderTarget::getGLGpu() const { | 148 GrGLGpu* GrGLRenderTarget::getGLGpu() const { |
147 SkASSERT(!this->wasDestroyed()); | 149 SkASSERT(!this->wasDestroyed()); |
148 return static_cast<GrGLGpu*>(this->getGpu()); | 150 return static_cast<GrGLGpu*>(this->getGpu()); |
149 } | 151 } |
150 | 152 |
| 153 bool GrGLRenderTarget::canAttemptStencilAttachment() const { |
| 154 // When we have not created the FBO ID we do not attempt to modify its attac
hments. |
| 155 return this->resourcePriv().refsWrappedObjects(); |
| 156 } |
| 157 |
151 void GrGLRenderTarget::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump)
const { | 158 void GrGLRenderTarget::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump)
const { |
152 // Don't log the backing texture's contribution to the memory size. This wil
l be handled by the | 159 // Don't log the backing texture's contribution to the memory size. This wil
l be handled by the |
153 // texture object. | 160 // texture object. |
154 | 161 |
155 // Log any renderbuffer's contribution to memory. We only do this if we own
the renderbuffer | 162 // Log any renderbuffer's contribution to memory. We only do this if we own
the renderbuffer |
156 // (have a fMSColorRenderbufferID). | 163 // (have a fMSColorRenderbufferID). |
157 if (fMSColorRenderbufferID) { | 164 if (fMSColorRenderbufferID) { |
158 size_t size = this->msaaSamples() * this->totalBytesPerSample(); | 165 size_t size = this->msaaSamples() * this->totalBytesPerSample(); |
159 | 166 |
160 // Due to this resource having both a texture and a renderbuffer compone
nt, dump as | 167 // Due to this resource having both a texture and a renderbuffer compone
nt, dump as |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 int GrGLRenderTarget::totalSamples() const { | 207 int GrGLRenderTarget::totalSamples() const { |
201 int total_samples = this->msaaSamples(); | 208 int total_samples = this->msaaSamples(); |
202 | 209 |
203 if (fTexFBOID != kUnresolvableFBOID) { | 210 if (fTexFBOID != kUnresolvableFBOID) { |
204 // If we own the resolve buffer then that is one more sample per pixel. | 211 // If we own the resolve buffer then that is one more sample per pixel. |
205 total_samples += 1; | 212 total_samples += 1; |
206 } | 213 } |
207 | 214 |
208 return total_samples; | 215 return total_samples; |
209 } | 216 } |
OLD | NEW |