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 "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 Loading... |
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, glInterface())); |
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 Loading... |
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()->onResetContext(); |
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 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1384 this->notifyIndexBufferDelete(desc.fID); | 1356 this->notifyIndexBufferDelete(desc.fID); |
1385 return NULL; | 1357 return NULL; |
1386 } | 1358 } |
1387 GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc
)); | 1359 GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc
)); |
1388 return indexBuffer; | 1360 return indexBuffer; |
1389 } | 1361 } |
1390 return NULL; | 1362 return NULL; |
1391 } | 1363 } |
1392 } | 1364 } |
1393 | 1365 |
1394 GrPath* GrGpuGL::onCreatePath(const SkPath& inPath, const SkStrokeRec& stroke) { | |
1395 SkASSERT(this->caps()->pathRenderingSupport()); | |
1396 return SkNEW_ARGS(GrGLPath, (this, inPath, stroke)); | |
1397 } | |
1398 | |
1399 GrPathRange* GrGpuGL::onCreatePathRange(size_t size, const SkStrokeRec& stroke)
{ | |
1400 SkASSERT(this->caps()->pathRenderingSupport()); | |
1401 return SkNEW_ARGS(GrGLPathRange, (this, size, stroke)); | |
1402 } | |
1403 | |
1404 void GrGpuGL::flushScissor() { | 1366 void GrGpuGL::flushScissor() { |
1405 if (fScissorState.fEnabled) { | 1367 if (fScissorState.fEnabled) { |
1406 // Only access the RT if scissoring is being enabled. We can call this b
efore performing | 1368 // Only access the RT if scissoring is being enabled. We can call this b
efore performing |
1407 // a glBitframebuffer for a surface->surface copy, which requires no RT
to be bound to the | 1369 // a glBitframebuffer for a surface->surface copy, which requires no RT
to be bound to the |
1408 // GrDrawState. | 1370 // GrDrawState. |
1409 const GrDrawState& drawState = this->getDrawState(); | 1371 const GrDrawState& drawState = this->getDrawState(); |
1410 const GrGLRenderTarget* rt = | 1372 const GrGLRenderTarget* rt = |
1411 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); | 1373 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); |
1412 | 1374 |
1413 SkASSERT(NULL != rt); | 1375 SkASSERT(NULL != rt); |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 int set_a_break_pt_here = 9; | 1813 int set_a_break_pt_here = 9; |
1852 aglSwapBuffers(aglGetCurrentContext()); | 1814 aglSwapBuffers(aglGetCurrentContext()); |
1853 #elif defined(SK_BUILD_FOR_WIN32) | 1815 #elif defined(SK_BUILD_FOR_WIN32) |
1854 SwapBuf(); | 1816 SwapBuf(); |
1855 int set_a_break_pt_here = 9; | 1817 int set_a_break_pt_here = 9; |
1856 SwapBuf(); | 1818 SwapBuf(); |
1857 #endif | 1819 #endif |
1858 #endif | 1820 #endif |
1859 } | 1821 } |
1860 | 1822 |
1861 static GrGLenum gr_stencil_op_to_gl_path_rendering_fill_mode(GrStencilOp op) { | |
1862 switch (op) { | |
1863 default: | |
1864 SkFAIL("Unexpected path fill."); | |
1865 /* fallthrough */; | |
1866 case kIncClamp_StencilOp: | |
1867 return GR_GL_COUNT_UP; | |
1868 case kInvert_StencilOp: | |
1869 return GR_GL_INVERT; | |
1870 } | |
1871 } | |
1872 | |
1873 void GrGpuGL::onGpuStencilPath(const GrPath* path, SkPath::FillType fill) { | |
1874 SkASSERT(this->caps()->pathRenderingSupport()); | |
1875 | |
1876 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); | |
1877 SkASSERT(NULL != this->drawState()->getRenderTarget()); | |
1878 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer()); | |
1879 | |
1880 flushPathStencilSettings(fill); | |
1881 | |
1882 // Decide how to manipulate the stencil buffer based on the fill rule. | |
1883 SkASSERT(!fHWPathStencilSettings.isTwoSided()); | |
1884 | |
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 fPathRendering->stencilFillPath(id, fillMode, writeMask); | |
1889 } | |
1890 | |
1891 void GrGpuGL::onGpuDrawPath(const GrPath* path, SkPath::FillType fill) { | |
1892 SkASSERT(this->caps()->pathRenderingSupport()); | |
1893 | |
1894 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); | |
1895 SkASSERT(NULL != this->drawState()->getRenderTarget()); | |
1896 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer()); | |
1897 SkASSERT(!fCurrentProgram->hasVertexShader()); | |
1898 | |
1899 flushPathStencilSettings(fill); | |
1900 const SkStrokeRec& stroke = path->getStroke(); | |
1901 | |
1902 SkPath::FillType nonInvertedFill = SkPath::ConvertToNonInverseFillType(fill)
; | |
1903 SkASSERT(!fHWPathStencilSettings.isTwoSided()); | |
1904 GrGLenum fillMode = | |
1905 gr_stencil_op_to_gl_path_rendering_fill_mode(fHWPathStencilSettings.pass
Op(GrStencilSettings::kFront_Face)); | |
1906 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFro
nt_Face); | |
1907 | |
1908 if (nonInvertedFill == fill) { | |
1909 if (stroke.needToApply()) { | |
1910 if (SkStrokeRec::kStrokeAndFill_Style == stroke.getStyle()) { | |
1911 fPathRendering->stencilFillPath(id, fillMode, writeMask); | |
1912 } | |
1913 fPathRendering->stencilThenCoverStrokePath(id, 0xffff, writeMask, GR
_GL_BOUNDING_BOX); | |
1914 } else { | |
1915 fPathRendering->stencilThenCoverFillPath(id, fillMode, writeMask, GR
_GL_BOUNDING_BOX); | |
1916 } | |
1917 } else { | |
1918 if (stroke.isFillStyle() || SkStrokeRec::kStrokeAndFill_Style == stroke.
getStyle()) { | |
1919 fPathRendering->stencilFillPath(id, fillMode, writeMask); | |
1920 } | |
1921 if (stroke.needToApply()) { | |
1922 fPathRendering->stencilStrokePath(id, 0xffff, writeMask); | |
1923 } | |
1924 | |
1925 GrDrawState* drawState = this->drawState(); | |
1926 GrDrawState::AutoViewMatrixRestore avmr; | |
1927 SkRect bounds = SkRect::MakeLTRB(0, 0, | |
1928 SkIntToScalar(drawState->getRenderTarge
t()->width()), | |
1929 SkIntToScalar(drawState->getRenderTarge
t()->height())); | |
1930 SkMatrix vmi; | |
1931 // mapRect through persp matrix may not be correct | |
1932 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewIn
verse(&vmi)) { | |
1933 vmi.mapRect(&bounds); | |
1934 // theoretically could set bloat = 0, instead leave it because of ma
trix inversion | |
1935 // precision. | |
1936 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_Scala
rHalf; | |
1937 bounds.outset(bloat, bloat); | |
1938 } else { | |
1939 avmr.setIdentity(drawState); | |
1940 } | |
1941 | |
1942 this->drawSimpleRect(bounds); | |
1943 } | |
1944 } | |
1945 | |
1946 void GrGpuGL::onGpuDrawPaths(const GrPathRange* pathRange, | |
1947 const uint32_t indices[], int count, | |
1948 const float transforms[], PathTransformType transfo
rmsType, | |
1949 SkPath::FillType fill) { | |
1950 SkASSERT(this->caps()->pathRenderingSupport()); | |
1951 SkASSERT(NULL != this->drawState()->getRenderTarget()); | |
1952 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer()); | |
1953 SkASSERT(!fCurrentProgram->hasVertexShader()); | |
1954 | |
1955 GrGLuint baseID = static_cast<const GrGLPathRange*>(pathRange)->basePathID()
; | |
1956 | |
1957 flushPathStencilSettings(fill); | |
1958 const SkStrokeRec& stroke = pathRange->getStroke(); | |
1959 | |
1960 SkPath::FillType nonInvertedFill = | |
1961 SkPath::ConvertToNonInverseFillType(fill); | |
1962 | |
1963 SkASSERT(!fHWPathStencilSettings.isTwoSided()); | |
1964 GrGLenum fillMode = | |
1965 gr_stencil_op_to_gl_path_rendering_fill_mode( | |
1966 fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); | |
1967 GrGLint writeMask = | |
1968 fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face); | |
1969 | |
1970 if (nonInvertedFill == fill) { | |
1971 if (stroke.needToApply()) { | |
1972 if (SkStrokeRec::kStrokeAndFill_Style == stroke.getStyle()) { | |
1973 fPathRendering->stencilFillPathInstanced( | |
1974 count, GR_GL_UNSIGNED_INT, indices, baseID,
fillMode, | |
1975 writeMask, gXformType2GLType[transformsType]
, | |
1976 transforms); | |
1977 } | |
1978 fPathRendering->stencilThenCoverStrokePathInstanced( | |
1979 count, GR_GL_UNSIGNED_INT, indices, baseID, 0xff
ff, writeMask, | |
1980 GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES, | |
1981 gXformType2GLType[transformsType], transforms); | |
1982 } else { | |
1983 fPathRendering->stencilThenCoverFillPathInstanced( | |
1984 count, GR_GL_UNSIGNED_INT, indices, baseID, fill
Mode, writeMask, | |
1985 GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES, | |
1986 gXformType2GLType[transformsType], transforms); | |
1987 } | |
1988 } else { | |
1989 if (stroke.isFillStyle() || SkStrokeRec::kStrokeAndFill_Style == stroke.
getStyle()) { | |
1990 fPathRendering->stencilFillPathInstanced( | |
1991 count, GR_GL_UNSIGNED_INT, indices, baseID, fill
Mode, | |
1992 writeMask, gXformType2GLType[transformsType], | |
1993 transforms); | |
1994 } | |
1995 if (stroke.needToApply()) { | |
1996 fPathRendering->stencilStrokePathInstanced( | |
1997 count, GR_GL_UNSIGNED_INT, indices, baseID, 0xff
ff, | |
1998 writeMask, gXformType2GLType[transformsType], | |
1999 transforms); | |
2000 } | |
2001 | |
2002 GrDrawState* drawState = this->drawState(); | |
2003 GrDrawState::AutoViewMatrixRestore avmr; | |
2004 SkRect bounds = SkRect::MakeLTRB(0, 0, | |
2005 SkIntToScalar(drawState->getRenderTarge
t()->width()), | |
2006 SkIntToScalar(drawState->getRenderTarge
t()->height())); | |
2007 SkMatrix vmi; | |
2008 // mapRect through persp matrix may not be correct | |
2009 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewIn
verse(&vmi)) { | |
2010 vmi.mapRect(&bounds); | |
2011 // theoretically could set bloat = 0, instead leave it because of ma
trix inversion | |
2012 // precision. | |
2013 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_Scala
rHalf; | |
2014 bounds.outset(bloat, bloat); | |
2015 } else { | |
2016 avmr.setIdentity(drawState); | |
2017 } | |
2018 | |
2019 this->drawSimpleRect(bounds); | |
2020 } | |
2021 } | |
2022 | |
2023 void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { | 1823 void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { |
2024 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); | 1824 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |
2025 if (rt->needsResolve()) { | 1825 if (rt->needsResolve()) { |
2026 // Some extensions automatically resolves the texture when it is read. | 1826 // Some extensions automatically resolves the texture when it is read. |
2027 if (this->glCaps().usesMSAARenderBuffers()) { | 1827 if (this->glCaps().usesMSAARenderBuffers()) { |
2028 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); | 1828 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); |
2029 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); | 1829 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); |
2030 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; | 1830 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; |
2031 // make sure we go through flushRenderTarget() since we've modified | 1831 // make sure we go through flushRenderTarget() since we've modified |
2032 // the bound DRAW FBO ID. | 1832 // the bound DRAW FBO ID. |
(...skipping 25 matching lines...) Expand all Loading... |
2058 r.fLeft, r.fBottom, right, top, | 1858 r.fLeft, r.fBottom, right, top, |
2059 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); | 1859 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); |
2060 } | 1860 } |
2061 } | 1861 } |
2062 rt->flagAsResolved(); | 1862 rt->flagAsResolved(); |
2063 } | 1863 } |
2064 } | 1864 } |
2065 | 1865 |
2066 namespace { | 1866 namespace { |
2067 | 1867 |
2068 GrGLenum gr_to_gl_stencil_func(GrStencilFunc basicFunc) { | |
2069 static const GrGLenum gTable[] = { | |
2070 GR_GL_ALWAYS, // kAlways_StencilFunc | |
2071 GR_GL_NEVER, // kNever_StencilFunc | |
2072 GR_GL_GREATER, // kGreater_StencilFunc | |
2073 GR_GL_GEQUAL, // kGEqual_StencilFunc | |
2074 GR_GL_LESS, // kLess_StencilFunc | |
2075 GR_GL_LEQUAL, // kLEqual_StencilFunc, | |
2076 GR_GL_EQUAL, // kEqual_StencilFunc, | |
2077 GR_GL_NOTEQUAL, // kNotEqual_StencilFunc, | |
2078 }; | |
2079 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kBasicStencilFuncCount); | |
2080 GR_STATIC_ASSERT(0 == kAlways_StencilFunc); | |
2081 GR_STATIC_ASSERT(1 == kNever_StencilFunc); | |
2082 GR_STATIC_ASSERT(2 == kGreater_StencilFunc); | |
2083 GR_STATIC_ASSERT(3 == kGEqual_StencilFunc); | |
2084 GR_STATIC_ASSERT(4 == kLess_StencilFunc); | |
2085 GR_STATIC_ASSERT(5 == kLEqual_StencilFunc); | |
2086 GR_STATIC_ASSERT(6 == kEqual_StencilFunc); | |
2087 GR_STATIC_ASSERT(7 == kNotEqual_StencilFunc); | |
2088 SkASSERT((unsigned) basicFunc < kBasicStencilFuncCount); | |
2089 | |
2090 return gTable[basicFunc]; | |
2091 } | |
2092 | 1868 |
2093 GrGLenum gr_to_gl_stencil_op(GrStencilOp op) { | 1869 GrGLenum gr_to_gl_stencil_op(GrStencilOp op) { |
2094 static const GrGLenum gTable[] = { | 1870 static const GrGLenum gTable[] = { |
2095 GR_GL_KEEP, // kKeep_StencilOp | 1871 GR_GL_KEEP, // kKeep_StencilOp |
2096 GR_GL_REPLACE, // kReplace_StencilOp | 1872 GR_GL_REPLACE, // kReplace_StencilOp |
2097 GR_GL_INCR_WRAP, // kIncWrap_StencilOp | 1873 GR_GL_INCR_WRAP, // kIncWrap_StencilOp |
2098 GR_GL_INCR, // kIncClamp_StencilOp | 1874 GR_GL_INCR, // kIncClamp_StencilOp |
2099 GR_GL_DECR_WRAP, // kDecWrap_StencilOp | 1875 GR_GL_DECR_WRAP, // kDecWrap_StencilOp |
2100 GR_GL_DECR, // kDecClamp_StencilOp | 1876 GR_GL_DECR, // kDecClamp_StencilOp |
2101 GR_GL_ZERO, // kZero_StencilOp | 1877 GR_GL_ZERO, // kZero_StencilOp |
2102 GR_GL_INVERT, // kInvert_StencilOp | 1878 GR_GL_INVERT, // kInvert_StencilOp |
2103 }; | 1879 }; |
2104 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kStencilOpCount); | 1880 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kStencilOpCount); |
2105 GR_STATIC_ASSERT(0 == kKeep_StencilOp); | 1881 GR_STATIC_ASSERT(0 == kKeep_StencilOp); |
2106 GR_STATIC_ASSERT(1 == kReplace_StencilOp); | 1882 GR_STATIC_ASSERT(1 == kReplace_StencilOp); |
2107 GR_STATIC_ASSERT(2 == kIncWrap_StencilOp); | 1883 GR_STATIC_ASSERT(2 == kIncWrap_StencilOp); |
2108 GR_STATIC_ASSERT(3 == kIncClamp_StencilOp); | 1884 GR_STATIC_ASSERT(3 == kIncClamp_StencilOp); |
2109 GR_STATIC_ASSERT(4 == kDecWrap_StencilOp); | 1885 GR_STATIC_ASSERT(4 == kDecWrap_StencilOp); |
2110 GR_STATIC_ASSERT(5 == kDecClamp_StencilOp); | 1886 GR_STATIC_ASSERT(5 == kDecClamp_StencilOp); |
2111 GR_STATIC_ASSERT(6 == kZero_StencilOp); | 1887 GR_STATIC_ASSERT(6 == kZero_StencilOp); |
2112 GR_STATIC_ASSERT(7 == kInvert_StencilOp); | 1888 GR_STATIC_ASSERT(7 == kInvert_StencilOp); |
2113 SkASSERT((unsigned) op < kStencilOpCount); | 1889 SkASSERT((unsigned) op < kStencilOpCount); |
2114 return gTable[op]; | 1890 return gTable[op]; |
2115 } | 1891 } |
2116 | 1892 |
2117 void set_gl_stencil(const GrGLInterface* gl, | 1893 void set_gl_stencil(const GrGLInterface* gl, |
2118 const GrStencilSettings& settings, | 1894 const GrStencilSettings& settings, |
2119 GrGLenum glFace, | 1895 GrGLenum glFace, |
2120 GrStencilSettings::Face grFace) { | 1896 GrStencilSettings::Face grFace) { |
2121 GrGLenum glFunc = gr_to_gl_stencil_func(settings.func(grFace)); | 1897 GrGLenum glFunc = GrToGLStencilFunc(settings.func(grFace)); |
2122 GrGLenum glFailOp = gr_to_gl_stencil_op(settings.failOp(grFace)); | 1898 GrGLenum glFailOp = gr_to_gl_stencil_op(settings.failOp(grFace)); |
2123 GrGLenum glPassOp = gr_to_gl_stencil_op(settings.passOp(grFace)); | 1899 GrGLenum glPassOp = gr_to_gl_stencil_op(settings.passOp(grFace)); |
2124 | 1900 |
2125 GrGLint ref = settings.funcRef(grFace); | 1901 GrGLint ref = settings.funcRef(grFace); |
2126 GrGLint mask = settings.funcMask(grFace); | 1902 GrGLint mask = settings.funcMask(grFace); |
2127 GrGLint writeMask = settings.writeMask(grFace); | 1903 GrGLint writeMask = settings.writeMask(grFace); |
2128 | 1904 |
2129 if (GR_GL_FRONT_AND_BACK == glFace) { | 1905 if (GR_GL_FRONT_AND_BACK == glFace) { |
2130 // we call the combined func just in case separate stencil is not | 1906 // we call the combined func just in case separate stencil is not |
2131 // supported. | 1907 // supported. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2199 } else { | 1975 } else { |
2200 if (kNo_TriState != fMSAAEnabled) { | 1976 if (kNo_TriState != fMSAAEnabled) { |
2201 GL_CALL(Disable(GR_GL_MULTISAMPLE)); | 1977 GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
2202 fMSAAEnabled = kNo_TriState; | 1978 fMSAAEnabled = kNo_TriState; |
2203 } | 1979 } |
2204 } | 1980 } |
2205 } | 1981 } |
2206 } | 1982 } |
2207 } | 1983 } |
2208 | 1984 |
2209 void GrGpuGL::flushPathStencilSettings(SkPath::FillType fill) { | |
2210 GrStencilSettings pathStencilSettings; | |
2211 this->getPathStencilSettingsForFillType(fill, &pathStencilSettings); | |
2212 if (fHWPathStencilSettings != pathStencilSettings) { | |
2213 // Just the func, ref, and mask is set here. The op and write mask are p
arams to the call | |
2214 // that draws the path to the SB (glStencilFillPath) | |
2215 GrGLenum func = | |
2216 gr_to_gl_stencil_func(pathStencilSettings.func(GrStencilSettings::kF
ront_Face)); | |
2217 fPathRendering->pathStencilFunc( | |
2218 func, pathStencilSettings.funcRef(GrStencilSettings:
:kFront_Face), | |
2219 pathStencilSettings.funcMask(GrStencilSettings::kFro
nt_Face)); | |
2220 | |
2221 fHWPathStencilSettings = pathStencilSettings; | |
2222 } | |
2223 } | |
2224 | |
2225 void GrGpuGL::flushBlend(bool isLines, | 1985 void GrGpuGL::flushBlend(bool isLines, |
2226 GrBlendCoeff srcCoeff, | 1986 GrBlendCoeff srcCoeff, |
2227 GrBlendCoeff dstCoeff) { | 1987 GrBlendCoeff dstCoeff) { |
2228 // Any optimization to disable blending should have already been applied and | 1988 // Any optimization to disable blending should have already been applied and |
2229 // tweaked the coeffs to (1, 0). | 1989 // tweaked the coeffs to (1, 0). |
2230 bool blendOff = kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo
eff; | 1990 bool blendOff = kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo
eff; |
2231 if (blendOff) { | 1991 if (blendOff) { |
2232 if (kNo_TriState != fHWBlendState.fEnabled) { | 1992 if (kNo_TriState != fHWBlendState.fEnabled) { |
2233 GL_CALL(Disable(GR_GL_BLEND)); | 1993 GL_CALL(Disable(GR_GL_BLEND)); |
2234 fHWBlendState.fEnabled = kNo_TriState; | 1994 fHWBlendState.fEnabled = kNo_TriState; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2361 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_A, swi
zzle[3])); | 2121 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_A, swi
zzle[3])); |
2362 } else { | 2122 } else { |
2363 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL
int)); | 2123 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL
int)); |
2364 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara
ms.fSwizzleRGBA); | 2124 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara
ms.fSwizzleRGBA); |
2365 GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA,
swizzle)); | 2125 GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA,
swizzle)); |
2366 } | 2126 } |
2367 } | 2127 } |
2368 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); | 2128 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); |
2369 } | 2129 } |
2370 | 2130 |
2371 void GrGpuGL::setProjectionMatrix(const SkMatrix& matrix, | |
2372 const SkISize& renderTargetSize, | |
2373 GrSurfaceOrigin renderTargetOrigin) { | |
2374 | |
2375 SkASSERT(this->glCaps().pathRenderingSupport()); | |
2376 | |
2377 if (renderTargetOrigin == fHWProjectionMatrixState.fRenderTargetOrigin && | |
2378 renderTargetSize == fHWProjectionMatrixState.fRenderTargetSize && | |
2379 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { | |
2380 return; | |
2381 } | |
2382 | |
2383 fHWProjectionMatrixState.fViewMatrix = matrix; | |
2384 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; | |
2385 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; | |
2386 | |
2387 GrGLfloat glMatrix[4 * 4]; | |
2388 fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix); | |
2389 GL_CALL(MatrixLoadf(GR_GL_PROJECTION, glMatrix)); | |
2390 } | |
2391 | |
2392 void GrGpuGL::enablePathTexGen(int unitIdx, | |
2393 PathTexGenComponents components, | |
2394 const GrGLfloat* coefficients) { | |
2395 SkASSERT(this->glCaps().pathRenderingSupport()); | |
2396 SkASSERT(components >= kS_PathTexGenComponents && | |
2397 components <= kSTR_PathTexGenComponents); | |
2398 SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= unitIdx); | |
2399 | |
2400 if (GR_GL_OBJECT_LINEAR == fHWPathTexGenSettings[unitIdx].fMode && | |
2401 components == fHWPathTexGenSettings[unitIdx].fNumComponents && | |
2402 !memcmp(coefficients, fHWPathTexGenSettings[unitIdx].fCoefficients, | |
2403 3 * components * sizeof(GrGLfloat))) { | |
2404 return; | |
2405 } | |
2406 | |
2407 this->setTextureUnit(unitIdx); | |
2408 | |
2409 fHWPathTexGenSettings[unitIdx].fNumComponents = components; | |
2410 fPathRendering->pathTexGen(GR_GL_TEXTURE0 + unitIdx, | |
2411 GR_GL_OBJECT_LINEAR, | |
2412 components, | |
2413 coefficients); | |
2414 | |
2415 memcpy(fHWPathTexGenSettings[unitIdx].fCoefficients, coefficients, | |
2416 3 * components * sizeof(GrGLfloat)); | |
2417 } | |
2418 | |
2419 void GrGpuGL::enablePathTexGen(int unitIdx, PathTexGenComponents components, | |
2420 const SkMatrix& matrix) { | |
2421 GrGLfloat coefficients[3 * 3]; | |
2422 SkASSERT(this->glCaps().pathRenderingSupport()); | |
2423 SkASSERT(components >= kS_PathTexGenComponents && | |
2424 components <= kSTR_PathTexGenComponents); | |
2425 | |
2426 coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]); | |
2427 coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]); | |
2428 coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]); | |
2429 | |
2430 if (components >= kST_PathTexGenComponents) { | |
2431 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); | |
2432 coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]); | |
2433 coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]); | |
2434 } | |
2435 | |
2436 if (components >= kSTR_PathTexGenComponents) { | |
2437 coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]); | |
2438 coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]); | |
2439 coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]); | |
2440 } | |
2441 | |
2442 enablePathTexGen(unitIdx, components, coefficients); | |
2443 } | |
2444 | |
2445 void GrGpuGL::flushPathTexGenSettings(int numUsedTexCoordSets) { | |
2446 SkASSERT(this->glCaps().pathRenderingSupport()); | |
2447 SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= numUsedTexCoordSe
ts); | |
2448 | |
2449 // Only write the inactive path tex gens, since active path tex gens were | |
2450 // written when they were enabled. | |
2451 | |
2452 SkDEBUGCODE( | |
2453 for (int i = 0; i < numUsedTexCoordSets; i++) { | |
2454 SkASSERT(0 != fHWPathTexGenSettings[i].fNumComponents); | |
2455 } | |
2456 ); | |
2457 | |
2458 for (int i = numUsedTexCoordSets; i < fHWActivePathTexGenSets; i++) { | |
2459 SkASSERT(0 != fHWPathTexGenSettings[i].fNumComponents); | |
2460 | |
2461 this->setTextureUnit(i); | |
2462 fPathRendering->pathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL); | |
2463 fHWPathTexGenSettings[i].fNumComponents = 0; | |
2464 } | |
2465 | |
2466 fHWActivePathTexGenSets = numUsedTexCoordSets; | |
2467 } | |
2468 | |
2469 void GrGpuGL::flushMiscFixedFunctionState() { | 2131 void GrGpuGL::flushMiscFixedFunctionState() { |
2470 | 2132 |
2471 const GrDrawState& drawState = this->getDrawState(); | 2133 const GrDrawState& drawState = this->getDrawState(); |
2472 | 2134 |
2473 if (drawState.isDitherState()) { | 2135 if (drawState.isDitherState()) { |
2474 if (kYes_TriState != fHWDitherEnabled) { | 2136 if (kYes_TriState != fHWDitherEnabled) { |
2475 GL_CALL(Enable(GR_GL_DITHER)); | 2137 GL_CALL(Enable(GR_GL_DITHER)); |
2476 fHWDitherEnabled = kYes_TriState; | 2138 fHWDitherEnabled = kYes_TriState; |
2477 } | 2139 } |
2478 } else { | 2140 } else { |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2967 this->setVertexArrayID(gpu, 0); | 2629 this->setVertexArrayID(gpu, 0); |
2968 } | 2630 } |
2969 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2631 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2970 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2632 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2971 fDefaultVertexArrayAttribState.resize(attrCount); | 2633 fDefaultVertexArrayAttribState.resize(attrCount); |
2972 } | 2634 } |
2973 attribState = &fDefaultVertexArrayAttribState; | 2635 attribState = &fDefaultVertexArrayAttribState; |
2974 } | 2636 } |
2975 return attribState; | 2637 return attribState; |
2976 } | 2638 } |
OLD | NEW |