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" |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 if (resetBits & kView_GrGLBackendState) { | 349 if (resetBits & kView_GrGLBackendState) { |
350 fHWScissorSettings.invalidate(); | 350 fHWScissorSettings.invalidate(); |
351 fHWViewport.invalidate(); | 351 fHWViewport.invalidate(); |
352 } | 352 } |
353 | 353 |
354 if (resetBits & kStencil_GrGLBackendState) { | 354 if (resetBits & kStencil_GrGLBackendState) { |
355 fHWStencilSettings.invalidate(); | 355 fHWStencilSettings.invalidate(); |
356 fHWStencilTestEnabled = kUnknown_TriState; | 356 fHWStencilTestEnabled = kUnknown_TriState; |
357 } | 357 } |
358 | 358 |
| 359 if (resetBits & kPathRendering_GrGLBackendState && this->glCaps().pathRender
ingSupport()) { |
| 360 fHWPathStencilSettings.invalidate(); |
| 361 } |
| 362 |
359 // Vertex | 363 // Vertex |
360 if (resetBits & kVertex_GrGLBackendState) { | 364 if (resetBits & kVertex_GrGLBackendState) { |
361 fHWGeometryState.invalidate(); | 365 fHWGeometryState.invalidate(); |
362 } | 366 } |
363 | 367 |
364 if (resetBits & kRenderTarget_GrGLBackendState) { | 368 if (resetBits & kRenderTarget_GrGLBackendState) { |
365 fHWBoundRenderTarget = NULL; | 369 fHWBoundRenderTarget = NULL; |
366 } | 370 } |
367 | 371 |
368 if (resetBits & kFixedFunction_GrGLBackendState && this->glCaps().fixedFunct
ionSupport()) { | 372 if (resetBits & kFixedFunction_GrGLBackendState && this->glCaps().fixedFunct
ionSupport()) { |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1263 return NULL; | 1267 return NULL; |
1264 } | 1268 } |
1265 GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc
)); | 1269 GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc
)); |
1266 return indexBuffer; | 1270 return indexBuffer; |
1267 } | 1271 } |
1268 return NULL; | 1272 return NULL; |
1269 } | 1273 } |
1270 } | 1274 } |
1271 | 1275 |
1272 GrPath* GrGpuGL::onCreatePath(const SkPath& inPath) { | 1276 GrPath* GrGpuGL::onCreatePath(const SkPath& inPath) { |
1273 SkASSERT(this->caps()->pathStencilingSupport()); | 1277 SkASSERT(this->caps()->pathRenderingSupport()); |
1274 return SkNEW_ARGS(GrGLPath, (this, inPath)); | 1278 return SkNEW_ARGS(GrGLPath, (this, inPath)); |
1275 } | 1279 } |
1276 | 1280 |
1277 void GrGpuGL::flushScissor() { | 1281 void GrGpuGL::flushScissor() { |
1278 const GrDrawState& drawState = this->getDrawState(); | 1282 const GrDrawState& drawState = this->getDrawState(); |
1279 const GrGLRenderTarget* rt = | 1283 const GrGLRenderTarget* rt = |
1280 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); | 1284 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); |
1281 | 1285 |
1282 SkASSERT(NULL != rt); | 1286 SkASSERT(NULL != rt); |
1283 const GrGLIRect& vp = rt->getViewport(); | 1287 const GrGLIRect& vp = rt->getViewport(); |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1673 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); | 1677 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
1674 } | 1678 } |
1675 const GrStencilSettings& even_odd_nv_path_stencil_settings() { | 1679 const GrStencilSettings& even_odd_nv_path_stencil_settings() { |
1676 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, | 1680 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
1677 kInvert_StencilOp, | 1681 kInvert_StencilOp, |
1678 kInvert_StencilOp, | 1682 kInvert_StencilOp, |
1679 kAlwaysIfInClip_StencilFunc, | 1683 kAlwaysIfInClip_StencilFunc, |
1680 kOnes16, kOnes16, kOnes16); | 1684 kOnes16, kOnes16, kOnes16); |
1681 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); | 1685 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
1682 } | 1686 } |
| 1687 GrGLenum gr_stencil_op_to_gl_path_rendering_fill_mode(GrStencilOp op) { |
| 1688 switch (op) { |
| 1689 default: |
| 1690 GrCrash("Unexpected path fill."); |
| 1691 /* fallthrough */; |
| 1692 case kIncClamp_StencilOp: |
| 1693 return GR_GL_COUNT_UP; |
| 1694 case kInvert_StencilOp: |
| 1695 return GR_GL_INVERT; |
| 1696 } |
| 1697 } |
1683 } | 1698 } |
1684 | 1699 |
1685 void GrGpuGL::setStencilPathSettings(const GrPath&, | 1700 const GrStencilSettings& GrGpuGL::getPathStencilSettingsForFillType(SkPath::Fill
Type fill) { |
1686 SkPath::FillType fill, | |
1687 GrStencilSettings* settings) { | |
1688 switch (fill) { | 1701 switch (fill) { |
1689 case SkPath::kEvenOdd_FillType: | |
1690 *settings = even_odd_nv_path_stencil_settings(); | |
1691 return; | |
1692 case SkPath::kWinding_FillType: | |
1693 *settings = winding_nv_path_stencil_settings(); | |
1694 return; | |
1695 default: | 1702 default: |
1696 GrCrash("Unexpected path fill."); | 1703 GrCrash("Unexpected path fill."); |
| 1704 /* fallthrough */; |
| 1705 case SkPath::kWinding_FillType: |
| 1706 case SkPath::kInverseWinding_FillType: |
| 1707 return winding_nv_path_stencil_settings(); |
| 1708 case SkPath::kEvenOdd_FillType: |
| 1709 case SkPath::kInverseEvenOdd_FillType: |
| 1710 return even_odd_nv_path_stencil_settings(); |
1697 } | 1711 } |
1698 } | 1712 } |
1699 | 1713 |
1700 void GrGpuGL::onGpuStencilPath(const GrPath* path, SkPath::FillType fill) { | 1714 void GrGpuGL::onGpuStencilPath(const GrPath* path, SkPath::FillType fill) { |
1701 SkASSERT(this->caps()->pathStencilingSupport()); | 1715 SkASSERT(this->caps()->pathRenderingSupport()); |
1702 | 1716 |
1703 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); | 1717 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); |
1704 GrDrawState* drawState = this->drawState(); | 1718 GrDrawState* drawState = this->drawState(); |
1705 SkASSERT(NULL != drawState->getRenderTarget()); | 1719 SkASSERT(NULL != drawState->getRenderTarget()); |
1706 if (NULL == drawState->getRenderTarget()->getStencilBuffer()) { | 1720 SkASSERT(NULL != drawState->getRenderTarget()->getStencilBuffer()); |
1707 return; | |
1708 } | |
1709 | 1721 |
1710 // Decide how to manipulate the stencil buffer based on the fill rule. | 1722 // Decide how to manipulate the stencil buffer based on the fill rule. |
1711 // Also, assert that the stencil settings we set in setStencilPathSettings | 1723 SkASSERT(!fPathStencilSettings.isTwoSided()); |
1712 // are present. | 1724 |
1713 SkASSERT(!fStencilSettings.isTwoSided()); | 1725 GrGLenum fillMode = |
1714 GrGLenum fillMode; | 1726 gr_stencil_op_to_gl_path_rendering_fill_mode(fPathStencilSettings.passOp
(GrStencilSettings::kFront_Face)); |
1715 switch (fill) { | 1727 GrGLint writeMask = fPathStencilSettings.writeMask(GrStencilSettings::kFront
_Face); |
1716 case SkPath::kWinding_FillType: | 1728 GL_CALL(StencilFillPath(id, fillMode, writeMask)); |
1717 fillMode = GR_GL_COUNT_UP; | 1729 } |
1718 SkASSERT(kIncClamp_StencilOp == | 1730 |
1719 fStencilSettings.passOp(GrStencilSettings::kFront_Face)); | 1731 void GrGpuGL::onGpuFillPath(const GrPath* path, SkPath::FillType fill) { |
1720 SkASSERT(kIncClamp_StencilOp == | 1732 SkASSERT(this->caps()->pathRenderingSupport()); |
1721 fStencilSettings.failOp(GrStencilSettings::kFront_Face)); | 1733 |
1722 break; | 1734 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); |
1723 case SkPath::kEvenOdd_FillType: | 1735 GrDrawState* drawState = this->drawState(); |
1724 fillMode = GR_GL_INVERT; | 1736 SkASSERT(NULL != drawState->getRenderTarget()); |
1725 SkASSERT(kInvert_StencilOp == | 1737 SkASSERT(NULL != drawState->getRenderTarget()->getStencilBuffer()); |
1726 fStencilSettings.passOp(GrStencilSettings::kFront_Face)); | 1738 |
1727 SkASSERT(kInvert_StencilOp == | 1739 SkPath::FillType nonInvertedFill = SkPath::ConvertToNonInverseFillType(fill)
; |
1728 fStencilSettings.failOp(GrStencilSettings::kFront_Face)); | 1740 SkASSERT(!fPathStencilSettings.isTwoSided()); |
1729 break; | 1741 GrGLenum fillMode = |
1730 default: | 1742 gr_stencil_op_to_gl_path_rendering_fill_mode(fPathStencilSettings.passOp
(GrStencilSettings::kFront_Face)); |
1731 // Only the above two fill rules are allowed. | 1743 GrGLint writeMask = fPathStencilSettings.writeMask(GrStencilSettings::kFront
_Face); |
1732 GrCrash("Unexpected path fill."); | 1744 GL_CALL(StencilFillPath(id, fillMode, writeMask)); |
1733 return; // suppress unused var warning. | 1745 |
| 1746 if (!fCurrentProgram->hasVertexShader() && nonInvertedFill == fill) { |
| 1747 GL_CALL(CoverFillPath(id, GR_GL_BOUNDING_BOX)); |
| 1748 } else { |
| 1749 GrDrawState::AutoViewMatrixRestore avmr; |
| 1750 SkRect bounds; |
| 1751 if (nonInvertedFill == fill) { |
| 1752 bounds = path->getBounds(); |
| 1753 } else { |
| 1754 bounds = SkRect::MakeLTRB(0, 0, |
| 1755 SkIntToScalar(drawState->getRenderTarget()
->width()), |
| 1756 SkIntToScalar(drawState->getRenderTarget()
->height())); |
| 1757 SkMatrix vmi; |
| 1758 // mapRect through persp matrix may not be correct |
| 1759 if (!drawState->getViewMatrix().hasPerspective() && drawState->getVi
ewInverse(&vmi)) { |
| 1760 vmi.mapRect(&bounds); |
| 1761 // theoretically could set bloat = 0, instead leave it because o
f matrix inversion |
| 1762 // precision. |
| 1763 SkScalar bloat = drawState->getViewMatrix().getMaxStretch() * SK
_ScalarHalf; |
| 1764 bounds.outset(bloat, bloat); |
| 1765 } else { |
| 1766 avmr.setIdentity(drawState); |
| 1767 } |
| 1768 } |
| 1769 |
| 1770 this->drawSimpleRect(bounds, NULL); |
1734 } | 1771 } |
1735 GrGLint writeMask = fStencilSettings.writeMask(GrStencilSettings::kFront_Fac
e); | |
1736 GL_CALL(StencilFillPath(id, fillMode, writeMask)); | |
1737 } | 1772 } |
1738 | 1773 |
1739 void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { | 1774 void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { |
1740 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); | 1775 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |
1741 if (rt->needsResolve()) { | 1776 if (rt->needsResolve()) { |
1742 // Some extensions automatically resolves the texture when it is read. | 1777 // Some extensions automatically resolves the texture when it is read. |
1743 if (this->glCaps().usesMSAARenderBuffers()) { | 1778 if (this->glCaps().usesMSAARenderBuffers()) { |
1744 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); | 1779 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); |
1745 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); | 1780 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); |
1746 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; | 1781 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1850 GR_GL_CALL(gl, StencilOp(glFailOp, glPassOp, glPassOp)); | 1885 GR_GL_CALL(gl, StencilOp(glFailOp, glPassOp, glPassOp)); |
1851 } else { | 1886 } else { |
1852 GR_GL_CALL(gl, StencilFuncSeparate(glFace, glFunc, ref, mask)); | 1887 GR_GL_CALL(gl, StencilFuncSeparate(glFace, glFunc, ref, mask)); |
1853 GR_GL_CALL(gl, StencilMaskSeparate(glFace, writeMask)); | 1888 GR_GL_CALL(gl, StencilMaskSeparate(glFace, writeMask)); |
1854 GR_GL_CALL(gl, StencilOpSeparate(glFace, glFailOp, glPassOp, glPassOp)); | 1889 GR_GL_CALL(gl, StencilOpSeparate(glFace, glFailOp, glPassOp, glPassOp)); |
1855 } | 1890 } |
1856 } | 1891 } |
1857 } | 1892 } |
1858 | 1893 |
1859 void GrGpuGL::flushStencil(DrawType type) { | 1894 void GrGpuGL::flushStencil(DrawType type) { |
1860 if (kStencilPath_DrawType == type) { | 1895 if ((kStencilPath_DrawType == type || kFillPath_DrawType == type) && |
1861 SkASSERT(!fStencilSettings.isTwoSided()); | 1896 fHWPathStencilSettings != fPathStencilSettings) { |
| 1897 |
1862 // Just the func, ref, and mask is set here. The op and write mask are p
arams to the call | 1898 // Just the func, ref, and mask is set here. The op and write mask are p
arams to the call |
1863 // that draws the path to the SB (glStencilFillPath) | 1899 // that draws the path to the SB (glStencilFillPath) |
1864 GrGLenum func = | 1900 GrGLenum func = |
1865 gr_to_gl_stencil_func(fStencilSettings.func(GrStencilSettings::kFron
t_Face)); | 1901 gr_to_gl_stencil_func(fPathStencilSettings.func(GrStencilSettings::k
Front_Face)); |
1866 GL_CALL(PathStencilFunc(func, | 1902 GL_CALL(PathStencilFunc(func, |
1867 fStencilSettings.funcRef(GrStencilSettings::kFro
nt_Face), | 1903 fPathStencilSettings.funcRef(GrStencilSettings::
kFront_Face), |
1868 fStencilSettings.funcMask(GrStencilSettings::kFr
ont_Face))); | 1904 fPathStencilSettings.funcMask(GrStencilSettings:
:kFront_Face))); |
1869 } else if (fHWStencilSettings != fStencilSettings) { | 1905 |
| 1906 fHWPathStencilSettings = fPathStencilSettings; |
| 1907 } |
| 1908 |
| 1909 if (kStencilPath_DrawType != type && fHWStencilSettings != fStencilSettings)
{ |
1870 if (fStencilSettings.isDisabled()) { | 1910 if (fStencilSettings.isDisabled()) { |
1871 if (kNo_TriState != fHWStencilTestEnabled) { | 1911 if (kNo_TriState != fHWStencilTestEnabled) { |
1872 GL_CALL(Disable(GR_GL_STENCIL_TEST)); | 1912 GL_CALL(Disable(GR_GL_STENCIL_TEST)); |
1873 fHWStencilTestEnabled = kNo_TriState; | 1913 fHWStencilTestEnabled = kNo_TriState; |
1874 } | 1914 } |
1875 } else { | 1915 } else { |
1876 if (kYes_TriState != fHWStencilTestEnabled) { | 1916 if (kYes_TriState != fHWStencilTestEnabled) { |
1877 GL_CALL(Enable(GR_GL_STENCIL_TEST)); | 1917 GL_CALL(Enable(GR_GL_STENCIL_TEST)); |
1878 fHWStencilTestEnabled = kYes_TriState; | 1918 fHWStencilTestEnabled = kYes_TriState; |
1879 } | 1919 } |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2707 this->setVertexArrayID(gpu, 0); | 2747 this->setVertexArrayID(gpu, 0); |
2708 } | 2748 } |
2709 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2749 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2710 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2750 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2711 fDefaultVertexArrayAttribState.resize(attrCount); | 2751 fDefaultVertexArrayAttribState.resize(attrCount); |
2712 } | 2752 } |
2713 attribState = &fDefaultVertexArrayAttribState; | 2753 attribState = &fDefaultVertexArrayAttribState; |
2714 } | 2754 } |
2715 return attribState; | 2755 return attribState; |
2716 } | 2756 } |
OLD | NEW |