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 | 8 |
9 #include "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
10 #include "GrGLStencilBuffer.h" | 10 #include "GrGLStencilBuffer.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } | 146 } |
147 | 147 |
148 fProgramCache = SkNEW_ARGS(ProgramCache, (this)); | 148 fProgramCache = SkNEW_ARGS(ProgramCache, (this)); |
149 | 149 |
150 SkASSERT(this->glCaps().maxVertexAttributes() >= GrGeometryProcessor::kMaxVe
rtexAttribs); | 150 SkASSERT(this->glCaps().maxVertexAttributes() >= GrGeometryProcessor::kMaxVe
rtexAttribs); |
151 | 151 |
152 fLastSuccessfulStencilFmtIdx = 0; | 152 fLastSuccessfulStencilFmtIdx = 0; |
153 fHWProgramID = 0; | 153 fHWProgramID = 0; |
154 fTempSrcFBOID = 0; | 154 fTempSrcFBOID = 0; |
155 fTempDstFBOID = 0; | 155 fTempDstFBOID = 0; |
| 156 fStencilClearFBOID = 0; |
156 | 157 |
157 if (this->glCaps().pathRenderingSupport()) { | 158 if (this->glCaps().pathRenderingSupport()) { |
158 fPathRendering.reset(new GrGLPathRendering(this)); | 159 fPathRendering.reset(new GrGLPathRendering(this)); |
159 } | 160 } |
160 } | 161 } |
161 | 162 |
162 GrGLGpu::~GrGLGpu() { | 163 GrGLGpu::~GrGLGpu() { |
163 if (0 != fHWProgramID) { | 164 if (0 != fHWProgramID) { |
164 // detach the current program so there is no confusion on OpenGL's part | 165 // detach the current program so there is no confusion on OpenGL's part |
165 // that we want it to be deleted | 166 // that we want it to be deleted |
166 SkASSERT(fHWProgramID == fCurrentProgram->programID()); | 167 SkASSERT(fHWProgramID == fCurrentProgram->programID()); |
167 GL_CALL(UseProgram(0)); | 168 GL_CALL(UseProgram(0)); |
168 } | 169 } |
169 | 170 |
170 if (0 != fTempSrcFBOID) { | 171 if (0 != fTempSrcFBOID) { |
171 GL_CALL(DeleteFramebuffers(1, &fTempSrcFBOID)); | 172 GL_CALL(DeleteFramebuffers(1, &fTempSrcFBOID)); |
172 } | 173 } |
173 if (0 != fTempDstFBOID) { | 174 if (0 != fTempDstFBOID) { |
174 GL_CALL(DeleteFramebuffers(1, &fTempDstFBOID)); | 175 GL_CALL(DeleteFramebuffers(1, &fTempDstFBOID)); |
175 } | 176 } |
| 177 if (0 != fStencilClearFBOID) { |
| 178 GL_CALL(DeleteFramebuffers(1, &fStencilClearFBOID)); |
| 179 } |
176 | 180 |
177 delete fProgramCache; | 181 delete fProgramCache; |
178 } | 182 } |
179 | 183 |
180 void GrGLGpu::contextAbandoned() { | 184 void GrGLGpu::contextAbandoned() { |
181 INHERITED::contextAbandoned(); | 185 INHERITED::contextAbandoned(); |
182 fProgramCache->abandon(); | 186 fProgramCache->abandon(); |
183 fHWProgramID = 0; | 187 fHWProgramID = 0; |
184 fTempSrcFBOID = 0; | 188 fTempSrcFBOID = 0; |
185 fTempDstFBOID = 0; | 189 fTempDstFBOID = 0; |
| 190 fStencilClearFBOID = 0; |
186 if (this->glCaps().pathRenderingSupport()) { | 191 if (this->glCaps().pathRenderingSupport()) { |
187 this->glPathRendering()->abandonGpuResources(); | 192 this->glPathRendering()->abandonGpuResources(); |
188 } | 193 } |
189 } | 194 } |
190 | 195 |
191 /////////////////////////////////////////////////////////////////////////////// | 196 /////////////////////////////////////////////////////////////////////////////// |
192 GrPixelConfig GrGLGpu::preferredReadPixelsConfig(GrPixelConfig readConfig, | 197 GrPixelConfig GrGLGpu::preferredReadPixelsConfig(GrPixelConfig readConfig, |
193 GrPixelConfig surfaceConfig) co
nst { | 198 GrPixelConfig surfaceConfig) co
nst { |
194 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == readConfig
) { | 199 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == readConfig
) { |
195 return kBGRA_8888_GrPixelConfig; | 200 return kBGRA_8888_GrPixelConfig; |
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 sFmt.fInterna
lFormat, | 1170 sFmt.fInterna
lFormat, |
1166 width, height
)); | 1171 width, height
)); |
1167 created = (GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glI
nterface())); | 1172 created = (GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glI
nterface())); |
1168 } | 1173 } |
1169 if (created) { | 1174 if (created) { |
1170 | 1175 |
1171 // After sized formats we attempt an unsized format and take | 1176 // After sized formats we attempt an unsized format and take |
1172 // whatever sizes GL gives us. In that case we query for the size. | 1177 // whatever sizes GL gives us. In that case we query for the size. |
1173 GrGLStencilBuffer::Format format = sFmt; | 1178 GrGLStencilBuffer::Format format = sFmt; |
1174 get_stencil_rb_sizes(this->glInterface(), &format); | 1179 get_stencil_rb_sizes(this->glInterface(), &format); |
1175 SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, | 1180 SkAutoTUnref<GrGLStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, |
1176 (this, sbDesc, width, height,
samples, format))); | 1181 (this, sbDesc, width, height,
samples, format))); |
1177 if (this->attachStencilBufferToRenderTarget(sb, rt)) { | 1182 if (this->attachStencilBufferToRenderTarget(sb, rt)) { |
1178 fLastSuccessfulStencilFmtIdx = sIdx; | 1183 fLastSuccessfulStencilFmtIdx = sIdx; |
1179 rt->renderTargetPriv().didAttachStencilBuffer(sb); | 1184 rt->renderTargetPriv().didAttachStencilBuffer(sb); |
| 1185 |
| 1186 // Clear the stencil buffer. We use a special purpose FBO for th
is so that the |
| 1187 // entire stencil buffer is cleared, even if it is attached to a
n FBO with a |
| 1188 // smaller color target. |
| 1189 if (0 == fStencilClearFBOID) { |
| 1190 GL_CALL(GenFramebuffers(1, &fStencilClearFBOID)); |
| 1191 } |
| 1192 |
| 1193 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fStencilClearFBOID)); |
| 1194 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 1195 fStats.incRenderTargetBinds(); |
| 1196 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1197 GR_GL_STENCIL_ATTACHMENT, |
| 1198 GR_GL_RENDERBUFFER, sbDesc.fRend
erbufferID)); |
| 1199 if (sFmt.fPacked) { |
| 1200 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1201 GR_GL_DEPTH_ATTACHMENT, |
| 1202 GR_GL_RENDERBUFFER, sbDesc.f
RenderbufferID)); |
| 1203 } |
| 1204 |
| 1205 GL_CALL(ClearStencil(0)); |
| 1206 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
| 1207 |
| 1208 // Unbind the SB from the FBO so that we don't keep it alive. |
| 1209 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1210 GR_GL_STENCIL_ATTACHMENT, |
| 1211 GR_GL_RENDERBUFFER, 0)); |
| 1212 if (sFmt.fPacked) { |
| 1213 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1214 GR_GL_DEPTH_ATTACHMENT, |
| 1215 GR_GL_RENDERBUFFER, 0)); |
| 1216 } |
| 1217 |
1180 return true; | 1218 return true; |
1181 } | 1219 } |
1182 // Remove the scratch key from this resource so we don't grab it fro
m the cache ever | 1220 // Remove the scratch key from this resource so we don't grab it fro
m the cache ever |
1183 // again. | 1221 // again. |
1184 sb->resourcePriv().removeScratchKey(); | 1222 sb->resourcePriv().removeScratchKey(); |
1185 // Set this to 0 since we handed the valid ID off to the failed sten
cil buffer resource. | 1223 // Set this to 0 since we handed the valid ID off to the failed sten
cil buffer resource. |
1186 sbDesc.fRenderbufferID = 0; | 1224 sbDesc.fRenderbufferID = 0; |
1187 } | 1225 } |
1188 } | 1226 } |
1189 GL_CALL(DeleteRenderbuffers(1, &sbDesc.fRenderbufferID)); | 1227 GL_CALL(DeleteRenderbuffers(1, &sbDesc.fRenderbufferID)); |
(...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2759 this->setVertexArrayID(gpu, 0); | 2797 this->setVertexArrayID(gpu, 0); |
2760 } | 2798 } |
2761 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2799 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2762 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2800 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2763 fDefaultVertexArrayAttribState.resize(attrCount); | 2801 fDefaultVertexArrayAttribState.resize(attrCount); |
2764 } | 2802 } |
2765 attribState = &fDefaultVertexArrayAttribState; | 2803 attribState = &fDefaultVertexArrayAttribState; |
2766 } | 2804 } |
2767 return attribState; | 2805 return attribState; |
2768 } | 2806 } |
OLD | NEW |