• 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 GrInnerFanTriangulator_DEFINED
9 #define GrInnerFanTriangulator_DEFINED
10 
11 #include "src/gpu/geometry/GrTriangulator.h"
12 
13 // Triangulates the inner polygon(s) of a path (i.e., the triangle fan for a Redbook rendering
14 // method). When combined with the outer curves and breadcrumb triangles, these produce a complete
15 // path. If a breadcrumbCollector is not provided, pathToPolys fails upon self intersection.
16 class GrInnerFanTriangulator : private GrTriangulator {
17 public:
18     using GrTriangulator::BreadcrumbTriangleList;
19 
GrInnerFanTriangulator(const SkPath & path,SkArenaAlloc * alloc)20     GrInnerFanTriangulator(const SkPath& path, SkArenaAlloc* alloc)
21             : GrTriangulator(path, alloc) {
22         fPreserveCollinearVertices = true;
23         fCollectBreadcrumbTriangles = true;
24     }
25 
pathToTriangles(GrEagerVertexAllocator * vertexAlloc,BreadcrumbTriangleList * breadcrumbList,bool * isLinear)26     int pathToTriangles(GrEagerVertexAllocator* vertexAlloc, BreadcrumbTriangleList* breadcrumbList,
27                         bool* isLinear) const {
28         Poly* polys = this->pathToPolys(breadcrumbList, isLinear);
29         return this->polysToTriangles(polys, vertexAlloc, breadcrumbList);
30     }
31 
pathToPolys(BreadcrumbTriangleList * breadcrumbList,bool * isLinear)32     Poly* pathToPolys(BreadcrumbTriangleList* breadcrumbList, bool* isLinear) const {
33         Poly* polys = this->GrTriangulator::pathToPolys(0, SkRect::MakeEmpty(), isLinear);
34         breadcrumbList->concat(std::move(fBreadcrumbList));
35         return polys;
36     }
37 
polysToTriangles(Poly * polys,GrEagerVertexAllocator * vertexAlloc,BreadcrumbTriangleList * breadcrumbList)38     int polysToTriangles(Poly* polys, GrEagerVertexAllocator* vertexAlloc,
39                          BreadcrumbTriangleList* breadcrumbList) const {
40         int vertexCount = this->GrTriangulator::polysToTriangles(polys, vertexAlloc);
41         breadcrumbList->concat(std::move(fBreadcrumbList));
42         return vertexCount;
43     }
44 };
45 
46 #endif
47