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 | |
Chris Dalton | b03f4a1 | 2021-01-27 17:45:52 -0700 | [diff] [blame] | 8 | #ifndef GrTessellatingStencilFillOp_DEFINED |
| 9 | #define GrTessellatingStencilFillOp_DEFINED |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 10 | |
| 11 | #include "src/gpu/ops/GrDrawOp.h" |
| 12 | #include "src/gpu/tessellate/GrPathShader.h" |
| 13 | #include "src/gpu/tessellate/GrTessellationPathRenderer.h" |
| 14 | |
| 15 | class GrPathTessellator; |
| 16 | |
| 17 | // Draws paths using a standard Redbook "stencil then fill" method. Curves get linearized by either |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame^] | 18 | // GPU tessellation shaders or indirect draws. This Op doesn't apply analytic AA, so it requires |
| 19 | // MSAA if AA is desired. |
Chris Dalton | b03f4a1 | 2021-01-27 17:45:52 -0700 | [diff] [blame] | 20 | class GrTessellatingStencilFillOp : public GrDrawOp { |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 21 | private: |
| 22 | DEFINE_OP_CLASS_ID |
| 23 | |
Chris Dalton | b03f4a1 | 2021-01-27 17:45:52 -0700 | [diff] [blame] | 24 | GrTessellatingStencilFillOp(const SkMatrix& viewMatrix, const SkPath& path, GrPaint&& paint, |
| 25 | GrAAType aaType, GrTessellationPathRenderer::OpFlags opFlags) |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 26 | : GrDrawOp(ClassID()) |
| 27 | , fOpFlags(opFlags) |
| 28 | , fViewMatrix(viewMatrix) |
| 29 | , fPath(path) |
| 30 | , fAAType(aaType) |
| 31 | , fColor(paint.getColor4f()) |
| 32 | , fProcessors(std::move(paint)) { |
| 33 | SkRect devBounds; |
| 34 | fViewMatrix.mapRect(&devBounds, path.getBounds()); |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame^] | 35 | this->setBounds(devBounds, HasAABloat::kNo, IsHairline::kNo); |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Chris Dalton | b03f4a1 | 2021-01-27 17:45:52 -0700 | [diff] [blame] | 38 | const char* name() const override { return "GrTessellatingStencilFillOp"; } |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 39 | void visitProxies(const VisitProxyFunc& fn) const override; |
| 40 | FixedFunctionFlags fixedFunctionFlags() const override; |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame^] | 41 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override; |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 42 | |
| 43 | // Chooses the rendering method we will use and creates the corresponding tessellator and |
| 44 | // stencil/fill programs. |
| 45 | void prePreparePrograms(const GrPathShader::ProgramArgs&, GrAppliedClip&& clip); |
| 46 | |
| 47 | void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*, |
| 48 | const GrXferProcessor::DstProxyView&, GrXferBarrierFlags, |
| 49 | GrLoadOp colorLoadOp) override; |
| 50 | void onPrepare(GrOpFlushState*) override; |
| 51 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
| 52 | |
| 53 | const GrTessellationPathRenderer::OpFlags fOpFlags; |
| 54 | const SkMatrix fViewMatrix; |
| 55 | const SkPath fPath; |
| 56 | const GrAAType fAAType; |
| 57 | SkPMColor4f fColor; |
| 58 | GrProcessorSet fProcessors; |
| 59 | |
| 60 | // Decided during prePreparePrograms. |
| 61 | GrPathTessellator* fTessellator = nullptr; |
| 62 | const GrProgramInfo* fStencilFanProgram = nullptr; |
| 63 | const GrProgramInfo* fStencilPathProgram = nullptr; |
| 64 | const GrProgramInfo* fFillBBoxProgram = nullptr; |
| 65 | |
| 66 | // Filled during onPrepare. |
| 67 | sk_sp<const GrBuffer> fFanBuffer; |
| 68 | int fFanBaseVertex = 0; |
| 69 | int fFanVertexCount = 0; |
| 70 | |
| 71 | friend class GrOp; // For ctor. |
| 72 | }; |
| 73 | |
| 74 | #endif |