static void testPathOpsRectsMain(PathOpsThreadState* data) { SkASSERT(data); PathOpsThreadState& state = *data; char pathStr[1024]; // gdb: set print elements 400 sk_bzero(pathStr, sizeof(pathStr)); for (int a = 0 ; a < 6; ++a) { for (int b = a + 1 ; b < 7; ++b) { for (int c = 0 ; c < 6; ++c) { for (int d = c + 1 ; d < 7; ++d) { for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) { for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f) { SkPath pathA, pathB; char* str = pathStr; pathA.setFillType((SkPath::FillType) e); str += sprintf(str, " path.setFillType(SkPath::k%s_FillType);\n", e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType ? "EvenOdd" : "?UNDEFINED"); pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB), SkIntToScalar(state.fB), SkPath::kCW_Direction); str += sprintf(str, " path.addRect(%d, %d, %d, %d," " SkPath::kCW_Direction);\n", state.fA, state.fA, state.fB, state.fB); pathA.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD), SkIntToScalar(state.fD), SkPath::kCW_Direction); str += sprintf(str, " path.addRect(%d, %d, %d, %d," " SkPath::kCW_Direction);\n", state.fC, state.fC, state.fD, state.fD); pathA.close(); pathB.setFillType((SkPath::FillType) f); str += sprintf(str, " pathB.setFillType(SkPath::k%s_FillType);\n", f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType ? "EvenOdd" : "?UNDEFINED"); pathB.addRect(SkIntToScalar(a), SkIntToScalar(a), SkIntToScalar(b), SkIntToScalar(b), SkPath::kCW_Direction); str += sprintf(str, " pathB.addRect(%d, %d, %d, %d," " SkPath::kCW_Direction);\n", a, a, b, b); pathB.addRect(SkIntToScalar(c), SkIntToScalar(c), SkIntToScalar(d), SkIntToScalar(d), SkPath::kCW_Direction); str += sprintf(str, " pathB.addRect(%d, %d, %d, %d," " SkPath::kCW_Direction);\n", c, c, d, d); pathB.close(); for (int op = 0 ; op <= kXOR_PathOp; ++op) { outputProgress(state.fPathStr, pathStr, (SkPathOp) op); testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op); } } } } } } } }
DEF_TEST(PathOpsInverse, reporter) { SkPath one, two; for (int op = kDifference_PathOp; op <= kReverseDifference_PathOp; ++op) { for (int oneFill = SkPath::kWinding_FillType; oneFill <= SkPath::kInverseEvenOdd_FillType; ++oneFill) { for (int oneDir = SkPath::kCW_Direction; oneDir != SkPath::kCCW_Direction; ++oneDir) { one.reset(); one.setFillType((SkPath::FillType) oneFill); one.addRect(0, 0, 6, 6, (SkPath::Direction) oneDir); for (int twoFill = SkPath::kWinding_FillType; twoFill <= SkPath::kInverseEvenOdd_FillType; ++twoFill) { for (int twoDir = SkPath::kCW_Direction; twoDir != SkPath::kCCW_Direction; ++twoDir) { two.reset(); two.setFillType((SkPath::FillType) twoFill); two.addRect(3, 3, 9, 9, (SkPath::Direction) twoDir); testPathOp(reporter, one, two, (SkPathOp) op); } } } } } }
static void testOpCubicsMain(PathOpsThreadState* data) { #if DEBUG_SHOW_TEST_NAME strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH); #endif SkASSERT(data); PathOpsThreadState& state = *data; SkString pathStr; for (int a = 0 ; a < 6; ++a) { for (int b = a + 1 ; b < 7; ++b) { for (int c = 0 ; c < 6; ++c) { for (int d = c + 1 ; d < 7; ++d) { for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) { for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f) { SkPath pathA, pathB; pathA.setFillType((SkPath::FillType) e); pathA.moveTo(SkIntToScalar(state.fA), SkIntToScalar(state.fB)); pathA.cubicTo(SkIntToScalar(state.fC), SkIntToScalar(state.fD), SkIntToScalar(b), SkIntToScalar(a), SkIntToScalar(d), SkIntToScalar(c)); pathA.close(); pathB.setFillType((SkPath::FillType) f); pathB.moveTo(SkIntToScalar(a), SkIntToScalar(b)); pathB.cubicTo(SkIntToScalar(c), SkIntToScalar(d), SkIntToScalar(state.fB), SkIntToScalar(state.fA), SkIntToScalar(state.fD), SkIntToScalar(state.fC)); pathB.close(); for (int op = 0 ; op <= kXOR_SkPathOp; ++op) { if (state.fReporter->verbose()) { pathStr.printf("static void cubicOp%d(skiatest::Reporter* reporter," " const char* filename) {\n", loopNo); pathStr.appendf(" SkPath path, pathB;\n"); pathStr.appendf(" path.setFillType(SkPath::k%s_FillType);\n", e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType ? "EvenOdd" : "?UNDEFINED"); pathStr.appendf(" path.moveTo(%d,%d);\n", state.fA, state.fB); pathStr.appendf(" path.cubicTo(%d,%d, %d,%d, %d,%d);\n", state.fC, state.fD, b, a, d, c); pathStr.appendf(" path.close();\n"); pathStr.appendf(" pathB.setFillType(SkPath::k%s_FillType);\n", f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType ? "EvenOdd" : "?UNDEFINED"); pathStr.appendf(" pathB.moveTo(%d,%d);\n", a, b); pathStr.appendf(" pathB.cubicTo(%d,%d, %d,%d, %d,%d);\n", c, d, state.fB, state.fA, state.fD, state.fC); pathStr.appendf(" pathB.close();\n"); pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n", SkPathOpsDebug::OpStr((SkPathOp) op)); pathStr.appendf("}\n"); outputProgress(state.fPathStr, pathStr.c_str(), (SkPathOp) op); } if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "cubics")) { if (state.fReporter->verbose()) { ++loopNo; goto skipToNext; } } } } } skipToNext: ; } } } } }
static void testOpLoopsMain(PathOpsThreadState* data) { #if DEBUG_SHOW_TEST_NAME strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH); #endif SkASSERT(data); PathOpsThreadState& state = *data; char pathStr[1024]; // gdb: set print elements 400 bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? if (progress) { sk_bzero(pathStr, sizeof(pathStr)); } for (int a = 0 ; a < 6; ++a) { for (int b = a + 1 ; b < 7; ++b) { for (int c = 0 ; c < 6; ++c) { for (int d = c + 1 ; d < 7; ++d) { // define 4 points that form two lines that often cross; one line is (a, b) (c, d) SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)}; SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6, SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 }; SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6, SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 }; SkPoint endC = { midA.fX + v.fY * state.fC / 3, midA.fY + v.fX * state.fC / 3 }; SkPoint endD = { midB.fX - v.fY * state.fD / 3, midB.fY + v.fX * state.fD / 3 }; SkPath pathA, pathB; if (progress) { char* str = pathStr; const int loopNo = 17; str += sprintf(str, "static void loop%d(skiatest::Reporter* reporter," " const char* filename) {\n", loopNo); str += sprintf(str, " SkPath path, pathB;\n"); str += sprintf(str, " path.moveTo(%d,%d);\n", a, b); str += sprintf(str, " path.cubicTo(%d,%d, ", c, d); str += add_point(str, endC.fX, endC.fY); str += sprintf(str, ", "); str += add_point(str, endD.fX, endD.fY); str += sprintf(str, ");\n"); str += sprintf(str, " path.close();\n"); str += sprintf(str, " pathB.moveTo(%d,%d);\n", c, d); str += sprintf(str, " pathB.cubicTo("); str += add_point(str, endC.fX, endC.fY); str += sprintf(str, ", "); str += add_point(str, endD.fX, endD.fY); str += sprintf(str, ", %d,%d);\n", a, b); str += sprintf(str, " pathB.close();\n"); str += sprintf(str, " testPathOp(reporter, path, pathB, kIntersect_SkPathOp," " filename);\n"); str += sprintf(str, "}\n"); } pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b)); pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY); pathA.close(); pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d)); pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b)); pathB.close(); // SkDebugf("%s\n", pathStr); if (progress) { outputProgress(state.fPathStr, pathStr, kIntersect_SkPathOp); } testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, "loops"); } } } } }
static void testOpLoopsMain(PathOpsThreadState* data) { #if DEBUG_SHOW_TEST_NAME strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH); #endif SkASSERT(data); PathOpsThreadState& state = *data; SkString pathStr; for (int a = 0 ; a < 6; ++a) { for (int b = a + 1 ; b < 7; ++b) { for (int c = 0 ; c < 6; ++c) { for (int d = c + 1 ; d < 7; ++d) { // define 4 points that form two lines that often cross; one line is (a, b) (c, d) SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)}; SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6, SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 }; SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6, SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 }; SkPoint endC = { midA.fX + v.fY * state.fC / 3, midA.fY + v.fX * state.fC / 3 }; SkPoint endD = { midB.fX - v.fY * state.fD / 3, midB.fY + v.fX * state.fD / 3 }; SkPath pathA, pathB; pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b)); pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY); pathA.close(); pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d)); pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b)); pathB.close(); // SkDebugf("%s\n", pathStr); if (state.fReporter->verbose()) { pathStr.printf("static void loop%d(skiatest::Reporter* reporter," " const char* filename) {\n", loopNo); pathStr.appendf(" SkPath path, pathB;\n"); pathStr.appendf(" path.moveTo(%d,%d);\n", a, b); pathStr.appendf(" path.cubicTo(%d,%d, ", c, d); add_point(&pathStr, endC.fX, endC.fY); pathStr.appendf(", "); add_point(&pathStr, endD.fX, endD.fY); pathStr.appendf(");\n"); pathStr.appendf(" path.close();\n"); pathStr.appendf(" pathB.moveTo(%d,%d);\n", c, d); pathStr.appendf(" pathB.cubicTo("); add_point(&pathStr, endC.fX, endC.fY); pathStr.appendf(", "); add_point(&pathStr, endD.fX, endD.fY); pathStr.appendf(", %d,%d);\n", a, b); pathStr.appendf(" pathB.close();\n"); pathStr.appendf(" testPathOp(reporter, path, pathB, kIntersect_SkPathOp," " filename);\n"); pathStr.appendf("}\n"); state.outputProgress(pathStr.c_str(), kIntersect_SkPathOp); } SkString testName; testName.printf("thread_loops%d", ++gLoopsTestNo); testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, testName.c_str()); if (PathOpsDebug::gCheckForDuplicateNames) return; } } } } }
static void testPathOpsRectsMain(PathOpsThreadState* data) { SkASSERT(data); PathOpsThreadState& state = *data; char pathStr[1024]; // gdb: set print elements 400 bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? if (progress) { sk_bzero(pathStr, sizeof(pathStr)); } for (int a = 0 ; a < 6; ++a) { for (int b = a + 1 ; b < 7; ++b) { for (int c = 0 ; c < 6; ++c) { for (int d = c + 1 ; d < 7; ++d) { for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) { for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f) { static int testNum = 6; if (progress) { char* str = pathStr; str += sprintf(str, "static void rects%d(skiatest::Reporter* reporter, const char* filename) {\n", testNum); str += sprintf(str, " SkPath path, pathB;"); str += sprintf(str, " path.setFillType(SkPath::k%s_FillType);\n", e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType ? "EvenOdd" : "?UNDEFINED"); str += sprintf(str, " path.addRect(%d, %d, %d, %d," " SkPath::kCW_Direction);\n", state.fA, state.fA, state.fB, state.fB); str += sprintf(str, " path.addRect(%d, %d, %d, %d," " SkPath::kCW_Direction);\n", state.fC, state.fC, state.fD, state.fD); str += sprintf(str, " pathB.setFillType(SkPath::k%s_FillType);\n", f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType ? "EvenOdd" : "?UNDEFINED"); str += sprintf(str, " pathB.addRect(%d, %d, %d, %d," " SkPath::kCW_Direction);\n", a, a, b, b); str += sprintf(str, " pathB.addRect(%d, %d, %d, %d," " SkPath::kCW_Direction);\n", c, c, d, d); str += sprintf(str, " testPathOp(reporter, path, pathB, kDifference_SkPathOp, filename);\n"); str += sprintf(str, "}\n\n"); } SkPath pathA, pathB; pathA.setFillType((SkPath::FillType) e); pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB), SkIntToScalar(state.fB), SkPath::kCW_Direction); pathA.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD), SkIntToScalar(state.fD), SkPath::kCW_Direction); pathA.close(); pathB.setFillType((SkPath::FillType) f); pathB.addRect(SkIntToScalar(a), SkIntToScalar(a), SkIntToScalar(b), SkIntToScalar(b), SkPath::kCW_Direction); pathB.addRect(SkIntToScalar(c), SkIntToScalar(c), SkIntToScalar(d), SkIntToScalar(d), SkPath::kCW_Direction); pathB.close(); for (int op = 0 ; op <= kXOR_SkPathOp; ++op) { if (progress) { outputProgress(state.fPathStr, pathStr, (SkPathOp) op); } testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "rects"); } } } } } } } }