blob: 7cc4311aa575f1e4df2e818e34a831066033aadb [file] [log] [blame]
ethannicholase9709e82016-01-07 13:34:16 -08001/*
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
senorblanco6599eff2016-03-10 08:38:45 -080011#include "SkPoint.h"
12
13class SkPath;
14struct SkRect;
ethannicholase9709e82016-01-07 13:34:16 -080015
16/**
17 * Provides utility functions for converting paths to a collection of triangles.
18 */
19
20#define TESSELLATOR_WIREFRAME 0
21
22namespace GrTessellator {
23
senorblanco6599eff2016-03-10 08:38:45 -080024class VertexAllocator {
25public:
26 virtual ~VertexAllocator() {}
27 virtual SkPoint* lock(int vertexCount) = 0;
28 virtual void unlock(int actualCount) = 0;
29};
30
ethannicholase9709e82016-01-07 13:34:16 -080031struct WindingVertex {
32 SkPoint fPos;
33 int fWinding;
34};
35
36// Triangulates a path to an array of vertices. Each triangle is represented as a set of three
37// WindingVertex entries, each of which contains the position and winding count (which is the same
38// for all three vertices of a triangle). The 'verts' out parameter is set to point to the resultant
39// vertex array. CALLER IS RESPONSIBLE for deleting this buffer to avoid a memory leak!
halcanary9d524f22016-03-29 09:03:52 -070040int PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
ethannicholase9709e82016-01-07 13:34:16 -080041 WindingVertex** verts);
42
halcanary9d524f22016-03-29 09:03:52 -070043int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
senorblanco6599eff2016-03-10 08:38:45 -080044 VertexAllocator*, bool *isLinear);
ethannicholase9709e82016-01-07 13:34:16 -080045}
46
47#endif