Rework optimization override flags.

Previously, the Compiler optimization overrides only supported force-
disabling a particular behavior; we assumed that the default state of
a Compiler was to allow all optimizations. This assumption is about to
be invalidated, as the Inliner will soon be off by default unless you
are using GLES.

The override flags are now a tri-state; optimization and inlining can
be set to "default", "on" or "off".

Change-Id: I5637693222ca1de74ca1073c24d86c8e7c5026f6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/390136
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index 3297007..cc01495 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -72,11 +72,9 @@
 
 namespace SkSL {
 
-// Set these flags to `false` to disable optimization passes unilaterally.
 // These flags allow tools like Viewer or Nanobench to override the compiler's ProgramSettings.
-bool gSkSLOptimizer = true;
-bool gSkSLInliner = true;
-bool gSkSLDeadCodeElimination = true;
+Compiler::OverrideFlag Compiler::sOptimizer = OverrideFlag::kDefault;
+Compiler::OverrideFlag Compiler::sInliner = OverrideFlag::kDefault;
 
 using RefKind = VariableReference::RefKind;
 
@@ -405,11 +403,30 @@
     auto config = std::make_unique<ProgramConfig>(ProgramConfig{kind, settings});
     AutoProgramConfig autoConfig(fContext, config.get());
 
-    // Honor our global optimization-disable flags.
-    config->fSettings.fOptimize &= gSkSLOptimizer;
-    config->fSettings.fInlineThreshold *= (int)gSkSLInliner;
-    config->fSettings.fRemoveDeadVariables &= gSkSLDeadCodeElimination;
-    config->fSettings.fRemoveDeadFunctions &= gSkSLDeadCodeElimination;
+    // Honor our optimization-override flags.
+    switch (sOptimizer) {
+        case OverrideFlag::kDefault:
+            break;
+        case OverrideFlag::kOff:
+            config->fSettings.fOptimize = false;
+            break;
+        case OverrideFlag::kOn:
+            config->fSettings.fOptimize = true;
+            break;
+    }
+
+    switch (sInliner) {
+        case OverrideFlag::kDefault:
+            break;
+        case OverrideFlag::kOff:
+            config->fSettings.fInlineThreshold = 0;
+            break;
+        case OverrideFlag::kOn:
+            if (config->fSettings.fInlineThreshold == 0) {
+                config->fSettings.fInlineThreshold = kDefaultInlineThreshold;
+            }
+            break;
+    }
 
     // Disable optimization settings that depend on a parent setting which has been disabled.
     config->fSettings.fInlineThreshold *= (int)config->fSettings.fOptimize;