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, |
| 19 const GrSurfaceDesc& desc, |
| 20 const IDDesc& idDesc, |
| 21 GrGLStencilAttachment* stencil) |
17 : GrSurface(gpu, idDesc.fLifeCycle, desc) | 22 : GrSurface(gpu, idDesc.fLifeCycle, desc) |
18 , INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig) { | 23 , INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig, stencil) { |
19 this->init(desc, idDesc); | 24 this->init(desc, idDesc); |
20 this->registerWithCache(); | 25 this->registerWithCache(); |
21 } | 26 } |
22 | 27 |
23 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, cons
t IDDesc& idDesc, | 28 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, cons
t IDDesc& idDesc, |
24 Derived) | 29 Derived) |
25 : GrSurface(gpu, idDesc.fLifeCycle, desc) | 30 : GrSurface(gpu, idDesc.fLifeCycle, desc) |
26 , INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig) { | 31 , INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig) { |
27 this->init(desc, idDesc); | 32 this->init(desc, idDesc); |
28 } | 33 } |
(...skipping 20 matching lines...) Expand all Loading... |
49 } | 54 } |
50 SkASSERT(kUnknown_GrPixelConfig != fDesc.fConfig); | 55 SkASSERT(kUnknown_GrPixelConfig != fDesc.fConfig); |
51 SkASSERT(!GrPixelConfigIsCompressed(fDesc.fConfig)); | 56 SkASSERT(!GrPixelConfigIsCompressed(fDesc.fConfig)); |
52 size_t colorBytes = GrBytesPerPixel(fDesc.fConfig); | 57 size_t colorBytes = GrBytesPerPixel(fDesc.fConfig); |
53 SkASSERT(colorBytes > 0); | 58 SkASSERT(colorBytes > 0); |
54 fGpuMemorySize = colorValuesPerPixel * fDesc.fWidth * fDesc.fHeight * colorB
ytes; | 59 fGpuMemorySize = colorValuesPerPixel * fDesc.fWidth * fDesc.fHeight * colorB
ytes; |
55 | 60 |
56 SkASSERT(fGpuMemorySize <= WorseCaseSize(desc)); | 61 SkASSERT(fGpuMemorySize <= WorseCaseSize(desc)); |
57 } | 62 } |
58 | 63 |
| 64 GrGLRenderTarget* GrGLRenderTarget::CreateWrapped(GrGLGpu* gpu, |
| 65 const GrSurfaceDesc& desc, |
| 66 const IDDesc& idDesc, |
| 67 int stencilBits) { |
| 68 GrGLStencilAttachment* sb = nullptr; |
| 69 if (stencilBits) { |
| 70 GrGLStencilAttachment::IDDesc sbDesc; |
| 71 GrGLStencilAttachment::Format format; |
| 72 format.fInternalFormat = GrGLStencilAttachment::kUnknownInternalFormat; |
| 73 format.fPacked = false; |
| 74 format.fStencilBits = stencilBits; |
| 75 format.fTotalBits = stencilBits; |
| 76 // Owndership of sb is passed to the GrRenderTarget so doesn't need to b
e deleted |
| 77 sb = new GrGLStencilAttachment(gpu, sbDesc, desc.fWidth, desc.fHeight, |
| 78 desc.fSampleCnt, format); |
| 79 } |
| 80 return (new GrGLRenderTarget(gpu, desc, idDesc, sb)); |
| 81 } |
| 82 |
59 size_t GrGLRenderTarget::onGpuMemorySize() const { | 83 size_t GrGLRenderTarget::onGpuMemorySize() const { |
60 return fGpuMemorySize; | 84 return fGpuMemorySize; |
61 } | 85 } |
62 | 86 |
| 87 bool GrGLRenderTarget::completeStencilAttachment() { |
| 88 GrGLGpu* gpu = this->getGLGpu(); |
| 89 const GrGLInterface* interface = gpu->glInterface(); |
| 90 GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAttachment
(); |
| 91 if (nullptr == stencil) { |
| 92 if (this->renderTargetPriv().getStencilAttachment()) { |
| 93 GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 94 GR_GL_STENCIL_ATTACHME
NT, |
| 95 GR_GL_RENDERBUFFER, 0)
); |
| 96 GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 97 GR_GL_DEPTH_ATTACHMENT
, |
| 98 GR_GL_RENDERBUFFER, 0)
); |
| 99 #ifdef SK_DEBUG |
| 100 GrGLenum status; |
| 101 GR_GL_CALL_RET(interface, status, CheckFramebufferStatus(GR_GL_FRAME
BUFFER)); |
| 102 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); |
| 103 #endif |
| 104 } |
| 105 return true; |
| 106 } else { |
| 107 const GrGLStencilAttachment* glStencil = static_cast<const GrGLStencilAt
tachment*>(stencil); |
| 108 GrGLuint rb = glStencil->renderbufferID(); |
| 109 |
| 110 gpu->invalidateBoundRenderTarget(); |
| 111 gpu->stats()->incRenderTargetBinds(); |
| 112 GR_GL_CALL(interface, BindFramebuffer(GR_GL_FRAMEBUFFER, this->renderFBO
ID())); |
| 113 GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 114 GR_GL_STENCIL_ATTACHMENT, |
| 115 GR_GL_RENDERBUFFER, rb)); |
| 116 if (glStencil->format().fPacked) { |
| 117 GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 118 GR_GL_DEPTH_ATTACHMENT
, |
| 119 GR_GL_RENDERBUFFER, rb
)); |
| 120 } else { |
| 121 GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 122 GR_GL_DEPTH_ATTACHMENT
, |
| 123 GR_GL_RENDERBUFFER, 0)
); |
| 124 } |
| 125 |
| 126 #ifdef SK_DEBUG |
| 127 GrGLenum status; |
| 128 GR_GL_CALL_RET(interface, status, CheckFramebufferStatus(GR_GL_FRAMEBUFF
ER)); |
| 129 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); |
| 130 #endif |
| 131 return true; |
| 132 } |
| 133 } |
| 134 |
63 void GrGLRenderTarget::onRelease() { | 135 void GrGLRenderTarget::onRelease() { |
64 if (kBorrowed_LifeCycle != fRTLifecycle) { | 136 if (kBorrowed_LifeCycle != fRTLifecycle) { |
65 if (fTexFBOID) { | 137 if (fTexFBOID) { |
66 GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); | 138 GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); |
67 } | 139 } |
68 if (fRTFBOID && fRTFBOID != fTexFBOID) { | 140 if (fRTFBOID && fRTFBOID != fTexFBOID) { |
69 GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); | 141 GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); |
70 } | 142 } |
71 if (fMSColorRenderbufferID) { | 143 if (fMSColorRenderbufferID) { |
72 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); | 144 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
73 } | 145 } |
74 } | 146 } |
75 fRTFBOID = 0; | 147 fRTFBOID = 0; |
76 fTexFBOID = 0; | 148 fTexFBOID = 0; |
77 fMSColorRenderbufferID = 0; | 149 fMSColorRenderbufferID = 0; |
78 INHERITED::onRelease(); | 150 INHERITED::onRelease(); |
79 } | 151 } |
80 | 152 |
81 void GrGLRenderTarget::onAbandon() { | 153 void GrGLRenderTarget::onAbandon() { |
82 fRTFBOID = 0; | 154 fRTFBOID = 0; |
83 fTexFBOID = 0; | 155 fTexFBOID = 0; |
84 fMSColorRenderbufferID = 0; | 156 fMSColorRenderbufferID = 0; |
85 INHERITED::onAbandon(); | 157 INHERITED::onAbandon(); |
86 } | 158 } |
| 159 |
| 160 GrGLGpu* GrGLRenderTarget::getGLGpu() const { |
| 161 SkASSERT(!this->wasDestroyed()); |
| 162 return static_cast<GrGLGpu*>(this->getGpu()); |
| 163 } |
| 164 |
OLD | NEW |