caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 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 | */ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 7 | #include "include/core/SkString.h" |
| 8 | #include "tests/PathOpsExtendedTest.h" |
| 9 | #include "tests/PathOpsThreadedCommon.h" |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 10 | |
| 11 | static int quadTest = 66; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 12 | |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 13 | static void testSimplifyQuadsMain(PathOpsThreadState* data) |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 14 | { |
| 15 | SkASSERT(data); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 16 | PathOpsThreadState& state = *data; |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 17 | SkString pathStr; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 18 | int ax = state.fA & 0x03; |
| 19 | int ay = state.fA >> 2; |
| 20 | int bx = state.fB & 0x03; |
| 21 | int by = state.fB >> 2; |
| 22 | int cx = state.fC & 0x03; |
| 23 | int cy = state.fC >> 2; |
| 24 | int dx = state.fD & 0x03; |
| 25 | int dy = state.fD >> 2; |
| 26 | for (int e = 0 ; e < 16; ++e) { |
| 27 | int ex = e & 0x03; |
| 28 | int ey = e >> 2; |
| 29 | for (int f = e ; f < 16; ++f) { |
| 30 | int fx = f & 0x03; |
| 31 | int fy = f >> 2; |
| 32 | for (int g = f ; g < 16; ++g) { |
| 33 | int gx = g & 0x03; |
| 34 | int gy = g >> 2; |
| 35 | for (int h = g ; h < 16; ++h) { |
| 36 | int hx = h & 0x03; |
| 37 | int hy = h >> 2; |
| 38 | SkPath path, out; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 39 | path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay)); |
| 40 | path.quadTo(SkIntToScalar(bx), SkIntToScalar(by), |
| 41 | SkIntToScalar(cx), SkIntToScalar(cy)); |
| 42 | path.lineTo(SkIntToScalar(dx), SkIntToScalar(dy)); |
| 43 | path.close(); |
| 44 | path.moveTo(SkIntToScalar(ex), SkIntToScalar(ey)); |
| 45 | path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy)); |
| 46 | path.quadTo(SkIntToScalar(gx), SkIntToScalar(gy), |
| 47 | SkIntToScalar(hx), SkIntToScalar(hy)); |
| 48 | path.close(); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 49 | if (state.fReporter->verbose()) { |
| 50 | pathStr.printf("static void testQuads%d(skiatest::Reporter* reporter," |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 51 | "const char* filename) {\n", quadTest); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 52 | pathStr.appendf(" SkPath path;\n"); |
| 53 | pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay); |
| 54 | pathStr.appendf(" path.quadTo(%d, %d, %d, %d);\n", bx, by, 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.quadTo(%d, %d, %d, %d);\n", gx, gy, hx, hy); |
| 60 | pathStr.appendf(" path.close();\n"); |
| 61 | pathStr.appendf(" testSimplify(reporter, path, filename);\n"); |
| 62 | pathStr.appendf("}\n"); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 63 | state.outputProgress(pathStr.c_str(), SkPathFillType::kWinding); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 64 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 65 | testSimplify(path, false, out, state, pathStr.c_str()); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 66 | path.setFillType(SkPathFillType::kEvenOdd); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 67 | if (state.fReporter->verbose()) { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 68 | state.outputProgress(pathStr.c_str(), SkPathFillType::kEvenOdd); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 69 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 70 | testSimplify(path, true, out, state, pathStr.c_str()); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 74 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 75 | } |
| 76 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 77 | DEF_TEST(PathOpsSimplifyQuadsThreaded, reporter) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 78 | initializeTests(reporter, "testQuads"); |
| 79 | PathOpsThreadedTestRunner testRunner(reporter); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 80 | int a = 0; |
| 81 | for (; a < 16; ++a) { |
| 82 | for (int b = a ; b < 16; ++b) { |
| 83 | for (int c = b ; c < 16; ++c) { |
| 84 | for (int d = c; d < 16; ++d) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 85 | *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( |
| 86 | &testSimplifyQuadsMain, a, b, c, d, &testRunner); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 87 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 88 | if (!reporter->allowExtendedTest()) goto finish; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 89 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 90 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 91 | } |
| 92 | finish: |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 93 | testRunner.render(); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 94 | } |