Update bench to be able to preprocess skps

This allows benchmarking of optimization improvements and plumbs in the purging API. The purging is necessary so we don't magically get faster because the saveLayers are always pre-generated.

R=jvanverth@google.com, reed@google.com

Author: robertphillips@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@14154 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/PictureBenchmark.cpp b/tools/PictureBenchmark.cpp
index 3cc3415..62369a4 100644
--- a/tools/PictureBenchmark.cpp
+++ b/tools/PictureBenchmark.cpp
@@ -23,6 +23,7 @@
 , fTimerTypes(0)
 , fTimeIndividualTiles(false)
 , fPurgeDecodedTex(false)
+, fPreprocess(false)
 {}
 
 PictureBenchmark::~PictureBenchmark() {
@@ -77,9 +78,22 @@
 
     // We throw this away to remove first time effects (such as paging in this program)
     fRenderer->setup();
+
+    if (fPreprocess) {
+        if (NULL != fRenderer->getCanvas()) {
+            fRenderer->getCanvas()->EXPERIMENTAL_optimize(pict);
+        }
+    }
+
     fRenderer->render(NULL);
     fRenderer->resetState(true);   // flush, swapBuffers and Finish
 
+    if (fPreprocess) {
+        if (NULL != fRenderer->getCanvas()) {
+            fRenderer->getCanvas()->EXPERIMENTAL_purge(pict);
+        }
+    }
+
     if (fPurgeDecodedTex) {
         fRenderer->purgeTextures();
     }
@@ -216,6 +230,12 @@
 
                 SkAssertResult(perRunTimerData.appendTimes(perRunTimer.get()));
 
+                if (fPreprocess) {
+                    if (NULL != fRenderer->getCanvas()) {
+                        fRenderer->getCanvas()->EXPERIMENTAL_purge(pict);
+                    }
+                }
+
                 if (fPurgeDecodedTex) {
                     fRenderer->purgeTextures();
                 }
diff --git a/tools/PictureBenchmark.h b/tools/PictureBenchmark.h
index e9d9f65..e149f8c 100644
--- a/tools/PictureBenchmark.h
+++ b/tools/PictureBenchmark.h
@@ -46,6 +46,9 @@
     void setPurgeDecodedTex(bool purgeDecodedTex) { fPurgeDecodedTex = purgeDecodedTex; }
     bool purgeDecodedText() const { return fPurgeDecodedTex; }
 
+    void setPreprocess(bool preprocess) { fPreprocess = preprocess; }
+    bool preprocess() const { return fPreprocess; }
+
     PictureRenderer* setRenderer(PictureRenderer*);
 
     void setTimerResultType(TimerData::Result resultType) { fTimerResult = resultType; }
@@ -62,6 +65,7 @@
     uint32_t          fTimerTypes; // bitfield of TimerData::TimerFlags values
     bool              fTimeIndividualTiles;
     bool              fPurgeDecodedTex;
+    bool              fPreprocess;
 
     void logProgress(const char msg[]);
 
diff --git a/tools/bench_pictures_main.cpp b/tools/bench_pictures_main.cpp
index 4952571..5ff519c 100644
--- a/tools/bench_pictures_main.cpp
+++ b/tools/bench_pictures_main.cpp
@@ -49,6 +49,8 @@
             "SK_LAZY_CACHE_STATS set to true. Report percentage of cache hits when using "
             "deferred image decoding.");
 
+DEFINE_bool(preprocess, false, "If true, perform device specific preprocessing before timing.");
+
 static char const * const gFilterTypes[] = {
     "paint",
     "point",
@@ -341,6 +343,7 @@
     }
 
     benchmark->setPurgeDecodedTex(FLAGS_purgeDecodedTex);
+    benchmark->setPreprocess(FLAGS_preprocess);
 
     if (FLAGS_readPath.count() < 1) {
         gLogger.logError(".skp files or directories are required.\n");