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/GrGLUtil.h" |
jvanverth | 39edf76 | 2014-12-22 11:44:19 -0800 | [diff] [blame] | 10 | #include "gl/GrGLGpu.h" |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 11 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 12 | #include "GrGLPath.h" |
| 13 | #include "GrGLPathRange.h" |
| 14 | #include "GrGLPathRendering.h" |
| 15 | |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 16 | #include "SkStream.h" |
| 17 | #include "SkTypeface.h" |
| 18 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 19 | #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) |
| 20 | #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] | 21 | |
kkinnunen | 702501d | 2016-01-13 23:36:45 -0800 | [diff] [blame] | 22 | // Number of paths to allocate per glGenPaths call. The call can be overly slow on command buffer GL |
| 23 | // implementation. The call has a result value, and thus waiting for the call completion is needed. |
| 24 | static const GrGLsizei kPathIDPreallocationAmount = 65536; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 25 | |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 26 | static const GrGLenum gIndexType2GLType[] = { |
| 27 | GR_GL_UNSIGNED_BYTE, |
| 28 | GR_GL_UNSIGNED_SHORT, |
| 29 | GR_GL_UNSIGNED_INT |
| 30 | }; |
| 31 | |
| 32 | GR_STATIC_ASSERT(0 == GrPathRange::kU8_PathIndexType); |
| 33 | GR_STATIC_ASSERT(1 == GrPathRange::kU16_PathIndexType); |
| 34 | GR_STATIC_ASSERT(2 == GrPathRange::kU32_PathIndexType); |
| 35 | GR_STATIC_ASSERT(GrPathRange::kU32_PathIndexType == GrPathRange::kLast_PathIndexType); |
| 36 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 37 | static const GrGLenum gXformType2GLType[] = { |
| 38 | GR_GL_NONE, |
| 39 | GR_GL_TRANSLATE_X, |
| 40 | GR_GL_TRANSLATE_Y, |
| 41 | GR_GL_TRANSLATE_2D, |
| 42 | GR_GL_TRANSPOSE_AFFINE_2D |
| 43 | }; |
| 44 | |
| 45 | GR_STATIC_ASSERT(0 == GrPathRendering::kNone_PathTransformType); |
| 46 | GR_STATIC_ASSERT(1 == GrPathRendering::kTranslateX_PathTransformType); |
| 47 | GR_STATIC_ASSERT(2 == GrPathRendering::kTranslateY_PathTransformType); |
| 48 | GR_STATIC_ASSERT(3 == GrPathRendering::kTranslate_PathTransformType); |
| 49 | GR_STATIC_ASSERT(4 == GrPathRendering::kAffine_PathTransformType); |
| 50 | GR_STATIC_ASSERT(GrPathRendering::kAffine_PathTransformType == GrPathRendering::kLast_PathTransformType); |
| 51 | |
| 52 | static GrGLenum gr_stencil_op_to_gl_path_rendering_fill_mode(GrStencilOp op) { |
| 53 | switch (op) { |
| 54 | default: |
| 55 | SkFAIL("Unexpected path fill."); |
| 56 | /* fallthrough */; |
| 57 | case kIncClamp_StencilOp: |
| 58 | return GR_GL_COUNT_UP; |
| 59 | case kInvert_StencilOp: |
| 60 | return GR_GL_INVERT; |
| 61 | } |
| 62 | } |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 63 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 64 | GrGLPathRendering::GrGLPathRendering(GrGLGpu* gpu) |
kkinnunen | 702501d | 2016-01-13 23:36:45 -0800 | [diff] [blame] | 65 | : GrPathRendering(gpu) |
| 66 | , fPreallocatedPathCount(0) { |
kkinnunen | 6bb6d40 | 2015-07-14 10:59:23 -0700 | [diff] [blame] | 67 | const GrGLInterface* glInterface = gpu->glInterface(); |
| 68 | fCaps.bindFragmentInputSupport = |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 69 | nullptr != glInterface->fFunctions.fBindFragmentInputLocation; |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | GrGLPathRendering::~GrGLPathRendering() { |
kkinnunen | 702501d | 2016-01-13 23:36:45 -0800 | [diff] [blame] | 73 | if (fPreallocatedPathCount > 0) { |
| 74 | this->deletePaths(fFirstPreallocatedPathID, fPreallocatedPathCount); |
| 75 | } |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void GrGLPathRendering::abandonGpuResources() { |
kkinnunen | 702501d | 2016-01-13 23:36:45 -0800 | [diff] [blame] | 79 | fPreallocatedPathCount = 0; |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 80 | } |
| 81 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 82 | void GrGLPathRendering::resetContext() { |
| 83 | fHWProjectionMatrixState.invalidate(); |
| 84 | // we don't use the model view matrix. |
jvanverth | 5053063 | 2015-04-27 10:36:27 -0700 | [diff] [blame] | 85 | GL_CALL(MatrixLoadIdentity(GR_GL_PATH_MODELVIEW)); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 86 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 87 | fHWPathStencilSettings.invalidate(); |
| 88 | } |
| 89 | |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 90 | GrPath* GrGLPathRendering::createPath(const SkPath& inPath, const GrStrokeInfo& stroke) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 91 | return new GrGLPath(this->gpu(), inPath, stroke); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 92 | } |
| 93 | |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 94 | GrPathRange* GrGLPathRendering::createPathRange(GrPathRange::PathGenerator* pathGenerator, |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 95 | const GrStrokeInfo& stroke) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 96 | return new GrGLPathRange(this->gpu(), pathGenerator, stroke); |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 97 | } |
| 98 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 99 | void GrGLPathRendering::onStencilPath(const StencilPathArgs& args, const GrPath* path) { |
| 100 | GrGLGpu* gpu = this->gpu(); |
| 101 | SkASSERT(gpu->caps()->shaderCaps()->pathRenderingSupport()); |
| 102 | gpu->flushColorWrite(false); |
| 103 | gpu->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); |
| 104 | |
| 105 | GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(args.fRenderTarget); |
| 106 | SkISize size = SkISize::Make(rt->width(), rt->height()); |
| 107 | this->setProjectionMatrix(*args.fViewMatrix, size, rt->origin()); |
| 108 | gpu->flushScissor(*args.fScissor, rt->getViewport(), rt->origin()); |
cdalton | 7e806f3 | 2015-11-11 15:16:07 -0800 | [diff] [blame] | 109 | gpu->flushHWAAState(rt, args.fUseHWAA); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 110 | gpu->flushRenderTarget(rt, nullptr); |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 111 | |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 112 | const GrGLPath* glPath = static_cast<const GrGLPath*>(path); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 113 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 114 | this->flushPathStencilSettings(*args.fStencil); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 115 | SkASSERT(!fHWPathStencilSettings.isTwoSided()); |
| 116 | |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 117 | GrGLenum fillMode = gr_stencil_op_to_gl_path_rendering_fill_mode( |
| 118 | fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 119 | GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face); |
| 120 | |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 121 | if (glPath->shouldFill()) { |
| 122 | GL_CALL(StencilFillPath(glPath->pathID(), fillMode, writeMask)); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 123 | } |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 124 | if (glPath->shouldStroke()) { |
| 125 | GL_CALL(StencilStrokePath(glPath->pathID(), 0xffff, writeMask)); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 129 | void GrGLPathRendering::onDrawPath(const DrawPathArgs& args, const GrPath* path) { |
| 130 | if (!this->gpu()->flushGLState(args)) { |
| 131 | return; |
| 132 | } |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 133 | const GrGLPath* glPath = static_cast<const GrGLPath*>(path); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 134 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 135 | this->flushPathStencilSettings(*args.fStencil); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 136 | SkASSERT(!fHWPathStencilSettings.isTwoSided()); |
| 137 | |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 138 | GrGLenum fillMode = gr_stencil_op_to_gl_path_rendering_fill_mode( |
| 139 | fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 140 | GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face); |
| 141 | |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 142 | if (glPath->shouldStroke()) { |
| 143 | if (glPath->shouldFill()) { |
| 144 | GL_CALL(StencilFillPath(glPath->pathID(), fillMode, writeMask)); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 145 | } |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 146 | GL_CALL(StencilThenCoverStrokePath(glPath->pathID(), 0xffff, writeMask, |
| 147 | GR_GL_BOUNDING_BOX)); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 148 | } else { |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 149 | GL_CALL(StencilThenCoverFillPath(glPath->pathID(), fillMode, writeMask, |
| 150 | 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 | } |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 180 | GL_CALL(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, |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 183 | gXformType2GLType[transformType], transformValues)); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 184 | } else { |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 185 | GL_CALL(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, |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -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) { |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 195 | float coefficients[3 * 3]; |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 196 | SkASSERT(components >= 1 && components <= 3); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 197 | |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 198 | coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]); |
| 199 | coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]); |
| 200 | coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 201 | |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 202 | if (components >= 2) { |
| 203 | coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); |
| 204 | coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]); |
| 205 | coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 206 | } |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 207 | |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 208 | if (components >= 3) { |
| 209 | coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]); |
| 210 | coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]); |
| 211 | coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 212 | } |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 213 | |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 214 | GL_CALL(ProgramPathFragmentInputGen(program, location, genMode, components, coefficients)); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | void GrGLPathRendering::setProjectionMatrix(const SkMatrix& matrix, |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 218 | const SkISize& renderTargetSize, |
| 219 | GrSurfaceOrigin renderTargetOrigin) { |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 220 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 221 | SkASSERT(this->gpu()->glCaps().shaderCaps()->pathRenderingSupport()); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 222 | |
| 223 | if (renderTargetOrigin == fHWProjectionMatrixState.fRenderTargetOrigin && |
| 224 | renderTargetSize == fHWProjectionMatrixState.fRenderTargetSize && |
| 225 | matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | fHWProjectionMatrixState.fViewMatrix = matrix; |
| 230 | fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; |
| 231 | fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; |
| 232 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 233 | float glMatrix[4 * 4]; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 234 | fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix); |
jvanverth | 5053063 | 2015-04-27 10:36:27 -0700 | [diff] [blame] | 235 | GL_CALL(MatrixLoadf(GR_GL_PATH_PROJECTION, glMatrix)); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 236 | } |
| 237 | |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 238 | GrGLuint GrGLPathRendering::genPaths(GrGLsizei range) { |
kkinnunen | 702501d | 2016-01-13 23:36:45 -0800 | [diff] [blame] | 239 | SkASSERT(range > 0); |
| 240 | GrGLuint firstID; |
| 241 | if (fPreallocatedPathCount >= range) { |
| 242 | firstID = fFirstPreallocatedPathID; |
| 243 | fPreallocatedPathCount -= range; |
| 244 | fFirstPreallocatedPathID += range; |
| 245 | return firstID; |
| 246 | } |
| 247 | // Allocate range + the amount to fill up preallocation amount. If succeed, either join with |
| 248 | // the existing preallocation range or delete the existing and use the new (potentially partial) |
| 249 | // preallocation range. |
| 250 | GrGLsizei allocAmount = range + (kPathIDPreallocationAmount - fPreallocatedPathCount); |
| 251 | if (allocAmount >= range) { |
| 252 | GL_CALL_RET(firstID, GenPaths(allocAmount)); |
| 253 | |
| 254 | if (firstID != 0) { |
| 255 | if (fPreallocatedPathCount > 0 && |
| 256 | firstID == fFirstPreallocatedPathID + fPreallocatedPathCount) { |
| 257 | firstID = fFirstPreallocatedPathID; |
| 258 | fPreallocatedPathCount += allocAmount - range; |
| 259 | fFirstPreallocatedPathID += range; |
| 260 | return firstID; |
| 261 | } |
| 262 | |
| 263 | if (allocAmount > range) { |
| 264 | if (fPreallocatedPathCount > 0) { |
| 265 | this->deletePaths(fFirstPreallocatedPathID, fPreallocatedPathCount); |
| 266 | } |
| 267 | fFirstPreallocatedPathID = firstID + range; |
| 268 | fPreallocatedPathCount = allocAmount - range; |
| 269 | } |
| 270 | // Special case: if allocAmount == range, we have full preallocated range. |
| 271 | return firstID; |
| 272 | } |
| 273 | } |
| 274 | // Failed to allocate with preallocation. Remove existing preallocation and try to allocate just |
| 275 | // the range. |
| 276 | if (fPreallocatedPathCount > 0) { |
| 277 | this->deletePaths(fFirstPreallocatedPathID, fPreallocatedPathCount); |
| 278 | fPreallocatedPathCount = 0; |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 279 | } |
| 280 | |
kkinnunen | 702501d | 2016-01-13 23:36:45 -0800 | [diff] [blame] | 281 | GL_CALL_RET(firstID, GenPaths(range)); |
| 282 | if (firstID == 0) { |
| 283 | SkDebugf("Warning: Failed to allocate path\n"); |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 284 | } |
kkinnunen | 702501d | 2016-01-13 23:36:45 -0800 | [diff] [blame] | 285 | return firstID; |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 286 | } |
| 287 | |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 288 | void GrGLPathRendering::deletePaths(GrGLuint path, GrGLsizei range) { |
kkinnunen | 702501d | 2016-01-13 23:36:45 -0800 | [diff] [blame] | 289 | GL_CALL(DeletePaths(path, range)); |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 290 | } |
| 291 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 292 | void GrGLPathRendering::flushPathStencilSettings(const GrStencilSettings& stencilSettings) { |
| 293 | if (fHWPathStencilSettings != stencilSettings) { |
kkinnunen | 1517f93 | 2016-01-25 06:07:26 -0800 | [diff] [blame] | 294 | SkASSERT(stencilSettings.isValid()); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 295 | // Just the func, ref, and mask is set here. The op and write mask are params to the call |
| 296 | // that draws the path to the SB (glStencilFillPath) |
kkinnunen | 1517f93 | 2016-01-25 06:07:26 -0800 | [diff] [blame] | 297 | const GrStencilSettings::Face kFront_Face = GrStencilSettings::kFront_Face; |
| 298 | GrStencilFunc func = stencilSettings.func(kFront_Face); |
| 299 | uint16_t funcRef = stencilSettings.funcRef(kFront_Face); |
| 300 | uint16_t funcMask = stencilSettings.funcMask(kFront_Face); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 301 | |
kkinnunen | 1517f93 | 2016-01-25 06:07:26 -0800 | [diff] [blame] | 302 | if (!fHWPathStencilSettings.isValid() || |
| 303 | func != fHWPathStencilSettings.func(kFront_Face) || |
| 304 | funcRef != fHWPathStencilSettings.funcRef(kFront_Face) || |
| 305 | funcMask != fHWPathStencilSettings.funcMask(kFront_Face)) { |
| 306 | GL_CALL(PathStencilFunc(GrToGLStencilFunc(func), funcRef, funcMask)); |
| 307 | } |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 308 | fHWPathStencilSettings = stencilSettings; |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 309 | } |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 310 | } |
| 311 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 312 | inline GrGLGpu* GrGLPathRendering::gpu() { |
| 313 | return static_cast<GrGLGpu*>(fGpu); |
| 314 | } |