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