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