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 | |
Chris Dalton | 05007df | 2021-02-04 00:24:52 -0700 | [diff] [blame] | 8 | #ifndef GrStrokeTessellateOp_DEFINED |
| 9 | #define GrStrokeTessellateOp_DEFINED |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 10 | |
| 11 | #include "include/core/SkStrokeRec.h" |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame] | 12 | #include "src/gpu/ops/GrMeshDrawOp.h" |
| 13 | #include "src/gpu/tessellate/GrPathShader.h" |
Chris Dalton | 9b5b7db7 | 2021-03-30 10:59:34 -0600 | [diff] [blame] | 14 | #include "src/gpu/tessellate/GrStrokeTessellator.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 | |
Chris Dalton | 42582fc | 2021-02-18 11:29:49 -0700 | [diff] [blame] | 18 | // Renders strokes by linearizing them into sorted "parametric" and "radial" edges. See |
| 19 | // GrStrokeTessellateShader. |
| 20 | class GrStrokeTessellateOp : public GrDrawOp { |
| 21 | public: |
| 22 | GrStrokeTessellateOp(GrAAType, const SkMatrix&, const SkPath&, const SkStrokeRec&, GrPaint&&); |
| 23 | |
| 24 | private: |
| 25 | using ShaderFlags = GrStrokeTessellateShader::ShaderFlags; |
Chris Dalton | ed82686 | 2021-02-22 12:01:12 -0700 | [diff] [blame] | 26 | using PathStrokeList = GrStrokeTessellator::PathStrokeList; |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame] | 27 | DEFINE_OP_CLASS_ID |
| 28 | |
Chris Dalton | ed82686 | 2021-02-22 12:01:12 -0700 | [diff] [blame] | 29 | SkStrokeRec& headStroke() { return fPathStrokeList.fStroke; } |
| 30 | SkPMColor4f& headColor() { return fPathStrokeList.fColor; } |
Chris Dalton | 42582fc | 2021-02-18 11:29:49 -0700 | [diff] [blame] | 31 | |
Chris Dalton | 1017a35 | 2021-02-18 15:22:54 -0700 | [diff] [blame] | 32 | // Returns whether it is a good tradeoff to use the dynamic states flagged in the given |
| 33 | // bitfield. Dynamic states improve batching, but if they aren't already enabled, they come at |
| 34 | // the cost of having to write out more data with each patch or instance. |
| 35 | bool shouldUseDynamicStates(ShaderFlags neededDynamicStates) const { |
| 36 | // Use the dynamic states if either (1) they are all already enabled anyway, or (2) we don't |
Chris Dalton | 42582fc | 2021-02-18 11:29:49 -0700 | [diff] [blame] | 37 | // have many verbs. |
| 38 | constexpr static int kMaxVerbsToEnableDynamicState = 50; |
Chris Dalton | 1017a35 | 2021-02-18 15:22:54 -0700 | [diff] [blame] | 39 | bool anyStateDisabled = (bool)(~fShaderFlags & neededDynamicStates); |
| 40 | bool allStatesEnabled = !anyStateDisabled; |
| 41 | return allStatesEnabled || (fTotalCombinedVerbCnt <= kMaxVerbsToEnableDynamicState); |
| 42 | } |
| 43 | |
Chris Dalton | 7d97991 | 2021-05-11 12:36:51 -0600 | [diff] [blame^] | 44 | bool canUseHardwareTessellation(int numVerbs, const GrCaps& caps); |
Chris Dalton | 42582fc | 2021-02-18 11:29:49 -0700 | [diff] [blame] | 45 | |
Chris Dalton | 05007df | 2021-02-04 00:24:52 -0700 | [diff] [blame] | 46 | const char* name() const override { return "GrStrokeTessellateOp"; } |
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; |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 49 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override; |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 50 | CombineResult onCombineIfPossible(GrOp*, SkArenaAlloc*, const GrCaps&) override; |
| 51 | |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame] | 52 | // Creates the tessellator and the stencil/fill program(s) we will use with it. |
| 53 | void prePrepareTessellator(GrPathShader::ProgramArgs&&, GrAppliedClip&&); |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 54 | |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame] | 55 | void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*, |
| 56 | const GrXferProcessor::DstProxyView&, GrXferBarrierFlags, |
| 57 | GrLoadOp colorLoadOp) override; |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 58 | |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame] | 59 | void onPrepare(GrOpFlushState*) override; |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 60 | |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame] | 61 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
Chris Dalton | 06b52ad | 2020-12-15 10:01:35 -0700 | [diff] [blame] | 62 | |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 63 | const GrAAType fAAType; |
| 64 | const SkMatrix fViewMatrix; |
Chris Dalton | 42582fc | 2021-02-18 11:29:49 -0700 | [diff] [blame] | 65 | ShaderFlags fShaderFlags = ShaderFlags::kNone; |
Chris Dalton | ed82686 | 2021-02-22 12:01:12 -0700 | [diff] [blame] | 66 | PathStrokeList fPathStrokeList; |
| 67 | PathStrokeList** fPathStrokeTail = &fPathStrokeList.fNext; |
Chris Dalton | 7b80726 | 2020-12-10 10:22:50 -0700 | [diff] [blame] | 68 | int fTotalCombinedVerbCnt = 0; |
Chris Dalton | 1017a35 | 2021-02-18 15:22:54 -0700 | [diff] [blame] | 69 | GrProcessorSet fProcessors; |
| 70 | bool fNeedsStencil = false; |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 71 | |
Chris Dalton | 2224100 | 2021-02-04 09:47:40 -0700 | [diff] [blame] | 72 | GrStrokeTessellator* fTessellator = nullptr; |
| 73 | const GrProgramInfo* fStencilProgram = nullptr; // Only used if the stroke has transparency. |
Chris Dalton | 55abaf5 | 2020-12-08 10:25:13 -0700 | [diff] [blame] | 74 | const GrProgramInfo* fFillProgram = nullptr; |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | #endif |