• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 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 GrTessellator_DEFINED
9 #define GrTessellator_DEFINED
10 
11 #include "include/core/SkPoint.h"
12 #include "include/private/SkColorData.h"
13 #include "src/gpu/GrColor.h"
14 
15 class GrEagerVertexAllocator;
16 class SkPath;
17 struct SkRect;
18 
19 /**
20  * Provides utility functions for converting paths to a collection of triangles.
21  */
22 
23 #define TESSELLATOR_WIREFRAME 0
24 
25 namespace GrTessellator {
26 
27 struct WindingVertex {
28     SkPoint fPos;
29     int fWinding;
30 };
31 
32 // Triangulates a path to an array of vertices. Each triangle is represented as a set of three
33 // WindingVertex entries, each of which contains the position and winding count (which is the same
34 // for all three vertices of a triangle). The 'verts' out parameter is set to point to the resultant
35 // vertex array. CALLER IS RESPONSIBLE for deleting this buffer to avoid a memory leak!
36 int PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
37                    WindingVertex** verts);
38 
39 enum class Mode {
40     kNormal,
41 
42     // Surround path edges with coverage ramps for antialiasing.
43     kEdgeAntialias,
44 
45     // Tessellate only each contour's inner polygon. The inner polygons connect the endpoints of
46     // each verb. (i.e., they are the path that would result from collapsing all curves to single
47     // lines.)
48     //
49     // If the inner polygons are not simple (e.g., self intersection, double winding), then the
50     // tessellator aborts and returns 0.
51     kSimpleInnerPolygons
52 };
53 
GetVertexStride(Mode mode)54 constexpr size_t GetVertexStride(Mode mode) {
55     return sizeof(SkPoint) + ((Mode::kEdgeAntialias == mode) ? sizeof(float) : 0);
56 }
57 
58 int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
59                     GrEagerVertexAllocator*, Mode, bool *isLinear);
60 }
61 
62 #endif
63