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 "GrColor.h"
12 #include "SkColorData.h"
13 #include "SkPoint.h"
14 
15 class SkPath;
16 struct SkRect;
17 
18 /**
19  * Provides utility functions for converting paths to a collection of triangles.
20  */
21 
22 #define TESSELLATOR_WIREFRAME 0
23 
24 namespace GrTessellator {
25 
26 class VertexAllocator {
27 public:
28     VertexAllocator(size_t stride) : fStride(stride) {}
29     virtual ~VertexAllocator() {}
30     virtual void* lock(int vertexCount) = 0;
31     virtual void unlock(int actualCount) = 0;
32     size_t stride() const { return fStride; }
33 private:
34     size_t fStride;
35 };
36 
37 struct WindingVertex {
38     SkPoint fPos;
39     int fWinding;
40 };
41 
42 // Triangulates a path to an array of vertices. Each triangle is represented as a set of three
43 // WindingVertex entries, each of which contains the position and winding count (which is the same
44 // for all three vertices of a triangle). The 'verts' out parameter is set to point to the resultant
45 // vertex array. CALLER IS RESPONSIBLE for deleting this buffer to avoid a memory leak!
46 int PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
47                    WindingVertex** verts);
48 
49 int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
50                     VertexAllocator*, bool antialias, bool *isLinear);
51 }
52 
53 #endif
54