Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 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 PathStencilCoverOp_DEFINED |
| 9 | #define PathStencilCoverOp_DEFINED |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 10 | |
| 11 | #include "src/gpu/ops/GrDrawOp.h" |
Chris Dalton | 8a1bbaa | 2021-07-28 14:43:07 -0600 | [diff] [blame] | 12 | #include "src/gpu/tessellate/GrPathTessellator.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 | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 15 | |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 16 | namespace skgpu::v1 { |
| 17 | |
Chris Dalton | 031d76b | 2021-06-08 16:32:00 -0600 | [diff] [blame] | 18 | // Draws paths using a standard Redbook "stencil then cover" method. Curves get linearized by either |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 19 | // GPU tessellation shaders or indirect draws. This Op doesn't apply analytic AA, so it requires |
| 20 | // MSAA if AA is desired. |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 21 | class PathStencilCoverOp final : public GrDrawOp { |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 22 | private: |
| 23 | DEFINE_OP_CLASS_ID |
| 24 | |
Chris Dalton | 8a1bbaa | 2021-07-28 14:43:07 -0600 | [diff] [blame] | 25 | using PathDrawList = GrPathTessellator::PathDrawList; |
| 26 | |
Chris Dalton | baae2dd | 2021-06-25 14:52:49 -0600 | [diff] [blame] | 27 | // If the path is inverse filled, drawBounds must be the entire backing store dimensions of the |
| 28 | // render target. |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 29 | PathStencilCoverOp(SkArenaAlloc* arena, |
| 30 | const SkMatrix& viewMatrix, |
| 31 | const SkPath& path, |
| 32 | GrPaint&& paint, |
| 33 | GrAAType aaType, |
| 34 | GrTessellationPathFlags pathFlags, |
| 35 | const SkRect& drawBounds) |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 36 | : GrDrawOp(ClassID()) |
Chris Dalton | 8a1bbaa | 2021-07-28 14:43:07 -0600 | [diff] [blame] | 37 | , fPathDrawList(arena->make<PathDrawList>(viewMatrix, path)) |
| 38 | , fTotalCombinedPathVerbCnt(path.countVerbs()) |
| 39 | , fPathCount(1) |
Chris Dalton | 917f919 | 2021-06-08 14:32:37 -0600 | [diff] [blame] | 40 | , fPathFlags(pathFlags) |
Chris Dalton | 8a1bbaa | 2021-07-28 14:43:07 -0600 | [diff] [blame] | 41 | , fAAType(aaType) |
| 42 | , fColor(paint.getColor4f()) |
| 43 | , fProcessors(std::move(paint)) { |
| 44 | this->setBounds(drawBounds, HasAABloat::kNo, IsHairline::kNo); |
| 45 | SkDEBUGCODE(fOriginalDrawBounds = drawBounds;) |
| 46 | } |
| 47 | |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 48 | // Constructs a PathStencilCoverOp from an existing draw list. |
Chris Dalton | 8a1bbaa | 2021-07-28 14:43:07 -0600 | [diff] [blame] | 49 | // FIXME: The only user of this method is the atlas. We should move the GrProgramInfos into |
| 50 | // GrPathTessellator so the atlas can use that directly instead of going through this class. |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 51 | PathStencilCoverOp(const PathDrawList* pathDrawList, |
| 52 | int totalCombinedVerbCnt, |
| 53 | int pathCount, |
| 54 | GrPaint&& paint, |
| 55 | GrAAType aaType, |
| 56 | GrTessellationPathFlags pathFlags, |
| 57 | const SkRect& drawBounds) |
Chris Dalton | 8a1bbaa | 2021-07-28 14:43:07 -0600 | [diff] [blame] | 58 | : GrDrawOp(ClassID()) |
| 59 | , fPathDrawList(pathDrawList) |
| 60 | , fTotalCombinedPathVerbCnt(totalCombinedVerbCnt) |
| 61 | , fPathCount(pathCount) |
| 62 | , fPathFlags(pathFlags) |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 63 | , fAAType(aaType) |
| 64 | , fColor(paint.getColor4f()) |
| 65 | , fProcessors(std::move(paint)) { |
Chris Dalton | baae2dd | 2021-06-25 14:52:49 -0600 | [diff] [blame] | 66 | this->setBounds(drawBounds, HasAABloat::kNo, IsHairline::kNo); |
| 67 | SkDEBUGCODE(fOriginalDrawBounds = drawBounds;) |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 70 | const char* name() const override { return "PathStencilCoverOp"; } |
Robert Phillips | 294723d | 2021-06-17 09:23:58 -0400 | [diff] [blame] | 71 | void visitProxies(const GrVisitProxyFunc&) const override; |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 72 | FixedFunctionFlags fixedFunctionFlags() const override; |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 73 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override; |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 74 | |
Chris Dalton | 8a1bbaa | 2021-07-28 14:43:07 -0600 | [diff] [blame] | 75 | // All paths in fPathDrawList are required to have the same fill type. |
| 76 | SkPathFillType pathFillType() const { |
| 77 | return fPathDrawList->fPath.getFillType(); |
| 78 | } |
| 79 | |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 80 | // Chooses the rendering method we will use and creates the corresponding tessellator and |
Chris Dalton | 031d76b | 2021-06-08 16:32:00 -0600 | [diff] [blame] | 81 | // stencil/cover programs. |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 82 | void prePreparePrograms(const GrTessellationShader::ProgramArgs&, GrAppliedClip&& clip); |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 83 | |
| 84 | void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*, |
John Stiles | 52cb1d0 | 2021-06-02 11:58:05 -0400 | [diff] [blame] | 85 | const GrDstProxyView&, GrXferBarrierFlags, GrLoadOp colorLoadOp) override; |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 86 | void onPrepare(GrOpFlushState*) override; |
| 87 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
| 88 | |
Chris Dalton | 8a1bbaa | 2021-07-28 14:43:07 -0600 | [diff] [blame] | 89 | const PathDrawList* fPathDrawList; |
| 90 | const int fTotalCombinedPathVerbCnt; |
| 91 | const int fPathCount; |
Robert Phillips | 832f3fb | 2021-08-18 13:05:15 -0400 | [diff] [blame] | 92 | const GrTessellationPathFlags fPathFlags; |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 93 | const GrAAType fAAType; |
| 94 | SkPMColor4f fColor; |
| 95 | GrProcessorSet fProcessors; |
Chris Dalton | baae2dd | 2021-06-25 14:52:49 -0600 | [diff] [blame] | 96 | SkDEBUGCODE(SkRect fOriginalDrawBounds;) |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 97 | |
| 98 | // Decided during prePreparePrograms. |
| 99 | GrPathTessellator* fTessellator = nullptr; |
| 100 | const GrProgramInfo* fStencilFanProgram = nullptr; |
| 101 | const GrProgramInfo* fStencilPathProgram = nullptr; |
Chris Dalton | 031d76b | 2021-06-08 16:32:00 -0600 | [diff] [blame] | 102 | const GrProgramInfo* fCoverBBoxProgram = nullptr; |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 103 | |
| 104 | // Filled during onPrepare. |
| 105 | sk_sp<const GrBuffer> fFanBuffer; |
| 106 | int fFanBaseVertex = 0; |
| 107 | int fFanVertexCount = 0; |
| 108 | |
Chris Dalton | c91dd69 | 2021-05-24 15:04:47 -0600 | [diff] [blame] | 109 | sk_sp<const GrBuffer> fBBoxBuffer; |
| 110 | int fBBoxBaseInstance = 0; |
| 111 | |
Chris Dalton | a05ccc3 | 2021-06-29 19:42:13 -0600 | [diff] [blame] | 112 | // Only used if sk_VertexID is not supported. |
| 113 | sk_sp<const GrGpuBuffer> fBBoxVertexBufferIfNoIDSupport; |
| 114 | |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 115 | friend class GrOp; // For ctor. |
| 116 | }; |
| 117 | |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 118 | } // namespace skgpu::v1 |
| 119 | |
| 120 | #endif // PathStencilCoverOp_DEFINED |