Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 Google LLC. |
| 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 "src/gpu/tessellate/GrPathInnerTriangulateOp.h" |
| 9 | |
| 10 | #include "src/gpu/GrEagerVertexAllocator.h" |
Chris Dalton | d9bdc32 | 2021-06-01 19:22:05 -0600 | [diff] [blame] | 11 | #include "src/gpu/GrGpu.h" |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 12 | #include "src/gpu/GrInnerFanTriangulator.h" |
| 13 | #include "src/gpu/GrOpFlushState.h" |
| 14 | #include "src/gpu/GrRecordingContextPriv.h" |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 15 | #include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h" |
Chris Dalton | d9bdc32 | 2021-06-01 19:22:05 -0600 | [diff] [blame] | 16 | #include "src/gpu/tessellate/GrPathCurveTessellator.h" |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 17 | #include "src/gpu/tessellate/GrTessellationPathRenderer.h" |
Chris Dalton | 3b41278 | 2021-06-01 13:40:03 -0600 | [diff] [blame] | 18 | #include "src/gpu/tessellate/shaders/GrPathTessellationShader.h" |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 19 | |
Chris Dalton | 917f919 | 2021-06-08 14:32:37 -0600 | [diff] [blame] | 20 | using PathFlags = GrTessellationPathRenderer::PathFlags; |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 21 | |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 22 | namespace { |
| 23 | |
| 24 | // Fills an array of convex hulls surrounding 4-point cubic or conic instances. This shader is used |
Chris Dalton | 031d76b | 2021-06-08 16:32:00 -0600 | [diff] [blame] | 25 | // for the "cover" pass after the curves have been fully stencilled. |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 26 | class HullShader : public GrPathTessellationShader { |
| 27 | public: |
| 28 | HullShader(const SkMatrix& viewMatrix, SkPMColor4f color) |
| 29 | : GrPathTessellationShader(kTessellate_HullShader_ClassID, |
| 30 | GrPrimitiveType::kTriangleStrip, 0, viewMatrix, color) { |
| 31 | constexpr static Attribute kPtsAttribs[] = { |
| 32 | {"input_points_0_1", kFloat4_GrVertexAttribType, kFloat4_GrSLType}, |
| 33 | {"input_points_2_3", kFloat4_GrVertexAttribType, kFloat4_GrSLType}}; |
| 34 | this->setInstanceAttributes(kPtsAttribs, SK_ARRAY_COUNT(kPtsAttribs)); |
| 35 | } |
| 36 | |
| 37 | private: |
Chris Dalton | b63711a | 2021-06-01 14:52:02 -0600 | [diff] [blame] | 38 | const char* name() const final { return "tessellate_HullShader"; } |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 39 | void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const final {} |
| 40 | GrGLSLGeometryProcessor* createGLSLInstance(const GrShaderCaps&) const final; |
| 41 | }; |
| 42 | |
| 43 | GrGLSLGeometryProcessor* HullShader::createGLSLInstance(const GrShaderCaps&) const { |
| 44 | class Impl : public GrPathTessellationShader::Impl { |
Chris Dalton | d2b8ba3 | 2021-06-09 00:12:59 -0600 | [diff] [blame] | 45 | void emitVertexCode(const GrPathTessellationShader&, GrGLSLVertexBuilder* v, |
| 46 | GrGPArgs* gpArgs) override { |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 47 | v->codeAppend(R"( |
| 48 | float4x2 P = float4x2(input_points_0_1, input_points_2_3); |
| 49 | if (isinf(P[3].y)) { // Is the curve a conic? |
| 50 | float w = P[3].x; |
| 51 | if (isinf(w)) { |
| 52 | // A conic with w=Inf is an exact triangle. |
| 53 | P = float4x2(P[0], P[1], P[2], P[2]); |
| 54 | } else { |
| 55 | // Convert the points to a trapeziodal hull that circumcscribes the conic. |
| 56 | float2 p1w = P[1] * w; |
| 57 | float T = .51; // Bias outward a bit to ensure we cover the outermost samples. |
| 58 | float2 c1 = mix(P[0], p1w, T); |
| 59 | float2 c2 = mix(P[2], p1w, T); |
| 60 | float iw = 1 / mix(1, w, T); |
| 61 | P = float4x2(P[0], c1 * iw, c2 * iw, P[2]); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | // Translate the points to v0..3 where v0=0. |
| 66 | float2 v1 = P[1] - P[0], v2 = P[2] - P[0], v3 = P[3] - P[0]; |
| 67 | |
| 68 | // Reorder the points so v2 bisects v1 and v3. |
| 69 | if (sign(determinant(float2x2(v2,v1))) == sign(determinant(float2x2(v2,v3)))) { |
| 70 | float2 tmp = P[2]; |
| 71 | if (sign(determinant(float2x2(v1,v2))) != sign(determinant(float2x2(v1,v3)))) { |
| 72 | P[2] = P[1]; // swap(P2, P1) |
| 73 | P[1] = tmp; |
| 74 | } else { |
| 75 | P[2] = P[3]; // swap(P2, P3) |
| 76 | P[3] = tmp; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // sk_VertexID comes in fan order. Convert to strip order. |
| 81 | int vertexidx = sk_VertexID; |
| 82 | vertexidx ^= vertexidx >> 1; |
| 83 | |
| 84 | // Find the "turn direction" of each corner and net turn direction. |
| 85 | float vertexdir = 0; |
| 86 | float netdir = 0; |
| 87 | for (int i = 0; i < 4; ++i) { |
| 88 | float2 prev = P[i] - P[(i + 3) & 3], next = P[(i + 1) & 3] - P[i]; |
| 89 | float dir = sign(determinant(float2x2(prev, next))); |
| 90 | if (i == vertexidx) { |
| 91 | vertexdir = dir; |
| 92 | } |
| 93 | netdir += dir; |
| 94 | } |
| 95 | |
| 96 | // Remove the non-convex vertex, if any. |
| 97 | if (vertexdir != sign(netdir)) { |
| 98 | vertexidx = (vertexidx + 1) & 3; |
| 99 | } |
| 100 | |
| 101 | float2 localcoord = P[vertexidx]; |
| 102 | float2 vertexpos = AFFINE_MATRIX * localcoord + TRANSLATE;)"); |
| 103 | gpArgs->fLocalCoordVar.set(kFloat2_GrSLType, "localcoord"); |
| 104 | gpArgs->fPositionVar.set(kFloat2_GrSLType, "vertexpos"); |
| 105 | } |
| 106 | }; |
| 107 | return new Impl; |
| 108 | } |
| 109 | |
| 110 | } // namespace |
| 111 | |
Robert Phillips | 294723d | 2021-06-17 09:23:58 -0400 | [diff] [blame] | 112 | void GrPathInnerTriangulateOp::visitProxies(const GrVisitProxyFunc& func) const { |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 113 | if (fPipelineForFills) { |
Robert Phillips | 294723d | 2021-06-17 09:23:58 -0400 | [diff] [blame] | 114 | fPipelineForFills->visitProxies(func); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 115 | } else { |
Robert Phillips | 294723d | 2021-06-17 09:23:58 -0400 | [diff] [blame] | 116 | fProcessors.visitProxies(func); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
| 120 | GrDrawOp::FixedFunctionFlags GrPathInnerTriangulateOp::fixedFunctionFlags() const { |
| 121 | auto flags = FixedFunctionFlags::kUsesStencil; |
| 122 | if (GrAAType::kNone != fAAType) { |
| 123 | flags |= FixedFunctionFlags::kUsesHWAA; |
| 124 | } |
| 125 | return flags; |
| 126 | } |
| 127 | |
| 128 | GrProcessorSet::Analysis GrPathInnerTriangulateOp::finalize(const GrCaps& caps, |
| 129 | const GrAppliedClip* clip, |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 130 | GrClampType clampType) { |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 131 | return fProcessors.finalize(fColor, GrProcessorAnalysisCoverage::kNone, clip, nullptr, caps, |
| 132 | clampType, &fColor); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 135 | void GrPathInnerTriangulateOp::pushFanStencilProgram(const GrTessellationShader::ProgramArgs& args, |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 136 | const GrPipeline* pipelineForStencils, |
| 137 | const GrUserStencilSettings* stencil) { |
| 138 | SkASSERT(pipelineForStencils); |
Chris Dalton | b63711a | 2021-06-01 14:52:02 -0600 | [diff] [blame] | 139 | auto shader = GrPathTessellationShader::MakeSimpleTriangleShader(args.fArena, fViewMatrix, |
| 140 | SK_PMColor4fTRANSPARENT); |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 141 | fFanPrograms.push_back(GrTessellationShader::MakeProgram(args, shader, pipelineForStencils, |
| 142 | stencil)); } |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 143 | |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 144 | void GrPathInnerTriangulateOp::pushFanFillProgram(const GrTessellationShader::ProgramArgs& args, |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 145 | const GrUserStencilSettings* stencil) { |
| 146 | SkASSERT(fPipelineForFills); |
Chris Dalton | b63711a | 2021-06-01 14:52:02 -0600 | [diff] [blame] | 147 | auto shader = GrPathTessellationShader::MakeSimpleTriangleShader(args.fArena, fViewMatrix, |
| 148 | fColor); |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 149 | fFanPrograms.push_back(GrTessellationShader::MakeProgram(args, shader, fPipelineForFills, |
| 150 | stencil)); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 153 | void GrPathInnerTriangulateOp::prePreparePrograms(const GrTessellationShader::ProgramArgs& args, |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 154 | GrAppliedClip&& appliedClip) { |
| 155 | SkASSERT(!fFanTriangulator); |
| 156 | SkASSERT(!fFanPolys); |
| 157 | SkASSERT(!fPipelineForFills); |
| 158 | SkASSERT(!fTessellator); |
| 159 | SkASSERT(!fStencilCurvesProgram); |
| 160 | SkASSERT(fFanPrograms.empty()); |
Chris Dalton | 031d76b | 2021-06-08 16:32:00 -0600 | [diff] [blame] | 161 | SkASSERT(!fCoverHullsProgram); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 162 | |
| 163 | if (fPath.countVerbs() <= 0) { |
| 164 | return; |
| 165 | } |
| 166 | |
Chris Dalton | 031d76b | 2021-06-08 16:32:00 -0600 | [diff] [blame] | 167 | // If using wireframe, we have to fall back on a standard Redbook "stencil then cover" algorithm |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 168 | // instead of bypassing the stencil buffer to fill the fan directly. |
Chris Dalton | 917f919 | 2021-06-08 14:32:37 -0600 | [diff] [blame] | 169 | bool forceRedbookStencilPass = (fPathFlags & (PathFlags::kStencilOnly | PathFlags::kWireframe)); |
| 170 | bool doFill = !(fPathFlags & PathFlags::kStencilOnly); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 171 | |
| 172 | bool isLinear; |
| 173 | fFanTriangulator = args.fArena->make<GrInnerFanTriangulator>(fPath, args.fArena); |
| 174 | fFanPolys = fFanTriangulator->pathToPolys(&fFanBreadcrumbs, &isLinear); |
| 175 | |
| 176 | // Create a pipeline for stencil passes if needed. |
| 177 | const GrPipeline* pipelineForStencils = nullptr; |
| 178 | if (forceRedbookStencilPass || !isLinear) { // Curves always get stencilled. |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 179 | pipelineForStencils = GrPathTessellationShader::MakeStencilOnlyPipeline( |
Chris Dalton | 917f919 | 2021-06-08 14:32:37 -0600 | [diff] [blame] | 180 | args, fAAType, fPathFlags, appliedClip.hardClip()); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | // Create a pipeline for fill passes if needed. |
| 184 | if (doFill) { |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 185 | fPipelineForFills = GrTessellationShader::MakePipeline(args, fAAType, |
| 186 | std::move(appliedClip), |
| 187 | std::move(fProcessors)); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | // Pass 1: Tessellate the outer curves into the stencil buffer. |
| 191 | if (!isLinear) { |
Chris Dalton | 26666bd | 2021-06-08 16:25:46 -0600 | [diff] [blame] | 192 | fTessellator = GrPathCurveTessellator::Make(args.fArena, fViewMatrix, |
| 193 | SK_PMColor4fTRANSPARENT, |
Chris Dalton | d2b8ba3 | 2021-06-09 00:12:59 -0600 | [diff] [blame] | 194 | GrPathCurveTessellator::DrawInnerFan::kNo, |
Chris Dalton | 198ac15 | 2021-06-09 13:49:43 -0600 | [diff] [blame] | 195 | fPath.countVerbs(), *pipelineForStencils, |
| 196 | *args.fCaps); |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 197 | const GrUserStencilSettings* stencilPathSettings = |
Chris Dalton | baae2dd | 2021-06-25 14:52:49 -0600 | [diff] [blame^] | 198 | GrPathTessellationShader::StencilPathSettings(GrFillRuleForSkPath(fPath)); |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 199 | fStencilCurvesProgram = GrTessellationShader::MakeProgram(args, fTessellator->shader(), |
| 200 | pipelineForStencils, |
| 201 | stencilPathSettings); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | // Pass 2: Fill the path's inner fan with a stencil test against the curves. |
| 205 | if (fFanPolys) { |
| 206 | if (forceRedbookStencilPass) { |
Chris Dalton | 031d76b | 2021-06-08 16:32:00 -0600 | [diff] [blame] | 207 | // Use a standard Redbook "stencil then cover" algorithm instead of bypassing the |
| 208 | // stencil buffer to fill the fan directly. |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 209 | const GrUserStencilSettings* stencilPathSettings = |
Chris Dalton | baae2dd | 2021-06-25 14:52:49 -0600 | [diff] [blame^] | 210 | GrPathTessellationShader::StencilPathSettings(GrFillRuleForSkPath(fPath)); |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 211 | this->pushFanStencilProgram(args, pipelineForStencils, stencilPathSettings); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 212 | if (doFill) { |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 213 | this->pushFanFillProgram(args, |
| 214 | GrPathTessellationShader::TestAndResetStencilSettings()); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 215 | } |
| 216 | } else if (isLinear) { |
| 217 | // There are no outer curves! Ignore stencil and fill the path directly. |
| 218 | SkASSERT(!pipelineForStencils); |
| 219 | this->pushFanFillProgram(args, &GrUserStencilSettings::kUnused); |
| 220 | } else if (!fPipelineForFills->hasStencilClip()) { |
| 221 | // These are a twist on the standard Redbook stencil settings that allow us to fill the |
| 222 | // inner polygon directly to the final render target. By the time these programs |
| 223 | // execute, the outer curves will already be stencilled in. So if the stencil value is |
| 224 | // zero, then it means the sample in question is not affected by any curves and we can |
| 225 | // fill it in directly. If the stencil value is nonzero, then we don't fill and instead |
| 226 | // continue the standard Redbook counting process. |
| 227 | constexpr static GrUserStencilSettings kFillOrIncrDecrStencil( |
| 228 | GrUserStencilSettings::StaticInitSeparate< |
| 229 | 0x0000, 0x0000, |
| 230 | GrUserStencilTest::kEqual, GrUserStencilTest::kEqual, |
| 231 | 0xffff, 0xffff, |
| 232 | GrUserStencilOp::kKeep, GrUserStencilOp::kKeep, |
| 233 | GrUserStencilOp::kIncWrap, GrUserStencilOp::kDecWrap, |
| 234 | 0xffff, 0xffff>()); |
| 235 | |
| 236 | constexpr static GrUserStencilSettings kFillOrInvertStencil( |
| 237 | GrUserStencilSettings::StaticInit< |
| 238 | 0x0000, |
| 239 | GrUserStencilTest::kEqual, |
| 240 | 0xffff, |
| 241 | GrUserStencilOp::kKeep, |
| 242 | // "Zero" instead of "Invert" because the fan only touches any given pixel once. |
| 243 | GrUserStencilOp::kZero, |
| 244 | 0xffff>()); |
| 245 | |
| 246 | auto* stencil = (fPath.getFillType() == SkPathFillType::kWinding) |
| 247 | ? &kFillOrIncrDecrStencil |
| 248 | : &kFillOrInvertStencil; |
| 249 | this->pushFanFillProgram(args, stencil); |
| 250 | } else { |
| 251 | // This is the same idea as above, but we use two passes instead of one because there is |
| 252 | // a stencil clip. The stencil test isn't expressive enough to do the above tests and |
| 253 | // also check the clip bit in a single pass. |
| 254 | constexpr static GrUserStencilSettings kFillIfZeroAndInClip( |
| 255 | GrUserStencilSettings::StaticInit< |
| 256 | 0x0000, |
| 257 | GrUserStencilTest::kEqualIfInClip, |
| 258 | 0xffff, |
| 259 | GrUserStencilOp::kKeep, |
| 260 | GrUserStencilOp::kKeep, |
| 261 | 0xffff>()); |
| 262 | |
| 263 | constexpr static GrUserStencilSettings kIncrDecrStencilIfNonzero( |
| 264 | GrUserStencilSettings::StaticInitSeparate< |
| 265 | 0x0000, 0x0000, |
| 266 | // No need to check the clip because the previous stencil pass will have only |
| 267 | // written to samples already inside the clip. |
| 268 | GrUserStencilTest::kNotEqual, GrUserStencilTest::kNotEqual, |
| 269 | 0xffff, 0xffff, |
| 270 | GrUserStencilOp::kIncWrap, GrUserStencilOp::kDecWrap, |
| 271 | GrUserStencilOp::kKeep, GrUserStencilOp::kKeep, |
| 272 | 0xffff, 0xffff>()); |
| 273 | |
| 274 | constexpr static GrUserStencilSettings kInvertStencilIfNonZero( |
| 275 | GrUserStencilSettings::StaticInit< |
| 276 | 0x0000, |
| 277 | // No need to check the clip because the previous stencil pass will have only |
| 278 | // written to samples already inside the clip. |
| 279 | GrUserStencilTest::kNotEqual, |
| 280 | 0xffff, |
| 281 | // "Zero" instead of "Invert" because the fan only touches any given pixel once. |
| 282 | GrUserStencilOp::kZero, |
| 283 | GrUserStencilOp::kKeep, |
| 284 | 0xffff>()); |
| 285 | |
| 286 | // Pass 2a: Directly fill fan samples whose stencil values (from curves) are zero. |
| 287 | this->pushFanFillProgram(args, &kFillIfZeroAndInClip); |
| 288 | |
| 289 | // Pass 2b: Redbook counting on fan samples whose stencil values (from curves) != 0. |
| 290 | auto* stencil = (fPath.getFillType() == SkPathFillType::kWinding) |
| 291 | ? &kIncrDecrStencilIfNonzero |
| 292 | : &kInvertStencilIfNonZero; |
| 293 | this->pushFanStencilProgram(args, pipelineForStencils, stencil); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | // Pass 3: Draw convex hulls around each curve. |
| 298 | if (doFill && !isLinear) { |
| 299 | // By the time this program executes, every pixel will be filled in except the ones touched |
| 300 | // by curves. We issue a final cover pass over the curves by drawing their convex hulls. |
| 301 | // This will fill in any remaining samples and reset the stencil values back to zero. |
| 302 | SkASSERT(fTessellator); |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 303 | auto* hullShader = args.fArena->make<HullShader>(fViewMatrix, fColor); |
Chris Dalton | 031d76b | 2021-06-08 16:32:00 -0600 | [diff] [blame] | 304 | fCoverHullsProgram = GrTessellationShader::MakeProgram( |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 305 | args, hullShader, fPipelineForFills, |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 306 | GrPathTessellationShader::TestAndResetStencilSettings()); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
| 310 | void GrPathInnerTriangulateOp::onPrePrepare(GrRecordingContext* context, |
| 311 | const GrSurfaceProxyView& writeView, |
| 312 | GrAppliedClip* clip, |
John Stiles | 52cb1d0 | 2021-06-02 11:58:05 -0400 | [diff] [blame] | 313 | const GrDstProxyView& dstProxyView, |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 314 | GrXferBarrierFlags renderPassXferBarriers, |
| 315 | GrLoadOp colorLoadOp) { |
| 316 | this->prePreparePrograms({context->priv().recordTimeAllocator(), writeView, &dstProxyView, |
| 317 | renderPassXferBarriers, colorLoadOp, context->priv().caps()}, |
| 318 | (clip) ? std::move(*clip) : GrAppliedClip::Disabled()); |
| 319 | if (fStencilCurvesProgram) { |
| 320 | context->priv().recordProgramInfo(fStencilCurvesProgram); |
| 321 | } |
| 322 | for (const GrProgramInfo* fanProgram : fFanPrograms) { |
| 323 | context->priv().recordProgramInfo(fanProgram); |
| 324 | } |
Chris Dalton | 031d76b | 2021-06-08 16:32:00 -0600 | [diff] [blame] | 325 | if (fCoverHullsProgram) { |
| 326 | context->priv().recordProgramInfo(fCoverHullsProgram); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
| 330 | void GrPathInnerTriangulateOp::onPrepare(GrOpFlushState* flushState) { |
| 331 | if (!fFanTriangulator) { |
| 332 | this->prePreparePrograms({flushState->allocator(), flushState->writeView(), |
| 333 | &flushState->dstProxyView(), flushState->renderPassBarriers(), |
| 334 | flushState->colorLoadOp(), &flushState->caps()}, |
| 335 | flushState->detachAppliedClip()); |
| 336 | if (!fFanTriangulator) { |
| 337 | return; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | if (fFanPolys) { |
| 342 | GrEagerDynamicVertexAllocator alloc(flushState, &fFanBuffer, &fBaseFanVertex); |
| 343 | fFanVertexCount = fFanTriangulator->polysToTriangles(fFanPolys, &alloc, &fFanBreadcrumbs); |
| 344 | } |
| 345 | |
| 346 | if (fTessellator) { |
| 347 | // Must be called after polysToTriangles() in order for fFanBreadcrumbs to be complete. |
Chris Dalton | 569c01b | 2021-05-25 10:11:46 -0600 | [diff] [blame] | 348 | fTessellator->prepare(flushState, this->bounds(), fPath, &fFanBreadcrumbs); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
| 352 | void GrPathInnerTriangulateOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { |
| 353 | if (fStencilCurvesProgram) { |
| 354 | SkASSERT(fTessellator); |
| 355 | flushState->bindPipelineAndScissorClip(*fStencilCurvesProgram, this->bounds()); |
| 356 | fTessellator->draw(flushState); |
Chris Dalton | d9bdc32 | 2021-06-01 19:22:05 -0600 | [diff] [blame] | 357 | if (flushState->caps().requiresManualFBBarrierAfterTessellatedStencilDraw()) { |
| 358 | flushState->gpu()->insertManualFramebufferBarrier(); // http://skbug.com/9739 |
| 359 | } |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | for (const GrProgramInfo* fanProgram : fFanPrograms) { |
| 363 | SkASSERT(fFanBuffer); |
| 364 | flushState->bindPipelineAndScissorClip(*fanProgram, this->bounds()); |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 365 | flushState->bindTextures(fanProgram->geomProc(), nullptr, fanProgram->pipeline()); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 366 | flushState->bindBuffers(nullptr, nullptr, fFanBuffer); |
| 367 | flushState->draw(fFanVertexCount, fBaseFanVertex); |
| 368 | } |
| 369 | |
Chris Dalton | 031d76b | 2021-06-08 16:32:00 -0600 | [diff] [blame] | 370 | if (fCoverHullsProgram) { |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 371 | SkASSERT(fTessellator); |
Chris Dalton | 031d76b | 2021-06-08 16:32:00 -0600 | [diff] [blame] | 372 | flushState->bindPipelineAndScissorClip(*fCoverHullsProgram, this->bounds()); |
| 373 | flushState->bindTextures(fCoverHullsProgram->geomProc(), nullptr, *fPipelineForFills); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 374 | fTessellator->drawHullInstances(flushState); |
| 375 | } |
| 376 | } |