PathOpsSimplifyTrianglesThreadedTest.cpp revision 16cfe40276bfb0a4d98c9ad995b8e5b134a49b19
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 "PathOpsExtendedTest.h" 8#include "PathOpsThreadedCommon.h" 9 10static void testSimplifyTrianglesMain(PathOpsThreadState* data) { 11 SkASSERT(data); 12 PathOpsThreadState& state = *data; 13 char pathStr[1024]; 14 sk_bzero(pathStr, sizeof(pathStr)); 15 state.fKey = "?"; 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 for (int d = 0; d < 15; ++d) { 23 int dx = d & 0x03; 24 int dy = d >> 2; 25 for (int e = d + 1; e < 16; ++e) { 26 int ex = e & 0x03; 27 int ey = e >> 2; 28 for (int f = d + 1; f < 16; ++f) { 29 if (e == f) { 30 continue; 31 } 32 int fx = f & 0x03; 33 int fy = f >> 2; 34 if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) { 35 continue; 36 } 37 SkPath path, out; 38 path.setFillType(SkPath::kWinding_FillType); 39 path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay)); 40 path.lineTo(SkIntToScalar(bx), SkIntToScalar(by)); 41 path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy)); 42 path.close(); 43 path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy)); 44 path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey)); 45 path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy)); 46 path.close(); 47 char* str = pathStr; 48 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay); 49 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by); 50 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy); 51 str += sprintf(str, " path.close();\n"); 52 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy); 53 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey); 54 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy); 55 str += sprintf(str, " path.close();\n"); 56 outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType); 57 ShowTestName(&state, d, e, f, 0); 58 testSimplify(path, false, out, state, pathStr); 59 path.setFillType(SkPath::kEvenOdd_FillType); 60 outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType); 61 ShowTestName(&state, d, e, f, 1); 62 testSimplify(path, true, out, state, pathStr); 63 } 64 } 65 } 66} 67 68static void PathOpsSimplifyTrianglesThreadedTest(skiatest::Reporter* reporter) { 69 int threadCount = initializeTests(reporter, "testTriangles"); 70 PathOpsThreadedTestRunner testRunner(reporter, threadCount); 71 for (int a = 0; a < 15; ++a) { 72 int ax = a & 0x03; 73 int ay = a >> 2; 74 for (int b = a + 1; b < 16; ++b) { 75 int bx = b & 0x03; 76 int by = b >> 2; 77 for (int c = a + 1; c < 16; ++c) { 78 if (b == c) { 79 continue; 80 } 81 int cx = c & 0x03; 82 int cy = c >> 2; 83 if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) { 84 continue; 85 } 86 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable, 87 (&testSimplifyTrianglesMain, a, b, c, 0, &testRunner)); 88 } 89 if (!reporter->allowExtendedTest()) goto finish; 90 } 91 } 92finish: 93 testRunner.render(); 94} 95 96#include "TestClassDef.h" 97DEFINE_TESTCLASS_SHORT(PathOpsSimplifyTrianglesThreadedTest) 98