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 "GrGLStencilBuffer.h" | 10 #include "GrGLStencilBuffer.h" |
11 #include "GrTemplates.h" | 11 #include "GrTemplates.h" |
12 #include "GrTypes.h" | 12 #include "GrTypes.h" |
13 #include "SkStrokeRec.h" | 13 #include "SkStrokeRec.h" |
14 #include "SkTemplates.h" | 14 #include "SkTemplates.h" |
15 | 15 |
| 16 int gBindFrameBufferCount = 0; |
| 17 |
16 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) | 18 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
17 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) | 19 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) |
18 | 20 |
19 #define SKIP_CACHE_CHECK true | 21 #define SKIP_CACHE_CHECK true |
20 | 22 |
21 #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR | 23 #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR |
22 #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface) | 24 #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface) |
23 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call) | 25 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call) |
24 #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface) | 26 #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface) |
25 #else | 27 #else |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 if (desc->fRTFBOID != desc->fTexFBOID) { | 864 if (desc->fRTFBOID != desc->fTexFBOID) { |
863 SkASSERT(desc->fSampleCnt > 0); | 865 SkASSERT(desc->fSampleCnt > 0); |
864 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, | 866 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, |
865 desc->fMSColorRenderbufferID)); | 867 desc->fMSColorRenderbufferID)); |
866 if (!renderbuffer_storage_msaa(fGLContext, | 868 if (!renderbuffer_storage_msaa(fGLContext, |
867 desc->fSampleCnt, | 869 desc->fSampleCnt, |
868 msColorFormat, | 870 msColorFormat, |
869 width, height)) { | 871 width, height)) { |
870 goto FAILED; | 872 goto FAILED; |
871 } | 873 } |
| 874 gBindFrameBufferCount++; |
872 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID)); | 875 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID)); |
873 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 876 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
874 GR_GL_COLOR_ATTACHMENT0, | 877 GR_GL_COLOR_ATTACHMENT0, |
875 GR_GL_RENDERBUFFER, | 878 GR_GL_RENDERBUFFER, |
876 desc->fMSColorRenderbufferID)); | 879 desc->fMSColorRenderbufferID)); |
877 if (desc->fCheckAllocation || | 880 if (desc->fCheckAllocation || |
878 !this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) { | 881 !this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) { |
879 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 882 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
880 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 883 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
881 goto FAILED; | 884 goto FAILED; |
882 } | 885 } |
883 fGLContext.caps()->markConfigAsValidColorAttachment(desc->fConfig); | 886 fGLContext.caps()->markConfigAsValidColorAttachment(desc->fConfig); |
884 } | 887 } |
885 } | 888 } |
| 889 gBindFrameBufferCount++; |
886 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID)); | 890 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID)); |
887 | 891 |
888 if (this->glCaps().usesImplicitMSAAResolve() && desc->fSampleCnt > 0) { | 892 if (this->glCaps().usesImplicitMSAAResolve() && desc->fSampleCnt > 0) { |
889 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, | 893 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, |
890 GR_GL_COLOR_ATTACHMENT0, | 894 GR_GL_COLOR_ATTACHMENT0, |
891 GR_GL_TEXTURE_2D, | 895 GR_GL_TEXTURE_2D, |
892 texID, 0, desc->fSampleCnt)); | 896 texID, 0, desc->fSampleCnt)); |
893 } else { | 897 } else { |
894 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, | 898 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
895 GR_GL_COLOR_ATTACHMENT0, | 899 GR_GL_COLOR_ATTACHMENT0, |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 1241 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
1238 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); | 1242 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); |
1239 #endif | 1243 #endif |
1240 } | 1244 } |
1241 return true; | 1245 return true; |
1242 } else { | 1246 } else { |
1243 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb); | 1247 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb); |
1244 GrGLuint rb = glsb->renderbufferID(); | 1248 GrGLuint rb = glsb->renderbufferID(); |
1245 | 1249 |
1246 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | 1250 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 1251 gBindFrameBufferCount++; |
1247 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); | 1252 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); |
1248 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1253 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1249 GR_GL_STENCIL_ATTACHMENT, | 1254 GR_GL_STENCIL_ATTACHMENT, |
1250 GR_GL_RENDERBUFFER, rb)); | 1255 GR_GL_RENDERBUFFER, rb)); |
1251 if (glsb->format().fPacked) { | 1256 if (glsb->format().fPacked) { |
1252 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1257 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1253 GR_GL_DEPTH_ATTACHMENT, | 1258 GR_GL_DEPTH_ATTACHMENT, |
1254 GR_GL_RENDERBUFFER, rb)); | 1259 GR_GL_RENDERBUFFER, rb)); |
1255 } else { | 1260 } else { |
1256 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1261 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 if (NULL == renderTarget) { | 1444 if (NULL == renderTarget) { |
1440 renderTarget = this->drawState()->getRenderTarget(); | 1445 renderTarget = this->drawState()->getRenderTarget(); |
1441 if (NULL == renderTarget) { | 1446 if (NULL == renderTarget) { |
1442 return; | 1447 return; |
1443 } | 1448 } |
1444 } | 1449 } |
1445 | 1450 |
1446 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget); | 1451 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget); |
1447 if (renderTarget->getUniqueID() != fHWBoundRenderTargetUniqueID) { | 1452 if (renderTarget->getUniqueID() != fHWBoundRenderTargetUniqueID) { |
1448 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | 1453 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 1454 gBindFrameBufferCount++; |
1449 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, glRT->renderFBOID())); | 1455 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, glRT->renderFBOID())); |
1450 } | 1456 } |
1451 switch (this->glCaps().invalidateFBType()) { | 1457 switch (this->glCaps().invalidateFBType()) { |
1452 case GrGLCaps::kNone_InvalidateFBType: | 1458 case GrGLCaps::kNone_InvalidateFBType: |
1453 SkFAIL("Should never get here."); | 1459 SkFAIL("Should never get here."); |
1454 break; | 1460 break; |
1455 case GrGLCaps::kInvalidate_InvalidateFBType: | 1461 case GrGLCaps::kInvalidate_InvalidateFBType: |
1456 if (0 == glRT->renderFBOID()) { | 1462 if (0 == glRT->renderFBOID()) { |
1457 // When rendering to the default framebuffer the legal values f
or attachments | 1463 // When rendering to the default framebuffer the legal values f
or attachments |
1458 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the vari
ous FBO attachment | 1464 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the vari
ous FBO attachment |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 switch (tgt->getResolveType()) { | 1610 switch (tgt->getResolveType()) { |
1605 case GrGLRenderTarget::kCantResolve_ResolveType: | 1611 case GrGLRenderTarget::kCantResolve_ResolveType: |
1606 return false; | 1612 return false; |
1607 case GrGLRenderTarget::kAutoResolves_ResolveType: | 1613 case GrGLRenderTarget::kAutoResolves_ResolveType: |
1608 artr.set(this->drawState(), target); | 1614 artr.set(this->drawState(), target); |
1609 this->flushRenderTarget(&SkIRect::EmptyIRect()); | 1615 this->flushRenderTarget(&SkIRect::EmptyIRect()); |
1610 break; | 1616 break; |
1611 case GrGLRenderTarget::kCanResolve_ResolveType: | 1617 case GrGLRenderTarget::kCanResolve_ResolveType: |
1612 this->onResolveRenderTarget(tgt); | 1618 this->onResolveRenderTarget(tgt); |
1613 // we don't track the state of the READ FBO ID. | 1619 // we don't track the state of the READ FBO ID. |
| 1620 gBindFrameBufferCount++; |
1614 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, | 1621 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
1615 tgt->textureFBOID())); | 1622 tgt->textureFBOID())); |
1616 break; | 1623 break; |
1617 default: | 1624 default: |
1618 SkFAIL("Unknown resolve type"); | 1625 SkFAIL("Unknown resolve type"); |
1619 } | 1626 } |
1620 | 1627 |
1621 const GrGLIRect& glvp = tgt->getViewport(); | 1628 const GrGLIRect& glvp = tgt->getViewport(); |
1622 | 1629 |
1623 // the read rect is viewport-relative | 1630 // the read rect is viewport-relative |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 } | 1710 } |
1704 | 1711 |
1705 void GrGpuGL::flushRenderTarget(const SkIRect* bound) { | 1712 void GrGpuGL::flushRenderTarget(const SkIRect* bound) { |
1706 | 1713 |
1707 GrGLRenderTarget* rt = | 1714 GrGLRenderTarget* rt = |
1708 static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget()); | 1715 static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget()); |
1709 SkASSERT(NULL != rt); | 1716 SkASSERT(NULL != rt); |
1710 | 1717 |
1711 uint32_t rtID = rt->getUniqueID(); | 1718 uint32_t rtID = rt->getUniqueID(); |
1712 if (fHWBoundRenderTargetUniqueID != rtID) { | 1719 if (fHWBoundRenderTargetUniqueID != rtID) { |
| 1720 gBindFrameBufferCount++; |
1713 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID())); | 1721 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID())); |
1714 #ifdef SK_DEBUG | 1722 #ifdef SK_DEBUG |
1715 // don't do this check in Chromium -- this is causing | 1723 // don't do this check in Chromium -- this is causing |
1716 // lots of repeated command buffer flushes when the compositor is | 1724 // lots of repeated command buffer flushes when the compositor is |
1717 // rendering with Ganesh, which is really slow; even too slow for | 1725 // rendering with Ganesh, which is really slow; even too slow for |
1718 // Debug mode. | 1726 // Debug mode. |
1719 if (!this->glContext().isChromium()) { | 1727 if (!this->glContext().isChromium()) { |
1720 GrGLenum status; | 1728 GrGLenum status; |
1721 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 1729 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
1722 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 1730 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 #endif | 1813 #endif |
1806 #endif | 1814 #endif |
1807 } | 1815 } |
1808 | 1816 |
1809 void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { | 1817 void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { |
1810 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); | 1818 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |
1811 if (rt->needsResolve()) { | 1819 if (rt->needsResolve()) { |
1812 // Some extensions automatically resolves the texture when it is read. | 1820 // Some extensions automatically resolves the texture when it is read. |
1813 if (this->glCaps().usesMSAARenderBuffers()) { | 1821 if (this->glCaps().usesMSAARenderBuffers()) { |
1814 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); | 1822 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); |
| 1823 gBindFrameBufferCount++; |
1815 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); | 1824 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); |
| 1825 gBindFrameBufferCount++; |
1816 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; | 1826 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; |
1817 // make sure we go through flushRenderTarget() since we've modified | 1827 // make sure we go through flushRenderTarget() since we've modified |
1818 // the bound DRAW FBO ID. | 1828 // the bound DRAW FBO ID. |
1819 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | 1829 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
1820 const GrGLIRect& vp = rt->getViewport(); | 1830 const GrGLIRect& vp = rt->getViewport(); |
1821 const SkIRect dirtyRect = rt->getResolveRect(); | 1831 const SkIRect dirtyRect = rt->getResolveRect(); |
1822 GrGLIRect r; | 1832 GrGLIRect r; |
1823 r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, | 1833 r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, |
1824 dirtyRect.width(), dirtyRect.height(), target->origi
n()); | 1834 dirtyRect.width(), dirtyRect.height(), target->origi
n()); |
1825 | 1835 |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2381 inline GrGLuint bind_surface_as_fbo(const GrGLInterface* gl, | 2391 inline GrGLuint bind_surface_as_fbo(const GrGLInterface* gl, |
2382 GrSurface* surface, | 2392 GrSurface* surface, |
2383 GrGLenum fboTarget, | 2393 GrGLenum fboTarget, |
2384 GrGLIRect* viewport) { | 2394 GrGLIRect* viewport) { |
2385 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarge
t()); | 2395 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarge
t()); |
2386 GrGLuint tempFBOID; | 2396 GrGLuint tempFBOID; |
2387 if (NULL == rt) { | 2397 if (NULL == rt) { |
2388 SkASSERT(NULL != surface->asTexture()); | 2398 SkASSERT(NULL != surface->asTexture()); |
2389 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textur
eID(); | 2399 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textur
eID(); |
2390 GR_GL_CALL(gl, GenFramebuffers(1, &tempFBOID)); | 2400 GR_GL_CALL(gl, GenFramebuffers(1, &tempFBOID)); |
| 2401 gBindFrameBufferCount++; |
2391 GR_GL_CALL(gl, BindFramebuffer(fboTarget, tempFBOID)); | 2402 GR_GL_CALL(gl, BindFramebuffer(fboTarget, tempFBOID)); |
2392 GR_GL_CALL(gl, FramebufferTexture2D(fboTarget, | 2403 GR_GL_CALL(gl, FramebufferTexture2D(fboTarget, |
2393 GR_GL_COLOR_ATTACHMENT0, | 2404 GR_GL_COLOR_ATTACHMENT0, |
2394 GR_GL_TEXTURE_2D, | 2405 GR_GL_TEXTURE_2D, |
2395 texID, | 2406 texID, |
2396 0)); | 2407 0)); |
2397 viewport->fLeft = 0; | 2408 viewport->fLeft = 0; |
2398 viewport->fBottom = 0; | 2409 viewport->fBottom = 0; |
2399 viewport->fWidth = surface->width(); | 2410 viewport->fWidth = surface->width(); |
2400 viewport->fHeight = surface->height(); | 2411 viewport->fHeight = surface->height(); |
2401 } else { | 2412 } else { |
2402 tempFBOID = 0; | 2413 tempFBOID = 0; |
| 2414 gBindFrameBufferCount++; |
2403 GR_GL_CALL(gl, BindFramebuffer(fboTarget, rt->renderFBOID())); | 2415 GR_GL_CALL(gl, BindFramebuffer(fboTarget, rt->renderFBOID())); |
2404 *viewport = rt->getViewport(); | 2416 *viewport = rt->getViewport(); |
2405 } | 2417 } |
2406 return tempFBOID; | 2418 return tempFBOID; |
2407 } | 2419 } |
2408 | 2420 |
2409 } | 2421 } |
2410 | 2422 |
2411 void GrGpuGL::initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc)
{ | 2423 void GrGpuGL::initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc)
{ |
2412 // Check for format issues with glCopyTexSubImage2D | 2424 // Check for format issues with glCopyTexSubImage2D |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2610 this->setVertexArrayID(gpu, 0); | 2622 this->setVertexArrayID(gpu, 0); |
2611 } | 2623 } |
2612 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2624 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2613 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2625 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2614 fDefaultVertexArrayAttribState.resize(attrCount); | 2626 fDefaultVertexArrayAttribState.resize(attrCount); |
2615 } | 2627 } |
2616 attribState = &fDefaultVertexArrayAttribState; | 2628 attribState = &fDefaultVertexArrayAttribState; |
2617 } | 2629 } |
2618 return attribState; | 2630 return attribState; |
2619 } | 2631 } |
OLD | NEW |