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 "GrGLGpu.h" | 11 #include "GrGLGpu.h" |
| 12 #include "GrGLUtil.h" |
11 | 13 |
12 #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) | 14 #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) |
13 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) | 15 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
14 | 16 |
15 // Because this class is virtually derived from GrSurface we must explicitly cal
l its constructor. | 17 // 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) | 18 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, cons
t IDDesc& idDesc) |
17 : GrSurface(gpu, idDesc.fLifeCycle, desc) | 19 : GrSurface(gpu, idDesc.fLifeCycle, desc) |
18 , INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig) { | 20 , INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig) { |
19 this->init(desc, idDesc); | 21 this->init(desc, idDesc); |
20 this->registerWithCache(); | 22 this->registerWithCache(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 SkASSERT(colorBytes > 0); | 55 SkASSERT(colorBytes > 0); |
54 fGpuMemorySize = colorValuesPerPixel * fDesc.fWidth * fDesc.fHeight * colorB
ytes; | 56 fGpuMemorySize = colorValuesPerPixel * fDesc.fWidth * fDesc.fHeight * colorB
ytes; |
55 | 57 |
56 SkASSERT(fGpuMemorySize <= WorseCaseSize(desc)); | 58 SkASSERT(fGpuMemorySize <= WorseCaseSize(desc)); |
57 } | 59 } |
58 | 60 |
59 size_t GrGLRenderTarget::onGpuMemorySize() const { | 61 size_t GrGLRenderTarget::onGpuMemorySize() const { |
60 return fGpuMemorySize; | 62 return fGpuMemorySize; |
61 } | 63 } |
62 | 64 |
| 65 bool GrGLRenderTarget::completeStencilAttachment() { |
| 66 GrGLGpu* gpu = this->getGLGpu(); |
| 67 const GrGLInterface* interface = gpu->glInterface(); |
| 68 GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAttachment
(); |
| 69 if (nullptr == stencil) { |
| 70 if (this->renderTargetPriv().getStencilAttachment()) { |
| 71 GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 72 GR_GL_STENCIL_ATTACHME
NT, |
| 73 GR_GL_RENDERBUFFER, 0)
); |
| 74 GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 75 GR_GL_DEPTH_ATTACHMENT
, |
| 76 GR_GL_RENDERBUFFER, 0)
); |
| 77 #ifdef SK_DEBUG |
| 78 GrGLenum status; |
| 79 GR_GL_CALL_RET(interface, status, CheckFramebufferStatus(GR_GL_FRAME
BUFFER)); |
| 80 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); |
| 81 #endif |
| 82 } |
| 83 return true; |
| 84 } else { |
| 85 const GrGLStencilAttachment* glStencil = static_cast<const GrGLStencilAt
tachment*>(stencil); |
| 86 GrGLuint rb = glStencil->renderbufferID(); |
| 87 |
| 88 gpu->invalidateBoundRenderTarget(); |
| 89 gpu->stats()->incRenderTargetBinds(); |
| 90 GR_GL_CALL(interface, BindFramebuffer(GR_GL_FRAMEBUFFER, this->renderFBO
ID())); |
| 91 GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 92 GR_GL_STENCIL_ATTACHMENT, |
| 93 GR_GL_RENDERBUFFER, rb)); |
| 94 if (glStencil->format().fPacked) { |
| 95 GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 96 GR_GL_DEPTH_ATTACHMENT
, |
| 97 GR_GL_RENDERBUFFER, rb
)); |
| 98 } else { |
| 99 GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 100 GR_GL_DEPTH_ATTACHMENT
, |
| 101 GR_GL_RENDERBUFFER, 0)
); |
| 102 } |
| 103 |
| 104 #ifdef SK_DEBUG |
| 105 GrGLenum status; |
| 106 GR_GL_CALL_RET(interface, status, CheckFramebufferStatus(GR_GL_FRAMEBUFF
ER)); |
| 107 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); |
| 108 #endif |
| 109 return true; |
| 110 } |
| 111 } |
| 112 |
63 void GrGLRenderTarget::onRelease() { | 113 void GrGLRenderTarget::onRelease() { |
64 if (kBorrowed_LifeCycle != fRTLifecycle) { | 114 if (kBorrowed_LifeCycle != fRTLifecycle) { |
65 if (fTexFBOID) { | 115 if (fTexFBOID) { |
66 GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); | 116 GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); |
67 } | 117 } |
68 if (fRTFBOID && fRTFBOID != fTexFBOID) { | 118 if (fRTFBOID && fRTFBOID != fTexFBOID) { |
69 GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); | 119 GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); |
70 } | 120 } |
71 if (fMSColorRenderbufferID) { | 121 if (fMSColorRenderbufferID) { |
72 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); | 122 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
73 } | 123 } |
74 } | 124 } |
75 fRTFBOID = 0; | 125 fRTFBOID = 0; |
76 fTexFBOID = 0; | 126 fTexFBOID = 0; |
77 fMSColorRenderbufferID = 0; | 127 fMSColorRenderbufferID = 0; |
78 INHERITED::onRelease(); | 128 INHERITED::onRelease(); |
79 } | 129 } |
80 | 130 |
81 void GrGLRenderTarget::onAbandon() { | 131 void GrGLRenderTarget::onAbandon() { |
82 fRTFBOID = 0; | 132 fRTFBOID = 0; |
83 fTexFBOID = 0; | 133 fTexFBOID = 0; |
84 fMSColorRenderbufferID = 0; | 134 fMSColorRenderbufferID = 0; |
85 INHERITED::onAbandon(); | 135 INHERITED::onAbandon(); |
86 } | 136 } |
| 137 |
| 138 GrGLGpu* GrGLRenderTarget::getGLGpu() const { |
| 139 SkASSERT(!this->wasDestroyed()); |
| 140 return static_cast<GrGLGpu*>(this->getGpu()); |
| 141 } |
| 142 |
OLD | NEW |