| 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 gXformFormat2GLType[] = { |
| 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 == kNone_GrTransformFormat); |
| 47 GR_STATIC_ASSERT(1 == kTranslateX_GrTransformFormat); |
| 48 GR_STATIC_ASSERT(2 == kTranslateY_GrTransformFormat); |
| 49 GR_STATIC_ASSERT(3 == kTranslate_GrTransformFormat); |
| 50 GR_STATIC_ASSERT(4 == kAffine_GrTransformFormat); |
| 51 GR_STATIC_ASSERT(kAffine_GrTransformFormat == kLast_GrTransformFormat); |
| 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 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 } | 1371 } |
| 1356 return NULL; | 1372 return NULL; |
| 1357 } | 1373 } |
| 1358 } | 1374 } |
| 1359 | 1375 |
| 1360 GrPath* GrGpuGL::onCreatePath(const SkPath& inPath, const SkStrokeRec& stroke) { | 1376 GrPath* GrGpuGL::onCreatePath(const SkPath& inPath, const SkStrokeRec& stroke) { |
| 1361 SkASSERT(this->caps()->pathRenderingSupport()); | 1377 SkASSERT(this->caps()->pathRenderingSupport()); |
| 1362 return SkNEW_ARGS(GrGLPath, (this, inPath, stroke)); | 1378 return SkNEW_ARGS(GrGLPath, (this, inPath, stroke)); |
| 1363 } | 1379 } |
| 1364 | 1380 |
| 1381 GrPathRange* GrGpuGL::onCreatePathRange(size_t size, const SkStrokeRec& stroke)
{ |
| 1382 SkASSERT(this->caps()->pathRenderingSupport()); |
| 1383 return SkNEW_ARGS(GrGLPathRange, (this, size, stroke)); |
| 1384 } |
| 1385 |
| 1365 void GrGpuGL::flushScissor() { | 1386 void GrGpuGL::flushScissor() { |
| 1366 if (fScissorState.fEnabled) { | 1387 if (fScissorState.fEnabled) { |
| 1367 // Only access the RT if scissoring is being enabled. We can call this b
efore performing | 1388 // Only access the RT if scissoring is being enabled. We can call this b
efore performing |
| 1368 // a glBitframebuffer for a surface->surface copy, which requires no RT
to be bound to the | 1389 // a glBitframebuffer for a surface->surface copy, which requires no RT
to be bound to the |
| 1369 // GrDrawState. | 1390 // GrDrawState. |
| 1370 const GrDrawState& drawState = this->getDrawState(); | 1391 const GrDrawState& drawState = this->getDrawState(); |
| 1371 const GrGLRenderTarget* rt = | 1392 const GrGLRenderTarget* rt = |
| 1372 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); | 1393 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); |
| 1373 | 1394 |
| 1374 SkASSERT(NULL != rt); | 1395 SkASSERT(NULL != rt); |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1893 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_Scala
rHalf; | 1914 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_Scala
rHalf; |
| 1894 bounds.outset(bloat, bloat); | 1915 bounds.outset(bloat, bloat); |
| 1895 } else { | 1916 } else { |
| 1896 avmr.setIdentity(drawState); | 1917 avmr.setIdentity(drawState); |
| 1897 } | 1918 } |
| 1898 | 1919 |
| 1899 this->drawSimpleRect(bounds, NULL); | 1920 this->drawSimpleRect(bounds, NULL); |
| 1900 } | 1921 } |
| 1901 } | 1922 } |
| 1902 | 1923 |
| 1903 void GrGpuGL::onGpuDrawPaths(int pathCount, const GrPath** paths, | 1924 void GrGpuGL::onGpuDrawPaths(const GrPathRange* pathRange, |
| 1904 const SkMatrix* transforms, | 1925 const uint32_t indices[], int count, |
| 1905 SkPath::FillType fill, | 1926 const float transforms[], GrTransformFormat transfo
rmsFormat, |
| 1906 SkStrokeRec::Style stroke) { | 1927 SkPath::FillType fill) { |
| 1907 SkASSERT(this->caps()->pathRenderingSupport()); | 1928 SkASSERT(this->caps()->pathRenderingSupport()); |
| 1908 SkASSERT(NULL != this->drawState()->getRenderTarget()); | 1929 SkASSERT(NULL != this->drawState()->getRenderTarget()); |
| 1909 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer()); | 1930 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer()); |
| 1910 SkASSERT(!fCurrentProgram->hasVertexShader()); | 1931 SkASSERT(!fCurrentProgram->hasVertexShader()); |
| 1911 SkASSERT(stroke != SkStrokeRec::kHairline_Style); | |
| 1912 | 1932 |
| 1913 SkAutoMalloc pathData(pathCount * sizeof(GrGLuint)); | 1933 GrGLuint baseID = static_cast<const GrGLPathRange*>(pathRange)->basePathID()
; |
| 1914 SkAutoMalloc transformData(pathCount * sizeof(GrGLfloat) * 6); | |
| 1915 GrGLfloat* transformValues = | |
| 1916 reinterpret_cast<GrGLfloat*>(transformData.get()); | |
| 1917 GrGLuint* pathIDs = reinterpret_cast<GrGLuint*>(pathData.get()); | |
| 1918 | |
| 1919 for (int i = 0; i < pathCount; ++i) { | |
| 1920 SkASSERT(transforms[i].asAffine(NULL)); | |
| 1921 const SkMatrix& m = transforms[i]; | |
| 1922 transformValues[i * 6] = m.getScaleX(); | |
| 1923 transformValues[i * 6 + 1] = m.getSkewY(); | |
| 1924 transformValues[i * 6 + 2] = m.getSkewX(); | |
| 1925 transformValues[i * 6 + 3] = m.getScaleY(); | |
| 1926 transformValues[i * 6 + 4] = m.getTranslateX(); | |
| 1927 transformValues[i * 6 + 5] = m.getTranslateY(); | |
| 1928 pathIDs[i] = static_cast<const GrGLPath*>(paths[i])->pathID(); | |
| 1929 } | |
| 1930 | 1934 |
| 1931 flushPathStencilSettings(fill); | 1935 flushPathStencilSettings(fill); |
| 1936 const SkStrokeRec& stroke = pathRange->getStroke(); |
| 1937 SkASSERT(!stroke.isHairlineStyle()); |
| 1932 | 1938 |
| 1933 SkPath::FillType nonInvertedFill = | 1939 SkPath::FillType nonInvertedFill = |
| 1934 SkPath::ConvertToNonInverseFillType(fill); | 1940 SkPath::ConvertToNonInverseFillType(fill); |
| 1935 | 1941 |
| 1936 SkASSERT(!fHWPathStencilSettings.isTwoSided()); | 1942 SkASSERT(!fHWPathStencilSettings.isTwoSided()); |
| 1937 GrGLenum fillMode = | 1943 GrGLenum fillMode = |
| 1938 gr_stencil_op_to_gl_path_rendering_fill_mode( | 1944 gr_stencil_op_to_gl_path_rendering_fill_mode( |
| 1939 fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); | 1945 fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
| 1940 GrGLint writeMask = | 1946 GrGLint writeMask = |
| 1941 fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face); | 1947 fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face); |
| 1942 | 1948 |
| 1943 bool doFill = stroke == SkStrokeRec::kFill_Style | 1949 if (stroke.isFillStyle() || SkStrokeRec::kStrokeAndFill_Style == stroke.getS
tyle()) { |
| 1944 || stroke == SkStrokeRec::kStrokeAndFill_Style; | 1950 GL_CALL(StencilFillPathInstanced(count, GR_GL_UNSIGNED_INT, indices, bas
eID, fillMode, |
| 1945 bool doStroke = stroke == SkStrokeRec::kStroke_Style | 1951 writeMask, gXformFormat2GLType[transfor
msFormat], |
| 1946 || stroke == SkStrokeRec::kStrokeAndFill_Style; | 1952 transforms)); |
| 1947 | |
| 1948 if (doFill) { | |
| 1949 GL_CALL(StencilFillPathInstanced(pathCount, GR_GL_UNSIGNED_INT, | |
| 1950 pathIDs, 0, | |
| 1951 fillMode, writeMask, | |
| 1952 GR_GL_AFFINE_2D, transformValues)); | |
| 1953 } | 1953 } |
| 1954 if (doStroke) { | 1954 if (stroke.needToApply()) { |
| 1955 GL_CALL(StencilStrokePathInstanced(pathCount, GR_GL_UNSIGNED_INT, | 1955 GL_CALL(StencilStrokePathInstanced(count, GR_GL_UNSIGNED_INT, indices, b
aseID, 0xffff, |
| 1956 pathIDs, 0, | 1956 writeMask, gXformFormat2GLType[transf
ormsFormat], |
| 1957 0xffff, writeMask, | 1957 transforms)); |
| 1958 GR_GL_AFFINE_2D, transformValues)); | |
| 1959 } | 1958 } |
| 1960 | 1959 |
| 1961 if (nonInvertedFill == fill) { | 1960 if (nonInvertedFill == fill) { |
| 1962 if (doStroke) { | 1961 if (stroke.needToApply()) { |
| 1963 GL_CALL(CoverStrokePathInstanced( | 1962 GL_CALL(CoverStrokePathInstanced( |
| 1964 pathCount, GR_GL_UNSIGNED_INT, pathIDs, 0, | 1963 count, GR_GL_UNSIGNED_INT, indices, baseID, |
| 1965 GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES, | 1964 GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES, |
| 1966 GR_GL_AFFINE_2D, transformValues)); | 1965 gXformFormat2GLType[transformsFormat], transforms)); |
| 1967 } else { | 1966 } else { |
| 1968 GL_CALL(CoverFillPathInstanced( | 1967 GL_CALL(CoverFillPathInstanced( |
| 1969 pathCount, GR_GL_UNSIGNED_INT, pathIDs, 0, | 1968 count, GR_GL_UNSIGNED_INT, indices, baseID, |
| 1970 GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES, | 1969 GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES, |
| 1971 GR_GL_AFFINE_2D, transformValues)); | 1970 gXformFormat2GLType[transformsFormat], transforms)); |
| 1972 | |
| 1973 } | 1971 } |
| 1974 } else { | 1972 } else { |
| 1975 GrDrawState* drawState = this->drawState(); | 1973 GrDrawState* drawState = this->drawState(); |
| 1976 GrDrawState::AutoViewMatrixRestore avmr; | 1974 GrDrawState::AutoViewMatrixRestore avmr; |
| 1977 SkRect bounds = SkRect::MakeLTRB(0, 0, | 1975 SkRect bounds = SkRect::MakeLTRB(0, 0, |
| 1978 SkIntToScalar(drawState->getRenderTarge
t()->width()), | 1976 SkIntToScalar(drawState->getRenderTarge
t()->width()), |
| 1979 SkIntToScalar(drawState->getRenderTarge
t()->height())); | 1977 SkIntToScalar(drawState->getRenderTarge
t()->height())); |
| 1980 SkMatrix vmi; | 1978 SkMatrix vmi; |
| 1981 // mapRect through persp matrix may not be correct | 1979 // mapRect through persp matrix may not be correct |
| 1982 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewIn
verse(&vmi)) { | 1980 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewIn
verse(&vmi)) { |
| (...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3018 this->setVertexArrayID(gpu, 0); | 3016 this->setVertexArrayID(gpu, 0); |
| 3019 } | 3017 } |
| 3020 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3018 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 3021 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3019 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 3022 fDefaultVertexArrayAttribState.resize(attrCount); | 3020 fDefaultVertexArrayAttribState.resize(attrCount); |
| 3023 } | 3021 } |
| 3024 attribState = &fDefaultVertexArrayAttribState; | 3022 attribState = &fDefaultVertexArrayAttribState; |
| 3025 } | 3023 } |
| 3026 return attribState; | 3024 return attribState; |
| 3027 } | 3025 } |
| OLD | NEW |