cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "gl/GrGLPathRendering.h" |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 9 | #include "gl/GrGLNameAllocator.h" |
| 10 | #include "gl/GrGLUtil.h" |
jvanverth | 39edf76 | 2014-12-22 11:44:19 -0800 | [diff] [blame] | 11 | #include "gl/GrGLGpu.h" |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 12 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 13 | #include "GrGLPath.h" |
| 14 | #include "GrGLPathRange.h" |
| 15 | #include "GrGLPathRendering.h" |
| 16 | |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 17 | #include "SkStream.h" |
| 18 | #include "SkTypeface.h" |
| 19 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 20 | #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) |
| 21 | #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->gpu()->glInterface(), RET, X) |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 22 | |
| 23 | |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 24 | static const GrGLenum gIndexType2GLType[] = { |
| 25 | GR_GL_UNSIGNED_BYTE, |
| 26 | GR_GL_UNSIGNED_SHORT, |
| 27 | GR_GL_UNSIGNED_INT |
| 28 | }; |
| 29 | |
| 30 | GR_STATIC_ASSERT(0 == GrPathRange::kU8_PathIndexType); |
| 31 | GR_STATIC_ASSERT(1 == GrPathRange::kU16_PathIndexType); |
| 32 | GR_STATIC_ASSERT(2 == GrPathRange::kU32_PathIndexType); |
| 33 | GR_STATIC_ASSERT(GrPathRange::kU32_PathIndexType == GrPathRange::kLast_PathIndexType); |
| 34 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 35 | static const GrGLenum gXformType2GLType[] = { |
| 36 | GR_GL_NONE, |
| 37 | GR_GL_TRANSLATE_X, |
| 38 | GR_GL_TRANSLATE_Y, |
| 39 | GR_GL_TRANSLATE_2D, |
| 40 | GR_GL_TRANSPOSE_AFFINE_2D |
| 41 | }; |
| 42 | |
| 43 | GR_STATIC_ASSERT(0 == GrPathRendering::kNone_PathTransformType); |
| 44 | GR_STATIC_ASSERT(1 == GrPathRendering::kTranslateX_PathTransformType); |
| 45 | GR_STATIC_ASSERT(2 == GrPathRendering::kTranslateY_PathTransformType); |
| 46 | GR_STATIC_ASSERT(3 == GrPathRendering::kTranslate_PathTransformType); |
| 47 | GR_STATIC_ASSERT(4 == GrPathRendering::kAffine_PathTransformType); |
| 48 | GR_STATIC_ASSERT(GrPathRendering::kAffine_PathTransformType == GrPathRendering::kLast_PathTransformType); |
| 49 | |
| 50 | static GrGLenum gr_stencil_op_to_gl_path_rendering_fill_mode(GrStencilOp op) { |
| 51 | switch (op) { |
| 52 | default: |
| 53 | SkFAIL("Unexpected path fill."); |
| 54 | /* fallthrough */; |
| 55 | case kIncClamp_StencilOp: |
| 56 | return GR_GL_COUNT_UP; |
| 57 | case kInvert_StencilOp: |
| 58 | return GR_GL_INVERT; |
| 59 | } |
| 60 | } |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 61 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 62 | GrGLPathRendering::GrGLPathRendering(GrGLGpu* gpu) |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 63 | : GrPathRendering(gpu) { |
jvanverth | 439f23e | 2015-06-30 09:40:38 -0700 | [diff] [blame] | 64 | const GrGLInterface* glInterface = gpu->glInterface(); |
| 65 | fCaps.stencilThenCoverSupport = |
| 66 | NULL != glInterface->fFunctions.fStencilThenCoverFillPath && |
| 67 | NULL != glInterface->fFunctions.fStencilThenCoverStrokePath && |
| 68 | NULL != glInterface->fFunctions.fStencilThenCoverFillPathInstanced && |
| 69 | NULL != glInterface->fFunctions.fStencilThenCoverStrokePathInstanced; |
| 70 | fCaps.fragmentInputGenSupport = |
| 71 | NULL != glInterface->fFunctions.fProgramPathFragmentInputGen; |
| 72 | |
| 73 | SkASSERT(fCaps.fragmentInputGenSupport); |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | GrGLPathRendering::~GrGLPathRendering() { |
| 77 | } |
| 78 | |
| 79 | void GrGLPathRendering::abandonGpuResources() { |
| 80 | fPathNameAllocator.reset(NULL); |
| 81 | } |
| 82 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 83 | void GrGLPathRendering::resetContext() { |
| 84 | fHWProjectionMatrixState.invalidate(); |
| 85 | // we don't use the model view matrix. |
jvanverth | 5053063 | 2015-04-27 10:36:27 -0700 | [diff] [blame] | 86 | GL_CALL(MatrixLoadIdentity(GR_GL_PATH_MODELVIEW)); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 87 | |
jvanverth | 439f23e | 2015-06-30 09:40:38 -0700 | [diff] [blame] | 88 | SkASSERT(fCaps.fragmentInputGenSupport); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 89 | fHWPathStencilSettings.invalidate(); |
| 90 | } |
| 91 | |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 92 | GrPath* GrGLPathRendering::createPath(const SkPath& inPath, const GrStrokeInfo& stroke) { |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 93 | return SkNEW_ARGS(GrGLPath, (this->gpu(), inPath, stroke)); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 94 | } |
| 95 | |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 96 | GrPathRange* GrGLPathRendering::createPathRange(GrPathRange::PathGenerator* pathGenerator, |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 97 | const GrStrokeInfo& stroke) { |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 98 | return SkNEW_ARGS(GrGLPathRange, (this->gpu(), pathGenerator, stroke)); |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 99 | } |
| 100 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 101 | void GrGLPathRendering::onStencilPath(const StencilPathArgs& args, const GrPath* path) { |
| 102 | GrGLGpu* gpu = this->gpu(); |
| 103 | SkASSERT(gpu->caps()->shaderCaps()->pathRenderingSupport()); |
| 104 | gpu->flushColorWrite(false); |
| 105 | gpu->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); |
| 106 | |
| 107 | GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(args.fRenderTarget); |
| 108 | SkISize size = SkISize::Make(rt->width(), rt->height()); |
| 109 | this->setProjectionMatrix(*args.fViewMatrix, size, rt->origin()); |
| 110 | gpu->flushScissor(*args.fScissor, rt->getViewport(), rt->origin()); |
| 111 | gpu->flushHWAAState(rt, args.fUseHWAA); |
| 112 | gpu->flushRenderTarget(rt, NULL); |
| 113 | |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 114 | const GrGLPath* glPath = static_cast<const GrGLPath*>(path); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 115 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 116 | this->flushPathStencilSettings(*args.fStencil); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 117 | SkASSERT(!fHWPathStencilSettings.isTwoSided()); |
| 118 | |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 119 | GrGLenum fillMode = gr_stencil_op_to_gl_path_rendering_fill_mode( |
| 120 | fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 121 | GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face); |
| 122 | |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 123 | if (glPath->shouldFill()) { |
| 124 | GL_CALL(StencilFillPath(glPath->pathID(), fillMode, writeMask)); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 125 | } |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 126 | if (glPath->shouldStroke()) { |
| 127 | GL_CALL(StencilStrokePath(glPath->pathID(), 0xffff, writeMask)); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 131 | void GrGLPathRendering::onDrawPath(const DrawPathArgs& args, const GrPath* path) { |
| 132 | if (!this->gpu()->flushGLState(args)) { |
| 133 | return; |
| 134 | } |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 135 | const GrGLPath* glPath = static_cast<const GrGLPath*>(path); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 136 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 137 | this->flushPathStencilSettings(*args.fStencil); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 138 | SkASSERT(!fHWPathStencilSettings.isTwoSided()); |
| 139 | |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 140 | GrGLenum fillMode = gr_stencil_op_to_gl_path_rendering_fill_mode( |
| 141 | fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 142 | GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face); |
| 143 | |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 144 | if (glPath->shouldStroke()) { |
| 145 | if (glPath->shouldFill()) { |
| 146 | GL_CALL(StencilFillPath(glPath->pathID(), fillMode, writeMask)); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 147 | } |
jvanverth | 439f23e | 2015-06-30 09:40:38 -0700 | [diff] [blame] | 148 | this->stencilThenCoverStrokePath(glPath->pathID(), 0xffff, writeMask, GR_GL_BOUNDING_BOX); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 149 | } else { |
jvanverth | 439f23e | 2015-06-30 09:40:38 -0700 | [diff] [blame] | 150 | this->stencilThenCoverFillPath(glPath->pathID(), fillMode, writeMask, GR_GL_BOUNDING_BOX); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 154 | void GrGLPathRendering::onDrawPaths(const DrawPathArgs& args, const GrPathRange* pathRange, |
| 155 | const void* indices, PathIndexType indexType, |
| 156 | const float transformValues[], PathTransformType transformType, |
| 157 | int count) { |
| 158 | if (!this->gpu()->flushGLState(args)) { |
| 159 | return; |
| 160 | } |
| 161 | this->flushPathStencilSettings(*args.fStencil); |
| 162 | SkASSERT(!fHWPathStencilSettings.isTwoSided()); |
| 163 | |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 164 | |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 165 | const GrGLPathRange* glPathRange = static_cast<const GrGLPathRange*>(pathRange); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 166 | |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 167 | GrGLenum fillMode = |
| 168 | gr_stencil_op_to_gl_path_rendering_fill_mode( |
| 169 | fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
| 170 | GrGLint writeMask = |
| 171 | fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face); |
| 172 | |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 173 | if (glPathRange->shouldStroke()) { |
| 174 | if (glPathRange->shouldFill()) { |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 175 | GL_CALL(StencilFillPathInstanced( |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 176 | count, gIndexType2GLType[indexType], indices, glPathRange->basePathID(), |
| 177 | fillMode, writeMask, gXformType2GLType[transformType], |
| 178 | transformValues)); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 179 | } |
jvanverth | 439f23e | 2015-06-30 09:40:38 -0700 | [diff] [blame] | 180 | this->stencilThenCoverStrokePathInstanced( |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 181 | count, gIndexType2GLType[indexType], indices, glPathRange->basePathID(), |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 182 | 0xffff, writeMask, GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES, |
jvanverth | 439f23e | 2015-06-30 09:40:38 -0700 | [diff] [blame] | 183 | gXformType2GLType[transformType], transformValues); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 184 | } else { |
jvanverth | 439f23e | 2015-06-30 09:40:38 -0700 | [diff] [blame] | 185 | this->stencilThenCoverFillPathInstanced( |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 186 | count, gIndexType2GLType[indexType], indices, glPathRange->basePathID(), |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 187 | fillMode, writeMask, GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES, |
jvanverth | 439f23e | 2015-06-30 09:40:38 -0700 | [diff] [blame] | 188 | gXformType2GLType[transformType], transformValues); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 192 | void GrGLPathRendering::setProgramPathFragmentInputTransform(GrGLuint program, GrGLint location, |
| 193 | GrGLenum genMode, GrGLint components, |
| 194 | const SkMatrix& matrix) { |
jvanverth | 439f23e | 2015-06-30 09:40:38 -0700 | [diff] [blame] | 195 | SkASSERT(caps().fragmentInputGenSupport); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 196 | GrGLfloat coefficients[3 * 3]; |
| 197 | SkASSERT(components >= 1 && components <= 3); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 198 | |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 199 | coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]); |
| 200 | coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]); |
| 201 | coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 202 | |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 203 | if (components >= 2) { |
| 204 | coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); |
| 205 | coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]); |
| 206 | coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 207 | } |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 208 | |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 209 | if (components >= 3) { |
| 210 | coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]); |
| 211 | coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]); |
| 212 | coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 213 | } |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 214 | |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 215 | GL_CALL(ProgramPathFragmentInputGen(program, location, genMode, components, coefficients)); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | void GrGLPathRendering::setProjectionMatrix(const SkMatrix& matrix, |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 219 | const SkISize& renderTargetSize, |
| 220 | GrSurfaceOrigin renderTargetOrigin) { |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 221 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 222 | SkASSERT(this->gpu()->glCaps().shaderCaps()->pathRenderingSupport()); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 223 | |
| 224 | if (renderTargetOrigin == fHWProjectionMatrixState.fRenderTargetOrigin && |
| 225 | renderTargetSize == fHWProjectionMatrixState.fRenderTargetSize && |
| 226 | matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | fHWProjectionMatrixState.fViewMatrix = matrix; |
| 231 | fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; |
| 232 | fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; |
| 233 | |
| 234 | GrGLfloat glMatrix[4 * 4]; |
| 235 | fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix); |
jvanverth | 5053063 | 2015-04-27 10:36:27 -0700 | [diff] [blame] | 236 | GL_CALL(MatrixLoadf(GR_GL_PATH_PROJECTION, glMatrix)); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 237 | } |
| 238 | |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 239 | GrGLuint GrGLPathRendering::genPaths(GrGLsizei range) { |
| 240 | if (range > 1) { |
| 241 | GrGLuint name; |
| 242 | GL_CALL_RET(name, GenPaths(range)); |
| 243 | return name; |
| 244 | } |
| 245 | |
| 246 | if (NULL == fPathNameAllocator.get()) { |
| 247 | static const int range = 65536; |
| 248 | GrGLuint firstName; |
| 249 | GL_CALL_RET(firstName, GenPaths(range)); |
| 250 | fPathNameAllocator.reset(SkNEW_ARGS(GrGLNameAllocator, (firstName, firstName + range))); |
| 251 | } |
| 252 | |
| 253 | // When allocating names one at a time, pull from a client-side pool of |
| 254 | // available names in order to save a round trip to the GL server. |
| 255 | GrGLuint name = fPathNameAllocator->allocateName(); |
| 256 | |
| 257 | if (0 == name) { |
| 258 | // Our reserved path names are all in use. Fall back on GenPaths. |
| 259 | GL_CALL_RET(name, GenPaths(1)); |
| 260 | } |
| 261 | |
| 262 | return name; |
| 263 | } |
| 264 | |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 265 | void GrGLPathRendering::deletePaths(GrGLuint path, GrGLsizei range) { |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 266 | if (range > 1) { |
| 267 | // It is not supported to delete names in ranges that were allocated |
| 268 | // individually using GrGLPathNameAllocator. |
| 269 | SkASSERT(NULL == fPathNameAllocator.get() || |
| 270 | path + range <= fPathNameAllocator->firstName() || |
| 271 | path >= fPathNameAllocator->endName()); |
| 272 | GL_CALL(DeletePaths(path, range)); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | if (NULL == fPathNameAllocator.get() || |
| 277 | path < fPathNameAllocator->firstName() || |
| 278 | path >= fPathNameAllocator->endName()) { |
| 279 | // If we aren't inside fPathNameAllocator's range then this name was |
| 280 | // generated by the GenPaths fallback (or else was never allocated). |
| 281 | GL_CALL(DeletePaths(path, 1)); |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | // Make the path empty to save memory, but don't free the name in the driver. |
| 286 | GL_CALL(PathCommands(path, 0, NULL, 0, GR_GL_FLOAT, NULL)); |
| 287 | fPathNameAllocator->free(path); |
| 288 | } |
| 289 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 290 | void GrGLPathRendering::flushPathStencilSettings(const GrStencilSettings& stencilSettings) { |
| 291 | if (fHWPathStencilSettings != stencilSettings) { |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 292 | // Just the func, ref, and mask is set here. The op and write mask are params to the call |
| 293 | // that draws the path to the SB (glStencilFillPath) |
| 294 | GrGLenum func = |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 295 | GrToGLStencilFunc(stencilSettings.func(GrStencilSettings::kFront_Face)); |
| 296 | GL_CALL(PathStencilFunc(func, stencilSettings.funcRef(GrStencilSettings::kFront_Face), |
| 297 | stencilSettings.funcMask(GrStencilSettings::kFront_Face))); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 298 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 299 | fHWPathStencilSettings = stencilSettings; |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 300 | } |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 301 | } |
| 302 | |
jvanverth | 439f23e | 2015-06-30 09:40:38 -0700 | [diff] [blame] | 303 | inline void GrGLPathRendering::stencilThenCoverFillPath(GrGLuint path, GrGLenum fillMode, |
| 304 | GrGLuint mask, GrGLenum coverMode) { |
| 305 | if (caps().stencilThenCoverSupport) { |
| 306 | GL_CALL(StencilThenCoverFillPath(path, fillMode, mask, coverMode)); |
| 307 | return; |
| 308 | } |
| 309 | GL_CALL(StencilFillPath(path, fillMode, mask)); |
| 310 | GL_CALL(CoverFillPath(path, coverMode)); |
| 311 | } |
| 312 | |
| 313 | inline void GrGLPathRendering::stencilThenCoverStrokePath(GrGLuint path, GrGLint reference, |
| 314 | GrGLuint mask, GrGLenum coverMode) { |
| 315 | if (caps().stencilThenCoverSupport) { |
| 316 | GL_CALL(StencilThenCoverStrokePath(path, reference, mask, coverMode)); |
| 317 | return; |
| 318 | } |
| 319 | GL_CALL(StencilStrokePath(path, reference, mask)); |
| 320 | GL_CALL(CoverStrokePath(path, coverMode)); |
| 321 | } |
| 322 | |
| 323 | inline void GrGLPathRendering::stencilThenCoverFillPathInstanced( |
| 324 | GrGLsizei numPaths, GrGLenum pathNameType, const GrGLvoid *paths, |
| 325 | GrGLuint pathBase, GrGLenum fillMode, GrGLuint mask, GrGLenum coverMode, |
| 326 | GrGLenum transformType, const GrGLfloat *transformValues) { |
| 327 | if (caps().stencilThenCoverSupport) { |
| 328 | GL_CALL(StencilThenCoverFillPathInstanced(numPaths, pathNameType, paths, pathBase, fillMode, |
| 329 | mask, coverMode, transformType, transformValues)); |
| 330 | return; |
| 331 | } |
| 332 | GL_CALL(StencilFillPathInstanced(numPaths, pathNameType, paths, pathBase, |
| 333 | fillMode, mask, transformType, transformValues)); |
| 334 | GL_CALL(CoverFillPathInstanced(numPaths, pathNameType, paths, pathBase, |
| 335 | coverMode, transformType, transformValues)); |
| 336 | } |
| 337 | |
| 338 | inline void GrGLPathRendering::stencilThenCoverStrokePathInstanced( |
| 339 | GrGLsizei numPaths, GrGLenum pathNameType, const GrGLvoid *paths, |
| 340 | GrGLuint pathBase, GrGLint reference, GrGLuint mask, GrGLenum coverMode, |
| 341 | GrGLenum transformType, const GrGLfloat *transformValues) { |
| 342 | if (caps().stencilThenCoverSupport) { |
| 343 | GL_CALL(StencilThenCoverStrokePathInstanced(numPaths, pathNameType, paths, pathBase, |
| 344 | reference, mask, coverMode, transformType, |
| 345 | transformValues)); |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | GL_CALL(StencilStrokePathInstanced(numPaths, pathNameType, paths, pathBase, |
| 350 | reference, mask, transformType, transformValues)); |
| 351 | GL_CALL(CoverStrokePathInstanced(numPaths, pathNameType, paths, pathBase, |
| 352 | coverMode, transformType, transformValues)); |
| 353 | } |
| 354 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 355 | inline GrGLGpu* GrGLPathRendering::gpu() { |
| 356 | return static_cast<GrGLGpu*>(fGpu); |
| 357 | } |