SkVertState.cpp 2.7 KB

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