PathOpsOpLoopThreadedTest.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 "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 = 17;
  13. static void add_point(SkString* str, SkScalar x, SkScalar y) {
  14. int asInt = SkScalarRoundToInt(x);
  15. if (SkIntToScalar(asInt) == x) {
  16. str->appendf("%d", asInt);
  17. } else {
  18. str->appendf("%1.9gf", x);
  19. }
  20. str->appendf(",");
  21. asInt = SkScalarRoundToInt(y);
  22. if (SkIntToScalar(asInt) == y) {
  23. str->appendf("%d", asInt);
  24. } else {
  25. str->appendf("%1.9gf", y);
  26. }
  27. }
  28. static std::atomic<int> gLoopsTestNo{0};
  29. static void testOpLoopsMain(PathOpsThreadState* data) {
  30. #if DEBUG_SHOW_TEST_NAME
  31. strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
  32. #endif
  33. SkASSERT(data);
  34. PathOpsThreadState& state = *data;
  35. SkString pathStr;
  36. for (int a = 0 ; a < 6; ++a) {
  37. for (int b = a + 1 ; b < 7; ++b) {
  38. for (int c = 0 ; c < 6; ++c) {
  39. for (int d = c + 1 ; d < 7; ++d) {
  40. // define 4 points that form two lines that often cross; one line is (a, b) (c, d)
  41. SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)};
  42. SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6,
  43. SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 };
  44. SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6,
  45. SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 };
  46. SkPoint endC = { midA.fX + v.fY * state.fC / 3,
  47. midA.fY + v.fX * state.fC / 3 };
  48. SkPoint endD = { midB.fX - v.fY * state.fD / 3,
  49. midB.fY + v.fX * state.fD / 3 };
  50. SkPath pathA, pathB;
  51. pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b));
  52. pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY);
  53. pathA.close();
  54. pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d));
  55. pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b));
  56. pathB.close();
  57. // SkDebugf("%s\n", pathStr);
  58. if (state.fReporter->verbose()) {
  59. pathStr.printf("static void loop%d(skiatest::Reporter* reporter,"
  60. " const char* filename) {\n", loopNo);
  61. pathStr.appendf(" SkPath path, pathB;\n");
  62. pathStr.appendf(" path.moveTo(%d,%d);\n", a, b);
  63. pathStr.appendf(" path.cubicTo(%d,%d, ", c, d);
  64. add_point(&pathStr, endC.fX, endC.fY);
  65. pathStr.appendf(", ");
  66. add_point(&pathStr, endD.fX, endD.fY);
  67. pathStr.appendf(");\n");
  68. pathStr.appendf(" path.close();\n");
  69. pathStr.appendf(" pathB.moveTo(%d,%d);\n", c, d);
  70. pathStr.appendf(" pathB.cubicTo(");
  71. add_point(&pathStr, endC.fX, endC.fY);
  72. pathStr.appendf(", ");
  73. add_point(&pathStr, endD.fX, endD.fY);
  74. pathStr.appendf(", %d,%d);\n", a, b);
  75. pathStr.appendf(" pathB.close();\n");
  76. pathStr.appendf(" testPathOp(reporter, path, pathB, kIntersect_SkPathOp,"
  77. " filename);\n");
  78. pathStr.appendf("}\n");
  79. state.outputProgress(pathStr.c_str(), kIntersect_SkPathOp);
  80. }
  81. SkString testName;
  82. testName.printf("thread_loops%d", ++gLoopsTestNo);
  83. testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, testName.c_str());
  84. if (PathOpsDebug::gCheckForDuplicateNames) return;
  85. }
  86. }
  87. }
  88. }
  89. }
  90. DEF_TEST(PathOpsOpLoopsThreaded, reporter) {
  91. initializeTests(reporter, "loopOp");
  92. PathOpsThreadedTestRunner testRunner(reporter);
  93. for (int a = 0; a < 6; ++a) { // outermost
  94. for (int b = a + 1; b < 7; ++b) {
  95. for (int c = 0 ; c < 6; ++c) {
  96. for (int d = c + 1; d < 7; ++d) {
  97. *testRunner.fRunnables.append() =
  98. new PathOpsThreadedRunnable(&testOpLoopsMain, a, b, c, d, &testRunner);
  99. }
  100. }
  101. if (!reporter->allowExtendedTest()) goto finish;
  102. }
  103. }
  104. finish:
  105. testRunner.render();
  106. }