blob: 4f82ea8b8c32da9ee96b01bf25d3d5fab2b87ec4 [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"
Cary Clarka4083c92017-09-15 11:59:23 -040012#include "SkColorData.h"
senorblanco6599eff2016-03-10 08:38:45 -080013#include "SkPoint.h"
14
15class SkPath;
16struct SkRect;
ethannicholase9709e82016-01-07 13:34:16 -080017
18/**
19 * Provides utility functions for converting paths to a collection of triangles.
20 */
21
22#define TESSELLATOR_WIREFRAME 0
23
24namespace GrTessellator {
25
senorblanco6599eff2016-03-10 08:38:45 -080026class VertexAllocator {
27public:
senorblancof57372d2016-08-31 10:36:19 -070028 VertexAllocator(size_t stride) : fStride(stride) {}
senorblanco6599eff2016-03-10 08:38:45 -080029 virtual ~VertexAllocator() {}
senorblancof57372d2016-08-31 10:36:19 -070030 virtual void* lock(int vertexCount) = 0;
senorblanco6599eff2016-03-10 08:38:45 -080031 virtual void unlock(int actualCount) = 0;
senorblancof57372d2016-08-31 10:36:19 -070032 size_t stride() const { return fStride; }
33private:
34 size_t fStride;
senorblanco6599eff2016-03-10 08:38:45 -080035};
36
ethannicholase9709e82016-01-07 13:34:16 -080037struct 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!
halcanary9d524f22016-03-29 09:03:52 -070046int PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
ethannicholase9709e82016-01-07 13:34:16 -080047 WindingVertex** verts);
48
Ben Wagner63fd7602017-10-09 15:45:33 -040049int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
senorblancof57372d2016-08-31 10:36:19 -070050 VertexAllocator*, bool antialias, const GrColor& color,
51 bool canTweakAlphaForCoverage, bool *isLinear);
ethannicholase9709e82016-01-07 13:34:16 -080052}
53
54#endif