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 GrStrokeTessellationShader_DEFINED 9 #define GrStrokeTessellationShader_DEFINED 10 11 #include "src/gpu/ganesh/tessellate/GrTessellationShader.h" 12 13 #include "include/core/SkStrokeRec.h" 14 #include "src/gpu/ganesh/glsl/GrGLSLVarying.h" 15 #include "src/gpu/tessellate/Tessellation.h" 16 17 // Tessellates a batch of stroke patches directly to the canvas. Tessellated stroking works by 18 // creating stroke-width, orthogonal edges at set locations along the curve and then connecting them 19 // with a quad strip. These orthogonal edges come from two different sets: "parametric edges" and 20 // "radial edges". Parametric edges are spaced evenly in the parametric sense, and radial edges 21 // divide the curve's _rotation_ into even steps. The tessellation shader evaluates both sets of 22 // edges and sorts them into a single quad strip. With this combined set of edges we can stroke any 23 // curve, regardless of curvature. 24 class GrStrokeTessellationShader : public GrTessellationShader { 25 using PatchAttribs = skgpu::tess::PatchAttribs; 26 27 public: 28 29 // 'viewMatrix' is applied to the geometry post tessellation. It cannot have perspective. 30 GrStrokeTessellationShader(const GrShaderCaps&, PatchAttribs, const SkMatrix& viewMatrix, 31 const SkStrokeRec&, SkPMColor4f); 32 attribs()33 PatchAttribs attribs() const { return fPatchAttribs; } hasDynamicStroke()34 bool hasDynamicStroke() const { return fPatchAttribs & PatchAttribs::kStrokeParams; } hasDynamicColor()35 bool hasDynamicColor() const { return fPatchAttribs & PatchAttribs::kColor; } hasExplicitCurveType()36 bool hasExplicitCurveType() const { return fPatchAttribs & PatchAttribs::kExplicitCurveType; } stroke()37 const SkStrokeRec& stroke() const { return fStroke;} 38 39 private: name()40 const char* name() const override { return "GrStrokeTessellationShader"; } 41 void addToKey(const GrShaderCaps&, skgpu::KeyBuilder*) const override; 42 std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const final; 43 44 const PatchAttribs fPatchAttribs; 45 const SkStrokeRec fStroke; 46 47 constexpr static int kMaxAttribCount = 6; 48 SkSTArray<kMaxAttribCount, Attribute> fAttribs; 49 50 class Impl; 51 }; 52 53 #endif 54