ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 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 | |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 8 | #ifndef GrTriangulator_DEFINED |
| 9 | #define GrTriangulator_DEFINED |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkPoint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/private/SkColorData.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrColor.h" |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 14 | |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 15 | class GrEagerVertexAllocator; |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 16 | class SkPath; |
| 17 | struct SkRect; |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 18 | |
| 19 | /** |
| 20 | * Provides utility functions for converting paths to a collection of triangles. |
| 21 | */ |
| 22 | |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 23 | #define TRIANGULATOR_WIREFRAME 0 |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 24 | |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 25 | namespace GrTriangulator { |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 26 | |
| 27 | struct 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! |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 36 | int PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds, |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 37 | WindingVertex** verts); |
| 38 | |
Chris Dalton | dcc8c54 | 2020-01-28 17:55:56 -0700 | [diff] [blame] | 39 | enum class Mode { |
| 40 | kNormal, |
Chris Dalton | 6ccc032 | 2020-01-29 11:38:16 -0700 | [diff] [blame] | 41 | |
| 42 | // Surround path edges with coverage ramps for antialiasing. |
| 43 | kEdgeAntialias, |
| 44 | |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 45 | // Triangulate only each contour's inner polygon. The inner polygons connect the endpoints of |
Chris Dalton | 6ccc032 | 2020-01-29 11:38:16 -0700 | [diff] [blame] | 46 | // 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 Dalton | dcc8c54 | 2020-01-28 17:55:56 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | constexpr size_t GetVertexStride(Mode mode) { |
| 55 | return sizeof(SkPoint) + ((Mode::kEdgeAntialias == mode) ? sizeof(float) : 0); |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 58 | int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds, |
Chris Dalton | 86d4cfd | 2020-11-03 13:51:21 -0700 | [diff] [blame] | 59 | GrEagerVertexAllocator*, Mode, bool *isLinear); |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 60 | } // namespace GrTriangulator |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 61 | |
| 62 | #endif |