PathOpsSimplifyQuadThreadedTest.cpp 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 quadTest = 66;
  11. static void testSimplifyQuadsMain(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.quadTo(SkIntToScalar(bx), SkIntToScalar(by),
  40. 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.quadTo(SkIntToScalar(gx), SkIntToScalar(gy),
  46. SkIntToScalar(hx), SkIntToScalar(hy));
  47. path.close();
  48. if (state.fReporter->verbose()) {
  49. pathStr.printf("static void testQuads%d(skiatest::Reporter* reporter,"
  50. "const char* filename) {\n", quadTest);
  51. pathStr.appendf(" SkPath path;\n");
  52. pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay);
  53. pathStr.appendf(" path.quadTo(%d, %d, %d, %d);\n", bx, by, cx, cy);
  54. pathStr.appendf(" path.lineTo(%d, %d);\n", dx, dy);
  55. pathStr.appendf(" path.close();\n");
  56. pathStr.appendf(" path.moveTo(%d, %d);\n", ex, ey);
  57. pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy);
  58. pathStr.appendf(" path.quadTo(%d, %d, %d, %d);\n", gx, gy, hx, hy);
  59. pathStr.appendf(" path.close();\n");
  60. pathStr.appendf(" testSimplify(reporter, path, filename);\n");
  61. pathStr.appendf("}\n");
  62. state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType);
  63. }
  64. testSimplify(path, false, out, state, pathStr.c_str());
  65. path.setFillType(SkPath::kEvenOdd_FillType);
  66. if (state.fReporter->verbose()) {
  67. state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType);
  68. }
  69. testSimplify(path, true, out, state, pathStr.c_str());
  70. }
  71. }
  72. }
  73. }
  74. }
  75. DEF_TEST(PathOpsSimplifyQuadsThreaded, reporter) {
  76. initializeTests(reporter, "testQuads");
  77. PathOpsThreadedTestRunner testRunner(reporter);
  78. int a = 0;
  79. for (; a < 16; ++a) {
  80. for (int b = a ; b < 16; ++b) {
  81. for (int c = b ; c < 16; ++c) {
  82. for (int d = c; d < 16; ++d) {
  83. *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
  84. &testSimplifyQuadsMain, a, b, c, d, &testRunner);
  85. }
  86. if (!reporter->allowExtendedTest()) goto finish;
  87. }
  88. }
  89. }
  90. finish:
  91. testRunner.render();
  92. }