1 /* 2 * Copyright 2014 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 10 static void testOpLoopsMain(PathOpsThreadState* data) { 11 #if DEBUG_SHOW_TEST_NAME 12 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH); 13 #endif 14 SkASSERT(data); 15 PathOpsThreadState& state = *data; 16 char pathStr[1024]; // gdb: set print elements 400 17 bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? 18 if (progress) { 19 sk_bzero(pathStr, sizeof(pathStr)); 20 } 21 for (int a = 0 ; a < 6; ++a) { 22 for (int b = a + 1 ; b < 7; ++b) { 23 for (int c = 0 ; c < 6; ++c) { 24 for (int d = c + 1 ; d < 7; ++d) { 25 // define 4 points that form two lines that often cross; one line is (a, b) (c, d) 26 SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)}; 27 SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6, 28 SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 }; 29 SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6, 30 SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 }; 31 SkPoint endC = { midA.fX + v.fY * state.fC / 3, 32 midA.fY + v.fX * state.fC / 3 }; 33 SkPoint endD = { midB.fX - v.fY * state.fD / 3, 34 midB.fY + v.fX * state.fD / 3 }; 35 SkPath pathA, pathB; 36 if (progress) { 37 char* str = pathStr; 38 str += sprintf(str, " path.moveTo(%d,%d);\n", a, b); 39 str += sprintf(str, " path.cubicTo(%d,%d, %1.9gf,%1.9gf, %1.9gf,%1.9gf);\n", 40 c, d, endC.fX, endC.fY, endD.fX, endD.fY); 41 str += sprintf(str, " path.close();\n"); 42 str += sprintf(str, " pathB.moveTo(%d,%d);\n", c, d); 43 str += sprintf(str, " pathB.cubicTo(%1.9gf,%1.9gf, %1.9gf,%1.9gf, %d,%d);\n", 44 endC.fX, endC.fY, endD.fX, endD.fY, a, b); 45 str += sprintf(str, " pathB.close();\n"); 46 } 47 pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b)); 48 pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY); 49 pathA.close(); 50 pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d)); 51 pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b)); 52 pathB.close(); 53 // SkDebugf("%s\n", pathStr); 54 if (progress) { 55 outputProgress(state.fPathStr, pathStr, kIntersect_PathOp); 56 } 57 testThreadedPathOp(state.fReporter, pathA, pathB, kIntersect_PathOp, "loops"); 58 } 59 } 60 } 61 } 62 } 63 64 DEF_TEST(PathOpsOpLoopsThreaded, reporter) { 65 int threadCount = initializeTests(reporter, "cubicOp"); 66 PathOpsThreadedTestRunner testRunner(reporter, threadCount); 67 for (int a = 0; a < 6; ++a) { // outermost 68 for (int b = a + 1; b < 7; ++b) { 69 for (int c = 0 ; c < 6; ++c) { 70 for (int d = c + 1; d < 7; ++d) { 71 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable, 72 (&testOpLoopsMain, a, b, c, d, &testRunner)); 73 } 74 } 75 if (!reporter->allowExtendedTest()) goto finish; 76 } 77 } 78 finish: 79 testRunner.render(); 80 ShowTestArray(); 81 } 82 83 DEF_TEST(PathOpsOpLoops, reporter) { 84 (void) initializeTests(reporter, "cubicOp"); 85 PathOpsThreadState state; 86 state.fReporter = reporter; 87 SkBitmap bitmap; 88 state.fBitmap = &bitmap; 89 char pathStr[PATH_STR_SIZE]; 90 state.fPathStr = pathStr; 91 for (state.fA = 0; state.fA < 6; ++state.fA) { // outermost 92 for (state.fB = state.fA + 1; state.fB < 7; ++state.fB) { 93 for (state.fC = 0 ; state.fC < 6; ++state.fC) { 94 for (state.fD = state.fC + 1; state.fD < 7; ++state.fD) { 95 testOpLoopsMain(&state); 96 } 97 } 98 if (!reporter->allowExtendedTest()) goto finish; 99 } 100 } 101 finish: 102 ShowTestArray(); 103 } 104