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 #if !defined(SK_ENABLE_OPTIMIZE_SIZE) 12 13 #include "src/gpu/ganesh/geometry/GrTriangulator.h" 14 15 // Triangulates the inner polygon(s) of a path (i.e., the triangle fan for a Redbook rendering 16 // method). When combined with the outer curves and breadcrumb triangles, these produce a complete 17 // path. If a breadcrumbCollector is not provided, pathToPolys fails upon self intersection. 18 class GrInnerFanTriangulator : private GrTriangulator { 19 public: 20 using GrTriangulator::BreadcrumbTriangleList; 21 GrInnerFanTriangulator(const SkPath & path,SkArenaAlloc * alloc)22 GrInnerFanTriangulator(const SkPath& path, SkArenaAlloc* alloc) 23 : GrTriangulator(path, alloc) { 24 fPreserveCollinearVertices = true; 25 fCollectBreadcrumbTriangles = true; 26 } 27 pathToTriangles(GrEagerVertexAllocator * vertexAlloc,BreadcrumbTriangleList * breadcrumbList,bool * isLinear)28 int pathToTriangles(GrEagerVertexAllocator* vertexAlloc, BreadcrumbTriangleList* breadcrumbList, 29 bool* isLinear) { 30 Poly* polys = this->pathToPolys(breadcrumbList, isLinear); 31 return this->polysToTriangles(polys, vertexAlloc, breadcrumbList); 32 } 33 pathToPolys(BreadcrumbTriangleList * breadcrumbList,bool * isLinear)34 Poly* pathToPolys(BreadcrumbTriangleList* breadcrumbList, bool* isLinear) { 35 auto [ polys, success ] = this->GrTriangulator::pathToPolys(0, SkRect::MakeEmpty(), 36 isLinear); 37 if (!success) { 38 return nullptr; 39 } 40 breadcrumbList->concat(std::move(fBreadcrumbList)); 41 return polys; 42 } 43 polysToTriangles(Poly * polys,GrEagerVertexAllocator * vertexAlloc,BreadcrumbTriangleList * breadcrumbList)44 int polysToTriangles(Poly* polys, GrEagerVertexAllocator* vertexAlloc, 45 BreadcrumbTriangleList* breadcrumbList) const { 46 int vertexCount = this->GrTriangulator::polysToTriangles(polys, vertexAlloc); 47 breadcrumbList->concat(std::move(fBreadcrumbList)); 48 return vertexCount; 49 } 50 }; 51 52 #else 53 54 // Stub out GrInnerFanTriangulator::BreadcrumbTriangleList for function declarations. 55 namespace GrInnerFanTriangulator { 56 struct BreadcrumbTriangleList { 57 BreadcrumbTriangleList() = delete; 58 }; 59 }; 60 61 #endif // SK_ENABLE_OPTIMIZE_SIZE 62 63 #endif // GrInnerFanTriangulator_DEFINED 64