blob: bff8033d7ae980a4fb9404d05e8f8946eebf26ca [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
Chris Dalton17dc4182020-03-25 16:18:16 -06008#ifndef GrTriangulator_DEFINED
9#define GrTriangulator_DEFINED
ethannicholase9709e82016-01-07 13:34:16 -080010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkPoint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/private/SkColorData.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040013#include "src/gpu/GrColor.h"
senorblanco6599eff2016-03-10 08:38:45 -080014
Chris Daltond081dce2020-01-23 12:09:04 -070015class GrEagerVertexAllocator;
senorblanco6599eff2016-03-10 08:38:45 -080016class SkPath;
17struct SkRect;
ethannicholase9709e82016-01-07 13:34:16 -080018
19/**
20 * Provides utility functions for converting paths to a collection of triangles.
21 */
22
Chris Dalton17dc4182020-03-25 16:18:16 -060023#define TRIANGULATOR_WIREFRAME 0
ethannicholase9709e82016-01-07 13:34:16 -080024
Chris Dalton17dc4182020-03-25 16:18:16 -060025namespace GrTriangulator {
ethannicholase9709e82016-01-07 13:34:16 -080026
27struct 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!
halcanary9d524f22016-03-29 09:03:52 -070036int PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
ethannicholase9709e82016-01-07 13:34:16 -080037 WindingVertex** verts);
38
Chris Daltondcc8c542020-01-28 17:55:56 -070039enum class Mode {
40 kNormal,
Chris Dalton6ccc0322020-01-29 11:38:16 -070041
42 // Surround path edges with coverage ramps for antialiasing.
43 kEdgeAntialias,
44
Chris Dalton17dc4182020-03-25 16:18:16 -060045 // Triangulate only each contour's inner polygon. The inner polygons connect the endpoints of
Chris Dalton6ccc0322020-01-29 11:38:16 -070046 // 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
Chris Daltondcc8c542020-01-28 17:55:56 -070052};
53
54constexpr size_t GetVertexStride(Mode mode) {
55 return sizeof(SkPoint) + ((Mode::kEdgeAntialias == mode) ? sizeof(float) : 0);
Chris Daltond081dce2020-01-23 12:09:04 -070056}
57
Ben Wagner63fd7602017-10-09 15:45:33 -040058int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
Chris Dalton86d4cfd2020-11-03 13:51:21 -070059 GrEagerVertexAllocator*, Mode, bool *isLinear);
John Stilesa6841be2020-08-06 14:11:56 -040060} // namespace GrTriangulator
ethannicholase9709e82016-01-07 13:34:16 -080061
62#endif