1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2014 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#ifndef SkVertState_DEFINED
9cb93a386Sopenharmony_ci#define SkVertState_DEFINED
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci#include "include/core/SkVertices.h"
12cb93a386Sopenharmony_ci
13cb93a386Sopenharmony_ci/** \struct VertState
14cb93a386Sopenharmony_ci    This is a helper for drawVertices(). It is used to iterate over the triangles
15cb93a386Sopenharmony_ci    that are to be rendered based on an SkCanvas::VertexMode and (optionally) an
16cb93a386Sopenharmony_ci    index array. It does not copy the index array and the client must ensure it
17cb93a386Sopenharmony_ci    remains valid for the lifetime of the VertState object.
18cb93a386Sopenharmony_ci*/
19cb93a386Sopenharmony_ci
20cb93a386Sopenharmony_cistruct VertState {
21cb93a386Sopenharmony_ci    int f0, f1, f2;
22cb93a386Sopenharmony_ci
23cb93a386Sopenharmony_ci    /**
24cb93a386Sopenharmony_ci     *  Construct a VertState from a vertex count, index array, and index count.
25cb93a386Sopenharmony_ci     *  If the vertices are unindexed pass nullptr for indices.
26cb93a386Sopenharmony_ci     */
27cb93a386Sopenharmony_ci    VertState(int vCount, const uint16_t indices[], int indexCount)
28cb93a386Sopenharmony_ci            : fIndices(indices) {
29cb93a386Sopenharmony_ci        fCurrIndex = 0;
30cb93a386Sopenharmony_ci        if (indices) {
31cb93a386Sopenharmony_ci            fCount = indexCount;
32cb93a386Sopenharmony_ci        } else {
33cb93a386Sopenharmony_ci            fCount = vCount;
34cb93a386Sopenharmony_ci        }
35cb93a386Sopenharmony_ci    }
36cb93a386Sopenharmony_ci
37cb93a386Sopenharmony_ci    typedef bool (*Proc)(VertState*);
38cb93a386Sopenharmony_ci
39cb93a386Sopenharmony_ci    /**
40cb93a386Sopenharmony_ci     *  Choose an appropriate function to traverse the vertices.
41cb93a386Sopenharmony_ci     *  @param mode    Specifies the SkCanvas::VertexMode.
42cb93a386Sopenharmony_ci     */
43cb93a386Sopenharmony_ci    Proc chooseProc(SkVertices::VertexMode mode);
44cb93a386Sopenharmony_ci
45cb93a386Sopenharmony_ciprivate:
46cb93a386Sopenharmony_ci    int             fCount;
47cb93a386Sopenharmony_ci    int             fCurrIndex;
48cb93a386Sopenharmony_ci    const uint16_t* fIndices;
49cb93a386Sopenharmony_ci
50cb93a386Sopenharmony_ci    static bool Triangles(VertState*);
51cb93a386Sopenharmony_ci    static bool TrianglesX(VertState*);
52cb93a386Sopenharmony_ci    static bool TriangleStrip(VertState*);
53cb93a386Sopenharmony_ci    static bool TriangleStripX(VertState*);
54cb93a386Sopenharmony_ci    static bool TriangleFan(VertState*);
55cb93a386Sopenharmony_ci    static bool TriangleFanX(VertState*);
56cb93a386Sopenharmony_ci};
57cb93a386Sopenharmony_ci
58cb93a386Sopenharmony_ci#endif
59