add a global may-we-JIT flag

The most interesting part of the CL is that we recheck gSkVMAllowJIT in
Program::eval() even though we've already checked it in the constructor.
This allows Viewer to toggle the JIT on and off without having to worry
about program caching. This is not something that you'd expect to come
up in practice if a program just sets gSkVMAllowJIT at the start of
main(); for real clients I think we can avoid all this with a simple
SkGraphics::allowJIT() that only lets clients opt-in, never back out.

I toyed with making '!' rotate through a tristate in Viewer, until I
realized that these really are independent bits: GMs like threshold_rt
that use both ordinary effects and SkVM-only effects demonstrate
different behavior and performance in all four modes.  So '!' continues
to toggle SkVMBlitter, and now '@' toggles the JIT.

I've left the test program default settings unchanged, with the JIT
enabled unless --nojit is passed.  Where we previously simplified the
command line by conflating --dylib with --skvm, we now conflate --dylib
with --jit.

Change-Id: If86bf524c657298c0846bcd33c706e3c3f91e788
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308184
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index d9da323..2c1a338 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -163,7 +163,8 @@
 static DEFINE_bool(redraw, false, "Toggle continuous redraw.");
 
 static DEFINE_bool(offscreen, false, "Force rendering to an offscreen surface.");
-static DEFINE_bool(skvm, false, "Try to use skvm blitters for raster.");
+static DEFINE_bool(skvm, false, "Force skvm blitters for raster.");
+static DEFINE_bool(jit, true, "JIT SkVM?");
 static DEFINE_bool(dylib, false, "JIT via dylib (much slower compile but easier to debug/profile)");
 static DEFINE_bool(stats, false, "Display stats overlay on startup.");
 
@@ -295,6 +296,7 @@
 static const char kRefreshStateName[] = "Refresh";
 
 extern bool gUseSkVMBlitter;
+extern bool gSkVMAllowJIT;
 extern bool gSkVMJITViaDylib;
 
 Viewer::Viewer(int argc, char** argv, void* platformData)
@@ -346,6 +348,7 @@
 #endif
 
     gUseSkVMBlitter = FLAGS_skvm;
+    gSkVMAllowJIT = FLAGS_jit;
     gSkVMJITViaDylib = FLAGS_dylib;
 
     ToolUtils::SetDefaultFontMgr();
@@ -656,11 +659,16 @@
         this->updateTitle();
         fWindow->inval();
     });
-    fCommands.addCommand('!', "SkVM", "Toggle SkVM", [this]() {
+    fCommands.addCommand('!', "SkVM", "Toggle SkVM blitter", [this]() {
         gUseSkVMBlitter = !gUseSkVMBlitter;
         this->updateTitle();
         fWindow->inval();
     });
+    fCommands.addCommand('@', "SkVM", "Toggle SkVM JIT", [this]() {
+        gSkVMAllowJIT = !gSkVMAllowJIT;
+        this->updateTitle();
+        fWindow->inval();
+    });
 
     // set up slides
     this->initSlides();
@@ -899,7 +907,10 @@
         title.append(" <serialize>");
     }
     if (gUseSkVMBlitter) {
-        title.append(" <skvm>");
+        title.append(" <SkVMBlitter>");
+    }
+    if (!gSkVMAllowJIT) {
+        title.append(" <SkVM interpreter>");
     }
 
     SkPaintTitleUpdater paintTitle(&title);