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 | |
| 8 | #ifndef GrTessellator_DEFINED |
| 9 | #define GrTessellator_DEFINED |
| 10 | |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 11 | #include "GrColor.h" |
Cary Clark | a4083c9 | 2017-09-15 11:59:23 -0400 | [diff] [blame] | 12 | #include "SkColorData.h" |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 13 | #include "SkPoint.h" |
| 14 | |
| 15 | class SkPath; |
| 16 | struct SkRect; |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * Provides utility functions for converting paths to a collection of triangles. |
| 20 | */ |
| 21 | |
| 22 | #define TESSELLATOR_WIREFRAME 0 |
| 23 | |
| 24 | namespace GrTessellator { |
| 25 | |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 26 | class VertexAllocator { |
| 27 | public: |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 28 | VertexAllocator(size_t stride) : fStride(stride) {} |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 29 | virtual ~VertexAllocator() {} |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 30 | virtual void* lock(int vertexCount) = 0; |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 31 | virtual void unlock(int actualCount) = 0; |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 32 | size_t stride() const { return fStride; } |
| 33 | private: |
| 34 | size_t fStride; |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 35 | }; |
| 36 | |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 37 | struct 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! |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 46 | int PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds, |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 47 | WindingVertex** verts); |
| 48 | |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 49 | int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds, |
Brian Osman | 0995fd5 | 2019-01-09 09:52:25 -0500 | [diff] [blame] | 50 | VertexAllocator*, bool antialias, bool *isLinear); |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | #endif |