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