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#include "src/core/SkVertState.h" 9cb93a386Sopenharmony_ci 10cb93a386Sopenharmony_cibool VertState::Triangles(VertState* state) { 11cb93a386Sopenharmony_ci int index = state->fCurrIndex; 12cb93a386Sopenharmony_ci if (index + 3 > state->fCount) { 13cb93a386Sopenharmony_ci return false; 14cb93a386Sopenharmony_ci } 15cb93a386Sopenharmony_ci state->f0 = index + 0; 16cb93a386Sopenharmony_ci state->f1 = index + 1; 17cb93a386Sopenharmony_ci state->f2 = index + 2; 18cb93a386Sopenharmony_ci state->fCurrIndex = index + 3; 19cb93a386Sopenharmony_ci return true; 20cb93a386Sopenharmony_ci} 21cb93a386Sopenharmony_ci 22cb93a386Sopenharmony_cibool VertState::TrianglesX(VertState* state) { 23cb93a386Sopenharmony_ci const uint16_t* indices = state->fIndices; 24cb93a386Sopenharmony_ci int index = state->fCurrIndex; 25cb93a386Sopenharmony_ci if (index + 3 > state->fCount) { 26cb93a386Sopenharmony_ci return false; 27cb93a386Sopenharmony_ci } 28cb93a386Sopenharmony_ci state->f0 = indices[index + 0]; 29cb93a386Sopenharmony_ci state->f1 = indices[index + 1]; 30cb93a386Sopenharmony_ci state->f2 = indices[index + 2]; 31cb93a386Sopenharmony_ci state->fCurrIndex = index + 3; 32cb93a386Sopenharmony_ci return true; 33cb93a386Sopenharmony_ci} 34cb93a386Sopenharmony_ci 35cb93a386Sopenharmony_cibool VertState::TriangleStrip(VertState* state) { 36cb93a386Sopenharmony_ci int index = state->fCurrIndex; 37cb93a386Sopenharmony_ci if (index + 3 > state->fCount) { 38cb93a386Sopenharmony_ci return false; 39cb93a386Sopenharmony_ci } 40cb93a386Sopenharmony_ci state->f2 = index + 2; 41cb93a386Sopenharmony_ci if (index & 1) { 42cb93a386Sopenharmony_ci state->f0 = index + 1; 43cb93a386Sopenharmony_ci state->f1 = index + 0; 44cb93a386Sopenharmony_ci } else { 45cb93a386Sopenharmony_ci state->f0 = index + 0; 46cb93a386Sopenharmony_ci state->f1 = index + 1; 47cb93a386Sopenharmony_ci } 48cb93a386Sopenharmony_ci state->fCurrIndex = index + 1; 49cb93a386Sopenharmony_ci return true; 50cb93a386Sopenharmony_ci} 51cb93a386Sopenharmony_ci 52cb93a386Sopenharmony_cibool VertState::TriangleStripX(VertState* state) { 53cb93a386Sopenharmony_ci const uint16_t* indices = state->fIndices; 54cb93a386Sopenharmony_ci int index = state->fCurrIndex; 55cb93a386Sopenharmony_ci if (index + 3 > state->fCount) { 56cb93a386Sopenharmony_ci return false; 57cb93a386Sopenharmony_ci } 58cb93a386Sopenharmony_ci state->f2 = indices[index + 2]; 59cb93a386Sopenharmony_ci if (index & 1) { 60cb93a386Sopenharmony_ci state->f0 = indices[index + 1]; 61cb93a386Sopenharmony_ci state->f1 = indices[index + 0]; 62cb93a386Sopenharmony_ci } else { 63cb93a386Sopenharmony_ci state->f0 = indices[index + 0]; 64cb93a386Sopenharmony_ci state->f1 = indices[index + 1]; 65cb93a386Sopenharmony_ci } 66cb93a386Sopenharmony_ci state->fCurrIndex = index + 1; 67cb93a386Sopenharmony_ci return true; 68cb93a386Sopenharmony_ci} 69cb93a386Sopenharmony_ci 70cb93a386Sopenharmony_cibool VertState::TriangleFan(VertState* state) { 71cb93a386Sopenharmony_ci int index = state->fCurrIndex; 72cb93a386Sopenharmony_ci if (index + 3 > state->fCount) { 73cb93a386Sopenharmony_ci return false; 74cb93a386Sopenharmony_ci } 75cb93a386Sopenharmony_ci state->f0 = 0; 76cb93a386Sopenharmony_ci state->f1 = index + 1; 77cb93a386Sopenharmony_ci state->f2 = index + 2; 78cb93a386Sopenharmony_ci state->fCurrIndex = index + 1; 79cb93a386Sopenharmony_ci return true; 80cb93a386Sopenharmony_ci} 81cb93a386Sopenharmony_ci 82cb93a386Sopenharmony_cibool VertState::TriangleFanX(VertState* state) { 83cb93a386Sopenharmony_ci const uint16_t* indices = state->fIndices; 84cb93a386Sopenharmony_ci int index = state->fCurrIndex; 85cb93a386Sopenharmony_ci if (index + 3 > state->fCount) { 86cb93a386Sopenharmony_ci return false; 87cb93a386Sopenharmony_ci } 88cb93a386Sopenharmony_ci state->f0 = indices[0]; 89cb93a386Sopenharmony_ci state->f1 = indices[index + 1]; 90cb93a386Sopenharmony_ci state->f2 = indices[index + 2]; 91cb93a386Sopenharmony_ci state->fCurrIndex = index + 1; 92cb93a386Sopenharmony_ci return true; 93cb93a386Sopenharmony_ci} 94cb93a386Sopenharmony_ci 95cb93a386Sopenharmony_ciVertState::Proc VertState::chooseProc(SkVertices::VertexMode mode) { 96cb93a386Sopenharmony_ci switch (mode) { 97cb93a386Sopenharmony_ci case SkVertices::kTriangles_VertexMode: 98cb93a386Sopenharmony_ci return fIndices ? TrianglesX : Triangles; 99cb93a386Sopenharmony_ci case SkVertices::kTriangleStrip_VertexMode: 100cb93a386Sopenharmony_ci return fIndices ? TriangleStripX : TriangleStrip; 101cb93a386Sopenharmony_ci case SkVertices::kTriangleFan_VertexMode: 102cb93a386Sopenharmony_ci return fIndices ? TriangleFanX : TriangleFan; 103cb93a386Sopenharmony_ci default: 104cb93a386Sopenharmony_ci return nullptr; 105cb93a386Sopenharmony_ci } 106cb93a386Sopenharmony_ci} 107