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

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

Issue 452823002: Separate GL path rendering state from GrGpuGL to GrGLPathRendering (Closed) Base URL: https://skia.googlesource.com/skia.git@00xx-cherrypick-pathrendering-class
Patch Set: Created 6 years, 4 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
« no previous file with comments | « src/gpu/gl/GrGpuGL.h ('k') | src/gpu/gl/GrGpuGL_program.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
12 #include "GrGLPathRange.h"
13 #include "GrGLPathRendering.h"
14 #include "GrGLShaderBuilder.h" 11 #include "GrGLShaderBuilder.h"
15 #include "GrTemplates.h" 12 #include "GrTemplates.h"
16 #include "GrTypes.h" 13 #include "GrTypes.h"
17 #include "SkStrokeRec.h" 14 #include "SkStrokeRec.h"
18 #include "SkTemplates.h" 15 #include "SkTemplates.h"
19 16
20 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) 17 #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) 18 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X)
22 19
23 #define SKIP_CACHE_CHECK true 20 #define SKIP_CACHE_CHECK true
24 21
25 #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR 22 #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR
26 #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface) 23 #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface)
27 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call) 24 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call)
28 #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface) 25 #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface)
29 #else 26 #else
30 #define CLEAR_ERROR_BEFORE_ALLOC(iface) 27 #define CLEAR_ERROR_BEFORE_ALLOC(iface)
31 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL(iface, call) 28 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL(iface, call)
32 #define CHECK_ALLOC_ERROR(iface) GR_GL_NO_ERROR 29 #define CHECK_ALLOC_ERROR(iface) GR_GL_NO_ERROR
33 #endif 30 #endif
34 31
35 32
36 /////////////////////////////////////////////////////////////////////////////// 33 ///////////////////////////////////////////////////////////////////////////////
37 34
38 static const GrGLenum gXformType2GLType[] = {
39 GR_GL_NONE,
40 GR_GL_TRANSLATE_X,
41 GR_GL_TRANSLATE_Y,
42 GR_GL_TRANSLATE_2D,
43 GR_GL_TRANSPOSE_AFFINE_2D
44 };
45
46 GR_STATIC_ASSERT(0 == GrDrawTarget::kNone_PathTransformType);
47 GR_STATIC_ASSERT(1 == GrDrawTarget::kTranslateX_PathTransformType);
48 GR_STATIC_ASSERT(2 == GrDrawTarget::kTranslateY_PathTransformType);
49 GR_STATIC_ASSERT(3 == GrDrawTarget::kTranslate_PathTransformType);
50 GR_STATIC_ASSERT(4 == GrDrawTarget::kAffine_PathTransformType);
51 GR_STATIC_ASSERT(GrDrawTarget::kAffine_PathTransformType == GrDrawTarget::kLast_ PathTransformType);
52 35
53 static const GrGLenum gXfermodeCoeff2Blend[] = { 36 static const GrGLenum gXfermodeCoeff2Blend[] = {
54 GR_GL_ZERO, 37 GR_GL_ZERO,
55 GR_GL_ONE, 38 GR_GL_ONE,
56 GR_GL_SRC_COLOR, 39 GR_GL_SRC_COLOR,
57 GR_GL_ONE_MINUS_SRC_COLOR, 40 GR_GL_ONE_MINUS_SRC_COLOR,
58 GR_GL_DST_COLOR, 41 GR_GL_DST_COLOR,
59 GR_GL_ONE_MINUS_DST_COLOR, 42 GR_GL_ONE_MINUS_DST_COLOR,
60 GR_GL_SRC_ALPHA, 43 GR_GL_SRC_ALPHA,
61 GR_GL_ONE_MINUS_SRC_ALPHA, 44 GR_GL_ONE_MINUS_SRC_ALPHA,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 static bool gPrintStartupSpew; 113 static bool gPrintStartupSpew;
131 114
132 GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) 115 GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context)
133 : GrGpu(context) 116 : GrGpu(context)
134 , fGLContext(ctx) { 117 , fGLContext(ctx) {
135 118
136 SkASSERT(ctx.isInitialized()); 119 SkASSERT(ctx.isInitialized());
137 fCaps.reset(SkRef(ctx.caps())); 120 fCaps.reset(SkRef(ctx.caps()));
138 121
139 fHWBoundTextureUniqueIDs.reset(this->glCaps().maxFragmentTextureUnits()); 122 fHWBoundTextureUniqueIDs.reset(this->glCaps().maxFragmentTextureUnits());
140 fHWPathTexGenSettings.reset(this->glCaps().maxFixedFunctionTextureCoords());
141 123
142 GrGLClearErr(fGLContext.interface()); 124 GrGLClearErr(fGLContext.interface());
143 if (gPrintStartupSpew) { 125 if (gPrintStartupSpew) {
144 const GrGLubyte* vendor; 126 const GrGLubyte* vendor;
145 const GrGLubyte* renderer; 127 const GrGLubyte* renderer;
146 const GrGLubyte* version; 128 const GrGLubyte* version;
147 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); 129 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR));
148 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); 130 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER));
149 GL_CALL_RET(version, GetString(GR_GL_VERSION)); 131 GL_CALL_RET(version, GetString(GR_GL_VERSION));
150 GrPrintf("------------------------- create GrGpuGL %p --------------\n", 132 GrPrintf("------------------------- create GrGpuGL %p --------------\n",
151 this); 133 this);
152 GrPrintf("------ VENDOR %s\n", vendor); 134 GrPrintf("------ VENDOR %s\n", vendor);
153 GrPrintf("------ RENDERER %s\n", renderer); 135 GrPrintf("------ RENDERER %s\n", renderer);
154 GrPrintf("------ VERSION %s\n", version); 136 GrPrintf("------ VERSION %s\n", version);
155 GrPrintf("------ EXTENSIONS\n"); 137 GrPrintf("------ EXTENSIONS\n");
156 ctx.extensions().print(); 138 ctx.extensions().print();
157 GrPrintf("\n"); 139 GrPrintf("\n");
158 GrPrintf(this->glCaps().dump().c_str()); 140 GrPrintf(this->glCaps().dump().c_str());
159 } 141 }
160 142
161 fProgramCache = SkNEW_ARGS(ProgramCache, (this)); 143 fProgramCache = SkNEW_ARGS(ProgramCache, (this));
162 144
163 SkASSERT(this->glCaps().maxVertexAttributes() >= GrDrawState::kMaxVertexAttr ibCnt); 145 SkASSERT(this->glCaps().maxVertexAttributes() >= GrDrawState::kMaxVertexAttr ibCnt);
164 146
165 fLastSuccessfulStencilFmtIdx = 0; 147 fLastSuccessfulStencilFmtIdx = 0;
166 fHWProgramID = 0; 148 fHWProgramID = 0;
167 149
168 if (this->glCaps().pathRenderingSupport()) { 150 if (this->glCaps().pathRenderingSupport()) {
169 fPathRendering.reset(GrGLPathRendering::Create(glInterface())); 151 fPathRendering.reset(GrGLPathRendering::Create(this));
170 } 152 }
171 } 153 }
172 154
173 GrGpuGL::~GrGpuGL() { 155 GrGpuGL::~GrGpuGL() {
174 if (0 != fHWProgramID) { 156 if (0 != fHWProgramID) {
175 // detach the current program so there is no confusion on OpenGL's part 157 // detach the current program so there is no confusion on OpenGL's part
176 // that we want it to be deleted 158 // that we want it to be deleted
177 SkASSERT(fHWProgramID == fCurrentProgram->programID()); 159 SkASSERT(fHWProgramID == fCurrentProgram->programID());
178 GL_CALL(UseProgram(0)); 160 GL_CALL(UseProgram(0));
179 } 161 }
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 if (resetBits & kVertex_GrGLBackendState) { 303 if (resetBits & kVertex_GrGLBackendState) {
322 fHWGeometryState.invalidate(); 304 fHWGeometryState.invalidate();
323 } 305 }
324 306
325 if (resetBits & kRenderTarget_GrGLBackendState) { 307 if (resetBits & kRenderTarget_GrGLBackendState) {
326 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; 308 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
327 } 309 }
328 310
329 if (resetBits & kPathRendering_GrGLBackendState) { 311 if (resetBits & kPathRendering_GrGLBackendState) {
330 if (this->caps()->pathRenderingSupport()) { 312 if (this->caps()->pathRenderingSupport()) {
331 fHWProjectionMatrixState.invalidate(); 313 this->glPathRendering()->resetContext();
332 // we don't use the model view matrix.
333 GL_CALL(MatrixLoadIdentity(GR_GL_MODELVIEW));
334
335 for (int i = 0; i < this->glCaps().maxFixedFunctionTextureCoords(); ++i) {
336 fPathRendering->pathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NU LL);
337 fHWPathTexGenSettings[i].fMode = GR_GL_NONE;
338 fHWPathTexGenSettings[i].fNumComponents = 0;
339 }
340 fHWActivePathTexGenSets = 0;
341 } 314 }
342 fHWPathStencilSettings.invalidate();
343 } 315 }
344 316
345 // we assume these values 317 // we assume these values
346 if (resetBits & kPixelStore_GrGLBackendState) { 318 if (resetBits & kPixelStore_GrGLBackendState) {
347 if (this->glCaps().unpackRowLengthSupport()) { 319 if (this->glCaps().unpackRowLengthSupport()) {
348 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); 320 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
349 } 321 }
350 if (this->glCaps().packRowLengthSupport()) { 322 if (this->glCaps().packRowLengthSupport()) {
351 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); 323 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0));
352 } 324 }
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 this->notifyIndexBufferDelete(desc.fID); 1337 this->notifyIndexBufferDelete(desc.fID);
1366 return NULL; 1338 return NULL;
1367 } 1339 }
1368 GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc )); 1340 GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc ));
1369 return indexBuffer; 1341 return indexBuffer;
1370 } 1342 }
1371 return NULL; 1343 return NULL;
1372 } 1344 }
1373 } 1345 }
1374 1346
1375 GrPath* GrGpuGL::onCreatePath(const SkPath& inPath, const SkStrokeRec& stroke) {
1376 SkASSERT(this->caps()->pathRenderingSupport());
1377 return SkNEW_ARGS(GrGLPath, (this, inPath, stroke));
1378 }
1379
1380 GrPathRange* GrGpuGL::onCreatePathRange(size_t size, const SkStrokeRec& stroke) {
1381 SkASSERT(this->caps()->pathRenderingSupport());
1382 return SkNEW_ARGS(GrGLPathRange, (this, size, stroke));
1383 }
1384
1385 void GrGpuGL::flushScissor() { 1347 void GrGpuGL::flushScissor() {
1386 if (fScissorState.fEnabled) { 1348 if (fScissorState.fEnabled) {
1387 // Only access the RT if scissoring is being enabled. We can call this b efore performing 1349 // Only access the RT if scissoring is being enabled. We can call this b efore performing
1388 // a glBitframebuffer for a surface->surface copy, which requires no RT to be bound to the 1350 // a glBitframebuffer for a surface->surface copy, which requires no RT to be bound to the
1389 // GrDrawState. 1351 // GrDrawState.
1390 const GrDrawState& drawState = this->getDrawState(); 1352 const GrDrawState& drawState = this->getDrawState();
1391 const GrGLRenderTarget* rt = 1353 const GrGLRenderTarget* rt =
1392 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); 1354 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget());
1393 1355
1394 SkASSERT(NULL != rt); 1356 SkASSERT(NULL != rt);
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1832 int set_a_break_pt_here = 9; 1794 int set_a_break_pt_here = 9;
1833 aglSwapBuffers(aglGetCurrentContext()); 1795 aglSwapBuffers(aglGetCurrentContext());
1834 #elif defined(SK_BUILD_FOR_WIN32) 1796 #elif defined(SK_BUILD_FOR_WIN32)
1835 SwapBuf(); 1797 SwapBuf();
1836 int set_a_break_pt_here = 9; 1798 int set_a_break_pt_here = 9;
1837 SwapBuf(); 1799 SwapBuf();
1838 #endif 1800 #endif
1839 #endif 1801 #endif
1840 } 1802 }
1841 1803
1842 static GrGLenum gr_stencil_op_to_gl_path_rendering_fill_mode(GrStencilOp op) {
1843 switch (op) {
1844 default:
1845 SkFAIL("Unexpected path fill.");
1846 /* fallthrough */;
1847 case kIncClamp_StencilOp:
1848 return GR_GL_COUNT_UP;
1849 case kInvert_StencilOp:
1850 return GR_GL_INVERT;
1851 }
1852 }
1853
1854 void GrGpuGL::onGpuStencilPath(const GrPath* path, SkPath::FillType fill) {
1855 SkASSERT(this->caps()->pathRenderingSupport());
1856
1857 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID();
1858 SkASSERT(NULL != this->drawState()->getRenderTarget());
1859 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer());
1860
1861 flushPathStencilSettings(fill);
1862
1863 // Decide how to manipulate the stencil buffer based on the fill rule.
1864 SkASSERT(!fHWPathStencilSettings.isTwoSided());
1865
1866 GrGLenum fillMode =
1867 gr_stencil_op_to_gl_path_rendering_fill_mode(fHWPathStencilSettings.pass Op(GrStencilSettings::kFront_Face));
1868 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFro nt_Face);
1869 fPathRendering->stencilFillPath(id, fillMode, writeMask);
1870 }
1871
1872 void GrGpuGL::onGpuDrawPath(const GrPath* path, SkPath::FillType fill) {
1873 SkASSERT(this->caps()->pathRenderingSupport());
1874
1875 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID();
1876 SkASSERT(NULL != this->drawState()->getRenderTarget());
1877 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer());
1878 SkASSERT(!fCurrentProgram->hasVertexShader());
1879
1880 flushPathStencilSettings(fill);
1881 const SkStrokeRec& stroke = path->getStroke();
1882
1883 SkPath::FillType nonInvertedFill = SkPath::ConvertToNonInverseFillType(fill) ;
1884 SkASSERT(!fHWPathStencilSettings.isTwoSided());
1885 GrGLenum fillMode =
1886 gr_stencil_op_to_gl_path_rendering_fill_mode(fHWPathStencilSettings.pass Op(GrStencilSettings::kFront_Face));
1887 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFro nt_Face);
1888
1889 if (nonInvertedFill == fill) {
1890 if (stroke.needToApply()) {
1891 if (SkStrokeRec::kStrokeAndFill_Style == stroke.getStyle()) {
1892 fPathRendering->stencilFillPath(id, fillMode, writeMask);
1893 }
1894 fPathRendering->stencilThenCoverStrokePath(id, 0xffff, writeMask, GR _GL_BOUNDING_BOX);
1895 } else {
1896 fPathRendering->stencilThenCoverFillPath(id, fillMode, writeMask, GR _GL_BOUNDING_BOX);
1897 }
1898 } else {
1899 if (stroke.isFillStyle() || SkStrokeRec::kStrokeAndFill_Style == stroke. getStyle()) {
1900 fPathRendering->stencilFillPath(id, fillMode, writeMask);
1901 }
1902 if (stroke.needToApply()) {
1903 fPathRendering->stencilStrokePath(id, 0xffff, writeMask);
1904 }
1905
1906 GrDrawState* drawState = this->drawState();
1907 GrDrawState::AutoViewMatrixRestore avmr;
1908 SkRect bounds = SkRect::MakeLTRB(0, 0,
1909 SkIntToScalar(drawState->getRenderTarge t()->width()),
1910 SkIntToScalar(drawState->getRenderTarge t()->height()));
1911 SkMatrix vmi;
1912 // mapRect through persp matrix may not be correct
1913 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewIn verse(&vmi)) {
1914 vmi.mapRect(&bounds);
1915 // theoretically could set bloat = 0, instead leave it because of ma trix inversion
1916 // precision.
1917 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_Scala rHalf;
1918 bounds.outset(bloat, bloat);
1919 } else {
1920 avmr.setIdentity(drawState);
1921 }
1922
1923 this->drawSimpleRect(bounds);
1924 }
1925 }
1926
1927 void GrGpuGL::onGpuDrawPaths(const GrPathRange* pathRange,
1928 const uint32_t indices[], int count,
1929 const float transforms[], PathTransformType transfo rmsType,
1930 SkPath::FillType fill) {
1931 SkASSERT(this->caps()->pathRenderingSupport());
1932 SkASSERT(NULL != this->drawState()->getRenderTarget());
1933 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer());
1934 SkASSERT(!fCurrentProgram->hasVertexShader());
1935
1936 GrGLuint baseID = static_cast<const GrGLPathRange*>(pathRange)->basePathID() ;
1937
1938 flushPathStencilSettings(fill);
1939 const SkStrokeRec& stroke = pathRange->getStroke();
1940
1941 SkPath::FillType nonInvertedFill =
1942 SkPath::ConvertToNonInverseFillType(fill);
1943
1944 SkASSERT(!fHWPathStencilSettings.isTwoSided());
1945 GrGLenum fillMode =
1946 gr_stencil_op_to_gl_path_rendering_fill_mode(
1947 fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face));
1948 GrGLint writeMask =
1949 fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face);
1950
1951 if (nonInvertedFill == fill) {
1952 if (stroke.needToApply()) {
1953 if (SkStrokeRec::kStrokeAndFill_Style == stroke.getStyle()) {
1954 fPathRendering->stencilFillPathInstanced(
1955 count, GR_GL_UNSIGNED_INT, indices, baseID, fillMode,
1956 writeMask, gXformType2GLType[transformsType] ,
1957 transforms);
1958 }
1959 fPathRendering->stencilThenCoverStrokePathInstanced(
1960 count, GR_GL_UNSIGNED_INT, indices, baseID, 0xff ff, writeMask,
1961 GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES,
1962 gXformType2GLType[transformsType], transforms);
1963 } else {
1964 fPathRendering->stencilThenCoverFillPathInstanced(
1965 count, GR_GL_UNSIGNED_INT, indices, baseID, fill Mode, writeMask,
1966 GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES,
1967 gXformType2GLType[transformsType], transforms);
1968 }
1969 } else {
1970 if (stroke.isFillStyle() || SkStrokeRec::kStrokeAndFill_Style == stroke. getStyle()) {
1971 fPathRendering->stencilFillPathInstanced(
1972 count, GR_GL_UNSIGNED_INT, indices, baseID, fill Mode,
1973 writeMask, gXformType2GLType[transformsType],
1974 transforms);
1975 }
1976 if (stroke.needToApply()) {
1977 fPathRendering->stencilStrokePathInstanced(
1978 count, GR_GL_UNSIGNED_INT, indices, baseID, 0xff ff,
1979 writeMask, gXformType2GLType[transformsType],
1980 transforms);
1981 }
1982
1983 GrDrawState* drawState = this->drawState();
1984 GrDrawState::AutoViewMatrixRestore avmr;
1985 SkRect bounds = SkRect::MakeLTRB(0, 0,
1986 SkIntToScalar(drawState->getRenderTarge t()->width()),
1987 SkIntToScalar(drawState->getRenderTarge t()->height()));
1988 SkMatrix vmi;
1989 // mapRect through persp matrix may not be correct
1990 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewIn verse(&vmi)) {
1991 vmi.mapRect(&bounds);
1992 // theoretically could set bloat = 0, instead leave it because of ma trix inversion
1993 // precision.
1994 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_Scala rHalf;
1995 bounds.outset(bloat, bloat);
1996 } else {
1997 avmr.setIdentity(drawState);
1998 }
1999
2000 this->drawSimpleRect(bounds);
2001 }
2002 }
2003
2004 void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { 1804 void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) {
2005 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); 1805 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target);
2006 if (rt->needsResolve()) { 1806 if (rt->needsResolve()) {
2007 // Some extensions automatically resolves the texture when it is read. 1807 // Some extensions automatically resolves the texture when it is read.
2008 if (this->glCaps().usesMSAARenderBuffers()) { 1808 if (this->glCaps().usesMSAARenderBuffers()) {
2009 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); 1809 SkASSERT(rt->textureFBOID() != rt->renderFBOID());
2010 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); 1810 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID()));
2011 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID())) ; 1811 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID())) ;
2012 // make sure we go through flushRenderTarget() since we've modified 1812 // make sure we go through flushRenderTarget() since we've modified
2013 // the bound DRAW FBO ID. 1813 // the bound DRAW FBO ID.
(...skipping 25 matching lines...) Expand all
2039 r.fLeft, r.fBottom, right, top, 1839 r.fLeft, r.fBottom, right, top,
2040 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); 1840 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST));
2041 } 1841 }
2042 } 1842 }
2043 rt->flagAsResolved(); 1843 rt->flagAsResolved();
2044 } 1844 }
2045 } 1845 }
2046 1846
2047 namespace { 1847 namespace {
2048 1848
2049 GrGLenum gr_to_gl_stencil_func(GrStencilFunc basicFunc) {
2050 static const GrGLenum gTable[] = {
2051 GR_GL_ALWAYS, // kAlways_StencilFunc
2052 GR_GL_NEVER, // kNever_StencilFunc
2053 GR_GL_GREATER, // kGreater_StencilFunc
2054 GR_GL_GEQUAL, // kGEqual_StencilFunc
2055 GR_GL_LESS, // kLess_StencilFunc
2056 GR_GL_LEQUAL, // kLEqual_StencilFunc,
2057 GR_GL_EQUAL, // kEqual_StencilFunc,
2058 GR_GL_NOTEQUAL, // kNotEqual_StencilFunc,
2059 };
2060 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kBasicStencilFuncCount);
2061 GR_STATIC_ASSERT(0 == kAlways_StencilFunc);
2062 GR_STATIC_ASSERT(1 == kNever_StencilFunc);
2063 GR_STATIC_ASSERT(2 == kGreater_StencilFunc);
2064 GR_STATIC_ASSERT(3 == kGEqual_StencilFunc);
2065 GR_STATIC_ASSERT(4 == kLess_StencilFunc);
2066 GR_STATIC_ASSERT(5 == kLEqual_StencilFunc);
2067 GR_STATIC_ASSERT(6 == kEqual_StencilFunc);
2068 GR_STATIC_ASSERT(7 == kNotEqual_StencilFunc);
2069 SkASSERT((unsigned) basicFunc < kBasicStencilFuncCount);
2070
2071 return gTable[basicFunc];
2072 }
2073 1849
2074 GrGLenum gr_to_gl_stencil_op(GrStencilOp op) { 1850 GrGLenum gr_to_gl_stencil_op(GrStencilOp op) {
2075 static const GrGLenum gTable[] = { 1851 static const GrGLenum gTable[] = {
2076 GR_GL_KEEP, // kKeep_StencilOp 1852 GR_GL_KEEP, // kKeep_StencilOp
2077 GR_GL_REPLACE, // kReplace_StencilOp 1853 GR_GL_REPLACE, // kReplace_StencilOp
2078 GR_GL_INCR_WRAP, // kIncWrap_StencilOp 1854 GR_GL_INCR_WRAP, // kIncWrap_StencilOp
2079 GR_GL_INCR, // kIncClamp_StencilOp 1855 GR_GL_INCR, // kIncClamp_StencilOp
2080 GR_GL_DECR_WRAP, // kDecWrap_StencilOp 1856 GR_GL_DECR_WRAP, // kDecWrap_StencilOp
2081 GR_GL_DECR, // kDecClamp_StencilOp 1857 GR_GL_DECR, // kDecClamp_StencilOp
2082 GR_GL_ZERO, // kZero_StencilOp 1858 GR_GL_ZERO, // kZero_StencilOp
2083 GR_GL_INVERT, // kInvert_StencilOp 1859 GR_GL_INVERT, // kInvert_StencilOp
2084 }; 1860 };
2085 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kStencilOpCount); 1861 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kStencilOpCount);
2086 GR_STATIC_ASSERT(0 == kKeep_StencilOp); 1862 GR_STATIC_ASSERT(0 == kKeep_StencilOp);
2087 GR_STATIC_ASSERT(1 == kReplace_StencilOp); 1863 GR_STATIC_ASSERT(1 == kReplace_StencilOp);
2088 GR_STATIC_ASSERT(2 == kIncWrap_StencilOp); 1864 GR_STATIC_ASSERT(2 == kIncWrap_StencilOp);
2089 GR_STATIC_ASSERT(3 == kIncClamp_StencilOp); 1865 GR_STATIC_ASSERT(3 == kIncClamp_StencilOp);
2090 GR_STATIC_ASSERT(4 == kDecWrap_StencilOp); 1866 GR_STATIC_ASSERT(4 == kDecWrap_StencilOp);
2091 GR_STATIC_ASSERT(5 == kDecClamp_StencilOp); 1867 GR_STATIC_ASSERT(5 == kDecClamp_StencilOp);
2092 GR_STATIC_ASSERT(6 == kZero_StencilOp); 1868 GR_STATIC_ASSERT(6 == kZero_StencilOp);
2093 GR_STATIC_ASSERT(7 == kInvert_StencilOp); 1869 GR_STATIC_ASSERT(7 == kInvert_StencilOp);
2094 SkASSERT((unsigned) op < kStencilOpCount); 1870 SkASSERT((unsigned) op < kStencilOpCount);
2095 return gTable[op]; 1871 return gTable[op];
2096 } 1872 }
2097 1873
2098 void set_gl_stencil(const GrGLInterface* gl, 1874 void set_gl_stencil(const GrGLInterface* gl,
2099 const GrStencilSettings& settings, 1875 const GrStencilSettings& settings,
2100 GrGLenum glFace, 1876 GrGLenum glFace,
2101 GrStencilSettings::Face grFace) { 1877 GrStencilSettings::Face grFace) {
2102 GrGLenum glFunc = gr_to_gl_stencil_func(settings.func(grFace)); 1878 GrGLenum glFunc = GrToGLStencilFunc(settings.func(grFace));
2103 GrGLenum glFailOp = gr_to_gl_stencil_op(settings.failOp(grFace)); 1879 GrGLenum glFailOp = gr_to_gl_stencil_op(settings.failOp(grFace));
2104 GrGLenum glPassOp = gr_to_gl_stencil_op(settings.passOp(grFace)); 1880 GrGLenum glPassOp = gr_to_gl_stencil_op(settings.passOp(grFace));
2105 1881
2106 GrGLint ref = settings.funcRef(grFace); 1882 GrGLint ref = settings.funcRef(grFace);
2107 GrGLint mask = settings.funcMask(grFace); 1883 GrGLint mask = settings.funcMask(grFace);
2108 GrGLint writeMask = settings.writeMask(grFace); 1884 GrGLint writeMask = settings.writeMask(grFace);
2109 1885
2110 if (GR_GL_FRONT_AND_BACK == glFace) { 1886 if (GR_GL_FRONT_AND_BACK == glFace) {
2111 // we call the combined func just in case separate stencil is not 1887 // we call the combined func just in case separate stencil is not
2112 // supported. 1888 // supported.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2180 } else { 1956 } else {
2181 if (kNo_TriState != fMSAAEnabled) { 1957 if (kNo_TriState != fMSAAEnabled) {
2182 GL_CALL(Disable(GR_GL_MULTISAMPLE)); 1958 GL_CALL(Disable(GR_GL_MULTISAMPLE));
2183 fMSAAEnabled = kNo_TriState; 1959 fMSAAEnabled = kNo_TriState;
2184 } 1960 }
2185 } 1961 }
2186 } 1962 }
2187 } 1963 }
2188 } 1964 }
2189 1965
2190 void GrGpuGL::flushPathStencilSettings(SkPath::FillType fill) {
2191 GrStencilSettings pathStencilSettings;
2192 this->getPathStencilSettingsForFillType(fill, &pathStencilSettings);
2193 if (fHWPathStencilSettings != pathStencilSettings) {
2194 // Just the func, ref, and mask is set here. The op and write mask are p arams to the call
2195 // that draws the path to the SB (glStencilFillPath)
2196 GrGLenum func =
2197 gr_to_gl_stencil_func(pathStencilSettings.func(GrStencilSettings::kF ront_Face));
2198 fPathRendering->pathStencilFunc(
2199 func, pathStencilSettings.funcRef(GrStencilSettings: :kFront_Face),
2200 pathStencilSettings.funcMask(GrStencilSettings::kFro nt_Face));
2201
2202 fHWPathStencilSettings = pathStencilSettings;
2203 }
2204 }
2205
2206 void GrGpuGL::flushBlend(bool isLines, 1966 void GrGpuGL::flushBlend(bool isLines,
2207 GrBlendCoeff srcCoeff, 1967 GrBlendCoeff srcCoeff,
2208 GrBlendCoeff dstCoeff) { 1968 GrBlendCoeff dstCoeff) {
2209 // Any optimization to disable blending should have already been applied and 1969 // Any optimization to disable blending should have already been applied and
2210 // tweaked the coeffs to (1, 0). 1970 // tweaked the coeffs to (1, 0).
2211 bool blendOff = kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo eff; 1971 bool blendOff = kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo eff;
2212 if (blendOff) { 1972 if (blendOff) {
2213 if (kNo_TriState != fHWBlendState.fEnabled) { 1973 if (kNo_TriState != fHWBlendState.fEnabled) {
2214 GL_CALL(Disable(GR_GL_BLEND)); 1974 GL_CALL(Disable(GR_GL_BLEND));
2215 fHWBlendState.fEnabled = kNo_TriState; 1975 fHWBlendState.fEnabled = kNo_TriState;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2342 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_A, swi zzle[3])); 2102 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_A, swi zzle[3]));
2343 } else { 2103 } else {
2344 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL int)); 2104 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL int));
2345 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara ms.fSwizzleRGBA); 2105 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara ms.fSwizzleRGBA);
2346 GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA, swizzle)); 2106 GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA, swizzle));
2347 } 2107 }
2348 } 2108 }
2349 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); 2109 texture->setCachedTexParams(newTexParams, this->getResetTimestamp());
2350 } 2110 }
2351 2111
2352 void GrGpuGL::setProjectionMatrix(const SkMatrix& matrix,
2353 const SkISize& renderTargetSize,
2354 GrSurfaceOrigin renderTargetOrigin) {
2355
2356 SkASSERT(this->glCaps().pathRenderingSupport());
2357
2358 if (renderTargetOrigin == fHWProjectionMatrixState.fRenderTargetOrigin &&
2359 renderTargetSize == fHWProjectionMatrixState.fRenderTargetSize &&
2360 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) {
2361 return;
2362 }
2363
2364 fHWProjectionMatrixState.fViewMatrix = matrix;
2365 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize;
2366 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin;
2367
2368 GrGLfloat glMatrix[4 * 4];
2369 fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix);
2370 GL_CALL(MatrixLoadf(GR_GL_PROJECTION, glMatrix));
2371 }
2372
2373 void GrGpuGL::enablePathTexGen(int unitIdx,
2374 PathTexGenComponents components,
2375 const GrGLfloat* coefficients) {
2376 SkASSERT(this->glCaps().pathRenderingSupport());
2377 SkASSERT(components >= kS_PathTexGenComponents &&
2378 components <= kSTR_PathTexGenComponents);
2379 SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= unitIdx);
2380
2381 if (GR_GL_OBJECT_LINEAR == fHWPathTexGenSettings[unitIdx].fMode &&
2382 components == fHWPathTexGenSettings[unitIdx].fNumComponents &&
2383 !memcmp(coefficients, fHWPathTexGenSettings[unitIdx].fCoefficients,
2384 3 * components * sizeof(GrGLfloat))) {
2385 return;
2386 }
2387
2388 this->setTextureUnit(unitIdx);
2389
2390 fHWPathTexGenSettings[unitIdx].fNumComponents = components;
2391 fPathRendering->pathTexGen(GR_GL_TEXTURE0 + unitIdx,
2392 GR_GL_OBJECT_LINEAR,
2393 components,
2394 coefficients);
2395
2396 memcpy(fHWPathTexGenSettings[unitIdx].fCoefficients, coefficients,
2397 3 * components * sizeof(GrGLfloat));
2398 }
2399
2400 void GrGpuGL::enablePathTexGen(int unitIdx, PathTexGenComponents components,
2401 const SkMatrix& matrix) {
2402 GrGLfloat coefficients[3 * 3];
2403 SkASSERT(this->glCaps().pathRenderingSupport());
2404 SkASSERT(components >= kS_PathTexGenComponents &&
2405 components <= kSTR_PathTexGenComponents);
2406
2407 coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]);
2408 coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]);
2409 coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]);
2410
2411 if (components >= kST_PathTexGenComponents) {
2412 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]);
2413 coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]);
2414 coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]);
2415 }
2416
2417 if (components >= kSTR_PathTexGenComponents) {
2418 coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]);
2419 coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]);
2420 coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]);
2421 }
2422
2423 enablePathTexGen(unitIdx, components, coefficients);
2424 }
2425
2426 void GrGpuGL::flushPathTexGenSettings(int numUsedTexCoordSets) {
2427 SkASSERT(this->glCaps().pathRenderingSupport());
2428 SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= numUsedTexCoordSe ts);
2429
2430 // Only write the inactive path tex gens, since active path tex gens were
2431 // written when they were enabled.
2432
2433 SkDEBUGCODE(
2434 for (int i = 0; i < numUsedTexCoordSets; i++) {
2435 SkASSERT(0 != fHWPathTexGenSettings[i].fNumComponents);
2436 }
2437 );
2438
2439 for (int i = numUsedTexCoordSets; i < fHWActivePathTexGenSets; i++) {
2440 SkASSERT(0 != fHWPathTexGenSettings[i].fNumComponents);
2441
2442 this->setTextureUnit(i);
2443 fPathRendering->pathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL);
2444 fHWPathTexGenSettings[i].fNumComponents = 0;
2445 }
2446
2447 fHWActivePathTexGenSets = numUsedTexCoordSets;
2448 }
2449
2450 void GrGpuGL::flushMiscFixedFunctionState() { 2112 void GrGpuGL::flushMiscFixedFunctionState() {
2451 2113
2452 const GrDrawState& drawState = this->getDrawState(); 2114 const GrDrawState& drawState = this->getDrawState();
2453 2115
2454 if (drawState.isDitherState()) { 2116 if (drawState.isDitherState()) {
2455 if (kYes_TriState != fHWDitherEnabled) { 2117 if (kYes_TriState != fHWDitherEnabled) {
2456 GL_CALL(Enable(GR_GL_DITHER)); 2118 GL_CALL(Enable(GR_GL_DITHER));
2457 fHWDitherEnabled = kYes_TriState; 2119 fHWDitherEnabled = kYes_TriState;
2458 } 2120 }
2459 } else { 2121 } else {
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
2943 this->setVertexArrayID(gpu, 0); 2605 this->setVertexArrayID(gpu, 0);
2944 } 2606 }
2945 int attrCount = gpu->glCaps().maxVertexAttributes(); 2607 int attrCount = gpu->glCaps().maxVertexAttributes();
2946 if (fDefaultVertexArrayAttribState.count() != attrCount) { 2608 if (fDefaultVertexArrayAttribState.count() != attrCount) {
2947 fDefaultVertexArrayAttribState.resize(attrCount); 2609 fDefaultVertexArrayAttribState.resize(attrCount);
2948 } 2610 }
2949 attribState = &fDefaultVertexArrayAttribState; 2611 attribState = &fDefaultVertexArrayAttribState;
2950 } 2612 }
2951 return attribState; 2613 return attribState;
2952 } 2614 }
OLDNEW
« no previous file with comments | « 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