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 "GrGLNameAllocator.h" | 10 #include "GrGLNameAllocator.h" |
11 #include "GrGLStencilBuffer.h" | 11 #include "GrGLStencilBuffer.h" |
12 #include "GrGLPath.h" | 12 #include "GrGLPath.h" |
| 13 #include "GrGLPathRange.h" |
13 #include "GrGLShaderBuilder.h" | 14 #include "GrGLShaderBuilder.h" |
14 #include "GrTemplates.h" | 15 #include "GrTemplates.h" |
15 #include "GrTypes.h" | 16 #include "GrTypes.h" |
16 #include "SkStrokeRec.h" | 17 #include "SkStrokeRec.h" |
17 #include "SkTemplates.h" | 18 #include "SkTemplates.h" |
18 | 19 |
19 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) | 20 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
20 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) | 21 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) |
21 | 22 |
22 #define SKIP_CACHE_CHECK true | 23 #define SKIP_CACHE_CHECK true |
23 | 24 |
24 #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR | 25 #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR |
25 #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface) | 26 #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface) |
26 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call) | 27 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call) |
27 #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface) | 28 #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface) |
28 #else | 29 #else |
29 #define CLEAR_ERROR_BEFORE_ALLOC(iface) | 30 #define CLEAR_ERROR_BEFORE_ALLOC(iface) |
30 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL(iface, call) | 31 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL(iface, call) |
31 #define CHECK_ALLOC_ERROR(iface) GR_GL_NO_ERROR | 32 #define CHECK_ALLOC_ERROR(iface) GR_GL_NO_ERROR |
32 #endif | 33 #endif |
33 | 34 |
34 | 35 |
35 /////////////////////////////////////////////////////////////////////////////// | 36 /////////////////////////////////////////////////////////////////////////////// |
36 | 37 |
| 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 |
37 static const GrGLenum gXfermodeCoeff2Blend[] = { | 53 static const GrGLenum gXfermodeCoeff2Blend[] = { |
38 GR_GL_ZERO, | 54 GR_GL_ZERO, |
39 GR_GL_ONE, | 55 GR_GL_ONE, |
40 GR_GL_SRC_COLOR, | 56 GR_GL_SRC_COLOR, |
41 GR_GL_ONE_MINUS_SRC_COLOR, | 57 GR_GL_ONE_MINUS_SRC_COLOR, |
42 GR_GL_DST_COLOR, | 58 GR_GL_DST_COLOR, |
43 GR_GL_ONE_MINUS_DST_COLOR, | 59 GR_GL_ONE_MINUS_DST_COLOR, |
44 GR_GL_SRC_ALPHA, | 60 GR_GL_SRC_ALPHA, |
45 GR_GL_ONE_MINUS_SRC_ALPHA, | 61 GR_GL_ONE_MINUS_SRC_ALPHA, |
46 GR_GL_DST_ALPHA, | 62 GR_GL_DST_ALPHA, |
(...skipping 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 } | 1378 } |
1363 return NULL; | 1379 return NULL; |
1364 } | 1380 } |
1365 } | 1381 } |
1366 | 1382 |
1367 GrPath* GrGpuGL::onCreatePath(const SkPath& inPath, const SkStrokeRec& stroke) { | 1383 GrPath* GrGpuGL::onCreatePath(const SkPath& inPath, const SkStrokeRec& stroke) { |
1368 SkASSERT(this->caps()->pathRenderingSupport()); | 1384 SkASSERT(this->caps()->pathRenderingSupport()); |
1369 return SkNEW_ARGS(GrGLPath, (this, inPath, stroke)); | 1385 return SkNEW_ARGS(GrGLPath, (this, inPath, stroke)); |
1370 } | 1386 } |
1371 | 1387 |
| 1388 GrPathRange* GrGpuGL::onCreatePathRange(size_t size, const SkStrokeRec& stroke)
{ |
| 1389 SkASSERT(this->caps()->pathRenderingSupport()); |
| 1390 return SkNEW_ARGS(GrGLPathRange, (this, size, stroke)); |
| 1391 } |
| 1392 |
1372 void GrGpuGL::flushScissor() { | 1393 void GrGpuGL::flushScissor() { |
1373 if (fScissorState.fEnabled) { | 1394 if (fScissorState.fEnabled) { |
1374 // Only access the RT if scissoring is being enabled. We can call this b
efore performing | 1395 // Only access the RT if scissoring is being enabled. We can call this b
efore performing |
1375 // a glBitframebuffer for a surface->surface copy, which requires no RT
to be bound to the | 1396 // a glBitframebuffer for a surface->surface copy, which requires no RT
to be bound to the |
1376 // GrDrawState. | 1397 // GrDrawState. |
1377 const GrDrawState& drawState = this->getDrawState(); | 1398 const GrDrawState& drawState = this->getDrawState(); |
1378 const GrGLRenderTarget* rt = | 1399 const GrGLRenderTarget* rt = |
1379 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); | 1400 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); |
1380 | 1401 |
1381 SkASSERT(NULL != rt); | 1402 SkASSERT(NULL != rt); |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_Scala
rHalf; | 1921 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_Scala
rHalf; |
1901 bounds.outset(bloat, bloat); | 1922 bounds.outset(bloat, bloat); |
1902 } else { | 1923 } else { |
1903 avmr.setIdentity(drawState); | 1924 avmr.setIdentity(drawState); |
1904 } | 1925 } |
1905 | 1926 |
1906 this->drawSimpleRect(bounds, NULL); | 1927 this->drawSimpleRect(bounds, NULL); |
1907 } | 1928 } |
1908 } | 1929 } |
1909 | 1930 |
1910 void GrGpuGL::onGpuDrawPaths(int pathCount, const GrPath** paths, | 1931 void GrGpuGL::onGpuDrawPaths(const GrPathRange* pathRange, |
1911 const SkMatrix* transforms, | 1932 const uint32_t indices[], int count, |
1912 SkPath::FillType fill, | 1933 const float transforms[], PathTransformType transfo
rmsType, |
1913 SkStrokeRec::Style stroke) { | 1934 SkPath::FillType fill) { |
1914 SkASSERT(this->caps()->pathRenderingSupport()); | 1935 SkASSERT(this->caps()->pathRenderingSupport()); |
1915 SkASSERT(NULL != this->drawState()->getRenderTarget()); | 1936 SkASSERT(NULL != this->drawState()->getRenderTarget()); |
1916 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer()); | 1937 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer()); |
1917 SkASSERT(!fCurrentProgram->hasVertexShader()); | 1938 SkASSERT(!fCurrentProgram->hasVertexShader()); |
1918 SkASSERT(stroke != SkStrokeRec::kHairline_Style); | |
1919 | 1939 |
1920 SkAutoMalloc pathData(pathCount * sizeof(GrGLuint)); | 1940 GrGLuint baseID = static_cast<const GrGLPathRange*>(pathRange)->basePathID()
; |
1921 SkAutoMalloc transformData(pathCount * sizeof(GrGLfloat) * 6); | |
1922 GrGLfloat* transformValues = | |
1923 reinterpret_cast<GrGLfloat*>(transformData.get()); | |
1924 GrGLuint* pathIDs = reinterpret_cast<GrGLuint*>(pathData.get()); | |
1925 | |
1926 for (int i = 0; i < pathCount; ++i) { | |
1927 SkASSERT(transforms[i].asAffine(NULL)); | |
1928 const SkMatrix& m = transforms[i]; | |
1929 transformValues[i * 6] = m.getScaleX(); | |
1930 transformValues[i * 6 + 1] = m.getSkewY(); | |
1931 transformValues[i * 6 + 2] = m.getSkewX(); | |
1932 transformValues[i * 6 + 3] = m.getScaleY(); | |
1933 transformValues[i * 6 + 4] = m.getTranslateX(); | |
1934 transformValues[i * 6 + 5] = m.getTranslateY(); | |
1935 pathIDs[i] = static_cast<const GrGLPath*>(paths[i])->pathID(); | |
1936 } | |
1937 | 1941 |
1938 flushPathStencilSettings(fill); | 1942 flushPathStencilSettings(fill); |
| 1943 const SkStrokeRec& stroke = pathRange->getStroke(); |
1939 | 1944 |
1940 SkPath::FillType nonInvertedFill = | 1945 SkPath::FillType nonInvertedFill = |
1941 SkPath::ConvertToNonInverseFillType(fill); | 1946 SkPath::ConvertToNonInverseFillType(fill); |
1942 | 1947 |
1943 SkASSERT(!fHWPathStencilSettings.isTwoSided()); | 1948 SkASSERT(!fHWPathStencilSettings.isTwoSided()); |
1944 GrGLenum fillMode = | 1949 GrGLenum fillMode = |
1945 gr_stencil_op_to_gl_path_rendering_fill_mode( | 1950 gr_stencil_op_to_gl_path_rendering_fill_mode( |
1946 fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); | 1951 fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
1947 GrGLint writeMask = | 1952 GrGLint writeMask = |
1948 fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face); | 1953 fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face); |
1949 | 1954 |
1950 bool doFill = stroke == SkStrokeRec::kFill_Style | 1955 if (stroke.isFillStyle() || SkStrokeRec::kStrokeAndFill_Style == stroke.getS
tyle()) { |
1951 || stroke == SkStrokeRec::kStrokeAndFill_Style; | 1956 GL_CALL(StencilFillPathInstanced(count, GR_GL_UNSIGNED_INT, indices, bas
eID, fillMode, |
1952 bool doStroke = stroke == SkStrokeRec::kStroke_Style | 1957 writeMask, gXformType2GLType[transforms
Type], |
1953 || stroke == SkStrokeRec::kStrokeAndFill_Style; | 1958 transforms)); |
1954 | |
1955 if (doFill) { | |
1956 GL_CALL(StencilFillPathInstanced(pathCount, GR_GL_UNSIGNED_INT, | |
1957 pathIDs, 0, | |
1958 fillMode, writeMask, | |
1959 GR_GL_AFFINE_2D, transformValues)); | |
1960 } | 1959 } |
1961 if (doStroke) { | 1960 if (stroke.needToApply()) { |
1962 GL_CALL(StencilStrokePathInstanced(pathCount, GR_GL_UNSIGNED_INT, | 1961 GL_CALL(StencilStrokePathInstanced(count, GR_GL_UNSIGNED_INT, indices, b
aseID, 0xffff, |
1963 pathIDs, 0, | 1962 writeMask, gXformType2GLType[transfor
msType], |
1964 0xffff, writeMask, | 1963 transforms)); |
1965 GR_GL_AFFINE_2D, transformValues)); | |
1966 } | 1964 } |
1967 | 1965 |
1968 if (nonInvertedFill == fill) { | 1966 if (nonInvertedFill == fill) { |
1969 if (doStroke) { | 1967 if (stroke.needToApply()) { |
1970 GL_CALL(CoverStrokePathInstanced( | 1968 GL_CALL(CoverStrokePathInstanced( |
1971 pathCount, GR_GL_UNSIGNED_INT, pathIDs, 0, | 1969 count, GR_GL_UNSIGNED_INT, indices, baseID, |
1972 GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES, | 1970 GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES, |
1973 GR_GL_AFFINE_2D, transformValues)); | 1971 gXformType2GLType[transformsType], transforms)); |
1974 } else { | 1972 } else { |
1975 GL_CALL(CoverFillPathInstanced( | 1973 GL_CALL(CoverFillPathInstanced( |
1976 pathCount, GR_GL_UNSIGNED_INT, pathIDs, 0, | 1974 count, GR_GL_UNSIGNED_INT, indices, baseID, |
1977 GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES, | 1975 GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES, |
1978 GR_GL_AFFINE_2D, transformValues)); | 1976 gXformType2GLType[transformsType], transforms)); |
1979 | |
1980 } | 1977 } |
1981 } else { | 1978 } else { |
1982 GrDrawState* drawState = this->drawState(); | 1979 GrDrawState* drawState = this->drawState(); |
1983 GrDrawState::AutoViewMatrixRestore avmr; | 1980 GrDrawState::AutoViewMatrixRestore avmr; |
1984 SkRect bounds = SkRect::MakeLTRB(0, 0, | 1981 SkRect bounds = SkRect::MakeLTRB(0, 0, |
1985 SkIntToScalar(drawState->getRenderTarge
t()->width()), | 1982 SkIntToScalar(drawState->getRenderTarge
t()->width()), |
1986 SkIntToScalar(drawState->getRenderTarge
t()->height())); | 1983 SkIntToScalar(drawState->getRenderTarge
t()->height())); |
1987 SkMatrix vmi; | 1984 SkMatrix vmi; |
1988 // mapRect through persp matrix may not be correct | 1985 // mapRect through persp matrix may not be correct |
1989 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewIn
verse(&vmi)) { | 1986 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewIn
verse(&vmi)) { |
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3036 this->setVertexArrayID(gpu, 0); | 3033 this->setVertexArrayID(gpu, 0); |
3037 } | 3034 } |
3038 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3035 int attrCount = gpu->glCaps().maxVertexAttributes(); |
3039 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3036 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
3040 fDefaultVertexArrayAttribState.resize(attrCount); | 3037 fDefaultVertexArrayAttribState.resize(attrCount); |
3041 } | 3038 } |
3042 attribState = &fDefaultVertexArrayAttribState; | 3039 attribState = &fDefaultVertexArrayAttribState; |
3043 } | 3040 } |
3044 return attribState; | 3041 return attribState; |
3045 } | 3042 } |
OLD | NEW |