--pictureDir foo will load serialized pictures <>.skp from the foo directory



git-svn-id: http://skia.googlecode.com/svn/trunk@4132 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 6bfa897..bc1b929 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -26,10 +26,22 @@
 #include "gl/GrGLUtil.h"
 #include "GrRenderTarget.h"
 
+#include "SkOSFile.h"
 #include "SkPDFDevice.h"
 #include "SkPDFDocument.h"
 #include "SkStream.h"
 
+extern SampleView* CreateSamplePictFileView(const char filename[]);
+
+class PictFileFactory : public SkViewFactory {
+    SkString fFilename;
+public:
+    PictFileFactory(const SkString& filename) : fFilename(filename) {}
+    virtual SkView* operator() () const SK_OVERRIDE {
+        return CreateSamplePictFileView(fFilename.c_str());
+    }
+};
+
 #define TEST_GPIPE
 
 #ifdef  TEST_GPIPE
@@ -655,7 +667,7 @@
 }
 
 static void usage(const char * argv0) {
-    SkDebugf("%s [--slide sampleName] [-i resourcePath] [--msaa sampleCount]\n", argv0);
+    SkDebugf("%s [--slide sampleName] [-i resourcePath] [--msaa sampleCount] [--pictureDir path]\n", argv0);
     SkDebugf("    sampleName: sample at which to start.\n");
     SkDebugf("    resourcePath: directory that stores image resources.\n");
     SkDebugf("    msaa: request multisampling with the given sample count.\n");
@@ -665,6 +677,7 @@
     : INHERITED(hwnd)
     , fDevManager(NULL) {
 
+    this->registerPictFileSamples(argv, argc);
     SkGMRegistyToSampleRegistry();
     {
         const SkViewRegister* reg = SkViewRegister::Head();
@@ -867,6 +880,38 @@
     SkSafeUnref(fDevManager);
 }
 
+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("/");
+    }
+    path->append(name);
+}
+
+void SampleWindow::registerPictFileSamples(char** argv, int argc) {
+    const char* pictDir = NULL;
+
+    for (int i = 0; i < argc; ++i) {
+        if (!strcmp(argv[i], "--pictureDir")) {
+            i += 1;
+            if (i < argc) {
+                pictDir = argv[i];
+                break;
+            }
+        }
+    }
+    if (pictDir) {
+        SkOSFile::Iter iter(pictDir, "skp");
+        SkString filename;
+        while (iter.next(&filename)) {
+            SkString path;
+            make_filepath(&path, pictDir, filename);
+            *fSamples.append() = new PictFileFactory(path);
+        }
+    }
+}
+
 int SampleWindow::findByTitle(const char title[]) {
     int i, count = fSamples.count();
     for (i = 0; i < count; i++) {