Flutter Engine
The Flutter Engine
GrAATriangulator.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google Inc.
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 GrAATriangulator_DEFINED
9#define GrAATriangulator_DEFINED
10
12#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
13
18
19#include <cstdint>
20#include <tuple>
21
23class SkPath;
24struct SkRect;
25
26// Triangulates the given path in device space with a mesh of alpha ramps for antialiasing.
28public:
29 static int PathToAATriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
30 GrEagerVertexAllocator* vertexAllocator) {
32 GrAATriangulator aaTriangulator(path, &alloc);
33 aaTriangulator.fRoundVerticesToQuarterPixel = true;
34 aaTriangulator.fEmitCoverage = true;
35 bool isLinear;
36 auto [ polys, success ] = aaTriangulator.pathToPolys(tolerance, clipBounds, &isLinear);
37 if (!success) {
38 return 0;
39 }
40 return aaTriangulator.polysToAATriangles(polys, vertexAllocator);
41 }
42
43 // Structs used by GrAATriangulator internals.
44 struct SSEdge;
45 struct EventList;
46 struct Event {
47 Event(SSEdge* edge, const SkPoint& point, uint8_t alpha)
48 : fEdge(edge), fPoint(point), fAlpha(alpha) {}
51 uint8_t fAlpha;
52 void apply(VertexList* mesh, const Comparator&, EventList* events, GrAATriangulator*);
53 };
55 enum class Op { kLessThan, kGreaterThan };
56 EventComparator(Op op) : fOp(op) {}
57 bool operator() (Event* const &e1, Event* const &e2) {
58 return fOp == Op::kLessThan ? e1->fAlpha < e2->fAlpha
59 : e1->fAlpha > e2->fAlpha;
60 }
62 };
63
64private:
65 GrAATriangulator(const SkPath& path, SkArenaAlloc* alloc) : GrTriangulator(path, alloc) {}
66
67 // For screenspace antialiasing, the algorithm is modified as follows:
68 //
69 // Run steps 1-5 above to produce polygons.
70 // 5b) Apply fill rules to extract boundary contours from the polygons:
71 void extractBoundary(EdgeList* boundary, Edge* e) const;
72 void extractBoundaries(const VertexList& inMesh, VertexList* innerVertices,
73 const Comparator&);
74
75 // 5c) Simplify boundaries to remove "pointy" vertices that cause inversions:
76 void simplifyBoundary(EdgeList* boundary, const Comparator&);
77
78 // 5d) Displace edges by half a pixel inward and outward along their normals. Intersect to find
79 // new vertices, and set zero alpha on the exterior and one alpha on the interior. Build a
80 // new antialiased mesh from those vertices:
81 void strokeBoundary(EdgeList* boundary, VertexList* innerMesh, const Comparator&);
82
83 // Run steps 3-6 above on the new mesh, and produce antialiased triangles.
84 std::tuple<Poly*, bool> tessellate(const VertexList& mesh, const Comparator&) override;
85 int polysToAATriangles(Poly*, GrEagerVertexAllocator*) const;
86
87 // Additional helpers and driver functions.
88 void makeEvent(SSEdge*, EventList* events) const;
89 void makeEvent(SSEdge*, Vertex* v, SSEdge* other, Vertex* dest, EventList* events,
90 const Comparator&) const;
91 void connectPartners(VertexList* mesh, const Comparator&);
92 void removeNonBoundaryEdges(const VertexList& mesh) const;
93 void connectSSEdge(Vertex* v, Vertex* dest, const Comparator&);
94 bool collapseOverlapRegions(VertexList* mesh, const Comparator&, EventComparator comp);
95
96 // FIXME: fOuterMesh should be plumbed through function parameters instead.
97 mutable VertexList fOuterMesh;
98};
99
100#endif // SK_ENABLE_OPTIMIZE_SIZE
101
102#endif // GrAATriangulator_DEFINED
float e1
static int PathToAATriangles(const SkPath &path, SkScalar tolerance, const SkRect &clipBounds, GrEagerVertexAllocator *vertexAllocator)
static constexpr int kArenaDefaultChunkSize
Definition: SkPath.h:59
float SkScalar
Definition: extension.cpp:12
SkMesh mesh
Definition: SkRecords.h:345
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
dest
Definition: zip.py:79
bool operator()(Event *const &e1, Event *const &e2)
Event(SSEdge *edge, const SkPoint &point, uint8_t alpha)
void apply(VertexList *mesh, const Comparator &, EventList *events, GrAATriangulator *)