| 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 "GrGLGpu.h" | 10 #include "GrGLGpu.h" |
| 11 | 11 |
| 12 #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) | 12 void GrGLFBO::deleteIfValid(GrGLGpu* gpu) { |
| 13 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) | 13 if (this->isValid()) { |
| 14 gpu->willDeleteOrAbandonFramebuffer(this); |
| 15 if (true /*fOwned*/) { |
| 16 GR_GL_CALL(gpu->glInterface(), DeleteFramebuffers(1, &fID)); |
| 17 } |
| 18 fGenID = SK_InvalidGenID; |
| 19 } |
| 20 } |
| 21 |
| 22 void GrGLFBO::abandon(GrGLGpu* gpu) { |
| 23 if (this->isValid()) { |
| 24 if (gpu) { |
| 25 gpu->willDeleteOrAbandonFramebuffer(this); |
| 26 } |
| 27 fGenID = SK_InvalidGenID; |
| 28 } |
| 29 } |
| 30 |
| 31 |
| 32 ////////////////////////////////////////////////////////////////////////////// |
| 33 |
| 34 #define GLGPU static_cast<GrGLGpu*>(this->getGpu()) |
| 35 #define GL_CALL(X) GR_GL_CALL(GLGPU->glInterface(), X) |
| 14 | 36 |
| 15 // Because this class is virtually derived from GrSurface we must explicitly cal
l its constructor. | 37 // Because this class is virtually derived from GrSurface we must explicitly cal
l its constructor. |
| 16 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, cons
t IDDesc& idDesc) | 38 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, cons
t IDDesc& idDesc) |
| 17 : GrSurface(gpu, idDesc.fLifeCycle, desc) | 39 : GrSurface(gpu, idDesc.fLifeCycle, desc) |
| 18 , INHERITED(gpu, idDesc.fLifeCycle, desc) { | 40 , INHERITED(gpu, idDesc.fLifeCycle, desc) { |
| 19 this->init(desc, idDesc); | 41 this->init(desc, idDesc); |
| 20 this->registerWithCache(); | 42 this->registerWithCache(); |
| 21 } | 43 } |
| 22 | 44 |
| 23 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, cons
t IDDesc& idDesc, | 45 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, cons
t IDDesc& idDesc, |
| 24 Derived) | 46 Derived) |
| 25 : GrSurface(gpu, idDesc.fLifeCycle, desc) | 47 : GrSurface(gpu, idDesc.fLifeCycle, desc) |
| 26 , INHERITED(gpu, idDesc.fLifeCycle, desc) { | 48 , INHERITED(gpu, idDesc.fLifeCycle, desc) { |
| 27 this->init(desc, idDesc); | 49 this->init(desc, idDesc); |
| 28 } | 50 } |
| 29 | 51 |
| 30 void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { | 52 void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { |
| 31 fRTFBOID = idDesc.fRTFBOID; | 53 fRenderFBO.reset(SkRef(idDesc.fRenderFBO.get())); |
| 32 fTexFBOID = idDesc.fTexFBOID; | 54 fTextureFBO.reset(SkSafeRef(idDesc.fTextureFBO.get())); |
| 33 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID; | 55 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID; |
| 34 fIsWrapped = kWrapped_LifeCycle == idDesc.fLifeCycle; | 56 fIsWrapped = kWrapped_LifeCycle == idDesc.fLifeCycle; |
| 35 | 57 |
| 36 fViewport.fLeft = 0; | 58 fViewport.fLeft = 0; |
| 37 fViewport.fBottom = 0; | 59 fViewport.fBottom = 0; |
| 38 fViewport.fWidth = desc.fWidth; | 60 fViewport.fWidth = desc.fWidth; |
| 39 fViewport.fHeight = desc.fHeight; | 61 fViewport.fHeight = desc.fHeight; |
| 40 | 62 |
| 41 // We own one color value for each MSAA sample. | 63 // We own one color value for each MSAA sample. |
| 42 fColorValuesPerPixel = SkTMax(1, fDesc.fSampleCnt); | 64 fColorValuesPerPixel = SkTMax(1, fDesc.fSampleCnt); |
| 43 if (fTexFBOID != fRTFBOID) { | 65 if (fTextureFBO && fTextureFBO != fRenderFBO) { |
| 44 // If we own the resolve buffer then that is one more sample per pixel. | 66 // If we own the resolve buffer then that is one more sample per pixel. |
| 45 fColorValuesPerPixel += 1; | 67 fColorValuesPerPixel += 1; |
| 46 } | 68 } |
| 47 } | 69 } |
| 48 | 70 |
| 49 size_t GrGLRenderTarget::onGpuMemorySize() const { | 71 size_t GrGLRenderTarget::onGpuMemorySize() const { |
| 50 SkASSERT(kUnknown_GrPixelConfig != fDesc.fConfig); | 72 SkASSERT(kUnknown_GrPixelConfig != fDesc.fConfig); |
| 51 SkASSERT(!GrPixelConfigIsCompressed(fDesc.fConfig)); | 73 SkASSERT(!GrPixelConfigIsCompressed(fDesc.fConfig)); |
| 52 size_t colorBytes = GrBytesPerPixel(fDesc.fConfig); | 74 size_t colorBytes = GrBytesPerPixel(fDesc.fConfig); |
| 53 SkASSERT(colorBytes > 0); | 75 SkASSERT(colorBytes > 0); |
| 54 return fColorValuesPerPixel * fDesc.fWidth * fDesc.fHeight * colorBytes; | 76 return fColorValuesPerPixel * fDesc.fWidth * fDesc.fHeight * colorBytes; |
| 55 } | 77 } |
| 56 | 78 |
| 57 void GrGLRenderTarget::onRelease() { | 79 void GrGLRenderTarget::onRelease() { |
| 80 GrGLGpu* gpu = GLGPU; |
| 58 if (!fIsWrapped) { | 81 if (!fIsWrapped) { |
| 59 if (fTexFBOID) { | 82 fRenderFBO->deleteIfValid(gpu); |
| 60 GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); | 83 if (fTextureFBO) { |
| 61 } | 84 fTextureFBO->deleteIfValid(gpu); |
| 62 if (fRTFBOID && fRTFBOID != fTexFBOID) { | |
| 63 GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); | |
| 64 } | 85 } |
| 65 if (fMSColorRenderbufferID) { | 86 if (fMSColorRenderbufferID) { |
| 66 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); | 87 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
| 88 fMSColorRenderbufferID = 0; |
| 67 } | 89 } |
| 90 } else { |
| 91 fRenderFBO->abandon(gpu); |
| 92 if (fTextureFBO) { |
| 93 fTextureFBO->abandon(gpu); |
| 94 } |
| 95 fMSColorRenderbufferID = 0; |
| 68 } | 96 } |
| 69 fRTFBOID = 0; | |
| 70 fTexFBOID = 0; | |
| 71 fMSColorRenderbufferID = 0; | |
| 72 fIsWrapped = false; | |
| 73 INHERITED::onRelease(); | 97 INHERITED::onRelease(); |
| 74 } | 98 } |
| 75 | 99 |
| 76 void GrGLRenderTarget::onAbandon() { | 100 void GrGLRenderTarget::onAbandon() { |
| 77 fRTFBOID = 0; | 101 GrGLGpu* gpu = GLGPU; |
| 78 fTexFBOID = 0; | 102 fRenderFBO->abandon(gpu); |
| 103 if (fTextureFBO) { |
| 104 fTextureFBO->abandon(gpu); |
| 105 } |
| 79 fMSColorRenderbufferID = 0; | 106 fMSColorRenderbufferID = 0; |
| 80 fIsWrapped = false; | |
| 81 INHERITED::onAbandon(); | 107 INHERITED::onAbandon(); |
| 82 } | 108 } |
| OLD | NEW |