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