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 8 #ifndef tessellate_PathWedgeTessellator_DEFINED 9 #define tessellate_PathWedgeTessellator_DEFINED 10 11 #include "src/gpu/tessellate/PathTessellator.h" 12 13 namespace skgpu { 14 15 // Prepares an array of "wedge" patches. A wedge is an independent, 5-point closed contour 16 // consisting of 4 control points plus an anchor point fanning from the center of the curve's 17 // resident contour. A wedge can be either a cubic or a conic. Quadratics and lines are converted to 18 // cubics. Once stencilled, these wedges alone define the complete path. 19 class PathWedgeTessellator final : public PathTessellator { 20 public: 21 static PathWedgeTessellator* Make(SkArenaAlloc* arena, 22 bool infinitySupport, 23 PatchAttribs attribs = PatchAttribs::kNone) { 24 return arena->make<PathWedgeTessellator>(infinitySupport, attribs); 25 } 26 27 PathWedgeTessellator(bool infinitySupport, PatchAttribs attribs = PatchAttribs::kNone) PathTessellator(infinitySupport,attribs)28 : PathTessellator(infinitySupport, attribs) { 29 fAttribs |= PatchAttribs::kFanPoint; 30 } 31 32 int patchPreallocCount(int totalCombinedPathVerbCnt) const final; 33 34 void writePatches(PatchWriter&, 35 int maxTessellationSegments, 36 const SkMatrix& shaderMatrix, 37 const PathDrawList&) final; 38 39 // Size of the vertex buffer to use when rendering with a fixed count shader. FixedVertexBufferSize(int maxFixedResolveLevel)40 constexpr static int FixedVertexBufferSize(int maxFixedResolveLevel) { 41 return (((1 << maxFixedResolveLevel) + 1) + 1/*fan vertex*/) * sizeof(SkPoint); 42 } 43 44 // Writes the vertex buffer to use when rendering with a fixed count shader. 45 static void WriteFixedVertexBuffer(VertexWriter, size_t bufferSize); 46 47 // Size of the index buffer to use when rendering with a fixed count shader. FixedIndexBufferSize(int maxFixedResolveLevel)48 constexpr static int FixedIndexBufferSize(int maxFixedResolveLevel) { 49 return (NumCurveTrianglesAtResolveLevel(maxFixedResolveLevel) + 1/*fan triangle*/) * 50 3 * sizeof(uint16_t); 51 } 52 53 // Writes the index buffer to use when rendering with a fixed count shader. 54 static void WriteFixedIndexBuffer(VertexWriter vertexWriter, size_t bufferSize); 55 56 #if SK_GPU_V1 57 void prepareFixedCountBuffers(GrMeshDrawTarget*) final; 58 59 void drawTessellated(GrOpFlushState*) const final; 60 void drawFixedCount(GrOpFlushState*) const final; 61 #endif 62 }; 63 64 } // namespace skgpu 65 66 #endif // tessellate_PathWedgeTessellator_DEFINED 67