1559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org/* 2559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org * Copyright 2014 Google Inc. 3559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org * 4559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be 5559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org * found in the LICENSE file. 6559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org */ 7559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org 8559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org#include "SkVertState.h" 9559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org 10559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgbool VertState::Triangles(VertState* state) { 11559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org int index = state->fCurrIndex; 12559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org if (index + 3 > state->fCount) { 13559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return false; 14559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org } 15559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f0 = index + 0; 16559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f1 = index + 1; 17559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f2 = index + 2; 18559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->fCurrIndex = index + 3; 19559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return true; 20559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org} 21559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org 22559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgbool VertState::TrianglesX(VertState* state) { 23559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org const uint16_t* indices = state->fIndices; 24559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org int index = state->fCurrIndex; 25559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org if (index + 3 > state->fCount) { 26559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return false; 27559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org } 28559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f0 = indices[index + 0]; 29559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f1 = indices[index + 1]; 30559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f2 = indices[index + 2]; 31559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->fCurrIndex = index + 3; 32559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return true; 33559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org} 34559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org 35559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgbool VertState::TriangleStrip(VertState* state) { 36559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org int index = state->fCurrIndex; 37559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org if (index + 3 > state->fCount) { 38559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return false; 39559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org } 40559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f2 = index + 2; 41559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org if (index & 1) { 42559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f0 = index + 1; 43559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f1 = index + 0; 44559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org } else { 45559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f0 = index + 0; 46559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f1 = index + 1; 47559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org } 48559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->fCurrIndex = index + 1; 49559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return true; 50559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org} 51559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org 52559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgbool VertState::TriangleStripX(VertState* state) { 53559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org const uint16_t* indices = state->fIndices; 54559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org int index = state->fCurrIndex; 55559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org if (index + 3 > state->fCount) { 56559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return false; 57559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org } 58559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f2 = indices[index + 2]; 59559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org if (index & 1) { 60559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f0 = indices[index + 1]; 61559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f1 = indices[index + 0]; 62559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org } else { 63559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f0 = indices[index + 0]; 64559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f1 = indices[index + 1]; 65559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org } 66559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->fCurrIndex = index + 1; 67559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return true; 68559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org} 69559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org 70559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgbool VertState::TriangleFan(VertState* state) { 71559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org int index = state->fCurrIndex; 72559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org if (index + 3 > state->fCount) { 73559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return false; 74559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org } 75559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f0 = 0; 76559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f1 = index + 1; 77559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f2 = index + 2; 78559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->fCurrIndex = index + 1; 79559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return true; 80559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org} 81559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org 82559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgbool VertState::TriangleFanX(VertState* state) { 83559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org const uint16_t* indices = state->fIndices; 84559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org int index = state->fCurrIndex; 85559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org if (index + 3 > state->fCount) { 86559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return false; 87559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org } 88559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f0 = indices[0]; 89559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f1 = indices[index + 1]; 90559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->f2 = indices[index + 2]; 91559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org state->fCurrIndex = index + 1; 92559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return true; 93559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org} 94559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org 95559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgVertState::Proc VertState::chooseProc(SkCanvas::VertexMode mode) { 96559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org switch (mode) { 97559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org case SkCanvas::kTriangles_VertexMode: 98559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return fIndices ? TrianglesX : Triangles; 99559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org case SkCanvas::kTriangleStrip_VertexMode: 100559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return fIndices ? TriangleStripX : TriangleStrip; 101559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org case SkCanvas::kTriangleFan_VertexMode: 102559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return fIndices ? TriangleFanX : TriangleFan; 103559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org default: 104559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org return NULL; 105559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org } 106559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org} 107