Add visualbench option to not reset between samples

Adds a --reset flag that controls whether we teardown the graphics
context between samples. Also modifies the timing algorithm to always/
only pre-warm after resetting the context.

BUG=skia:

Review URL: https://codereview.chromium.org/1442643007
diff --git a/tools/VisualBench/VisualInteractiveModule.cpp b/tools/VisualBench/VisualInteractiveModule.cpp
index b597b05..73bc53e 100755
--- a/tools/VisualBench/VisualInteractiveModule.cpp
+++ b/tools/VisualBench/VisualInteractiveModule.cpp
@@ -15,7 +15,7 @@
 __SK_FORCE_IMAGE_DECODER_LINKING;
 
 VisualInteractiveModule::VisualInteractiveModule(VisualBench* owner)
-    : INHERITED(owner, false)
+    : INHERITED(owner)
     , fCurrentMeasurement(0)
     , fAdvance(false) {
     memset(fMeasurements, 0, sizeof(fMeasurements));
diff --git a/tools/VisualBench/VisualLightweightBenchModule.cpp b/tools/VisualBench/VisualLightweightBenchModule.cpp
index af939ff..baca168 100644
--- a/tools/VisualBench/VisualLightweightBenchModule.cpp
+++ b/tools/VisualBench/VisualLightweightBenchModule.cpp
@@ -42,7 +42,7 @@
 #define HUMANIZE(time) humanize(time).c_str()
 
 VisualLightweightBenchModule::VisualLightweightBenchModule(VisualBench* owner)
-    : INHERITED(owner, true)
+    : INHERITED(owner)
     , fCurrentSample(0)
     , fResults(new ResultsWriter) {
     // Print header
diff --git a/tools/VisualBench/VisualStreamTimingModule.cpp b/tools/VisualBench/VisualStreamTimingModule.cpp
index ad7c1d0..cb748ca 100644
--- a/tools/VisualBench/VisualStreamTimingModule.cpp
+++ b/tools/VisualBench/VisualStreamTimingModule.cpp
@@ -9,9 +9,10 @@
 
 #include "SkCanvas.h"
 
-VisualStreamTimingModule::VisualStreamTimingModule(VisualBench* owner, bool preWarmBeforeSample)
+DEFINE_bool(reset, true, "Reset the GL context between samples.");
+
+VisualStreamTimingModule::VisualStreamTimingModule(VisualBench* owner)
     : fInitState(kReset_InitState)
-    , fPreWarmBeforeSample(preWarmBeforeSample)
     , fOwner(owner) {
     fBenchmarkStream.reset(new VisualBenchmarkStream(owner->getSurfaceProps()));
 }
@@ -36,18 +37,13 @@
 inline void VisualStreamTimingModule::handleTimingEvent(SkCanvas* canvas,
                                                         TimingStateMachine::ParentEvents event) {
     switch (event) {
-        case TimingStateMachine::kReset_ParentEvents:
-            fBenchmarkStream->current()->postTimingHooks(canvas);
-            fOwner->reset();
-            fInitState = kReset_InitState;
-            break;
         case TimingStateMachine::kTiming_ParentEvents:
             break;
         case TimingStateMachine::kTimingFinished_ParentEvents:
-            fBenchmarkStream->current()->postTimingHooks(canvas);
-            fOwner->reset();
             if (this->timingFinished(fBenchmarkStream->current(), fTSM.loops(),
                                      fTSM.lastMeasurement())) {
+                fBenchmarkStream->current()->postTimingHooks(canvas);
+                fOwner->reset();
                 fTSM.nextBenchmark();
                 if (!fBenchmarkStream->next()) {
                     SkDebugf("Exiting VisualBench successfully\n");
@@ -55,7 +51,13 @@
                 } else {
                     fInitState = kNewBenchmark_InitState;
                 }
-            } else {
+                break;
+            }
+            // fallthrough
+        case TimingStateMachine::kReset_ParentEvents:
+            if (FLAGS_reset) {
+                fBenchmarkStream->current()->postTimingHooks(canvas);
+                fOwner->reset();
                 fInitState = kReset_InitState;
             }
             break;
@@ -72,6 +74,6 @@
     this->handleInitState(canvas);
     this->renderFrame(canvas, fBenchmarkStream->current(), fTSM.loops());
     fOwner->present();
-    TimingStateMachine::ParentEvents event = fTSM.nextFrame(fPreWarmBeforeSample);
+    TimingStateMachine::ParentEvents event = fTSM.nextFrame(FLAGS_reset);
     this->handleTimingEvent(canvas, event);
 }
diff --git a/tools/VisualBench/VisualStreamTimingModule.h b/tools/VisualBench/VisualStreamTimingModule.h
index 5dbec69..80c67e8 100644
--- a/tools/VisualBench/VisualStreamTimingModule.h
+++ b/tools/VisualBench/VisualStreamTimingModule.h
@@ -24,7 +24,7 @@
  */
 class VisualStreamTimingModule : public VisualModule {
 public:
-    VisualStreamTimingModule(VisualBench* owner, bool preWarmBeforeSample);
+    VisualStreamTimingModule(VisualBench* owner);
     void draw(SkCanvas* canvas) override;
 
 private:
@@ -44,7 +44,6 @@
         kNewBenchmark_InitState,
     };
     InitState fInitState;
-    bool fPreWarmBeforeSample;
 
     // support framework
     VisualBench* fOwner;