Make global use-analytic-AA bit threadsafe.

I also had to cut it down to just a global atomic bool... as a field in a global singleton accessed through instance(), it's very hard to make threadsafe.

CQ_INCLUDE_TRYBOTS=master.client.skia:Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-TSAN-Trybot

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2937

Change-Id: If80be987906dd521fbe644d1d0d577009f06d0e3
Reviewed-on: https://skia-review.googlesource.com/2937
Reviewed-by: Yuqian Li <liyuqian@google.com>
Commit-Queue: Yuqian Li <liyuqian@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index 1191423..8d42b12 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -1180,7 +1180,7 @@
     }
 
     if (FLAGS_analyticAA) {
-        GlobalAAConfig::getInstance().fUseAnalyticAA = true;
+        gSkUseAnalyticAA = true;
     }
 
     int runs = 0;
diff --git a/dm/DM.cpp b/dm/DM.cpp
index c6e2ab9..0ce3738 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -1276,7 +1276,7 @@
     setup_crash_handler();
 
     if (FLAGS_analyticAA) {
-        GlobalAAConfig::getInstance().fUseAnalyticAA = true;
+        gSkUseAnalyticAA = true;
     }
 
     if (FLAGS_verbose) {
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 5d73162..52e063d 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -1802,8 +1802,7 @@
             }
             break;
         case 'A':
-            GlobalAAConfig::getInstance().fUseAnalyticAA =
-                    !GlobalAAConfig::getInstance().fUseAnalyticAA;
+            gSkUseAnalyticAA = !gSkUseAnalyticAA.load();
             this->inval(nullptr);
             break;
         case 'B':
diff --git a/src/core/SkScan.cpp b/src/core/SkScan.cpp
index 7fce3f1..ceb9ff6 100644
--- a/src/core/SkScan.cpp
+++ b/src/core/SkScan.cpp
@@ -10,6 +10,8 @@
 #include "SkBlitter.h"
 #include "SkRasterClip.h"
 
+std::atomic<bool> gSkUseAnalyticAA{false};
+
 static inline void blitrect(SkBlitter* blitter, const SkIRect& r) {
     blitter->blitRect(r.fLeft, r.fTop, r.width(), r.height());
 }
diff --git a/src/core/SkScan.h b/src/core/SkScan.h
index 1e3d60a..7d51369 100644
--- a/src/core/SkScan.h
+++ b/src/core/SkScan.h
@@ -11,6 +11,7 @@
 
 #include "SkFixed.h"
 #include "SkRect.h"
+#include <atomic>
 
 class SkRasterClip;
 class SkRegion;
@@ -22,21 +23,7 @@
 */
 typedef SkIRect SkXRect;
 
-class GlobalAAConfig {
-private:
-    GlobalAAConfig() {}
-
-public:
-    bool fUseAnalyticAA = false;
-
-    GlobalAAConfig(const GlobalAAConfig&) = delete;
-    void operator=(const GlobalAAConfig&) = delete;
-
-    static GlobalAAConfig& getInstance() {
-        static GlobalAAConfig instance;
-        return instance;
-    }
-};
+extern std::atomic<bool> gSkUseAnalyticAA;
 
 class AdditiveBlitter;
 
diff --git a/src/core/SkScan_AAAPath.cpp b/src/core/SkScan_AAAPath.cpp
index e5b8c57..501b2e6 100644
--- a/src/core/SkScan_AAAPath.cpp
+++ b/src/core/SkScan_AAAPath.cpp
@@ -1109,7 +1109,7 @@
     // If we're convex, then we need both edges, even the right edge is past the clip
     const bool canCullToTheRight = !path.isConvex();
 
-    SkASSERT(GlobalAAConfig::getInstance().fUseAnalyticAA);
+    SkASSERT(gSkUseAnalyticAA.load());
     int count = builder.build(path, clipRect, 0, canCullToTheRight, true);
     SkASSERT(count >= 0);
 
diff --git a/src/core/SkScan_AntiPath.cpp b/src/core/SkScan_AntiPath.cpp
index a300d74..53dac3f 100644
--- a/src/core/SkScan_AntiPath.cpp
+++ b/src/core/SkScan_AntiPath.cpp
@@ -750,7 +750,7 @@
 
 void SkScan::AntiFillPath(const SkPath& path, const SkRasterClip& clip,
                           SkBlitter* blitter) {
-    if (GlobalAAConfig::getInstance().fUseAnalyticAA) {
+    if (gSkUseAnalyticAA.load()) {
         SkScan::AAAFillPath(path, clip, blitter);
         return;
     }