Allow access to global glyph cache

The global glyph cache pointer is closed over in
SkStrikeCache.cpp. Allow access to it for future code
to move away from the global glyph cache.

BUG=skia:8091

Change-Id: I6e1fb712c082452e6a3b54f5fb5e6167caf9e757
Reviewed-on: https://skia-review.googlesource.com/136613
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/src/core/SkGraphics.cpp b/src/core/SkGraphics.cpp
index f169092..e88b0d0 100644
--- a/src/core/SkGraphics.cpp
+++ b/src/core/SkGraphics.cpp
@@ -26,6 +26,7 @@
 #include "SkStrikeCache.h"
 #include "SkTSearch.h"
 #include "SkTime.h"
+#include "SkTypefaceCache.h"
 #include "SkUtils.h"
 
 #include <stdlib.h>
@@ -108,3 +109,40 @@
         flags = nextSemi + 1;
     } while (nextSemi);
 }
+
+size_t SkGraphics::GetFontCacheLimit() {
+    return SkStrikeCache::GlobalStrikeCache()->getCacheSizeLimit();
+}
+
+size_t SkGraphics::SetFontCacheLimit(size_t bytes) {
+    return SkStrikeCache::GlobalStrikeCache()->setCacheSizeLimit(bytes);
+}
+
+size_t SkGraphics::GetFontCacheUsed() {
+    return SkStrikeCache::GlobalStrikeCache()->getTotalMemoryUsed();
+}
+
+int SkGraphics::GetFontCacheCountLimit() {
+    return SkStrikeCache::GlobalStrikeCache()->getCacheCountLimit();
+}
+
+int SkGraphics::SetFontCacheCountLimit(int count) {
+    return SkStrikeCache::GlobalStrikeCache()->setCacheCountLimit(count);
+}
+
+int SkGraphics::GetFontCacheCountUsed() {
+    return SkStrikeCache::GlobalStrikeCache()->getCacheCountUsed();
+}
+
+int SkGraphics::GetFontCachePointSizeLimit() {
+    return SkStrikeCache::GlobalStrikeCache()->getCachePointSizeLimit();
+}
+
+int SkGraphics::SetFontCachePointSizeLimit(int limit) {
+    return SkStrikeCache::GlobalStrikeCache()->setCachePointSizeLimit(limit);
+}
+
+void SkGraphics::PurgeFontCache() {
+    SkStrikeCache::GlobalStrikeCache()->purgeAll();
+    SkTypefaceCache::PurgeAll();
+}
diff --git a/src/core/SkStrikeCache.cpp b/src/core/SkStrikeCache.cpp
index fef46fd..64146e2 100644
--- a/src/core/SkStrikeCache.cpp
+++ b/src/core/SkStrikeCache.cpp
@@ -9,23 +9,16 @@
 
 #include <cctype>
 
-#include "SkDeduper.h"
 #include "SkGlyphCache.h"
 #include "SkGraphics.h"
 #include "SkMutex.h"
-#include "SkOnce.h"
 #include "SkTraceMemoryDump.h"
 #include "SkTypeface.h"
-#include "SkTypefaceCache.h"
 #include "SkPaintPriv.h"
 
-// Returns the shared globals
-static SkStrikeCache& get_globals() {
-    static SkOnce once;
-    static SkStrikeCache* globals;
-
-    once([]{ globals = new SkStrikeCache; });
-    return *globals;
+SkStrikeCache* SkStrikeCache::GlobalStrikeCache() {
+    static auto* cache = new SkStrikeCache;
+    return cache;
 }
 
 struct SkStrikeCache::Node {
@@ -94,21 +87,21 @@
 }
 
 void SkStrikeCache::Attach(Node* node) {
-    get_globals().attachNode(node);
+    GlobalStrikeCache()->attachNode(node);
 }
 
 SkExclusiveStrikePtr SkStrikeCache::FindStrikeExclusive(const SkDescriptor& desc) {
-    return get_globals().findStrikeExclusive(desc);
+    return GlobalStrikeCache()->findStrikeExclusive(desc);
 }
 
 bool SkStrikeCache::DesperationSearchForImage(const SkDescriptor& desc, SkGlyph* glyph,
                                               SkGlyphCache* targetCache) {
-    return get_globals().desperationSearchForImage(desc, glyph, targetCache);
+    return GlobalStrikeCache()->desperationSearchForImage(desc, glyph, targetCache);
 }
 
 bool SkStrikeCache::DesperationSearchForPath(
         const SkDescriptor& desc, SkGlyphID glyphID, SkPath* path) {
-    return get_globals().desperationSearchForPath(desc, glyphID, path);
+    return GlobalStrikeCache()->desperationSearchForPath(desc, glyphID, path);
 }
 
 std::unique_ptr<SkScalerContext> SkStrikeCache::CreateScalerContext(
@@ -162,14 +155,14 @@
 }
 
 void SkStrikeCache::PurgeAll() {
-    get_globals().purgeAll();
+    GlobalStrikeCache()->purgeAll();
 }
 
 void SkStrikeCache::Validate() {
 #ifdef SK_DEBUG
     auto visitor = [](const SkGlyphCache& cache) { cache.forceValidate(); };
 
-    get_globals().forEachStrike(visitor);
+    GlobalStrikeCache()->forEachStrike(visitor);
 #endif
 }
 
@@ -190,7 +183,7 @@
         counter += 1;
     };
 
-    get_globals().forEachStrike(visitor);
+    GlobalStrikeCache()->forEachStrike(visitor);
 }
 
 namespace {
@@ -234,7 +227,7 @@
         dump->setMemoryBacking(dumpName.c_str(), "malloc", nullptr);
     };
 
-    get_globals().forEachStrike(visitor);
+    GlobalStrikeCache()->forEachStrike(visitor);
 }
 
 
@@ -553,40 +546,3 @@
 #endif
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
-
-size_t SkGraphics::GetFontCacheLimit() {
-    return get_globals().getCacheSizeLimit();
-}
-
-size_t SkGraphics::SetFontCacheLimit(size_t bytes) {
-    return get_globals().setCacheSizeLimit(bytes);
-}
-
-size_t SkGraphics::GetFontCacheUsed() {
-    return get_globals().getTotalMemoryUsed();
-}
-
-int SkGraphics::GetFontCacheCountLimit() {
-    return get_globals().getCacheCountLimit();
-}
-
-int SkGraphics::SetFontCacheCountLimit(int count) {
-    return get_globals().setCacheCountLimit(count);
-}
-
-int SkGraphics::GetFontCacheCountUsed() {
-    return get_globals().getCacheCountUsed();
-}
-
-int SkGraphics::GetFontCachePointSizeLimit() {
-    return get_globals().getCachePointSizeLimit();
-}
-
-int SkGraphics::SetFontCachePointSizeLimit(int limit) {
-    return get_globals().setCachePointSizeLimit(limit);
-}
-
-void SkGraphics::PurgeFontCache() {
-    get_globals().purgeAll();
-    SkTypefaceCache::PurgeAll();
-}
diff --git a/src/core/SkStrikeCache.h b/src/core/SkStrikeCache.h
index 05e3aa4..dcec3de 100644
--- a/src/core/SkStrikeCache.h
+++ b/src/core/SkStrikeCache.h
@@ -67,6 +67,7 @@
         Node* fNode;
     };
 
+    static SkStrikeCache* GlobalStrikeCache();
 
     static ExclusiveStrikePtr FindStrikeExclusive(const SkDescriptor&);