| 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 GrStrokeTessellateOp_DEFINED |
| 9 | #define GrStrokeTessellateOp_DEFINED |
| 10 | |
| 11 | #include "include/core/SkStrokeRec.h" |
| 12 | #include "src/gpu/GrSTArenaList.h" |
| 13 | #include "src/gpu/ops/GrDrawOp.h" |
| 14 | #include "src/gpu/tessellate/GrStrokePatchBuilder.h" |
| 15 | |
| 16 | // Renders opaque, constant-color strokes by decomposing them into standalone tessellation patches. |
| 17 | // Each patch is either a "cubic" (single stroked bezier curve with butt caps) or a "join". Requires |
| 18 | // MSAA if antialiasing is desired. |
| 19 | class GrStrokeTessellateOp : public GrDrawOp { |
| 20 | public: |
| 21 | DEFINE_OP_CLASS_ID |
| 22 | |
| 23 | private: |
| 24 | // The provided matrix must be a similarity matrix for the time being. This is so we can |
| 25 | // bootstrap this Op on top of GrStrokeGeometry with minimal modifications. |
| 26 | // |
| 27 | // Patches can overlap, so until a stencil technique is implemented, the provided paint must be |
| 28 | // a constant blended color. |
| 29 | GrStrokeTessellateOp(GrAAType, const SkMatrix&, const SkPath&, const SkStrokeRec&, GrPaint&&); |
| 30 | |
| 31 | const char* name() const override { return "GrStrokeTessellateOp" ; } |
| 32 | void visitProxies(const VisitProxyFunc& fn) const override { fProcessors.visitProxies(fn); } |
| 33 | FixedFunctionFlags fixedFunctionFlags() const override; |
| 34 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, |
| 35 | bool hasMixedSampledCoverage, GrClampType) override; |
| 36 | CombineResult onCombineIfPossible(GrOp*, GrRecordingContext::Arenas*, const GrCaps&) override; |
| 37 | void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView*, GrAppliedClip*, |
| 38 | const GrXferProcessor::DstProxyView&) override; |
| 39 | void onPrepare(GrOpFlushState* state) override; |
| 40 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
| 41 | |
| 42 | struct PathStroke { |
| 43 | PathStroke(const SkPath& path, const SkStrokeRec& stroke) : fPath(path), fStroke(stroke) {} |
| 44 | SkPath fPath; |
| 45 | SkStrokeRec fStroke; |
| 46 | }; |
| 47 | |
| 48 | GrSTArenaList<PathStroke> fPathStrokes; |
| 49 | int fTotalCombinedVerbCnt; |
| 50 | |
| 51 | const GrAAType fAAType; |
| 52 | float fMatrixScale; // The matrix scale is applied to control points before tessellation. |
| 53 | SkMatrix fSkewMatrix; // The skew matrix is applied to the post-tessellation triangles. |
| 54 | float fMiterLimitOrZero = 0; // Zero if there is not a stroke with a miter join type. |
| 55 | SkPMColor4f fColor; |
| 56 | GrProcessorSet fProcessors; |
| 57 | |
| 58 | // S=1 because we will almost always fit everything into one single chunk. |
| 59 | SkSTArray<1, GrStrokePatchBuilder::VertexChunk> fVertexChunks; |
| 60 | |
| 61 | friend class GrOpMemoryPool; // For ctor. |
| 62 | }; |
| 63 | |
| 64 | #endif |
| 65 | |