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