SkVertState.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #ifndef SkVertState_DEFINED
  8. #define SkVertState_DEFINED
  9. #include "include/core/SkVertices.h"
  10. /** \struct VertState
  11. This is a helper for drawVertices(). It is used to iterate over the triangles
  12. that are to be rendered based on an SkCanvas::VertexMode and (optionally) an
  13. index array. It does not copy the index array and the client must ensure it
  14. remains valid for the lifetime of the VertState object.
  15. */
  16. struct VertState {
  17. int f0, f1, f2;
  18. /**
  19. * Construct a VertState from a vertex count, index array, and index count.
  20. * If the vertices are unindexed pass nullptr for indices.
  21. */
  22. VertState(int vCount, const uint16_t indices[], int indexCount)
  23. : fIndices(indices) {
  24. fCurrIndex = 0;
  25. if (indices) {
  26. fCount = indexCount;
  27. } else {
  28. fCount = vCount;
  29. }
  30. }
  31. typedef bool (*Proc)(VertState*);
  32. /**
  33. * Choose an appropriate function to traverse the vertices.
  34. * @param mode Specifies the SkCanvas::VertexMode.
  35. */
  36. Proc chooseProc(SkVertices::VertexMode mode);
  37. private:
  38. int fCount;
  39. int fCurrIndex;
  40. const uint16_t* fIndices;
  41. static bool Triangles(VertState*);
  42. static bool TrianglesX(VertState*);
  43. static bool TriangleStrip(VertState*);
  44. static bool TriangleStripX(VertState*);
  45. static bool TriangleFan(VertState*);
  46. static bool TriangleFanX(VertState*);
  47. };
  48. #endif