| 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 "GrGpuGL.h" | 9 #include "GrGpuGL.h" |
| 10 #include "GrGLNameAllocator.h" | 10 #include "GrGLNameAllocator.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 129 |
| 130 static bool gPrintStartupSpew; | 130 static bool gPrintStartupSpew; |
| 131 | 131 |
| 132 GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) | 132 GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) |
| 133 : GrGpu(context) | 133 : GrGpu(context) |
| 134 , fGLContext(ctx) { | 134 , fGLContext(ctx) { |
| 135 | 135 |
| 136 SkASSERT(ctx.isInitialized()); | 136 SkASSERT(ctx.isInitialized()); |
| 137 fCaps.reset(SkRef(ctx.caps())); | 137 fCaps.reset(SkRef(ctx.caps())); |
| 138 | 138 |
| 139 fHWBoundTextures.reset(this->glCaps().maxFragmentTextureUnits()); | 139 fHWBoundTextureUniqueIDs.reset(this->glCaps().maxFragmentTextureUnits()); |
| 140 fHWPathTexGenSettings.reset(this->glCaps().maxFixedFunctionTextureCoords()); | 140 fHWPathTexGenSettings.reset(this->glCaps().maxFixedFunctionTextureCoords()); |
| 141 | 141 |
| 142 GrGLClearErr(fGLContext.interface()); | 142 GrGLClearErr(fGLContext.interface()); |
| 143 if (gPrintStartupSpew) { | 143 if (gPrintStartupSpew) { |
| 144 const GrGLubyte* vendor; | 144 const GrGLubyte* vendor; |
| 145 const GrGLubyte* renderer; | 145 const GrGLubyte* renderer; |
| 146 const GrGLubyte* version; | 146 const GrGLubyte* version; |
| 147 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); | 147 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); |
| 148 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); | 148 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); |
| 149 GL_CALL_RET(version, GetString(GR_GL_VERSION)); | 149 GL_CALL_RET(version, GetString(GR_GL_VERSION)); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 GL_CALL(LineWidth(1)); | 280 GL_CALL(LineWidth(1)); |
| 281 } | 281 } |
| 282 | 282 |
| 283 if (resetBits & kAA_GrGLBackendState) { | 283 if (resetBits & kAA_GrGLBackendState) { |
| 284 fHWAAState.invalidate(); | 284 fHWAAState.invalidate(); |
| 285 } | 285 } |
| 286 | 286 |
| 287 fHWActiveTextureUnitIdx = -1; // invalid | 287 fHWActiveTextureUnitIdx = -1; // invalid |
| 288 | 288 |
| 289 if (resetBits & kTextureBinding_GrGLBackendState) { | 289 if (resetBits & kTextureBinding_GrGLBackendState) { |
| 290 for (int s = 0; s < fHWBoundTextures.count(); ++s) { | 290 for (int s = 0; s < fHWBoundTextureUniqueIDs.count(); ++s) { |
| 291 fHWBoundTextures[s] = NULL; | 291 fHWBoundTextureUniqueIDs[s] = SK_InvalidUniqueID; |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 | 294 |
| 295 if (resetBits & kBlend_GrGLBackendState) { | 295 if (resetBits & kBlend_GrGLBackendState) { |
| 296 fHWBlendState.invalidate(); | 296 fHWBlendState.invalidate(); |
| 297 } | 297 } |
| 298 | 298 |
| 299 if (resetBits & kView_GrGLBackendState) { | 299 if (resetBits & kView_GrGLBackendState) { |
| 300 fHWScissorSettings.invalidate(); | 300 fHWScissorSettings.invalidate(); |
| 301 fHWViewport.invalidate(); | 301 fHWViewport.invalidate(); |
| 302 } | 302 } |
| 303 | 303 |
| 304 if (resetBits & kStencil_GrGLBackendState) { | 304 if (resetBits & kStencil_GrGLBackendState) { |
| 305 fHWStencilSettings.invalidate(); | 305 fHWStencilSettings.invalidate(); |
| 306 fHWStencilTestEnabled = kUnknown_TriState; | 306 fHWStencilTestEnabled = kUnknown_TriState; |
| 307 } | 307 } |
| 308 | 308 |
| 309 // Vertex | 309 // Vertex |
| 310 if (resetBits & kVertex_GrGLBackendState) { | 310 if (resetBits & kVertex_GrGLBackendState) { |
| 311 fHWGeometryState.invalidate(); | 311 fHWGeometryState.invalidate(); |
| 312 } | 312 } |
| 313 | 313 |
| 314 if (resetBits & kRenderTarget_GrGLBackendState) { | 314 if (resetBits & kRenderTarget_GrGLBackendState) { |
| 315 fHWBoundRenderTarget = NULL; | 315 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 316 } | 316 } |
| 317 | 317 |
| 318 if (resetBits & kPathRendering_GrGLBackendState) { | 318 if (resetBits & kPathRendering_GrGLBackendState) { |
| 319 if (this->caps()->pathRenderingSupport()) { | 319 if (this->caps()->pathRenderingSupport()) { |
| 320 fHWProjectionMatrixState.invalidate(); | 320 fHWProjectionMatrixState.invalidate(); |
| 321 // we don't use the model view matrix. | 321 // we don't use the model view matrix. |
| 322 GL_CALL(MatrixLoadIdentity(GR_GL_MODELVIEW)); | 322 GL_CALL(MatrixLoadIdentity(GR_GL_MODELVIEW)); |
| 323 | 323 |
| 324 for (int i = 0; i < this->glCaps().maxFixedFunctionTextureCoords();
++i) { | 324 for (int i = 0; i < this->glCaps().maxFixedFunctionTextureCoords();
++i) { |
| 325 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL)); | 325 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL)); |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 &msColorFormat, | 882 &msColorFormat, |
| 883 NULL, | 883 NULL, |
| 884 NULL)) { | 884 NULL)) { |
| 885 goto FAILED; | 885 goto FAILED; |
| 886 } | 886 } |
| 887 } else { | 887 } else { |
| 888 desc->fRTFBOID = desc->fTexFBOID; | 888 desc->fRTFBOID = desc->fTexFBOID; |
| 889 } | 889 } |
| 890 | 890 |
| 891 // below here we may bind the FBO | 891 // below here we may bind the FBO |
| 892 fHWBoundRenderTarget = NULL; | 892 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 893 if (desc->fRTFBOID != desc->fTexFBOID) { | 893 if (desc->fRTFBOID != desc->fTexFBOID) { |
| 894 SkASSERT(desc->fSampleCnt > 0); | 894 SkASSERT(desc->fSampleCnt > 0); |
| 895 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, | 895 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, |
| 896 desc->fMSColorRenderbufferID)); | 896 desc->fMSColorRenderbufferID)); |
| 897 if (!renderbuffer_storage_msaa(fGLContext, | 897 if (!renderbuffer_storage_msaa(fGLContext, |
| 898 desc->fSampleCnt, | 898 desc->fSampleCnt, |
| 899 msColorFormat, | 899 msColorFormat, |
| 900 width, height)) { | 900 width, height)) { |
| 901 goto FAILED; | 901 goto FAILED; |
| 902 } | 902 } |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 GrGLenum status; | 1267 GrGLenum status; |
| 1268 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 1268 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 1269 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); | 1269 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); |
| 1270 #endif | 1270 #endif |
| 1271 } | 1271 } |
| 1272 return true; | 1272 return true; |
| 1273 } else { | 1273 } else { |
| 1274 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb); | 1274 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb); |
| 1275 GrGLuint rb = glsb->renderbufferID(); | 1275 GrGLuint rb = glsb->renderbufferID(); |
| 1276 | 1276 |
| 1277 fHWBoundRenderTarget = NULL; | 1277 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 1278 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); | 1278 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); |
| 1279 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1279 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1280 GR_GL_STENCIL_ATTACHMENT, | 1280 GR_GL_STENCIL_ATTACHMENT, |
| 1281 GR_GL_RENDERBUFFER, rb)); | 1281 GR_GL_RENDERBUFFER, rb)); |
| 1282 if (glsb->format().fPacked) { | 1282 if (glsb->format().fPacked) { |
| 1283 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1283 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1284 GR_GL_DEPTH_ATTACHMENT, | 1284 GR_GL_DEPTH_ATTACHMENT, |
| 1285 GR_GL_RENDERBUFFER, rb)); | 1285 GR_GL_RENDERBUFFER, rb)); |
| 1286 } else { | 1286 } else { |
| 1287 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1287 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1478 return; | 1478 return; |
| 1479 } | 1479 } |
| 1480 if (NULL == renderTarget) { | 1480 if (NULL == renderTarget) { |
| 1481 renderTarget = this->drawState()->getRenderTarget(); | 1481 renderTarget = this->drawState()->getRenderTarget(); |
| 1482 if (NULL == renderTarget) { | 1482 if (NULL == renderTarget) { |
| 1483 return; | 1483 return; |
| 1484 } | 1484 } |
| 1485 } | 1485 } |
| 1486 | 1486 |
| 1487 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget); | 1487 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget); |
| 1488 if (renderTarget != fHWBoundRenderTarget) { | 1488 if (renderTarget->getUniqueID() != fHWBoundRenderTargetUniqueID) { |
| 1489 fHWBoundRenderTarget = NULL; | 1489 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 1490 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, glRT->renderFBOID())); | 1490 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, glRT->renderFBOID())); |
| 1491 } | 1491 } |
| 1492 switch (this->glCaps().invalidateFBType()) { | 1492 switch (this->glCaps().invalidateFBType()) { |
| 1493 case GrGLCaps::kNone_FBFetchType: | 1493 case GrGLCaps::kNone_FBFetchType: |
| 1494 SkFAIL("Should never get here."); | 1494 SkFAIL("Should never get here."); |
| 1495 break; | 1495 break; |
| 1496 case GrGLCaps::kInvalidate_InvalidateFBType: | 1496 case GrGLCaps::kInvalidate_InvalidateFBType: |
| 1497 if (0 == glRT->renderFBOID()) { | 1497 if (0 == glRT->renderFBOID()) { |
| 1498 // When rendering to the default framebuffer the legal values f
or attachments | 1498 // When rendering to the default framebuffer the legal values f
or attachments |
| 1499 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the vari
ous FBO attachment | 1499 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the vari
ous FBO attachment |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1742 } | 1742 } |
| 1743 return true; | 1743 return true; |
| 1744 } | 1744 } |
| 1745 | 1745 |
| 1746 void GrGpuGL::flushRenderTarget(const SkIRect* bound) { | 1746 void GrGpuGL::flushRenderTarget(const SkIRect* bound) { |
| 1747 | 1747 |
| 1748 GrGLRenderTarget* rt = | 1748 GrGLRenderTarget* rt = |
| 1749 static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget()); | 1749 static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget()); |
| 1750 SkASSERT(NULL != rt); | 1750 SkASSERT(NULL != rt); |
| 1751 | 1751 |
| 1752 if (fHWBoundRenderTarget != rt) { | 1752 uint32_t rtID = rt->getUniqueID(); |
| 1753 if (fHWBoundRenderTargetUniqueID != rtID) { |
| 1753 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID())); | 1754 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID())); |
| 1754 #ifdef SK_DEBUG | 1755 #ifdef SK_DEBUG |
| 1755 // don't do this check in Chromium -- this is causing | 1756 // don't do this check in Chromium -- this is causing |
| 1756 // lots of repeated command buffer flushes when the compositor is | 1757 // lots of repeated command buffer flushes when the compositor is |
| 1757 // rendering with Ganesh, which is really slow; even too slow for | 1758 // rendering with Ganesh, which is really slow; even too slow for |
| 1758 // Debug mode. | 1759 // Debug mode. |
| 1759 if (!this->glContext().isChromium()) { | 1760 if (!this->glContext().isChromium()) { |
| 1760 GrGLenum status; | 1761 GrGLenum status; |
| 1761 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 1762 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 1762 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 1763 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 1763 GrPrintf("GrGpuGL::flushRenderTarget glCheckFramebufferStatus %x
\n", status); | 1764 GrPrintf("GrGpuGL::flushRenderTarget glCheckFramebufferStatus %x
\n", status); |
| 1764 } | 1765 } |
| 1765 } | 1766 } |
| 1766 #endif | 1767 #endif |
| 1767 fHWBoundRenderTarget = rt; | 1768 fHWBoundRenderTargetUniqueID = rtID; |
| 1768 const GrGLIRect& vp = rt->getViewport(); | 1769 const GrGLIRect& vp = rt->getViewport(); |
| 1769 if (fHWViewport != vp) { | 1770 if (fHWViewport != vp) { |
| 1770 vp.pushToGLViewport(this->glInterface()); | 1771 vp.pushToGLViewport(this->glInterface()); |
| 1771 fHWViewport = vp; | 1772 fHWViewport = vp; |
| 1772 } | 1773 } |
| 1773 } | 1774 } |
| 1774 if (NULL == bound || !bound->isEmpty()) { | 1775 if (NULL == bound || !bound->isEmpty()) { |
| 1775 rt->flagAsNeedingResolve(bound); | 1776 rt->flagAsNeedingResolve(bound); |
| 1776 } | 1777 } |
| 1777 | 1778 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2000 void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { | 2001 void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { |
| 2001 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); | 2002 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |
| 2002 if (rt->needsResolve()) { | 2003 if (rt->needsResolve()) { |
| 2003 // Some extensions automatically resolves the texture when it is read. | 2004 // Some extensions automatically resolves the texture when it is read. |
| 2004 if (this->glCaps().usesMSAARenderBuffers()) { | 2005 if (this->glCaps().usesMSAARenderBuffers()) { |
| 2005 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); | 2006 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); |
| 2006 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); | 2007 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); |
| 2007 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; | 2008 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; |
| 2008 // make sure we go through flushRenderTarget() since we've modified | 2009 // make sure we go through flushRenderTarget() since we've modified |
| 2009 // the bound DRAW FBO ID. | 2010 // the bound DRAW FBO ID. |
| 2010 fHWBoundRenderTarget = NULL; | 2011 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 2011 const GrGLIRect& vp = rt->getViewport(); | 2012 const GrGLIRect& vp = rt->getViewport(); |
| 2012 const SkIRect dirtyRect = rt->getResolveRect(); | 2013 const SkIRect dirtyRect = rt->getResolveRect(); |
| 2013 GrGLIRect r; | 2014 GrGLIRect r; |
| 2014 r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, | 2015 r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, |
| 2015 dirtyRect.width(), dirtyRect.height(), target->origi
n()); | 2016 dirtyRect.width(), dirtyRect.height(), target->origi
n()); |
| 2016 | 2017 |
| 2017 GrAutoTRestore<ScissorState> asr; | 2018 GrAutoTRestore<ScissorState> asr; |
| 2018 if (GrGLCaps::kES_Apple_MSFBOType == this->glCaps().msFBOType()) { | 2019 if (GrGLCaps::kES_Apple_MSFBOType == this->glCaps().msFBOType()) { |
| 2019 // Apple's extension uses the scissor as the blit bounds. | 2020 // Apple's extension uses the scissor as the blit bounds. |
| 2020 asr.reset(&fScissorState); | 2021 asr.reset(&fScissorState); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2294 SkASSERT(NULL != texture); | 2295 SkASSERT(NULL != texture); |
| 2295 | 2296 |
| 2296 // If we created a rt/tex and rendered to it without using a texture and now
we're texturing | 2297 // If we created a rt/tex and rendered to it without using a texture and now
we're texturing |
| 2297 // from the rt it will still be the last bound texture, but it needs resolvi
ng. So keep this | 2298 // from the rt it will still be the last bound texture, but it needs resolvi
ng. So keep this |
| 2298 // out of the "last != next" check. | 2299 // out of the "last != next" check. |
| 2299 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderT
arget()); | 2300 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderT
arget()); |
| 2300 if (NULL != texRT) { | 2301 if (NULL != texRT) { |
| 2301 this->onResolveRenderTarget(texRT); | 2302 this->onResolveRenderTarget(texRT); |
| 2302 } | 2303 } |
| 2303 | 2304 |
| 2304 if (fHWBoundTextures[unitIdx] != texture) { | 2305 uint32_t textureID = texture->getUniqueID(); |
| 2306 if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) { |
| 2305 this->setTextureUnit(unitIdx); | 2307 this->setTextureUnit(unitIdx); |
| 2306 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texture->textureID())); | 2308 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texture->textureID())); |
| 2307 fHWBoundTextures[unitIdx] = texture; | 2309 fHWBoundTextureUniqueIDs[unitIdx] = textureID; |
| 2308 } | 2310 } |
| 2309 | 2311 |
| 2310 ResetTimestamp timestamp; | 2312 ResetTimestamp timestamp; |
| 2311 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&ti
mestamp); | 2313 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&ti
mestamp); |
| 2312 bool setAll = timestamp < this->getResetTimestamp(); | 2314 bool setAll = timestamp < this->getResetTimestamp(); |
| 2313 GrGLTexture::TexParams newTexParams; | 2315 GrGLTexture::TexParams newTexParams; |
| 2314 | 2316 |
| 2315 static GrGLenum glMinFilterModes[] = { | 2317 static GrGLenum glMinFilterModes[] = { |
| 2316 GR_GL_NEAREST, | 2318 GR_GL_NEAREST, |
| 2317 GR_GL_LINEAR, | 2319 GR_GL_LINEAR, |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2525 case GrDrawState::kBoth_DrawFace: | 2527 case GrDrawState::kBoth_DrawFace: |
| 2526 GL_CALL(Disable(GR_GL_CULL_FACE)); | 2528 GL_CALL(Disable(GR_GL_CULL_FACE)); |
| 2527 break; | 2529 break; |
| 2528 default: | 2530 default: |
| 2529 SkFAIL("Unknown draw face."); | 2531 SkFAIL("Unknown draw face."); |
| 2530 } | 2532 } |
| 2531 fHWDrawFace = drawState.getDrawFace(); | 2533 fHWDrawFace = drawState.getDrawFace(); |
| 2532 } | 2534 } |
| 2533 } | 2535 } |
| 2534 | 2536 |
| 2535 void GrGpuGL::notifyRenderTargetDelete(GrRenderTarget* renderTarget) { | |
| 2536 SkASSERT(NULL != renderTarget); | |
| 2537 if (fHWBoundRenderTarget == renderTarget) { | |
| 2538 fHWBoundRenderTarget = NULL; | |
| 2539 } | |
| 2540 } | |
| 2541 | |
| 2542 void GrGpuGL::notifyTextureDelete(GrGLTexture* texture) { | |
| 2543 for (int s = 0; s < fHWBoundTextures.count(); ++s) { | |
| 2544 if (fHWBoundTextures[s] == texture) { | |
| 2545 // deleting bound texture does implied bind to 0 | |
| 2546 fHWBoundTextures[s] = NULL; | |
| 2547 } | |
| 2548 } | |
| 2549 } | |
| 2550 | |
| 2551 | |
| 2552 GrGLuint GrGpuGL::createGLPathObject() { | 2537 GrGLuint GrGpuGL::createGLPathObject() { |
| 2553 if (NULL == fPathNameAllocator.get()) { | 2538 if (NULL == fPathNameAllocator.get()) { |
| 2554 static const int range = 65536; | 2539 static const int range = 65536; |
| 2555 GrGLuint firstName; | 2540 GrGLuint firstName; |
| 2556 GL_CALL_RET(firstName, GenPaths(range)); | 2541 GL_CALL_RET(firstName, GenPaths(range)); |
| 2557 fPathNameAllocator.reset(SkNEW_ARGS(GrGLNameAllocator, (firstName, first
Name + range))); | 2542 fPathNameAllocator.reset(SkNEW_ARGS(GrGLNameAllocator, (firstName, first
Name + range))); |
| 2558 } | 2543 } |
| 2559 | 2544 |
| 2560 GrGLuint name = fPathNameAllocator->allocateName(); | 2545 GrGLuint name = fPathNameAllocator->allocateName(); |
| 2561 if (0 == name) { | 2546 if (0 == name) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2712 *externalType = GR_GL_FLOAT; | 2697 *externalType = GR_GL_FLOAT; |
| 2713 break; | 2698 break; |
| 2714 | 2699 |
| 2715 default: | 2700 default: |
| 2716 return false; | 2701 return false; |
| 2717 } | 2702 } |
| 2718 return true; | 2703 return true; |
| 2719 } | 2704 } |
| 2720 | 2705 |
| 2721 void GrGpuGL::setTextureUnit(int unit) { | 2706 void GrGpuGL::setTextureUnit(int unit) { |
| 2722 SkASSERT(unit >= 0 && unit < fHWBoundTextures.count()); | 2707 SkASSERT(unit >= 0 && unit < fHWBoundTextureUniqueIDs.count()); |
| 2723 if (unit != fHWActiveTextureUnitIdx) { | 2708 if (unit != fHWActiveTextureUnitIdx) { |
| 2724 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit)); | 2709 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit)); |
| 2725 fHWActiveTextureUnitIdx = unit; | 2710 fHWActiveTextureUnitIdx = unit; |
| 2726 } | 2711 } |
| 2727 } | 2712 } |
| 2728 | 2713 |
| 2729 void GrGpuGL::setScratchTextureUnit() { | 2714 void GrGpuGL::setScratchTextureUnit() { |
| 2730 // Bind the last texture unit since it is the least likely to be used by GrG
LProgram. | 2715 // Bind the last texture unit since it is the least likely to be used by GrG
LProgram. |
| 2731 int lastUnitIdx = fHWBoundTextures.count() - 1; | 2716 int lastUnitIdx = fHWBoundTextureUniqueIDs.count() - 1; |
| 2732 if (lastUnitIdx != fHWActiveTextureUnitIdx) { | 2717 if (lastUnitIdx != fHWActiveTextureUnitIdx) { |
| 2733 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + lastUnitIdx)); | 2718 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + lastUnitIdx)); |
| 2734 fHWActiveTextureUnitIdx = lastUnitIdx; | 2719 fHWActiveTextureUnitIdx = lastUnitIdx; |
| 2735 } | 2720 } |
| 2736 // clear out the this field so that if a program does use this unit it will
rebind the correct | 2721 // clear out the this field so that if a program does use this unit it will
rebind the correct |
| 2737 // texture. | 2722 // texture. |
| 2738 fHWBoundTextures[lastUnitIdx] = NULL; | 2723 fHWBoundTextureUniqueIDs[lastUnitIdx] = SK_InvalidUniqueID; |
| 2739 } | 2724 } |
| 2740 | 2725 |
| 2741 namespace { | 2726 namespace { |
| 2742 // Determines whether glBlitFramebuffer could be used between src and dst. | 2727 // Determines whether glBlitFramebuffer could be used between src and dst. |
| 2743 inline bool can_blit_framebuffer(const GrSurface* dst, | 2728 inline bool can_blit_framebuffer(const GrSurface* dst, |
| 2744 const GrSurface* src, | 2729 const GrSurface* src, |
| 2745 const GrGpuGL* gpu, | 2730 const GrGpuGL* gpu, |
| 2746 bool* wouldNeedTempFBO = NULL) { | 2731 bool* wouldNeedTempFBO = NULL) { |
| 2747 if (gpu->glCaps().isConfigRenderable(dst->config(), dst->desc().fSampleCnt >
0) && | 2732 if (gpu->glCaps().isConfigRenderable(dst->config(), dst->desc().fSampleCnt >
0) && |
| 2748 gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt >
0) && | 2733 gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt >
0) && |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2865 bool copied = false; | 2850 bool copied = false; |
| 2866 bool wouldNeedTempFBO = false; | 2851 bool wouldNeedTempFBO = false; |
| 2867 if (can_copy_texsubimage(dst, src, this, &wouldNeedTempFBO) && | 2852 if (can_copy_texsubimage(dst, src, this, &wouldNeedTempFBO) && |
| 2868 (!wouldNeedTempFBO || !inheritedCouldCopy)) { | 2853 (!wouldNeedTempFBO || !inheritedCouldCopy)) { |
| 2869 GrGLuint srcFBO; | 2854 GrGLuint srcFBO; |
| 2870 GrGLIRect srcVP; | 2855 GrGLIRect srcVP; |
| 2871 srcFBO = bind_surface_as_fbo(this->glInterface(), src, GR_GL_FRAMEBUFFER
, &srcVP); | 2856 srcFBO = bind_surface_as_fbo(this->glInterface(), src, GR_GL_FRAMEBUFFER
, &srcVP); |
| 2872 GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture()); | 2857 GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture()); |
| 2873 SkASSERT(NULL != dstTex); | 2858 SkASSERT(NULL != dstTex); |
| 2874 // We modified the bound FBO | 2859 // We modified the bound FBO |
| 2875 fHWBoundRenderTarget = NULL; | 2860 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 2876 GrGLIRect srcGLRect; | 2861 GrGLIRect srcGLRect; |
| 2877 srcGLRect.setRelativeTo(srcVP, | 2862 srcGLRect.setRelativeTo(srcVP, |
| 2878 srcRect.fLeft, | 2863 srcRect.fLeft, |
| 2879 srcRect.fTop, | 2864 srcRect.fTop, |
| 2880 srcRect.width(), | 2865 srcRect.width(), |
| 2881 srcRect.height(), | 2866 srcRect.height(), |
| 2882 src->origin()); | 2867 src->origin()); |
| 2883 | 2868 |
| 2884 this->setScratchTextureUnit(); | 2869 this->setScratchTextureUnit(); |
| 2885 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, dstTex->textureID())); | 2870 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, dstTex->textureID())); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2907 } | 2892 } |
| 2908 | 2893 |
| 2909 if (!selfOverlap) { | 2894 if (!selfOverlap) { |
| 2910 GrGLuint dstFBO; | 2895 GrGLuint dstFBO; |
| 2911 GrGLuint srcFBO; | 2896 GrGLuint srcFBO; |
| 2912 GrGLIRect dstVP; | 2897 GrGLIRect dstVP; |
| 2913 GrGLIRect srcVP; | 2898 GrGLIRect srcVP; |
| 2914 dstFBO = bind_surface_as_fbo(this->glInterface(), dst, GR_GL_DRAW_FR
AMEBUFFER, &dstVP); | 2899 dstFBO = bind_surface_as_fbo(this->glInterface(), dst, GR_GL_DRAW_FR
AMEBUFFER, &dstVP); |
| 2915 srcFBO = bind_surface_as_fbo(this->glInterface(), src, GR_GL_READ_FR
AMEBUFFER, &srcVP); | 2900 srcFBO = bind_surface_as_fbo(this->glInterface(), src, GR_GL_READ_FR
AMEBUFFER, &srcVP); |
| 2916 // We modified the bound FBO | 2901 // We modified the bound FBO |
| 2917 fHWBoundRenderTarget = NULL; | 2902 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 2918 GrGLIRect srcGLRect; | 2903 GrGLIRect srcGLRect; |
| 2919 GrGLIRect dstGLRect; | 2904 GrGLIRect dstGLRect; |
| 2920 srcGLRect.setRelativeTo(srcVP, | 2905 srcGLRect.setRelativeTo(srcVP, |
| 2921 srcRect.fLeft, | 2906 srcRect.fLeft, |
| 2922 srcRect.fTop, | 2907 srcRect.fTop, |
| 2923 srcRect.width(), | 2908 srcRect.width(), |
| 2924 srcRect.height(), | 2909 srcRect.height(), |
| 2925 src->origin()); | 2910 src->origin()); |
| 2926 dstGLRect.setRelativeTo(dstVP, | 2911 dstGLRect.setRelativeTo(dstVP, |
| 2927 dstRect.fLeft, | 2912 dstRect.fLeft, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3033 this->setVertexArrayID(gpu, 0); | 3018 this->setVertexArrayID(gpu, 0); |
| 3034 } | 3019 } |
| 3035 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3020 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 3036 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3021 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 3037 fDefaultVertexArrayAttribState.resize(attrCount); | 3022 fDefaultVertexArrayAttribState.resize(attrCount); |
| 3038 } | 3023 } |
| 3039 attribState = &fDefaultVertexArrayAttribState; | 3024 attribState = &fDefaultVertexArrayAttribState; |
| 3040 } | 3025 } |
| 3041 return attribState; | 3026 return attribState; |
| 3042 } | 3027 } |
| OLD | NEW |