Add Viewer checkbox to toggle Control-Flow Analysis.

This gives Viewer a way to dynamically toggle CFA off and on, so we can
immediately see the impact on shader optimization.

Change-Id: I912df70de126a74a1f0d11c511b2acc64f1e9f28
Bug: skia:11319
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/380456
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 12f3994..1ae8708 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -65,6 +65,10 @@
     #include "tools/viewer/SkRiveSlide.h"
 #endif
 
+namespace SkSL {
+extern bool gSkSLControlFlowAnalysis;
+}
+
 class CapturingShaderErrorHandler : public GrContextOptions::ShaderErrorHandler {
 public:
     void compileError(const char* shader, const char* errors) override {
@@ -2391,7 +2395,9 @@
                 bool doView      = ImGui::Button("View"); ImGui::SameLine();
                 bool doApply     = ImGui::Button("Apply Changes"); ImGui::SameLine();
                 bool doDump      = ImGui::Button("Dump SkSL to resources/sksl/"); ImGui::SameLine();
-                bool skslChecked = ImGui::Checkbox("SkSL", &sksl);
+                bool skslChecked = ImGui::Checkbox("SkSL", &sksl); ImGui::SameLine();
+                bool doControlFlow = ImGui::Checkbox("Control-Flow Analysis",
+                                                     &SkSL::gSkSLControlFlowAnalysis);
 
                 // We always want to dump shaders in SkSL format, not the backend format.
                 if (doDump) {
@@ -2400,7 +2406,7 @@
 
                 // If SkSL was checked, or if we are dumping shaders, we want to reset the cache and
                 // redo everything.
-                if (doDump || skslChecked) {
+                if (doDump || doControlFlow || skslChecked) {
                     params.fGrContextOptions.fShaderCacheStrategy =
                             sksl ? GrContextOptions::ShaderCacheStrategy::kSkSL
                                  : GrContextOptions::ShaderCacheStrategy::kBackendSource;