| 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" | 10 #include "GrRenderTargetPriv.h" |
| 11 #include "GrGLGpu.h" | 11 #include "GrGLGpu.h" |
| 12 #include "GrGLUtil.h" | 12 #include "GrGLUtil.h" |
| 13 #include "SkTraceMemoryDump.h" | 13 #include "SkTraceMemoryDump.h" |
| 14 | 14 |
| 15 #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) | 15 #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) |
| 16 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) | 16 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
| 17 | 17 |
| 18 // Because this class is virtually derived from GrSurface we must explicitly cal
l its constructor. | 18 // Because this class is virtually derived from GrSurface we must explicitly cal
l its constructor. |
| 19 // Constructor for wrapped render targets. |
| 19 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, | 20 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, |
| 20 const GrSurfaceDesc& desc, | 21 const GrSurfaceDesc& desc, |
| 21 const IDDesc& idDesc, | 22 const IDDesc& idDesc, |
| 22 GrGLStencilAttachment* stencil) | 23 GrGLStencilAttachment* stencil) |
| 23 : GrSurface(gpu, idDesc.fLifeCycle, desc) | 24 : GrSurface(gpu, desc) |
| 24 , INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig, stencil) { | 25 , INHERITED(gpu, desc, idDesc.fSampleConfig, stencil) { |
| 25 this->init(desc, idDesc); | 26 this->init(desc, idDesc); |
| 26 this->registerWithCache(); | 27 this->registerWithCacheWrapped(); |
| 27 } | 28 } |
| 28 | 29 |
| 29 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, cons
t IDDesc& idDesc, | 30 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, |
| 30 Derived) | 31 const IDDesc& idDesc) |
| 31 : GrSurface(gpu, idDesc.fLifeCycle, desc) | 32 : GrSurface(gpu, desc) |
| 32 , INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig) { | 33 , INHERITED(gpu, desc, idDesc.fSampleConfig) { |
| 33 this->init(desc, idDesc); | 34 this->init(desc, idDesc); |
| 34 } | 35 } |
| 35 | 36 |
| 36 void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { | 37 void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { |
| 37 fRTFBOID = idDesc.fRTFBOID; | 38 fRTFBOID = idDesc.fRTFBOID; |
| 38 fTexFBOID = idDesc.fTexFBOID; | 39 fTexFBOID = idDesc.fTexFBOID; |
| 39 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID; | 40 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID; |
| 40 fRTLifecycle = idDesc.fLifeCycle; | 41 fRTFBOLifeCycle = idDesc.fRTFBOLifeCycle; |
| 41 | 42 |
| 42 fViewport.fLeft = 0; | 43 fViewport.fLeft = 0; |
| 43 fViewport.fBottom = 0; | 44 fViewport.fBottom = 0; |
| 44 fViewport.fWidth = desc.fWidth; | 45 fViewport.fWidth = desc.fWidth; |
| 45 fViewport.fHeight = desc.fHeight; | 46 fViewport.fHeight = desc.fHeight; |
| 46 | 47 |
| 47 fGpuMemorySize = this->totalSamples() * this->totalBytesPerSample(); | 48 fGpuMemorySize = this->totalSamples() * this->totalBytesPerSample(); |
| 48 | 49 |
| 49 SkASSERT(fGpuMemorySize <= WorseCaseSize(desc)); | 50 SkASSERT(fGpuMemorySize <= WorseCaseSize(desc)); |
| 50 } | 51 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 #ifdef SK_DEBUG | 113 #ifdef SK_DEBUG |
| 113 GrGLenum status; | 114 GrGLenum status; |
| 114 GR_GL_CALL_RET(interface, status, CheckFramebufferStatus(GR_GL_FRAMEBUFF
ER)); | 115 GR_GL_CALL_RET(interface, status, CheckFramebufferStatus(GR_GL_FRAMEBUFF
ER)); |
| 115 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); | 116 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); |
| 116 #endif | 117 #endif |
| 117 return true; | 118 return true; |
| 118 } | 119 } |
| 119 } | 120 } |
| 120 | 121 |
| 121 void GrGLRenderTarget::onRelease() { | 122 void GrGLRenderTarget::onRelease() { |
| 122 if (kBorrowed_LifeCycle != fRTLifecycle) { | 123 if (GrBackendObjectLifeCycle::kBorrowed != fRTFBOLifeCycle) { |
| 123 if (fTexFBOID) { | 124 if (fTexFBOID) { |
| 124 GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); | 125 GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); |
| 125 } | 126 } |
| 126 if (fRTFBOID && fRTFBOID != fTexFBOID) { | 127 if (fRTFBOID && fRTFBOID != fTexFBOID) { |
| 127 GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); | 128 GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); |
| 128 } | 129 } |
| 129 if (fMSColorRenderbufferID) { | 130 if (fMSColorRenderbufferID) { |
| 130 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); | 131 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
| 131 } | 132 } |
| 132 } | 133 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 int GrGLRenderTarget::totalSamples() const { | 201 int GrGLRenderTarget::totalSamples() const { |
| 201 int total_samples = this->msaaSamples(); | 202 int total_samples = this->msaaSamples(); |
| 202 | 203 |
| 203 if (fTexFBOID != kUnresolvableFBOID) { | 204 if (fTexFBOID != kUnresolvableFBOID) { |
| 204 // If we own the resolve buffer then that is one more sample per pixel. | 205 // If we own the resolve buffer then that is one more sample per pixel. |
| 205 total_samples += 1; | 206 total_samples += 1; |
| 206 } | 207 } |
| 207 | 208 |
| 208 return total_samples; | 209 return total_samples; |
| 209 } | 210 } |
| OLD | NEW |