Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [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 PathTessellateOp_DEFINED |
| 9 | #define PathTessellateOp_DEFINED |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 10 | |
| 11 | #include "src/gpu/ops/GrDrawOp.h" |
| 12 | #include "src/gpu/tessellate/shaders/GrTessellationShader.h" |
| 13 | |
| 14 | class GrPathTessellator; |
| 15 | |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 16 | namespace skgpu::v1 { |
| 17 | |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 18 | // Tessellates a path directly to the color buffer, using one single render pass. This currently |
| 19 | // only works for convex paths. |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 20 | class PathTessellateOp final : public GrDrawOp { |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 21 | private: |
| 22 | DEFINE_OP_CLASS_ID |
| 23 | |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 24 | PathTessellateOp(const SkMatrix& viewMatrix, const SkPath& path, GrPaint&& paint, |
| 25 | GrAAType aaType, const GrUserStencilSettings* stencil, |
| 26 | const SkRect& drawBounds) |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 27 | : GrDrawOp(ClassID()) |
| 28 | , fViewMatrix(viewMatrix) |
| 29 | , fPath(path) |
| 30 | , fAAType(aaType) |
| 31 | , fStencil(stencil) |
| 32 | , fColor(paint.getColor4f()) |
| 33 | , fProcessors(std::move(paint)) { |
Chris Dalton | baae2dd | 2021-06-25 14:52:49 -0600 | [diff] [blame] | 34 | SkASSERT(!fPath.isInverseFillType()); |
| 35 | this->setBounds(drawBounds, HasAABloat::kNo, IsHairline::kNo); |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 36 | } |
| 37 | |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 38 | const char* name() const override { return "PathTessellateOp"; } |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 39 | bool usesMSAA() const override { return fAAType == GrAAType::kMSAA; } |
Robert Phillips | 294723d | 2021-06-17 09:23:58 -0400 | [diff] [blame] | 40 | void visitProxies(const GrVisitProxyFunc&) const override; |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 41 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override; |
| 42 | bool usesStencil() const override { return !fStencil->isUnused(); } |
| 43 | |
| 44 | void prepareTessellator(const GrTessellationShader::ProgramArgs&, GrAppliedClip&& clip); |
| 45 | |
| 46 | void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*, |
| 47 | const GrDstProxyView&, GrXferBarrierFlags, GrLoadOp colorLoadOp) override; |
| 48 | void onPrepare(GrOpFlushState*) override; |
| 49 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
| 50 | |
| 51 | const SkMatrix fViewMatrix; |
| 52 | const SkPath fPath; |
| 53 | const GrAAType fAAType; |
| 54 | const GrUserStencilSettings* const fStencil; |
| 55 | SkPMColor4f fColor; |
| 56 | GrProcessorSet fProcessors; |
| 57 | |
| 58 | // Decided during prepareTessellator. |
| 59 | GrPathTessellator* fTessellator = nullptr; |
| 60 | const GrProgramInfo* fTessellationProgram = nullptr; |
| 61 | |
| 62 | friend class GrOp; // For ctor. |
| 63 | }; |
| 64 | |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 65 | } // namespace skgpu::v1 |
| 66 | |
| 67 | #endif // PathTessellateOp_DEFINED |