Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: src/gpu/gl/GrGpuGL.cpp

Issue 23440049: Implement stroking a path with nv_path_rendering (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "GrGLPath.h" 11 #include "GrGLPath.h"
12 #include "GrGLShaderBuilder.h" 12 #include "GrGLShaderBuilder.h"
13 #include "GrTemplates.h" 13 #include "GrTemplates.h"
14 #include "GrTypes.h" 14 #include "GrTypes.h"
15 #include "SkStrokeRec.h"
15 #include "SkTemplates.h" 16 #include "SkTemplates.h"
16 17
17 static const GrGLuint GR_MAX_GLUINT = ~0U; 18 static const GrGLuint GR_MAX_GLUINT = ~0U;
18 static const GrGLint GR_INVAL_GLINT = ~0; 19 static const GrGLint GR_INVAL_GLINT = ~0;
19 20
20 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) 21 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
21 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) 22 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X)
22 23
23 24
24 #define SKIP_CACHE_CHECK true 25 #define SKIP_CACHE_CHECK true
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 this->notifyIndexBufferDelete(desc.fID); 1267 this->notifyIndexBufferDelete(desc.fID);
1267 return NULL; 1268 return NULL;
1268 } 1269 }
1269 GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc )); 1270 GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc ));
1270 return indexBuffer; 1271 return indexBuffer;
1271 } 1272 }
1272 return NULL; 1273 return NULL;
1273 } 1274 }
1274 } 1275 }
1275 1276
1276 GrPath* GrGpuGL::onCreatePath(const SkPath& inPath) { 1277 GrPath* GrGpuGL::onCreatePath(const SkPath& inPath, const SkStrokeRec& stroke) {
1277 SkASSERT(this->caps()->pathRenderingSupport()); 1278 SkASSERT(this->caps()->pathRenderingSupport());
1278 return SkNEW_ARGS(GrGLPath, (this, inPath)); 1279 return SkNEW_ARGS(GrGLPath, (this, inPath, stroke));
1279 } 1280 }
1280 1281
1281 void GrGpuGL::flushScissor() { 1282 void GrGpuGL::flushScissor() {
1282 const GrDrawState& drawState = this->getDrawState(); 1283 const GrDrawState& drawState = this->getDrawState();
1283 const GrGLRenderTarget* rt = 1284 const GrGLRenderTarget* rt =
1284 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); 1285 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget());
1285 1286
1286 SkASSERT(NULL != rt); 1287 SkASSERT(NULL != rt);
1287 const GrGLIRect& vp = rt->getViewport(); 1288 const GrGLIRect& vp = rt->getViewport();
1288 1289
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 1722
1722 // Decide how to manipulate the stencil buffer based on the fill rule. 1723 // Decide how to manipulate the stencil buffer based on the fill rule.
1723 SkASSERT(!fPathStencilSettings.isTwoSided()); 1724 SkASSERT(!fPathStencilSettings.isTwoSided());
1724 1725
1725 GrGLenum fillMode = 1726 GrGLenum fillMode =
1726 gr_stencil_op_to_gl_path_rendering_fill_mode(fPathStencilSettings.passOp (GrStencilSettings::kFront_Face)); 1727 gr_stencil_op_to_gl_path_rendering_fill_mode(fPathStencilSettings.passOp (GrStencilSettings::kFront_Face));
1727 GrGLint writeMask = fPathStencilSettings.writeMask(GrStencilSettings::kFront _Face); 1728 GrGLint writeMask = fPathStencilSettings.writeMask(GrStencilSettings::kFront _Face);
1728 GL_CALL(StencilFillPath(id, fillMode, writeMask)); 1729 GL_CALL(StencilFillPath(id, fillMode, writeMask));
1729 } 1730 }
1730 1731
1731 void GrGpuGL::onGpuFillPath(const GrPath* path, SkPath::FillType fill) { 1732 void GrGpuGL::onGpuDrawPath(const GrPath* path, const SkStrokeRec& stroke, SkPat h::FillType fill) {
1732 SkASSERT(this->caps()->pathRenderingSupport()); 1733 SkASSERT(this->caps()->pathRenderingSupport());
1733 1734
1734 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); 1735 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID();
1735 GrDrawState* drawState = this->drawState(); 1736 GrDrawState* drawState = this->drawState();
1736 SkASSERT(NULL != drawState->getRenderTarget()); 1737 SkASSERT(NULL != drawState->getRenderTarget());
1737 SkASSERT(NULL != drawState->getRenderTarget()->getStencilBuffer()); 1738 SkASSERT(NULL != drawState->getRenderTarget()->getStencilBuffer());
1738 1739
1739 SkPath::FillType nonInvertedFill = SkPath::ConvertToNonInverseFillType(fill) ;
1740 SkASSERT(!fPathStencilSettings.isTwoSided()); 1740 SkASSERT(!fPathStencilSettings.isTwoSided());
1741 GrGLenum fillMode = 1741 GrGLenum fillMode =
1742 gr_stencil_op_to_gl_path_rendering_fill_mode(fPathStencilSettings.passOp (GrStencilSettings::kFront_Face)); 1742 gr_stencil_op_to_gl_path_rendering_fill_mode(fPathStencilSettings.passOp (GrStencilSettings::kFront_Face));
1743 GrGLint writeMask = fPathStencilSettings.writeMask(GrStencilSettings::kFront _Face); 1743 GrGLint writeMask = fPathStencilSettings.writeMask(GrStencilSettings::kFront _Face);
1744 GL_CALL(StencilFillPath(id, fillMode, writeMask));
1745 1744
1746 if (!fCurrentProgram->hasVertexShader() && nonInvertedFill == fill) { 1745 if (stroke.isFillStyle() || SkStrokeRec::kStrokeAndFill_Style == stroke.getS tyle()) {
1747 GL_CALL(CoverFillPath(id, GR_GL_BOUNDING_BOX)); 1746 GL_CALL(StencilFillPath(id, fillMode, writeMask));
1747 }
1748
1749 if (stroke.needToApply()) {
1750 GL_CALL(StencilStrokePath(id, 0xffff, writeMask));
1751 }
1752
1753 bool isInverseFill = SkPath::ConvertToNonInverseFillType(fill) != fill;
1754
1755 if (!fCurrentProgram->hasVertexShader() && !isInverseFill) {
1756 if (stroke.needToApply()) {
1757 GL_CALL(CoverStrokePath(id, GR_GL_BOUNDING_BOX));
1758 } else {
1759 GL_CALL(CoverFillPath(id, GR_GL_BOUNDING_BOX));
1760 }
1748 } else { 1761 } else {
1749 GrDrawState::AutoViewMatrixRestore avmr; 1762 GrDrawState::AutoViewMatrixRestore avmr;
1763 SkMatrix vmi;
1750 SkRect bounds; 1764 SkRect bounds;
1751 if (nonInvertedFill == fill) { 1765 if (!isInverseFill) {
1752 bounds = path->getBounds(); 1766 bounds = path->getBounds();
1753 } else { 1767 } else {
1754 bounds = SkRect::MakeLTRB(0, 0, 1768 bounds = SkRect::MakeLTRB(0, 0,
1755 SkIntToScalar(drawState->getRenderTarget() ->width()), 1769 SkIntToScalar(drawState->getRenderTarget() ->width()),
1756 SkIntToScalar(drawState->getRenderTarget() ->height())); 1770 SkIntToScalar(drawState->getRenderTarget()->he ight()));
1757 SkMatrix vmi; 1771
1758 // mapRect through persp matrix may not be correct 1772 // mapRect through persp matrix may not be correct
1759 if (!drawState->getViewMatrix().hasPerspective() && drawState->getVi ewInverse(&vmi)) { 1773 if (!drawState->getViewMatrix().hasPerspective() && drawState->getVi ewInverse(&vmi)) {
1760 vmi.mapRect(&bounds); 1774 vmi.mapRect(&bounds);
1761 // theoretically could set bloat = 0, instead leave it because o f matrix inversion 1775 // theoretically could set bloat = 0, instead leave it because o f matrix inversion
1762 // precision. 1776 // precision.
1763 SkScalar bloat = drawState->getViewMatrix().getMaxStretch() * SK _ScalarHalf; 1777 SkScalar bloat = drawState->getViewMatrix().getMaxStretch() * SK _ScalarHalf;
1764 bounds.outset(bloat, bloat); 1778 bounds.outset(bloat, bloat);
1765 } else { 1779 } else {
1766 avmr.setIdentity(drawState); 1780 avmr.setIdentity(drawState);
1767 } 1781 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 GR_GL_CALL(gl, StencilOp(glFailOp, glPassOp, glPassOp)); 1899 GR_GL_CALL(gl, StencilOp(glFailOp, glPassOp, glPassOp));
1886 } else { 1900 } else {
1887 GR_GL_CALL(gl, StencilFuncSeparate(glFace, glFunc, ref, mask)); 1901 GR_GL_CALL(gl, StencilFuncSeparate(glFace, glFunc, ref, mask));
1888 GR_GL_CALL(gl, StencilMaskSeparate(glFace, writeMask)); 1902 GR_GL_CALL(gl, StencilMaskSeparate(glFace, writeMask));
1889 GR_GL_CALL(gl, StencilOpSeparate(glFace, glFailOp, glPassOp, glPassOp)); 1903 GR_GL_CALL(gl, StencilOpSeparate(glFace, glFailOp, glPassOp, glPassOp));
1890 } 1904 }
1891 } 1905 }
1892 } 1906 }
1893 1907
1894 void GrGpuGL::flushStencil(DrawType type) { 1908 void GrGpuGL::flushStencil(DrawType type) {
1895 if ((kStencilPath_DrawType == type || kFillPath_DrawType == type) && 1909 if ((kStencilPath_DrawType == type || kDrawPath_DrawType == type) &&
1896 fHWPathStencilSettings != fPathStencilSettings) { 1910 fHWPathStencilSettings != fPathStencilSettings) {
1897 1911
1898 // Just the func, ref, and mask is set here. The op and write mask are p arams to the call 1912 // Just the func, ref, and mask is set here. The op and write mask are p arams to the call
1899 // that draws the path to the SB (glStencilFillPath) 1913 // that draws the path to the SB (glStencilFillPath)
1900 GrGLenum func = 1914 GrGLenum func =
1901 gr_to_gl_stencil_func(fPathStencilSettings.func(GrStencilSettings::k Front_Face)); 1915 gr_to_gl_stencil_func(fPathStencilSettings.func(GrStencilSettings::k Front_Face));
1902 GL_CALL(PathStencilFunc(func, 1916 GL_CALL(PathStencilFunc(func,
1903 fPathStencilSettings.funcRef(GrStencilSettings:: kFront_Face), 1917 fPathStencilSettings.funcRef(GrStencilSettings:: kFront_Face),
1904 fPathStencilSettings.funcMask(GrStencilSettings: :kFront_Face))); 1918 fPathStencilSettings.funcMask(GrStencilSettings: :kFront_Face)));
1905 1919
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
2220 numComponents, 2234 numComponents,
2221 coefficients)); 2235 coefficients));
2222 2236
2223 memcpy(fHWTexGenSettings[unitIdx].fCoefficients, coefficients, 2237 memcpy(fHWTexGenSettings[unitIdx].fCoefficients, coefficients,
2224 3 * numComponents * sizeof(GrGLfloat)); 2238 3 * numComponents * sizeof(GrGLfloat));
2225 2239
2226 fHWActiveTexGenUnits = SkTMax(fHWActiveTexGenUnits, unitIdx); 2240 fHWActiveTexGenUnits = SkTMax(fHWActiveTexGenUnits, unitIdx);
2227 } 2241 }
2228 2242
2229 void GrGpuGL::enableTexGen(int unitIdx, int numComponents, const SkMatrix& matri x) { 2243 void GrGpuGL::enableTexGen(int unitIdx, int numComponents, const SkMatrix& matri x) {
2230
2231 GrGLfloat coefficients[9]; 2244 GrGLfloat coefficients[9];
2232 SkASSERT(this->glCaps().fixedFunctionSupport()); 2245 SkASSERT(this->glCaps().fixedFunctionSupport());
2233 SkASSERT(numComponents <= 3 && numComponents > 0); 2246 SkASSERT(numComponents <= 3 && numComponents > 0);
2234 2247
2235 coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]); 2248 coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]);
2236 coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]); 2249 coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]);
2237 coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]); 2250 coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]);
2238 2251
2239 if (numComponents >= 2) { 2252 if (numComponents >= 2) {
2240 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); 2253 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]);
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
2747 this->setVertexArrayID(gpu, 0); 2760 this->setVertexArrayID(gpu, 0);
2748 } 2761 }
2749 int attrCount = gpu->glCaps().maxVertexAttributes(); 2762 int attrCount = gpu->glCaps().maxVertexAttributes();
2750 if (fDefaultVertexArrayAttribState.count() != attrCount) { 2763 if (fDefaultVertexArrayAttribState.count() != attrCount) {
2751 fDefaultVertexArrayAttribState.resize(attrCount); 2764 fDefaultVertexArrayAttribState.resize(attrCount);
2752 } 2765 }
2753 attribState = &fDefaultVertexArrayAttribState; 2766 attribState = &fDefaultVertexArrayAttribState;
2754 } 2767 }
2755 return attribState; 2768 return attribState;
2756 } 2769 }
OLDNEW
« src/gpu/gl/GrGpuGL.h ('K') | « src/gpu/gl/GrGpuGL.h ('k') | src/gpu/gl/GrGpuGL_program.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698