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 | 2ed22fa | 2021-05-06 16:08:30 -0600 | [diff] [blame] | 8 | #ifndef GrPathStencilFillOp_DEFINED |
| 9 | #define GrPathStencilFillOp_DEFINED |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 10 | |
| 11 | #include "src/gpu/ops/GrDrawOp.h" |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 12 | #include "src/gpu/tessellate/GrTessellationPathRenderer.h" |
Chris Dalton | 3b41278 | 2021-06-01 13:40:03 -0600 | [diff] [blame] | 13 | #include "src/gpu/tessellate/shaders/GrTessellationShader.h" |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 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 | 2ed22fa | 2021-05-06 16:08:30 -0600 | [diff] [blame] | 20 | class GrPathStencilFillOp : public GrDrawOp { |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 21 | private: |
| 22 | DEFINE_OP_CLASS_ID |
| 23 | |
Chris Dalton | 2ed22fa | 2021-05-06 16:08:30 -0600 | [diff] [blame] | 24 | GrPathStencilFillOp(const SkMatrix& viewMatrix, const SkPath& path, GrPaint&& paint, |
Chris Dalton | 569c01b | 2021-05-25 10:11:46 -0600 | [diff] [blame] | 25 | GrAAType aaType, GrTessellationPathRenderer::OpFlags opFlags, |
| 26 | const SkRect& devBounds) |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 27 | : GrDrawOp(ClassID()) |
| 28 | , fOpFlags(opFlags) |
| 29 | , fViewMatrix(viewMatrix) |
| 30 | , fPath(path) |
| 31 | , fAAType(aaType) |
| 32 | , fColor(paint.getColor4f()) |
| 33 | , fProcessors(std::move(paint)) { |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 34 | this->setBounds(devBounds, HasAABloat::kNo, IsHairline::kNo); |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Chris Dalton | 2ed22fa | 2021-05-06 16:08:30 -0600 | [diff] [blame] | 37 | const char* name() const override { return "GrPathStencilFillOp"; } |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 38 | void visitProxies(const VisitProxyFunc& fn) const override; |
| 39 | FixedFunctionFlags fixedFunctionFlags() const override; |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 40 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override; |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 41 | |
| 42 | // Chooses the rendering method we will use and creates the corresponding tessellator and |
| 43 | // stencil/fill programs. |
Chris Dalton | 2f733ec | 2021-06-01 12:11:57 -0600 | [diff] [blame] | 44 | void prePreparePrograms(const GrTessellationShader::ProgramArgs&, GrAppliedClip&& clip); |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 45 | |
| 46 | void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*, |
John Stiles | 52cb1d0 | 2021-06-02 11:58:05 -0400 | [diff] [blame^] | 47 | const GrDstProxyView&, GrXferBarrierFlags, GrLoadOp colorLoadOp) override; |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 48 | void onPrepare(GrOpFlushState*) override; |
| 49 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
| 50 | |
| 51 | const GrTessellationPathRenderer::OpFlags fOpFlags; |
| 52 | const SkMatrix fViewMatrix; |
| 53 | const SkPath fPath; |
| 54 | const GrAAType fAAType; |
| 55 | SkPMColor4f fColor; |
| 56 | GrProcessorSet fProcessors; |
| 57 | |
| 58 | // Decided during prePreparePrograms. |
| 59 | GrPathTessellator* fTessellator = nullptr; |
| 60 | const GrProgramInfo* fStencilFanProgram = nullptr; |
| 61 | const GrProgramInfo* fStencilPathProgram = nullptr; |
| 62 | const GrProgramInfo* fFillBBoxProgram = nullptr; |
| 63 | |
| 64 | // Filled during onPrepare. |
| 65 | sk_sp<const GrBuffer> fFanBuffer; |
| 66 | int fFanBaseVertex = 0; |
| 67 | int fFanVertexCount = 0; |
| 68 | |
Chris Dalton | c91dd69 | 2021-05-24 15:04:47 -0600 | [diff] [blame] | 69 | sk_sp<const GrBuffer> fBBoxBuffer; |
| 70 | int fBBoxBaseInstance = 0; |
| 71 | |
Chris Dalton | 70a0d2c | 2021-01-26 12:01:21 -0700 | [diff] [blame] | 72 | friend class GrOp; // For ctor. |
| 73 | }; |
| 74 | |
| 75 | #endif |