PathOpsOpRectThreadedTest.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. // four rects, of four sizes
  13. // for 3 smaller sizes, tall, wide
  14. // top upper mid lower bottom aligned (3 bits, 5 values)
  15. // same with x (3 bits, 5 values)
  16. // not included, square, tall, wide (2 bits)
  17. // cw or ccw (1 bit)
  18. static int loopNo = 6;
  19. static std::atomic<int> gRectsTestNo{0};
  20. static void testPathOpsRectsMain(PathOpsThreadState* data)
  21. {
  22. SkASSERT(data);
  23. PathOpsThreadState& state = *data;
  24. SkString pathStr;
  25. for (int a = 0 ; a < 6; ++a) {
  26. for (int b = a + 1 ; b < 7; ++b) {
  27. for (int c = 0 ; c < 6; ++c) {
  28. for (int d = c + 1 ; d < 7; ++d) {
  29. for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) {
  30. for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f) {
  31. SkPath pathA, pathB;
  32. pathA.setFillType((SkPath::FillType) e);
  33. pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB),
  34. SkIntToScalar(state.fB), SkPath::kCW_Direction);
  35. pathA.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD),
  36. SkIntToScalar(state.fD), SkPath::kCW_Direction);
  37. pathA.close();
  38. pathB.setFillType((SkPath::FillType) f);
  39. pathB.addRect(SkIntToScalar(a), SkIntToScalar(a), SkIntToScalar(b),
  40. SkIntToScalar(b), SkPath::kCW_Direction);
  41. pathB.addRect(SkIntToScalar(c), SkIntToScalar(c), SkIntToScalar(d),
  42. SkIntToScalar(d), SkPath::kCW_Direction);
  43. pathB.close();
  44. for (int op = 0 ; op <= kXOR_SkPathOp; ++op) {
  45. if (state.fReporter->verbose()) {
  46. pathStr.printf(
  47. "static void rects%d(skiatest::Reporter* reporter,"
  48. "const char* filename) {\n", loopNo);
  49. pathStr.appendf(" SkPath path, pathB;");
  50. pathStr.appendf(" path.setFillType(SkPath::k%s_FillType);\n",
  51. e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType
  52. ? "EvenOdd" : "?UNDEFINED");
  53. pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
  54. " SkPath::kCW_Direction);\n", state.fA, state.fA, state.fB, state.fB);
  55. pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
  56. " SkPath::kCW_Direction);\n", state.fC, state.fC, state.fD, state.fD);
  57. pathStr.appendf(" pathB.setFillType(SkPath::k%s_FillType);\n",
  58. f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType
  59. ? "EvenOdd" : "?UNDEFINED");
  60. pathStr.appendf(" pathB.addRect(%d, %d, %d, %d,"
  61. " SkPath::kCW_Direction);\n", a, a, b, b);
  62. pathStr.appendf(" pathB.addRect(%d, %d, %d, %d,"
  63. " SkPath::kCW_Direction);\n", c, c, d, d);
  64. pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
  65. SkPathOpsDebug::OpStr((SkPathOp) op));
  66. pathStr.appendf("}\n\n");
  67. state.outputProgress(pathStr.c_str(), (SkPathOp) op);
  68. }
  69. SkString testName;
  70. testName.printf("thread_rects%d", ++gRectsTestNo);
  71. if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
  72. if (state.fReporter->verbose()) {
  73. ++loopNo;
  74. goto skipToNext;
  75. }
  76. }
  77. if (PathOpsDebug::gCheckForDuplicateNames) return;
  78. }
  79. }
  80. }
  81. skipToNext: ;
  82. }
  83. }
  84. }
  85. }
  86. }
  87. DEF_TEST(PathOpsRectsThreaded, reporter) {
  88. initializeTests(reporter, "testOp");
  89. PathOpsThreadedTestRunner testRunner(reporter);
  90. for (int a = 0; a < 6; ++a) { // outermost
  91. for (int b = a + 1; b < 7; ++b) {
  92. for (int c = 0 ; c < 6; ++c) {
  93. for (int d = c + 1; d < 7; ++d) {
  94. *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
  95. &testPathOpsRectsMain, a, b, c, d, &testRunner);
  96. }
  97. }
  98. if (!reporter->allowExtendedTest()) goto finish;
  99. }
  100. }
  101. finish:
  102. testRunner.render();
  103. }
  104. static std::atomic<int> gFastTestNo{0};
  105. static void testPathOpsFastMain(PathOpsThreadState* data)
  106. {
  107. SkASSERT(data);
  108. PathOpsThreadState& state = *data;
  109. SkString pathStr;
  110. int step = data->fReporter->allowExtendedTest() ? 2 : 5;
  111. for (bool a : { false, true } ) {
  112. for (bool b : { false, true } ) {
  113. for (int c = 0; c < 6; c += step) {
  114. for (int d = 0; d < 6; d += step) {
  115. for (int e = SkPath::kWinding_FillType; e <= SkPath::kInverseEvenOdd_FillType; ++e) {
  116. for (int f = SkPath::kWinding_FillType; f <= SkPath::kInverseEvenOdd_FillType; ++f) {
  117. SkPath pathA, pathB;
  118. pathA.setFillType((SkPath::FillType) e);
  119. if (a) {
  120. pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB) + c,
  121. SkIntToScalar(state.fB), SkPath::kCW_Direction);
  122. }
  123. pathA.close();
  124. pathB.setFillType((SkPath::FillType) f);
  125. if (b) {
  126. pathB.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD) + d,
  127. SkIntToScalar(state.fD), SkPath::kCW_Direction);
  128. }
  129. pathB.close();
  130. const char* fillTypeStr[] = { "Winding", "EvenOdd", "InverseWinding", "InverseEvenOdd" };
  131. for (int op = 0; op <= kXOR_SkPathOp; ++op) {
  132. if (state.fReporter->verbose()) {
  133. pathStr.printf(
  134. "static void fast%d(skiatest::Reporter* reporter,"
  135. "const char* filename) {\n", loopNo);
  136. pathStr.appendf(" SkPath path, pathB;");
  137. pathStr.appendf(" path.setFillType(SkPath::k%s_FillType);\n", fillTypeStr[e]);
  138. if (a) {
  139. pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
  140. " SkPath::kCW_Direction);\n", state.fA, state.fA, state.fB + c, state.fB);
  141. }
  142. pathStr.appendf(" path.setFillType(SkPath::k%s_FillType);\n", fillTypeStr[f]);
  143. if (b) {
  144. pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
  145. " SkPath::kCW_Direction);\n", state.fC, state.fC, state.fD + d, state.fD);
  146. }
  147. pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
  148. SkPathOpsDebug::OpStr((SkPathOp) op));
  149. pathStr.appendf("}\n\n");
  150. state.outputProgress(pathStr.c_str(), (SkPathOp) op);
  151. }
  152. SkString testName;
  153. testName.printf("fast%d", ++gFastTestNo);
  154. if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
  155. if (state.fReporter->verbose()) {
  156. ++loopNo;
  157. goto skipToNext;
  158. }
  159. }
  160. if (PathOpsDebug::gCheckForDuplicateNames) return;
  161. }
  162. }
  163. }
  164. skipToNext: ;
  165. }
  166. }
  167. }
  168. }
  169. }
  170. DEF_TEST(PathOpsFastThreaded, reporter) {
  171. initializeTests(reporter, "testOp");
  172. PathOpsThreadedTestRunner testRunner(reporter);
  173. int step = reporter->allowExtendedTest() ? 2 : 5;
  174. for (int a = 0; a < 6; a += step) { // outermost
  175. for (int b = a + 1; b < 7; b += step) {
  176. for (int c = 0 ; c < 6; c += step) {
  177. for (int d = c + 1; d < 7; d += step) {
  178. *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
  179. &testPathOpsFastMain, a, b, c, d, &testRunner);
  180. }
  181. }
  182. }
  183. }
  184. testRunner.render();
  185. }