Add offscreen mode to visualbench

Replaces "nvpr mode" with "offscreen mode" and a flag to enable/
disable nvpr. Assigns new config names to the various combinations of
flags and begins printing them with the bench results in order to match
nanobench.

BUG=skia:

Review URL: https://codereview.chromium.org/1473253002
diff --git a/tools/VisualBench/VisualBench.cpp b/tools/VisualBench/VisualBench.cpp
index 3f695d6..4b76307 100644
--- a/tools/VisualBench/VisualBench.cpp
+++ b/tools/VisualBench/VisualBench.cpp
@@ -22,6 +22,8 @@
 #include "VisualInteractiveModule.h"
 #include "gl/GrGLInterface.h"
 
+#include <stdlib.h>
+
 DEFINE_bool2(fullscreen, f, true, "Run fullscreen.");
 DEFINE_bool2(interactive, n, false, "Run in interactive mode.");
 DEFINE_bool2(dif, d, false, "Use device-independent fonts.");
@@ -35,6 +37,11 @@
 
     SkCommandLineFlags::Parse(argc, argv);
 
+    if (FLAGS_nvpr && !FLAGS_msaa) {
+        SkDebugf("Got nvpr without msaa. Exiting.\n");
+        exit(-1);
+    }
+
     // these have to happen after commandline parsing
     if (FLAGS_dif) {
         const SkSurfaceProps& props(INHERITED::getSurfaceProps());
@@ -90,7 +97,8 @@
 }
 
 void VisualBench::setupContext() {
-    if (!this->attach(kNativeGL_BackEndType, FLAGS_msaa, &fAttachmentInfo)) {
+    int screenSamples = FLAGS_offscreen ? 0 : FLAGS_msaa;
+    if (!this->attach(kNativeGL_BackEndType, screenSamples, &fAttachmentInfo)) {
         SkDebugf("Not possible to create backend.\n");
         INHERITED::detach();
         SkFAIL("Could not create backend\n");
@@ -103,7 +111,7 @@
     fInterface.reset(GrGLCreateNativeInterface());
 
     // TODO use the GLContext creation factories and also set this all up in configs
-    if (0 == FLAGS_nvpr) {
+    if (!FLAGS_nvpr) {
         fInterface.reset(GrGLInterfaceRemoveNVPR(fInterface));
     }
     SkASSERT(fInterface);
diff --git a/tools/VisualBench/VisualBenchmarkStream.cpp b/tools/VisualBench/VisualBenchmarkStream.cpp
index 7f072e8..183da75 100644
--- a/tools/VisualBench/VisualBenchmarkStream.cpp
+++ b/tools/VisualBench/VisualBenchmarkStream.cpp
@@ -21,7 +21,6 @@
 #include "GrContext.h"
 #endif
 
-DEFINE_bool(cpu, false, "Run in CPU mode?");
 DEFINE_string2(match, m, nullptr,
                "[~][^]substring[$] [...] of bench name to run.\n"
                "Multiple matches may be separated by spaces.\n"
@@ -137,8 +136,8 @@
     // TODO move this all to --config
     if (bench && FLAGS_cpu) {
         bench = new CpuWrappedBenchmark(fSurfaceProps, bench);
-    } else if (bench && 0 != FLAGS_nvpr) {
-        bench = new NvprWrappedBenchmark(fSurfaceProps, bench, FLAGS_nvpr);
+    } else if (bench && FLAGS_offscreen) {
+        bench = new GpuWrappedBenchmark(fSurfaceProps, bench, FLAGS_msaa);
     }
 
     fBenchmark.reset(bench);
diff --git a/tools/VisualBench/VisualFlags.cpp b/tools/VisualBench/VisualFlags.cpp
index 5876bde..84304c1 100644
--- a/tools/VisualBench/VisualFlags.cpp
+++ b/tools/VisualBench/VisualFlags.cpp
@@ -8,4 +8,6 @@
 #include "VisualFlags.h"
 
 DEFINE_int32(msaa, 0, "Number of msaa samples.");
-DEFINE_int32(nvpr, 0, "Number of stencil samples for nvpr, or zero to disable it.");
+DEFINE_bool(offscreen, false, "Perform rendering in an offscreen buffer.");
+DEFINE_bool(nvpr, false, "Use nvpr?");
+DEFINE_bool(cpu, false, "Run in CPU mode?");
diff --git a/tools/VisualBench/VisualFlags.h b/tools/VisualBench/VisualFlags.h
index 3735410..58a0970 100644
--- a/tools/VisualBench/VisualFlags.h
+++ b/tools/VisualBench/VisualFlags.h
@@ -12,6 +12,8 @@
 
 DECLARE_string(config);
 DECLARE_int32(msaa);
-DECLARE_int32(nvpr);
+DECLARE_bool(offscreen);
+DECLARE_bool(nvpr);
+DECLARE_bool(cpu);
 
 #endif
diff --git a/tools/VisualBench/VisualLightweightBenchModule.cpp b/tools/VisualBench/VisualLightweightBenchModule.cpp
index baca168..182a9d9 100644
--- a/tools/VisualBench/VisualLightweightBenchModule.cpp
+++ b/tools/VisualBench/VisualLightweightBenchModule.cpp
@@ -46,8 +46,8 @@
     , fCurrentSample(0)
     , fResults(new ResultsWriter) {
     // Print header
-    SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tbench\n", FLAGS_samples,
-             "samples");
+    SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n",
+             FLAGS_samples, "samples");
 
     // setup json logging if required
     if (!FLAGS_outResultsFile.isEmpty()) {
@@ -86,10 +86,26 @@
     // update log
     // Note: We currently log only the minimum.  It would be interesting to log more information
     SkString configName;
-    if (FLAGS_msaa > 0) {
-        configName.appendf("msaa_%d", FLAGS_msaa);
+    if (FLAGS_cpu) {
+        configName.append("cpu");
+    } else if (FLAGS_nvpr) {
+        if (FLAGS_offscreen) {
+            configName.appendf("nvpr_%d", FLAGS_msaa);
+        } else {
+            configName.appendf("nvpr_msaa_%d", FLAGS_msaa);
+        }
+    } else if (FLAGS_msaa > 0) {
+        if (FLAGS_offscreen) {
+            configName.appendf("offscreen_msaa_%d", FLAGS_msaa);
+        } else {
+            configName.appendf("msaa_%d", FLAGS_msaa);
+        }
     } else {
-        configName.appendf("gpu");
+        if (FLAGS_offscreen) {
+            configName.append("offscreen");
+        } else {
+            configName.append("gpu");
+        }
     }
     // Log bench name
     fResults->bench(shortName, benchmark->getSize().fX, benchmark->getSize().fY);
@@ -108,7 +124,7 @@
         SkDebugf("%s\n", shortName);
     } else {
         const double stdDevPercent = 100 * sqrt(stats.var) / stats.mean;
-        SkDebugf("%4d/%-4dMB\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\n",
+        SkDebugf("%4d/%-4dMB\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n",
                  sk_tools::getCurrResidentSetSizeMB(),
                  sk_tools::getMaxResidentSetSizeMB(),
                  loops,
@@ -118,6 +134,7 @@
                  HUMANIZE(stats.max),
                  stdDevPercent,
                  stats.plot.c_str(),
+                 configName.c_str(),
                  shortName);
     }
 }
diff --git a/tools/VisualBench/WrappedBenchmark.h b/tools/VisualBench/WrappedBenchmark.h
index dba6134..d16556c 100644
--- a/tools/VisualBench/WrappedBenchmark.h
+++ b/tools/VisualBench/WrappedBenchmark.h
@@ -95,10 +95,10 @@
 };
 
 // Create an MSAA & NVPR-enabled GPU backend
-class NvprWrappedBenchmark : public WrappedBenchmark {
+class GpuWrappedBenchmark : public WrappedBenchmark {
 public:
-    explicit NvprWrappedBenchmark(const SkSurfaceProps& surfaceProps, Benchmark* bench,
-                                  int numSamples)
+    explicit GpuWrappedBenchmark(const SkSurfaceProps& surfaceProps, Benchmark* bench,
+                                 int numSamples)
         : INHERITED(surfaceProps, bench)
         , fNumSamples(numSamples) {}