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