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_PathCurveTessellator_DEFINED 9 #define tessellate_PathCurveTessellator_DEFINED 10 11 #include "src/gpu/tessellate/PathTessellator.h" 12 13 namespace skgpu { 14 15 // Draws an array of "outer curve" patches. Each patch is an independent 4-point curve, representing 16 // either a cubic or a conic. Quadratics are converted to cubics and triangles are converted to 17 // conics with w=Inf. 18 class PathCurveTessellator final : public PathTessellator { 19 public: 20 static PathCurveTessellator* Make(SkArenaAlloc* arena, 21 bool infinitySupport, 22 PatchAttribs attribs = PatchAttribs::kNone) { 23 return arena->make<PathCurveTessellator>(infinitySupport, attribs); 24 } 25 26 PathCurveTessellator(bool infinitySupport, 27 PatchAttribs attribs = PatchAttribs::kNone) PathTessellator(infinitySupport,attribs)28 : PathTessellator(infinitySupport, attribs) {} 29 30 int patchPreallocCount(int totalCombinedPathVerbCnt) const final; 31 32 void writePatches(PatchWriter& patchWriter, 33 int maxTessellationSegments, 34 const SkMatrix& shaderMatrix, 35 const PathDrawList& pathDrawList) final; 36 37 // Size of the vertex buffer to use when rendering with a fixed count shader. FixedVertexBufferSize(int maxFixedResolveLevel)38 constexpr static int FixedVertexBufferSize(int maxFixedResolveLevel) { 39 return ((1 << maxFixedResolveLevel) + 1) * sizeof(SkPoint); 40 } 41 42 // Writes the vertex buffer to use when rendering with a fixed count shader. 43 static void WriteFixedVertexBuffer(VertexWriter, size_t bufferSize); 44 45 // Size of the index buffer to use when rendering with a fixed count shader. FixedIndexBufferSize(int maxFixedResolveLevel)46 constexpr static int FixedIndexBufferSize(int maxFixedResolveLevel) { 47 return NumCurveTrianglesAtResolveLevel(maxFixedResolveLevel) * 3 * sizeof(uint16_t); 48 } 49 50 // Writes the index buffer to use when rendering with a fixed count shader. WriteFixedIndexBuffer(VertexWriter vertexWriter,size_t bufferSize)51 static void WriteFixedIndexBuffer(VertexWriter vertexWriter, size_t bufferSize) { 52 WriteFixedIndexBufferBaseIndex(std::move(vertexWriter), bufferSize, 0); 53 } 54 55 static void WriteFixedIndexBufferBaseIndex(VertexWriter, size_t bufferSize, uint16_t baseIndex); 56 57 #if SK_GPU_V1 58 void prepareFixedCountBuffers(GrMeshDrawTarget*) final; 59 60 void drawTessellated(GrOpFlushState*) const final; 61 void drawFixedCount(GrOpFlushState*) const final; 62 63 // Draws a 4-point instance for each patch. This method is used for drawing convex hulls over 64 // each cubic with GrFillCubicHullShader. The caller is responsible for binding its desired 65 // pipeline ahead of time. 66 void drawHullInstances(GrOpFlushState*, sk_sp<const GrGpuBuffer> vertexBufferIfNeeded) const; 67 #endif 68 }; 69 70 } // namespace skgpu 71 72 #endif // tessellate_PathCurveTessellator_DEFINED 73