PathOpsSimplifyQuadralateralsThreadedTest.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 int loopNo = 1;
  11. static void testSimplifyQuadralateralsMain(PathOpsThreadState* data)
  12. {
  13. SkASSERT(data);
  14. PathOpsThreadState& state = *data;
  15. SkString pathStr;
  16. int ax = state.fA & 0x03;
  17. int ay = state.fA >> 2;
  18. int bx = state.fB & 0x03;
  19. int by = state.fB >> 2;
  20. int cx = state.fC & 0x03;
  21. int cy = state.fC >> 2;
  22. int dx = state.fD & 0x03;
  23. int dy = state.fD >> 2;
  24. for (int e = 0 ; e < 16; ++e) {
  25. int ex = e & 0x03;
  26. int ey = e >> 2;
  27. for (int f = e ; f < 16; ++f) {
  28. int fx = f & 0x03;
  29. int fy = f >> 2;
  30. for (int g = f ; g < 16; ++g) {
  31. int gx = g & 0x03;
  32. int gy = g >> 2;
  33. for (int h = g ; h < 16; ++h) {
  34. int hx = h & 0x03;
  35. int hy = h >> 2;
  36. SkPath path, out;
  37. path.setFillType(SkPath::kWinding_FillType);
  38. path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
  39. path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
  40. path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
  41. path.lineTo(SkIntToScalar(dx), SkIntToScalar(dy));
  42. path.close();
  43. path.moveTo(SkIntToScalar(ex), SkIntToScalar(ey));
  44. path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
  45. path.lineTo(SkIntToScalar(gx), SkIntToScalar(gy));
  46. path.lineTo(SkIntToScalar(hx), SkIntToScalar(hy));
  47. path.close();
  48. if (state.fReporter->verbose()) {
  49. pathStr.printf("static void quadralateralSimplify%d(skiatest::Reporter*"
  50. "reporter, const char* filename) {\n", loopNo);
  51. pathStr.appendf(" SkPath path;\n");
  52. pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay);
  53. pathStr.appendf(" path.lineTo(%d, %d);\n", bx, by);
  54. pathStr.appendf(" path.lineTo(%d, %d);\n", cx, cy);
  55. pathStr.appendf(" path.lineTo(%d, %d);\n", dx, dy);
  56. pathStr.appendf(" path.close();\n");
  57. pathStr.appendf(" path.moveTo(%d, %d);\n", ex, ey);
  58. pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy);
  59. pathStr.appendf(" path.lineTo(%d, %d);\n", gx, gy);
  60. pathStr.appendf(" path.lineTo(%d, %d);\n", hx, hy);
  61. pathStr.appendf(" path.close();\n");
  62. pathStr.appendf(" testPathSimplify(reporter, path, filename);\n");
  63. pathStr.appendf("}\n");
  64. state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType);
  65. }
  66. testSimplify(path, false, out, state, pathStr.c_str());
  67. path.setFillType(SkPath::kEvenOdd_FillType);
  68. if (state.fReporter->verbose()) {
  69. state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType);
  70. }
  71. testSimplify(path, true, out, state, pathStr.c_str());
  72. }
  73. }
  74. }
  75. }
  76. }
  77. DEF_TEST(PathOpsSimplifyQuadralateralsThreaded, reporter) {
  78. initializeTests(reporter, "testQuadralaterals");
  79. PathOpsThreadedTestRunner testRunner(reporter);
  80. for (int a = 0; a < 16; ++a) {
  81. for (int b = a ; b < 16; ++b) {
  82. for (int c = b ; c < 16; ++c) {
  83. for (int d = c; d < 16; ++d) {
  84. *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
  85. &testSimplifyQuadralateralsMain, a, b, c, d, &testRunner);
  86. }
  87. if (!reporter->allowExtendedTest()) goto finish;
  88. }
  89. }
  90. }
  91. finish:
  92. testRunner.render();
  93. }