path ops work in progress

BUG=

Review URL: https://codereview.chromium.org/18058007

git-svn-id: http://skia.googlecode.com/svn/trunk@9908 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/PathOpsExtendedTest.cpp b/tests/PathOpsExtendedTest.cpp
index a9ca58b..7a7dcb3 100644
--- a/tests/PathOpsExtendedTest.cpp
+++ b/tests/PathOpsExtendedTest.cpp
@@ -45,27 +45,34 @@
 static bool gComparePathsAssert = true;
 static bool gPathStrAssert = true;
 
-static void showPathContours(SkPath::Iter& iter, const char* suffix) {
+static const char* gFillTypeStr[] = {
+    "kWinding_FillType",
+    "kEvenOdd_FillType",
+    "kInverseWinding_FillType",
+    "kInverseEvenOdd_FillType"
+};
+
+static void showPathContours(SkPath::RawIter& iter, const char* pathName) {
     uint8_t verb;
     SkPoint pts[4];
     while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
         switch (verb) {
             case SkPath::kMove_Verb:
-                SkDebugf("    path%s.moveTo(%1.9g,%1.9g);\n", suffix, pts[0].fX, pts[0].fY);
+                SkDebugf("    %s.moveTo(%#1.9gf, %#1.9gf);\n", pathName, pts[0].fX, pts[0].fY);
                 continue;
             case SkPath::kLine_Verb:
-                SkDebugf("    path%s.lineTo(%1.9g,%1.9g);\n", suffix, pts[1].fX, pts[1].fY);
+                SkDebugf("    %s.lineTo(%#1.9gf, %#1.9gf);\n", pathName, pts[1].fX, pts[1].fY);
                 break;
             case SkPath::kQuad_Verb:
-                SkDebugf("    path%s.quadTo(%1.9g,%1.9g, %1.9g,%1.9g);\n", suffix,
+                SkDebugf("    %s.quadTo(%#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf);\n", pathName,
                     pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY);
                 break;
             case SkPath::kCubic_Verb:
-                SkDebugf("    path%s.cubicTo(%1.9g,%1.9g, %1.9g,%1.9g, %1.9g,%1.9g);\n", suffix,
-                    pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY, pts[3].fX, pts[3].fY);
+                SkDebugf("    %s.cubicTo(%#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf);\n",
+                    pathName, pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY, pts[3].fX, pts[3].fY);
                 break;
             case SkPath::kClose_Verb:
-                SkDebugf("    path%s.close();\n", suffix);
+                SkDebugf("    %s.close();\n", pathName);
                 break;
             default:
                 SkDEBUGFAIL("bad verb");
@@ -74,15 +81,8 @@
     }
 }
 
-static const char* fillTypeStr[] = {
-    "kWinding_FillType",
-    "kEvenOdd_FillType",
-    "kInverseWinding_FillType",
-    "kInverseEvenOdd_FillType"
-};
-
-static void showPath(const SkPath& path, const char* suffix) {
-    SkPath::Iter iter(path, true);
+static void showPath(const SkPath& path, const char* pathName, bool includeDeclaration) {
+    SkPath::RawIter iter(path);
 #define SUPPORT_RECT_CONTOUR_DETECTION 0
 #if SUPPORT_RECT_CONTOUR_DETECTION
     int rectCount = path.isRectContours() ? path.rectContours(NULL, NULL) : 0;
@@ -103,14 +103,17 @@
 #endif
     SkPath::FillType fillType = path.getFillType();
     SkASSERT(fillType >= SkPath::kWinding_FillType && fillType <= SkPath::kInverseEvenOdd_FillType);
-    SkDebugf("    path%s.setFillType(SkPath::%s);\n", suffix, fillTypeStr[fillType]);
-    iter.setPath(path, true);
-    showPathContours(iter, suffix);
+    if (includeDeclaration) {
+        SkDebugf("    SkPath %s;\n", pathName);
+    }
+    SkDebugf("    %s.setFillType(SkPath::%s);\n", pathName, gFillTypeStr[fillType]);
+    iter.setPath(path);
+    showPathContours(iter, pathName);
 }
 
 #if DEBUG_SHOW_TEST_NAME
 static void showPathData(const SkPath& path) {
-    SkPath::Iter iter(path, true);
+    SkPath::RawIter iter(path);
     uint8_t verb;
     SkPoint pts[4];
     while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
@@ -162,16 +165,26 @@
     }
 }
 
-#if 0
-static void showPath(const SkPath& path, const char* str, const SkMatrix& scale) {
-    SkPath scaled;
-    SkMatrix inverse;
-    bool success = scale.invert(&inverse);
-    if (!success) {
-        SkASSERT(0);
+#if DEBUG_SHOW_TEST_NAME
+
+void ShowFunctionHeader(const char* functionName) {
+    SkDebugf("\nstatic void %s(skiatest::Reporter* reporter) {\n", functionName);
+    if (strcmp("skphealth_com76", functionName) == 0) {
+        SkDebugf("found it\n");
     }
-    path.transform(inverse, &scaled);
-    showPath(scaled, str);
+}
+
+static const char* gOpStrs[] = {
+    "kDifference_PathOp",
+    "kIntersect_PathOp",
+    "kUnion_PathOp",
+    "kXor_PathOp",
+    "kReverseDifference_PathOp",
+};
+
+void ShowOp(SkPathOp op, const char* pathOne, const char* pathTwo) {
+    SkDebugf("    testPathOp(reporter, %s, %s, %s);\n", pathOne, pathTwo, gOpStrs[op]);
+    SkDebugf("}\n");
 }
 #endif
 
@@ -325,8 +338,7 @@
 
 static void showSimplifiedPath(const SkPath& one, const SkPath& two,
         const SkPath& scaledOne, const SkPath& scaledTwo) {
-    showPath(one, "");
- //   showPath(two, "simplified:");
+    showPath(one, "path", false);
     drawAsciiPaths(scaledOne, scaledTwo, true);
 }
 
@@ -356,13 +368,10 @@
     SkASSERT((unsigned) shapeOp < SK_ARRAY_COUNT(opStrs));
     SkDebugf("static void xOp#%s(skiatest::Reporter* reporter) {\n", opSuffixes[shapeOp]);
     SkDebugf("    SkPath path, pathB;\n");
-    showPath(a, "");
-    showPath(b, "B");
+    showPath(a, "path", false);
+    showPath(b, "pathB", false);
     SkDebugf("    testPathOp(reporter, path, pathB, %s);\n", opStrs[shapeOp]);
     SkDebugf("}\n");
-    // the region often isn't very helpful since it approximates curves with a lot of line-tos
- //   if (0) showPath(scaledOne, "region:", scale);
- //   showPath(two, "op result:");
     drawAsciiPaths(scaledOne, scaledTwo, true);
 }
 
@@ -450,7 +459,7 @@
     SkPath::FillType fillType = useXor ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType;
     path.setFillType(fillType);
     if (gShowPath) {
-        showPath(path, "");
+        showPath(path, "path", false);
     }
     if (!Simplify(path, &out)) {
         SkDebugf("%s did not expect failure\n", __FUNCTION__);
@@ -499,12 +508,25 @@
     return result == 0;
 }
 
-bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
-                 const SkPathOp shapeOp) {
 #if DEBUG_SHOW_TEST_NAME
-    showPathData(a);
-    showOp(shapeOp);
-    showPathData(b);
+void DebugShowPath(const SkPath& a, const SkPath& b, SkPathOp shapeOp, const char* testName) {
+        ShowFunctionHeader(testName);
+        showPath(a, "path", true);
+        showPath(b, "pathB", true);
+        ShowOp(shapeOp, "path", "pathB");
+}
+#endif
+
+bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
+                 const SkPathOp shapeOp, const char* testName) {
+#if DEBUG_SHOW_TEST_NAME
+    if (testName == NULL) {
+        showPathData(a);
+        showOp(shapeOp);
+        showPathData(b);
+    } else {
+        DebugShowPath(a, b, shapeOp, testName);
+    }
 #endif
     SkPath out;
     if (!Op(a, b, shapeOp, &out) ) {
@@ -566,7 +588,7 @@
             testNumber = atoi(numLoc) + 1;
         }
     }
-    return reporter->allowThreaded() ? SkThreadPool::kThreadPerCore : 0;
+    return reporter->allowThreaded() ? SkThreadPool::kThreadPerCore : 1;
 }
 
 void outputProgress(char* ramStr, const char* pathStr, SkPath::FillType pathFillType) {