blob: dd92015cc2a6d4a3d57b3bbb600c479da67c81f1 [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
senorblancof57372d2016-08-31 10:36:19 -070011#include "GrColor.h"
senorblanco6599eff2016-03-10 08:38:45 -080012#include "SkPoint.h"
13
14class SkPath;
15struct SkRect;
ethannicholase9709e82016-01-07 13:34:16 -080016
17/**
18 * Provides utility functions for converting paths to a collection of triangles.
19 */
20
21#define TESSELLATOR_WIREFRAME 0
22
23namespace GrTessellator {
24
senorblanco6599eff2016-03-10 08:38:45 -080025class VertexAllocator {
26public:
senorblancof57372d2016-08-31 10:36:19 -070027 VertexAllocator(size_t stride) : fStride(stride) {}
senorblanco6599eff2016-03-10 08:38:45 -080028 virtual ~VertexAllocator() {}
senorblancof57372d2016-08-31 10:36:19 -070029 virtual void* lock(int vertexCount) = 0;
senorblanco6599eff2016-03-10 08:38:45 -080030 virtual void unlock(int actualCount) = 0;
senorblancof57372d2016-08-31 10:36:19 -070031 size_t stride() const { return fStride; }
32private:
33 size_t fStride;
senorblanco6599eff2016-03-10 08:38:45 -080034};
35
ethannicholase9709e82016-01-07 13:34:16 -080036struct WindingVertex {
37 SkPoint fPos;
38 int fWinding;
39};
40
41// Triangulates a path to an array of vertices. Each triangle is represented as a set of three
42// WindingVertex entries, each of which contains the position and winding count (which is the same
43// for all three vertices of a triangle). The 'verts' out parameter is set to point to the resultant
44// vertex array. CALLER IS RESPONSIBLE for deleting this buffer to avoid a memory leak!
halcanary9d524f22016-03-29 09:03:52 -070045int PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
ethannicholase9709e82016-01-07 13:34:16 -080046 WindingVertex** verts);
47
senorblancof57372d2016-08-31 10:36:19 -070048int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
49 VertexAllocator*, bool antialias, const GrColor& color,
50 bool canTweakAlphaForCoverage, bool *isLinear);
ethannicholase9709e82016-01-07 13:34:16 -080051}
52
53#endif