Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 | |
| 8 | #ifndef GrStrokeOp_DEFINED |
| 9 | #define GrStrokeOp_DEFINED |
| 10 | |
| 11 | #include "include/core/SkStrokeRec.h" |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 12 | #include "src/gpu/GrSTArenaList.h" |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame^] | 13 | #include "src/gpu/ops/GrMeshDrawOp.h" |
| 14 | #include "src/gpu/tessellate/GrPathShader.h" |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 15 | |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame^] | 16 | class GrRecordingContext; |
| 17 | |
| 18 | // Prepares GPU data for, and then draws a stroke's tessellated geometry. |
| 19 | class GrStrokeTessellator { |
| 20 | public: |
| 21 | // Called before draw(). Prepares GPU buffers containing the geometry to tessellate. |
| 22 | virtual void prepare(GrMeshDrawOp::Target*, const SkMatrix&, const GrSTArenaList<SkPath>&, |
| 23 | const SkStrokeRec&, int totalCombinedVerbCnt) = 0; |
| 24 | |
| 25 | // Issues draw calls for the tessellated stroie. The caller is responsible for binding its |
| 26 | // desired pipeline ahead of time. |
| 27 | virtual void draw(GrOpFlushState*) const = 0; |
| 28 | |
| 29 | virtual ~GrStrokeTessellator() {} |
| 30 | }; |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 31 | |
| 32 | // Base class for ops that render opaque, constant-color strokes by linearizing them into sorted |
| 33 | // "parametric" and "radial" edges. See GrStrokeTessellateShader. |
| 34 | class GrStrokeOp : public GrDrawOp { |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame^] | 35 | public: |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 36 | // The provided matrix must be a similarity matrix for the time being. This is so we can |
| 37 | // bootstrap this Op on top of GrStrokeGeometry with minimal modifications. |
| 38 | // |
| 39 | // Patches can overlap, so until a stencil technique is implemented, the provided paint must be |
| 40 | // a constant blended color. |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame^] | 41 | GrStrokeOp(GrAAType, const SkMatrix&, const SkPath&, const SkStrokeRec&, GrPaint&&); |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 42 | |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame^] | 43 | protected: |
| 44 | DEFINE_OP_CLASS_ID |
| 45 | |
| 46 | const char* name() const override { return "GrStrokeOp"; } |
Chris Dalton | b064334 | 2020-12-15 01:04:12 -0700 | [diff] [blame] | 47 | void visitProxies(const VisitProxyFunc& fn) const override; |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 48 | FixedFunctionFlags fixedFunctionFlags() const override; |
| 49 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, |
| 50 | bool hasMixedSampledCoverage, GrClampType) override; |
| 51 | CombineResult onCombineIfPossible(GrOp*, SkArenaAlloc*, const GrCaps&) override; |
| 52 | |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame^] | 53 | // Creates the tessellator and the stencil/fill program(s) we will use with it. |
| 54 | void prePrepareTessellator(GrPathShader::ProgramArgs&&, GrAppliedClip&&); |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 55 | |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame^] | 56 | void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*, |
| 57 | const GrXferProcessor::DstProxyView&, GrXferBarrierFlags, |
| 58 | GrLoadOp colorLoadOp) override; |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 59 | |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame^] | 60 | void onPrepare(GrOpFlushState*) override; |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 61 | |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame^] | 62 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
Chris Dalton | 06b52ad | 2020-12-15 10:01:35 -0700 | [diff] [blame] | 63 | |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 64 | const GrAAType fAAType; |
| 65 | const SkMatrix fViewMatrix; |
| 66 | const SkStrokeRec fStroke; |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 67 | SkPMColor4f fColor; |
Chris Dalton | 55abaf5 | 2020-12-08 10:25:13 -0700 | [diff] [blame] | 68 | bool fNeedsStencil = false; |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 69 | GrProcessorSet fProcessors; |
| 70 | |
| 71 | GrSTArenaList<SkPath> fPathList; |
Chris Dalton | 7b80726 | 2020-12-10 10:22:50 -0700 | [diff] [blame] | 72 | int fTotalCombinedVerbCnt = 0; |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame^] | 73 | bool fHasConics = false; |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 74 | |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame^] | 75 | GrStrokeTessellator* fTessellator = nullptr; |
| 76 | const GrProgramInfo* fStencilProgram = nullptr; // Only used if the stroke has transparency. |
Chris Dalton | 55abaf5 | 2020-12-08 10:25:13 -0700 | [diff] [blame] | 77 | const GrProgramInfo* fFillProgram = nullptr; |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | #endif |