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 | #ifndef GrPathInnerTriangulateOp_DEFINED |
| 9 | #define GrPathInnerTriangulateOp_DEFINED |
| 10 | |
| 11 | #include "src/gpu/GrInnerFanTriangulator.h" |
| 12 | #include "src/gpu/ops/GrDrawOp.h" |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 13 | #include "src/gpu/tessellate/GrTessellationPathRenderer.h" |
Chris Dalton | 3b41278 | 2021-06-01 13:40:03 -0600 | [diff] [blame] | 14 | #include "src/gpu/tessellate/shaders/GrTessellationShader.h" |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 15 | |
Chris Dalton | a05ccc3 | 2021-06-29 19:42:13 -0600 | [diff] [blame] | 16 | class GrPathCurveTessellator; |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 17 | |
Chris Dalton | 031d76b | 2021-06-08 16:32:00 -0600 | [diff] [blame] | 18 | // This op is a 3-pass twist on the standard Redbook "stencil then cover" algorithm: |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 19 | // |
| 20 | // 1) Tessellate the path's outer curves into the stencil buffer. |
| 21 | // 2) Triangulate the path's inner fan and fill it with a stencil test against the curves. |
| 22 | // 3) Draw convex hulls around each curve that fill in remaining samples. |
| 23 | // |
| 24 | // In practice, a path's inner fan takes up a large majority of its pixels. So from a GPU load |
| 25 | // perspective, this op is effectively as fast as a single-pass algorithm. |
| 26 | class GrPathInnerTriangulateOp : public GrDrawOp { |
| 27 | private: |
| 28 | DEFINE_OP_CLASS_ID |
| 29 | |
| 30 | GrPathInnerTriangulateOp(const SkMatrix& viewMatrix, const SkPath& path, GrPaint&& paint, |
Chris Dalton | 917f919 | 2021-06-08 14:32:37 -0600 | [diff] [blame] | 31 | GrAAType aaType, GrTessellationPathRenderer::PathFlags pathFlags, |
Chris Dalton | baae2dd | 2021-06-25 14:52:49 -0600 | [diff] [blame] | 32 | const SkRect& drawBounds) |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 33 | : GrDrawOp(ClassID()) |
Chris Dalton | 917f919 | 2021-06-08 14:32:37 -0600 | [diff] [blame] | 34 | , fPathFlags(pathFlags) |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 35 | , fViewMatrix(viewMatrix) |
| 36 | , fPath(path) |
| 37 | , fAAType(aaType) |
| 38 | , fColor(paint.getColor4f()) |
| 39 | , fProcessors(std::move(paint)) { |
Chris Dalton | baae2dd | 2021-06-25 14:52:49 -0600 | [diff] [blame] | 40 | SkASSERT(!fPath.isInverseFillType()); |
| 41 | this->setBounds(drawBounds, HasAABloat::kNo, IsHairline::kNo); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | const char* name() const override { return "GrPathInnerTriangulateOp"; } |
Robert Phillips | 294723d | 2021-06-17 09:23:58 -0400 | [diff] [blame] | 45 | void visitProxies(const GrVisitProxyFunc&) const override; |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 46 | FixedFunctionFlags fixedFunctionFlags() const override; |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 47 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override; |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 48 | |
| 49 | // These calls set up the stencil & fill programs we will use prior to preparing and executing. |
Chris Dalton | a8c4de9 | 2021-07-26 21:46:28 +0000 | [diff] [blame^] | 50 | void pushFanStencilProgram(const GrTessellationShader::ProgramArgs&, |
| 51 | const GrPipeline* pipelineForStencils, const GrUserStencilSettings*); |
| 52 | void pushFanFillProgram(const GrTessellationShader::ProgramArgs&, const GrUserStencilSettings*); |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 53 | void prePreparePrograms(const GrTessellationShader::ProgramArgs&, GrAppliedClip&&); |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 54 | |
| 55 | void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*, |
John Stiles | 52cb1d0 | 2021-06-02 11:58:05 -0400 | [diff] [blame] | 56 | const GrDstProxyView&, GrXferBarrierFlags, GrLoadOp colorLoadOp) override; |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 57 | void onPrepare(GrOpFlushState*) override; |
| 58 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
| 59 | |
Chris Dalton | 917f919 | 2021-06-08 14:32:37 -0600 | [diff] [blame] | 60 | const GrTessellationPathRenderer::PathFlags fPathFlags; |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 61 | const SkMatrix fViewMatrix; |
| 62 | const SkPath fPath; |
| 63 | const GrAAType fAAType; |
| 64 | SkPMColor4f fColor; |
| 65 | GrProcessorSet fProcessors; |
| 66 | |
| 67 | // Triangulates the inner fan. |
| 68 | GrInnerFanTriangulator* fFanTriangulator = nullptr; |
| 69 | GrTriangulator::Poly* fFanPolys = nullptr; |
| 70 | GrInnerFanTriangulator::BreadcrumbTriangleList fFanBreadcrumbs; |
| 71 | |
| 72 | // This pipeline is shared by all programs that do filling. |
| 73 | const GrPipeline* fPipelineForFills = nullptr; |
| 74 | |
| 75 | // Tessellates the outer curves. |
Chris Dalton | a05ccc3 | 2021-06-29 19:42:13 -0600 | [diff] [blame] | 76 | GrPathCurveTessellator* fTessellator = nullptr; |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 77 | |
| 78 | // Pass 1: Tessellate the outer curves into the stencil buffer. |
| 79 | const GrProgramInfo* fStencilCurvesProgram = nullptr; |
| 80 | |
| 81 | // Pass 2: Fill the path's inner fan with a stencil test against the curves. (In extenuating |
| 82 | // circumstances this might require two separate draws.) |
| 83 | SkSTArray<2, const GrProgramInfo*> fFanPrograms; |
| 84 | |
| 85 | // Pass 3: Draw convex hulls around each curve. |
Chris Dalton | 031d76b | 2021-06-08 16:32:00 -0600 | [diff] [blame] | 86 | const GrProgramInfo* fCoverHullsProgram = nullptr; |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 87 | |
| 88 | // This buffer gets created by fFanTriangulator during onPrepare. |
| 89 | sk_sp<const GrBuffer> fFanBuffer; |
| 90 | int fBaseFanVertex = 0; |
| 91 | int fFanVertexCount = 0; |
| 92 | |
Chris Dalton | a05ccc3 | 2021-06-29 19:42:13 -0600 | [diff] [blame] | 93 | // Only used if sk_VertexID is not supported. |
| 94 | sk_sp<const GrGpuBuffer> fHullVertexBufferIfNoIDSupport; |
| 95 | |
Chris Dalton | ebb37e7 | 2021-01-27 17:59:45 -0700 | [diff] [blame] | 96 | friend class GrOp; // For ctor. |
| 97 | }; |
| 98 | |
| 99 | #endif |