PathOpsSimplifyDegenerateThreadedTest.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright 2012 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 "include/core/SkString.h"
  8. #include "tests/PathOpsExtendedTest.h"
  9. #include "tests/PathOpsThreadedCommon.h"
  10. static void testSimplifyDegeneratesMain(PathOpsThreadState* data) {
  11. SkASSERT(data);
  12. PathOpsThreadState& state = *data;
  13. int ax = state.fA & 0x03;
  14. int ay = state.fA >> 2;
  15. int bx = state.fB & 0x03;
  16. int by = state.fB >> 2;
  17. int cx = state.fC & 0x03;
  18. int cy = state.fC >> 2;
  19. for (int d = 0; d < 16; ++d) {
  20. int dx = d & 0x03;
  21. int dy = d >> 2;
  22. for (int e = d ; e < 16; ++e) {
  23. int ex = e & 0x03;
  24. int ey = e >> 2;
  25. for (int f = d ; f < 16; ++f) {
  26. int fx = f & 0x03;
  27. int fy = f >> 2;
  28. if (state.fD && (ex - dx) * (fy - dy)
  29. != (ey - dy) * (fx - dx)) {
  30. continue;
  31. }
  32. SkString pathStr;
  33. SkPath path, out;
  34. path.setFillType(SkPath::kWinding_FillType);
  35. path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
  36. path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
  37. path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
  38. path.close();
  39. path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy));
  40. path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey));
  41. path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
  42. path.close();
  43. if (state.fReporter->verbose()) {
  44. pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay);
  45. pathStr.appendf(" path.lineTo(%d, %d);\n", bx, by);
  46. pathStr.appendf(" path.lineTo(%d, %d);\n", cx, cy);
  47. pathStr.appendf(" path.close();\n");
  48. pathStr.appendf(" path.moveTo(%d, %d);\n", dx, dy);
  49. pathStr.appendf(" path.lineTo(%d, %d);\n", ex, ey);
  50. pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy);
  51. pathStr.appendf(" path.close();\n");
  52. state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType);
  53. }
  54. testSimplify(path, false, out, state, pathStr.c_str());
  55. path.setFillType(SkPath::kEvenOdd_FillType);
  56. if (state.fReporter->verbose()) {
  57. state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType);
  58. }
  59. testSimplify(path, true, out, state, pathStr.c_str());
  60. }
  61. }
  62. }
  63. }
  64. DEF_TEST(PathOpsSimplifyDegeneratesThreaded, reporter) {
  65. initializeTests(reporter, "testDegenerates");
  66. PathOpsThreadedTestRunner testRunner(reporter);
  67. for (int a = 0; a < 16; ++a) {
  68. int ax = a & 0x03;
  69. int ay = a >> 2;
  70. for (int b = a ; b < 16; ++b) {
  71. int bx = b & 0x03;
  72. int by = b >> 2;
  73. for (int c = a ; c < 16; ++c) {
  74. int cx = c & 0x03;
  75. int cy = c >> 2;
  76. bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax);
  77. *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
  78. &testSimplifyDegeneratesMain, a, b, c, abcIsATriangle, &testRunner);
  79. }
  80. if (!reporter->allowExtendedTest()) goto finish;
  81. }
  82. }
  83. finish:
  84. testRunner.render();
  85. }