| 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 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | 843 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 844 if (idDesc->fRTFBOID != idDesc->fTexFBOID) { | 844 if (idDesc->fRTFBOID != idDesc->fTexFBOID) { |
| 845 SkASSERT(desc.fSampleCnt > 0); | 845 SkASSERT(desc.fSampleCnt > 0); |
| 846 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbuffe
rID)); | 846 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbuffe
rID)); |
| 847 if (!renderbuffer_storage_msaa(fGLContext, | 847 if (!renderbuffer_storage_msaa(fGLContext, |
| 848 desc.fSampleCnt, | 848 desc.fSampleCnt, |
| 849 msColorFormat, | 849 msColorFormat, |
| 850 desc.fWidth, desc.fHeight)) { | 850 desc.fWidth, desc.fHeight)) { |
| 851 goto FAILED; | 851 goto FAILED; |
| 852 } | 852 } |
| 853 fGPUStats.incRenderTargetBinds(); | 853 fStats.incRenderTargetBinds(); |
| 854 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fRTFBOID)); | 854 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fRTFBOID)); |
| 855 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 855 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 856 GR_GL_COLOR_ATTACHMENT0, | 856 GR_GL_COLOR_ATTACHMENT0, |
| 857 GR_GL_RENDERBUFFER, | 857 GR_GL_RENDERBUFFER, |
| 858 idDesc->fMSColorRenderbufferID)); | 858 idDesc->fMSColorRenderbufferID)); |
| 859 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || | 859 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || |
| 860 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { | 860 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { |
| 861 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 861 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 862 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 862 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 863 goto FAILED; | 863 goto FAILED; |
| 864 } | 864 } |
| 865 fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig); | 865 fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig); |
| 866 } | 866 } |
| 867 } | 867 } |
| 868 fGPUStats.incRenderTargetBinds(); | 868 fStats.incRenderTargetBinds(); |
| 869 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fTexFBOID)); | 869 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fTexFBOID)); |
| 870 | 870 |
| 871 if (this->glCaps().usesImplicitMSAAResolve() && desc.fSampleCnt > 0) { | 871 if (this->glCaps().usesImplicitMSAAResolve() && desc.fSampleCnt > 0) { |
| 872 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, | 872 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, |
| 873 GR_GL_COLOR_ATTACHMENT0, | 873 GR_GL_COLOR_ATTACHMENT0, |
| 874 GR_GL_TEXTURE_2D, | 874 GR_GL_TEXTURE_2D, |
| 875 texID, 0, desc.fSampleCnt)); | 875 texID, 0, desc.fSampleCnt)); |
| 876 } else { | 876 } else { |
| 877 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, | 877 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
| 878 GR_GL_COLOR_ATTACHMENT0, | 878 GR_GL_COLOR_ATTACHMENT0, |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 1202 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 1203 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); | 1203 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); |
| 1204 #endif | 1204 #endif |
| 1205 } | 1205 } |
| 1206 return true; | 1206 return true; |
| 1207 } else { | 1207 } else { |
| 1208 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb); | 1208 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb); |
| 1209 GrGLuint rb = glsb->renderbufferID(); | 1209 GrGLuint rb = glsb->renderbufferID(); |
| 1210 | 1210 |
| 1211 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | 1211 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 1212 fGPUStats.incRenderTargetBinds(); | 1212 fStats.incRenderTargetBinds(); |
| 1213 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); | 1213 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); |
| 1214 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1214 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1215 GR_GL_STENCIL_ATTACHMENT, | 1215 GR_GL_STENCIL_ATTACHMENT, |
| 1216 GR_GL_RENDERBUFFER, rb)); | 1216 GR_GL_RENDERBUFFER, rb)); |
| 1217 if (glsb->format().fPacked) { | 1217 if (glsb->format().fPacked) { |
| 1218 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1218 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1219 GR_GL_DEPTH_ATTACHMENT, | 1219 GR_GL_DEPTH_ATTACHMENT, |
| 1220 GR_GL_RENDERBUFFER, rb)); | 1220 GR_GL_RENDERBUFFER, rb)); |
| 1221 } else { | 1221 } else { |
| 1222 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1222 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 | 1502 |
| 1503 void GrGLGpu::discard(GrRenderTarget* renderTarget) { | 1503 void GrGLGpu::discard(GrRenderTarget* renderTarget) { |
| 1504 SkASSERT(renderTarget); | 1504 SkASSERT(renderTarget); |
| 1505 if (!this->caps()->discardRenderTargetSupport()) { | 1505 if (!this->caps()->discardRenderTargetSupport()) { |
| 1506 return; | 1506 return; |
| 1507 } | 1507 } |
| 1508 | 1508 |
| 1509 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget); | 1509 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget); |
| 1510 if (renderTarget->getUniqueID() != fHWBoundRenderTargetUniqueID) { | 1510 if (renderTarget->getUniqueID() != fHWBoundRenderTargetUniqueID) { |
| 1511 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | 1511 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 1512 fGPUStats.incRenderTargetBinds(); | 1512 fStats.incRenderTargetBinds(); |
| 1513 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, glRT->renderFBOID())); | 1513 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, glRT->renderFBOID())); |
| 1514 } | 1514 } |
| 1515 switch (this->glCaps().invalidateFBType()) { | 1515 switch (this->glCaps().invalidateFBType()) { |
| 1516 case GrGLCaps::kNone_InvalidateFBType: | 1516 case GrGLCaps::kNone_InvalidateFBType: |
| 1517 SkFAIL("Should never get here."); | 1517 SkFAIL("Should never get here."); |
| 1518 break; | 1518 break; |
| 1519 case GrGLCaps::kInvalidate_InvalidateFBType: | 1519 case GrGLCaps::kInvalidate_InvalidateFBType: |
| 1520 if (0 == glRT->renderFBOID()) { | 1520 if (0 == glRT->renderFBOID()) { |
| 1521 // When rendering to the default framebuffer the legal values f
or attachments | 1521 // When rendering to the default framebuffer the legal values f
or attachments |
| 1522 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the vari
ous FBO attachment | 1522 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the vari
ous FBO attachment |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); | 1663 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); |
| 1664 switch (tgt->getResolveType()) { | 1664 switch (tgt->getResolveType()) { |
| 1665 case GrGLRenderTarget::kCantResolve_ResolveType: | 1665 case GrGLRenderTarget::kCantResolve_ResolveType: |
| 1666 return false; | 1666 return false; |
| 1667 case GrGLRenderTarget::kAutoResolves_ResolveType: | 1667 case GrGLRenderTarget::kAutoResolves_ResolveType: |
| 1668 this->flushRenderTarget(static_cast<GrGLRenderTarget*>(target), &SkI
Rect::EmptyIRect()); | 1668 this->flushRenderTarget(static_cast<GrGLRenderTarget*>(target), &SkI
Rect::EmptyIRect()); |
| 1669 break; | 1669 break; |
| 1670 case GrGLRenderTarget::kCanResolve_ResolveType: | 1670 case GrGLRenderTarget::kCanResolve_ResolveType: |
| 1671 this->onResolveRenderTarget(tgt); | 1671 this->onResolveRenderTarget(tgt); |
| 1672 // we don't track the state of the READ FBO ID. | 1672 // we don't track the state of the READ FBO ID. |
| 1673 fGPUStats.incRenderTargetBinds(); | 1673 fStats.incRenderTargetBinds(); |
| 1674 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, | 1674 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
| 1675 tgt->textureFBOID())); | 1675 tgt->textureFBOID())); |
| 1676 break; | 1676 break; |
| 1677 default: | 1677 default: |
| 1678 SkFAIL("Unknown resolve type"); | 1678 SkFAIL("Unknown resolve type"); |
| 1679 } | 1679 } |
| 1680 | 1680 |
| 1681 const GrGLIRect& glvp = tgt->getViewport(); | 1681 const GrGLIRect& glvp = tgt->getViewport(); |
| 1682 | 1682 |
| 1683 // the read rect is viewport-relative | 1683 // the read rect is viewport-relative |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1761 } | 1761 } |
| 1762 return true; | 1762 return true; |
| 1763 } | 1763 } |
| 1764 | 1764 |
| 1765 void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bound)
{ | 1765 void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bound)
{ |
| 1766 | 1766 |
| 1767 SkASSERT(target); | 1767 SkASSERT(target); |
| 1768 | 1768 |
| 1769 uint32_t rtID = target->getUniqueID(); | 1769 uint32_t rtID = target->getUniqueID(); |
| 1770 if (fHWBoundRenderTargetUniqueID != rtID) { | 1770 if (fHWBoundRenderTargetUniqueID != rtID) { |
| 1771 fGPUStats.incRenderTargetBinds(); | 1771 fStats.incRenderTargetBinds(); |
| 1772 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID())); | 1772 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID())); |
| 1773 #ifdef SK_DEBUG | 1773 #ifdef SK_DEBUG |
| 1774 // don't do this check in Chromium -- this is causing | 1774 // don't do this check in Chromium -- this is causing |
| 1775 // lots of repeated command buffer flushes when the compositor is | 1775 // lots of repeated command buffer flushes when the compositor is |
| 1776 // rendering with Ganesh, which is really slow; even too slow for | 1776 // rendering with Ganesh, which is really slow; even too slow for |
| 1777 // Debug mode. | 1777 // Debug mode. |
| 1778 if (!this->glContext().isChromium()) { | 1778 if (!this->glContext().isChromium()) { |
| 1779 GrGLenum status; | 1779 GrGLenum status; |
| 1780 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 1780 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 1781 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 1781 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1905 fPathRendering->drawPaths(pathRange, indices, indexType, transformValues, | 1905 fPathRendering->drawPaths(pathRange, indices, indexType, transformValues, |
| 1906 transformType, count, stencil); | 1906 transformType, count, stencil); |
| 1907 } | 1907 } |
| 1908 | 1908 |
| 1909 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { | 1909 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { |
| 1910 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); | 1910 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |
| 1911 if (rt->needsResolve()) { | 1911 if (rt->needsResolve()) { |
| 1912 // Some extensions automatically resolves the texture when it is read. | 1912 // Some extensions automatically resolves the texture when it is read. |
| 1913 if (this->glCaps().usesMSAARenderBuffers()) { | 1913 if (this->glCaps().usesMSAARenderBuffers()) { |
| 1914 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); | 1914 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); |
| 1915 fGPUStats.incRenderTargetBinds(); | 1915 fStats.incRenderTargetBinds(); |
| 1916 fGPUStats.incRenderTargetBinds(); | 1916 fStats.incRenderTargetBinds(); |
| 1917 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); | 1917 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); |
| 1918 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; | 1918 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; |
| 1919 // make sure we go through flushRenderTarget() since we've modified | 1919 // make sure we go through flushRenderTarget() since we've modified |
| 1920 // the bound DRAW FBO ID. | 1920 // the bound DRAW FBO ID. |
| 1921 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | 1921 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 1922 const GrGLIRect& vp = rt->getViewport(); | 1922 const GrGLIRect& vp = rt->getViewport(); |
| 1923 const SkIRect dirtyRect = rt->getResolveRect(); | 1923 const SkIRect dirtyRect = rt->getResolveRect(); |
| 1924 GrGLIRect r; | 1924 GrGLIRect r; |
| 1925 r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, | 1925 r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, |
| 1926 dirtyRect.width(), dirtyRect.height(), target->origi
n()); | 1926 dirtyRect.width(), dirtyRect.height(), target->origi
n()); |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2512 | 2512 |
| 2513 // If a temporary FBO was created, its non-zero ID is returned. The viewport tha
t the copy rect is | 2513 // If a temporary FBO was created, its non-zero ID is returned. The viewport tha
t the copy rect is |
| 2514 // relative to is output. | 2514 // relative to is output. |
| 2515 GrGLuint GrGLGpu::bindSurfaceAsFBO(GrSurface* surface, GrGLenum fboTarget, GrGLI
Rect* viewport) { | 2515 GrGLuint GrGLGpu::bindSurfaceAsFBO(GrSurface* surface, GrGLenum fboTarget, GrGLI
Rect* viewport) { |
| 2516 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarge
t()); | 2516 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarge
t()); |
| 2517 GrGLuint tempFBOID; | 2517 GrGLuint tempFBOID; |
| 2518 if (NULL == rt) { | 2518 if (NULL == rt) { |
| 2519 SkASSERT(surface->asTexture()); | 2519 SkASSERT(surface->asTexture()); |
| 2520 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textur
eID(); | 2520 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textur
eID(); |
| 2521 GR_GL_CALL(this->glInterface(), GenFramebuffers(1, &tempFBOID)); | 2521 GR_GL_CALL(this->glInterface(), GenFramebuffers(1, &tempFBOID)); |
| 2522 fGPUStats.incRenderTargetBinds(); | 2522 fStats.incRenderTargetBinds(); |
| 2523 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, tempFBOID)); | 2523 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, tempFBOID)); |
| 2524 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget, | 2524 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget, |
| 2525 GR_GL_COLOR_ATTACHM
ENT0, | 2525 GR_GL_COLOR_ATTACHM
ENT0, |
| 2526 GR_GL_TEXTURE_2D, | 2526 GR_GL_TEXTURE_2D, |
| 2527 texID, | 2527 texID, |
| 2528 0)); | 2528 0)); |
| 2529 viewport->fLeft = 0; | 2529 viewport->fLeft = 0; |
| 2530 viewport->fBottom = 0; | 2530 viewport->fBottom = 0; |
| 2531 viewport->fWidth = surface->width(); | 2531 viewport->fWidth = surface->width(); |
| 2532 viewport->fHeight = surface->height(); | 2532 viewport->fHeight = surface->height(); |
| 2533 } else { | 2533 } else { |
| 2534 tempFBOID = 0; | 2534 tempFBOID = 0; |
| 2535 fGPUStats.incRenderTargetBinds(); | 2535 fStats.incRenderTargetBinds(); |
| 2536 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, rt->renderFBO
ID())); | 2536 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, rt->renderFBO
ID())); |
| 2537 *viewport = rt->getViewport(); | 2537 *viewport = rt->getViewport(); |
| 2538 } | 2538 } |
| 2539 return tempFBOID; | 2539 return tempFBOID; |
| 2540 } | 2540 } |
| 2541 | 2541 |
| 2542 bool GrGLGpu::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc)
{ | 2542 bool GrGLGpu::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc)
{ |
| 2543 // In here we look for opportunities to use CopyTexSubImage, or fbo blit. If
neither are | 2543 // In here we look for opportunities to use CopyTexSubImage, or fbo blit. If
neither are |
| 2544 // possible and we return false to fallback to creating a render target dst
for render-to- | 2544 // possible and we return false to fallback to creating a render target dst
for render-to- |
| 2545 // texture. This code prefers CopyTexSubImage to fbo blit and avoids trigger
ing temporary fbo | 2545 // texture. This code prefers CopyTexSubImage to fbo blit and avoids trigger
ing temporary fbo |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2750 this->setVertexArrayID(gpu, 0); | 2750 this->setVertexArrayID(gpu, 0); |
| 2751 } | 2751 } |
| 2752 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2752 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 2753 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2753 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 2754 fDefaultVertexArrayAttribState.resize(attrCount); | 2754 fDefaultVertexArrayAttribState.resize(attrCount); |
| 2755 } | 2755 } |
| 2756 attribState = &fDefaultVertexArrayAttribState; | 2756 attribState = &fDefaultVertexArrayAttribState; |
| 2757 } | 2757 } |
| 2758 return attribState; | 2758 return attribState; |
| 2759 } | 2759 } |
| OLD | NEW |