add -wp option to write serialized pictures to the specified directory



git-svn-id: http://skia.googlecode.com/svn/trunk@4131 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 66cbc0c..61a0859 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -615,6 +615,23 @@
     }
 }
 
+static void write_picture_serialization(GM* gm, const ConfigData& rec,
+                                        const char writePicturePath[]) {
+    // only do this once, so we pick raster
+    if (kRaster_Backend == rec.fBackend &&
+        SkBitmap::kARGB_8888_Config == rec.fConfig) {
+
+        SkAutoTUnref<SkPicture> pict(generate_new_picture(gm));
+        
+        const char* pictureSuffix = "skp";
+        SkString path = make_filename(writePicturePath, "",
+                                      SkString(gm->shortName()), pictureSuffix);
+        
+        SkFILEWStream stream(path.c_str());
+        pict->serialize(&stream);
+    }
+}
+
 static void usage(const char * argv0) {
     SkDebugf(
         "%s [-w writePath] [-r readPath] [-d diffPath] [-i resourcePath]\n"
@@ -729,6 +746,7 @@
     setSystemPreferences();
 
     const char* writePath = NULL;   // if non-null, where we write the originals
+    const char* writePicturePath = NULL;    // if non-null, where we write serialized pictures
     const char* readPath = NULL;    // if non-null, were we read from to compare
     const char* diffPath = NULL;    // if non-null, where we write our diffs (from compare)
     const char* resourcePath = NULL;// if non-null, where we read from for image resources
@@ -752,6 +770,11 @@
             if (argv < stop && **argv) {
                 writePath = *argv;
             }
+        } else if (strcmp(*argv, "-wp") == 0) {
+            argv++;
+            if (argv < stop && **argv) {
+                writePicturePath = *argv;
+            }
         } else if (strcmp(*argv, "-r") == 0) {
             argv++;
             if (argv < stop && **argv) {
@@ -809,7 +832,9 @@
     if (writePath) {
         fprintf(stderr, "writing to %s\n", writePath);
     }
-
+    if (writePicturePath) {
+        fprintf(stderr, "writing pictures to %s\n", writePicturePath);
+    }
     if (resourcePath) {
         fprintf(stderr, "reading resources from %s\n", resourcePath);
     }
@@ -912,6 +937,10 @@
                                                          forwardRenderedBitmap,
                                                          readPath, diffPath);
             }
+            
+            if (!(gmFlags & GM::kSkipPicture_Flag) && writePicturePath) {
+                write_picture_serialization(gm, gRec[i], writePicturePath);
+            }
 
             // Update overall results.
             // We only tabulate the particular error types that we currently