commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 SkVertState_DEFINED |
| 9 | #define SkVertState_DEFINED |
| 10 | |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 11 | #include "SkVertices.h" |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 12 | |
| 13 | /** \struct VertState |
| 14 | This is a helper for drawVertices(). It is used to iterate over the triangles |
| 15 | that are to be rendered based on an SkCanvas::VertexMode and (optionally) an |
| 16 | index array. It does not copy the index array and the client must ensure it |
| 17 | remains valid for the lifetime of the VertState object. |
| 18 | */ |
| 19 | |
| 20 | struct VertState { |
| 21 | int f0, f1, f2; |
| 22 | |
| 23 | /** |
| 24 | * Construct a VertState from a vertex count, index array, and index count. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 25 | * If the vertices are unindexed pass nullptr for indices. |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 26 | */ |
| 27 | VertState(int vCount, const uint16_t indices[], int indexCount) |
| 28 | : fIndices(indices) { |
| 29 | fCurrIndex = 0; |
| 30 | if (indices) { |
| 31 | fCount = indexCount; |
| 32 | } else { |
| 33 | fCount = vCount; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | typedef bool (*Proc)(VertState*); |
| 38 | |
| 39 | /** |
| 40 | * Choose an appropriate function to traverse the vertices. |
| 41 | * @param mode Specifies the SkCanvas::VertexMode. |
| 42 | */ |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 43 | Proc chooseProc(SkVertices::VertexMode mode); |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 44 | |
| 45 | private: |
| 46 | int fCount; |
| 47 | int fCurrIndex; |
| 48 | const uint16_t* fIndices; |
| 49 | |
| 50 | static bool Triangles(VertState*); |
| 51 | static bool TrianglesX(VertState*); |
| 52 | static bool TriangleStrip(VertState*); |
| 53 | static bool TriangleStripX(VertState*); |
| 54 | static bool TriangleFan(VertState*); |
| 55 | static bool TriangleFanX(VertState*); |
| 56 | }; |
| 57 | |
| 58 | #endif |