PathOpsOpCubicThreadedTest.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/PathOpsDebug.h"
  9. #include "tests/PathOpsExtendedTest.h"
  10. #include "tests/PathOpsThreadedCommon.h"
  11. #include <atomic>
  12. static int loopNo = 158;
  13. static std::atomic<int> gCubicsTestNo{0};
  14. static void testOpCubicsMain(PathOpsThreadState* data) {
  15. #if DEBUG_SHOW_TEST_NAME
  16. strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
  17. #endif
  18. SkASSERT(data);
  19. PathOpsThreadState& state = *data;
  20. SkString pathStr;
  21. for (int a = 0 ; a < 6; ++a) {
  22. for (int b = a + 1 ; b < 7; ++b) {
  23. for (int c = 0 ; c < 6; ++c) {
  24. for (int d = c + 1 ; d < 7; ++d) {
  25. for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) {
  26. for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f) {
  27. SkPath pathA, pathB;
  28. pathA.setFillType((SkPath::FillType) e);
  29. pathA.moveTo(SkIntToScalar(state.fA), SkIntToScalar(state.fB));
  30. pathA.cubicTo(SkIntToScalar(state.fC), SkIntToScalar(state.fD), SkIntToScalar(b),
  31. SkIntToScalar(a), SkIntToScalar(d), SkIntToScalar(c));
  32. pathA.close();
  33. pathB.setFillType((SkPath::FillType) f);
  34. pathB.moveTo(SkIntToScalar(a), SkIntToScalar(b));
  35. pathB.cubicTo(SkIntToScalar(c), SkIntToScalar(d), SkIntToScalar(state.fB),
  36. SkIntToScalar(state.fA), SkIntToScalar(state.fD), SkIntToScalar(state.fC));
  37. pathB.close();
  38. for (int op = 0 ; op <= kXOR_SkPathOp; ++op) {
  39. if (state.fReporter->verbose()) {
  40. pathStr.printf("static void cubicOp%d(skiatest::Reporter* reporter,"
  41. " const char* filename) {\n", loopNo);
  42. pathStr.appendf(" SkPath path, pathB;\n");
  43. pathStr.appendf(" path.setFillType(SkPath::k%s_FillType);\n",
  44. e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType
  45. ? "EvenOdd" : "?UNDEFINED");
  46. pathStr.appendf(" path.moveTo(%d,%d);\n", state.fA, state.fB);
  47. pathStr.appendf(" path.cubicTo(%d,%d, %d,%d, %d,%d);\n", state.fC, state.fD,
  48. b, a, d, c);
  49. pathStr.appendf(" path.close();\n");
  50. pathStr.appendf(" pathB.setFillType(SkPath::k%s_FillType);\n",
  51. f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType
  52. ? "EvenOdd" : "?UNDEFINED");
  53. pathStr.appendf(" pathB.moveTo(%d,%d);\n", a, b);
  54. pathStr.appendf(" pathB.cubicTo(%d,%d, %d,%d, %d,%d);\n", c, d,
  55. state.fB, state.fA, state.fD, state.fC);
  56. pathStr.appendf(" pathB.close();\n");
  57. pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
  58. SkPathOpsDebug::OpStr((SkPathOp) op));
  59. pathStr.appendf("}\n");
  60. state.outputProgress(pathStr.c_str(), (SkPathOp) op);
  61. }
  62. SkString testName;
  63. testName.printf("thread_cubics%d", ++gCubicsTestNo);
  64. if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
  65. if (state.fReporter->verbose()) {
  66. ++loopNo;
  67. goto skipToNext;
  68. }
  69. }
  70. if (PathOpsDebug::gCheckForDuplicateNames) return;
  71. }
  72. }
  73. }
  74. skipToNext: ;
  75. }
  76. }
  77. }
  78. }
  79. }
  80. DEF_TEST(PathOpsOpCubicsThreaded, reporter) {
  81. initializeTests(reporter, "cubicOp");
  82. PathOpsThreadedTestRunner testRunner(reporter);
  83. for (int a = 0; a < 6; ++a) { // outermost
  84. for (int b = a + 1; b < 7; ++b) {
  85. for (int c = 0 ; c < 6; ++c) {
  86. for (int d = c + 1; d < 7; ++d) {
  87. *testRunner.fRunnables.append() =
  88. new PathOpsThreadedRunnable(&testOpCubicsMain, a, b, c, d, &testRunner);
  89. }
  90. }
  91. if (!reporter->allowExtendedTest()) goto finish;
  92. }
  93. }
  94. finish:
  95. testRunner.render();
  96. }