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/PathOpsSkpClipTest.cpp b/tests/PathOpsSkpClipTest.cpp
index 98e5553..f46ad97 100644
--- a/tests/PathOpsSkpClipTest.cpp
+++ b/tests/PathOpsSkpClipTest.cpp
@@ -1,3 +1,5 @@
+#include "PathOpsExtendedTest.h"
+#include "PathOpsThreadedCommon.h"
 #include "SkBitmap.h"
 #include "SkDevice.h"
 #include "SkCanvas.h"
@@ -7,60 +9,143 @@
 #include "SkOSFile.h"
 #include "SkPicture.h"
 #include "SkString.h"
-#include "Test.h"
+
+#ifdef SK_BUILD_FOR_WIN
+#define PATH_SLASH "\\"
+#define IN_DIR "D:" PATH_SLASH "skp"
+#define OUT_DIR "D:" PATH_SLASH
+#else
+#define PATH_SLASH "/"
+#define IN_DIR "/Volumes/Untitled" PATH_SLASH
+#define OUT_DIR PATH_SLASH
+#endif
+
+static const char pictDir[] = IN_DIR ;
+static const char outSkpClipDir[] = OUT_DIR "skpClip";
+static const char outOldClipDir[] = OUT_DIR "oldClip";
 
 static void make_filepath(SkString* path, const char* dir, const SkString& name) {
     size_t len = strlen(dir);
     path->set(dir);
-    if (len > 0 && dir[len - 1] != '/') {
-        path->append("\\");
+    if (len > 0 && dir[len - 1] != PATH_SLASH[0]) {
+        path->append(PATH_SLASH);
     }
     path->append(name);
 }
 
+static void testOne(const SkString& filename) {
+#if DEBUG_SHOW_TEST_NAME
+    SkString testName(filename);
+    const char http[] = "http";
+    if (testName.startsWith(http)) {
+        testName.remove(0, sizeof(http) - 1);
+    }
+    while (testName.startsWith("_")) {
+        testName.remove(0, 1);
+    }
+    const char dotSkp[] = ".skp";
+    if (testName.endsWith(dotSkp)) {
+        size_t len = testName.size();
+        testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1);
+    }
+    testName.prepend("skp");
+    testName.append("1");
+    strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRING_LENGTH);
+#endif
+    SkString path;
+    make_filepath(&path, pictDir, filename);
+    SkFILEStream stream(path.c_str());
+    if (!stream.isValid()) {
+        return;
+    }
+    bool success;
+    SkPicture* pic = SkNEW_ARGS(SkPicture, (&stream, &success, &SkImageDecoder::DecodeMemory));
+    if (!success) {
+        SkDebugf("unable to decode %s\n", filename.c_str());
+        return;
+    }
+    int width = pic->width();
+    int height = pic->height();
+    SkBitmap bitmap;
+    bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
+    success = bitmap.allocPixels();
+    if (!success) {
+        SkDebugf("unable to allocate bitmap for %s\n", filename.c_str());
+        return;
+    }
+    SkCanvas canvas(bitmap);
+    SkString pngName(filename);
+    pngName.remove(pngName.size() - 3, 3);
+    pngName.append("png");
+    for (int i = 0; i < 2; ++i) {
+        bool useOp = i ? true : false;
+        canvas.setAllowSimplifyClip(useOp);
+        pic->draw(&canvas);
+        SkString outFile;
+        make_filepath(&outFile, useOp ? outSkpClipDir : outOldClipDir, pngName);
+        SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100);
+    }
+    SkDELETE(pic);
+}
+
+const char skipBefore[] = "http___health_com.skp";
+
 static void PathOpsSkpClipTest(skiatest::Reporter* reporter) {
-    const char pictDir[] = "D:\\skp";
-    const char outSkpClipDir[] = "D:\\skpClip";
-    const char outOldClipDir[] = "D:\\oldClip";
     SkOSFile::Iter iter(pictDir, "skp");
     SkString filename;
+    int testCount = 0;
     while (iter.next(&filename)) {
-#if 01
-        if (strcmp(filename.c_str(), "desk_15min-lt.skp")) {
+        if (strcmp(filename.c_str(), skipBefore) < 0) {
             continue;
         }
-#endif
-        SkString path;
-        make_filepath(&path, pictDir, filename);
-        SkFILEStream stream(path.c_str());
-        if (!stream.isValid()) {
-            continue;
+        testOne(filename);
+        if (reporter->verbose()) {
+            SkDebugf(".");
+            if (++testCount % 100 == 0) {
+                SkDebugf("\n");
+            }
         }
-        bool success;
-        SkPicture* pic = SkNEW_ARGS(SkPicture, (&stream, &success, &SkImageDecoder::DecodeMemory));
-        if (!success) {
-            continue;
-        }
-        int width = pic->width();
-        int height = pic->height();
-        SkBitmap bitmap;
-        bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
-        bitmap.allocPixels();
-        SkCanvas canvas(bitmap);
-        filename.remove(filename.size() - 3, 3);
-        filename.append("png");
-        for (int i = 0; i < 2; ++i) {
-            bool useOp = i ? true : false;
-            canvas.setAllowSimplifyClip(useOp);
-            pic->draw(&canvas);
-            SkString outFile;
-            make_filepath(&outFile, useOp ? outSkpClipDir : outOldClipDir, filename);
-            SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100);
-        }
-        SkDELETE(pic);
         reporter->bumpTestCount();
     }
 }
 
+static void testSkpClipMain(PathOpsThreadState* data) {
+        SkString str(data->fSerialNo);
+        testOne(str);
+        if (data->fReporter->verbose()) {
+            SkDebugf(".");
+            static int threadTestCount;
+            sk_atomic_inc(&threadTestCount);
+            if (threadTestCount % 100 == 0) {
+                SkDebugf("\n");
+            }
+        }
+}
+
+static void PathOpsSkpClipThreadedTest(skiatest::Reporter* reporter) {
+    int threadCount = initializeTests(reporter, "skpClipThreadedTest");
+    PathOpsThreadedTestRunner testRunner(reporter, threadCount);
+    SkOSFile::Iter iter(pictDir, "skp");
+    SkString filename;
+    while (iter.next(&filename)) {
+        if (strcmp(filename.c_str(), skipBefore) < 0) {
+            continue;
+        }
+        *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable,
+                (&testSkpClipMain, filename.c_str(), &testRunner));
+        reporter->bumpTestCount();
+    }
+    testRunner.render();
+}
+
+static void PathOpsSkpClipTestOne(skiatest::Reporter* reporter) {
+    SkString filename(skipBefore);
+    testOne(filename);
+}
+
 #include "TestClassDef.h"
 DEFINE_TESTCLASS_SHORT(PathOpsSkpClipTest)
+
+DEFINE_TESTCLASS_SHORT(PathOpsSkpClipTestOne)
+
+DEFINE_TESTCLASS_SHORT(PathOpsSkpClipThreadedTest)