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