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