Make SkRemoteGlyphCache tests use private glyph cache

Change-Id: If6aa189f3badc7558ab8ecf71ee3d704b275b20f
Reviewed-on: https://skia-review.googlesource.com/136225
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp
index fa47670..10b1b41 100644
--- a/src/core/SkRemoteGlyphCache.cpp
+++ b/src/core/SkRemoteGlyphCache.cpp
@@ -734,8 +734,11 @@
     sk_sp<DiscardableHandleManager> fManager;
 };
 
-SkStrikeClient::SkStrikeClient(sk_sp<DiscardableHandleManager> discardableManager, bool isLogging)
+SkStrikeClient::SkStrikeClient(sk_sp<DiscardableHandleManager> discardableManager,
+                               bool isLogging,
+                               SkStrikeCache* strikeCache)
         : fDiscardableHandleManager(std::move(discardableManager))
+        , fStrikeCache{strikeCache ? strikeCache : SkStrikeCache::GetGlobalStrikeCache()}
         , fIsLogging{isLogging} {}
 
 SkStrikeClient::~SkStrikeClient() = default;
@@ -792,18 +795,19 @@
         SkAutoDescriptor ad;
         auto* client_desc = auto_descriptor_from_desc(sourceAd.getDesc(), tf->uniqueID(), &ad);
 
-        auto strike = SkStrikeCache::FindStrikeExclusive(*client_desc);
+        auto strike = fStrikeCache->findStrikeExclusive(*client_desc);
         if (strike == nullptr) {
             // Note that we don't need to deserialize the effects since we won't be generating any
             // glyphs here anyway, and the desc is still correct since it includes the serialized
             // effects.
             SkScalerContextEffects effects;
             auto scaler = SkStrikeCache::CreateScalerContext(*client_desc, effects, *tf);
-            strike = SkStrikeCache::CreateStrikeExclusive(
+            strike = fStrikeCache->createStrikeExclusive(
                     *client_desc, std::move(scaler), &fontMetrics,
                     skstd::make_unique<DiscardableStrikePinner>(spec.discardableHandleId,
                                                                 fDiscardableHandleManager));
-            static_cast<SkScalerContextProxy*>(strike->getScalerContext())->initCache(strike.get());
+            auto proxyContext = static_cast<SkScalerContextProxy*>(strike->getScalerContext());
+            proxyContext->initCache(strike.get(), fStrikeCache);
         }
 
         size_t glyphImagesCount = 0u;
@@ -865,7 +869,7 @@
     WireTypeface wire;
     if (len != sizeof(wire)) return nullptr;
     memcpy(&wire, buf, sizeof(wire));
-    return addTypeface(wire);
+    return this->addTypeface(wire);
 }
 
 sk_sp<SkTypeface> SkStrikeClient::addTypeface(const WireTypeface& wire) {
diff --git a/src/core/SkRemoteGlyphCache.h b/src/core/SkRemoteGlyphCache.h
index ac13920..f09228f 100644
--- a/src/core/SkRemoteGlyphCache.h
+++ b/src/core/SkRemoteGlyphCache.h
@@ -20,7 +20,6 @@
 #include "SkMakeUnique.h"
 #include "SkNoDrawCanvas.h"
 #include "SkRefCnt.h"
-#include "SkRemoteGlyphCache.h"
 #include "SkSerialProcs.h"
 #include "SkTypeface.h"
 
@@ -30,6 +29,7 @@
 struct SkPackedGlyphID;
 enum SkScalerContextFlags : uint32_t;
 class SkScalerContextRecDescriptor;
+class SkStrikeCache;
 class SkTextBlobRunIterator;
 class SkTypefaceProxy;
 struct WireTypeface;
@@ -212,7 +212,9 @@
         virtual void notifyCacheMiss(CacheMissType) {}
     };
 
-    SkStrikeClient(sk_sp<DiscardableHandleManager>, bool isLogging = true);
+    SkStrikeClient(sk_sp<DiscardableHandleManager>,
+                   bool isLogging = true,
+                   SkStrikeCache* strikeCache = nullptr);
     ~SkStrikeClient();
 
     // Deserializes the typeface previously serialized using the SkStrikeServer. Returns null if the
@@ -223,7 +225,9 @@
     // from a server when serializing the ops must be deserialized before the op
     // is rasterized.
     // Returns false if the data is invalid.
-    bool readStrikeData(const volatile void* memory, size_t memorySize);
+    bool readStrikeData(
+            const volatile void* memory,
+            size_t memorySize);
 
 private:
     class DiscardableStrikePinner;
@@ -232,6 +236,7 @@
 
     SkTHashMap<SkFontID, sk_sp<SkTypeface>> fRemoteFontIdToTypeface;
     sk_sp<DiscardableHandleManager> fDiscardableHandleManager;
+    SkStrikeCache* const fStrikeCache;
     const bool fIsLogging;
 };
 
diff --git a/src/core/SkStrikeCache.cpp b/src/core/SkStrikeCache.cpp
index fef46fd..5f3a46b 100644
--- a/src/core/SkStrikeCache.cpp
+++ b/src/core/SkStrikeCache.cpp
@@ -19,15 +19,6 @@
 #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;
-}
-
 struct SkStrikeCache::Node {
     Node(const SkDescriptor& desc,
         std::unique_ptr<SkScalerContext> scaler,
@@ -42,23 +33,35 @@
     std::unique_ptr<SkStrikePinner> fPinner;
 };
 
-SkStrikeCache::ExclusiveStrikePtr::ExclusiveStrikePtr(SkStrikeCache::Node* node) : fNode{node} {}
-SkStrikeCache::ExclusiveStrikePtr::ExclusiveStrikePtr() : fNode{nullptr} {}
+SkStrikeCache::ExclusiveStrikePtr::ExclusiveStrikePtr(
+        SkStrikeCache::Node* node, SkStrikeCache* strikeCache)
+        : fNode{node}
+        , fStrikeCache{strikeCache} {}
+SkStrikeCache::ExclusiveStrikePtr::ExclusiveStrikePtr()
+        : fNode{nullptr}
+        , fStrikeCache{nullptr} {}
 SkStrikeCache::ExclusiveStrikePtr::ExclusiveStrikePtr(ExclusiveStrikePtr&& o)
-    : fNode{o.fNode} {
+    : fNode{o.fNode}, fStrikeCache{o.fStrikeCache} {
     o.fNode = nullptr;
+    o.fStrikeCache = nullptr;
 }
 
 SkStrikeCache::ExclusiveStrikePtr&
 SkStrikeCache::ExclusiveStrikePtr::operator = (ExclusiveStrikePtr&& o) {
-    Attach(fNode);
+    if (fNode != nullptr) {
+        fStrikeCache->attachNode(fNode);
+    }
     fNode = o.fNode;
+    fStrikeCache = o.fStrikeCache;
     o.fNode = nullptr;
+    o.fStrikeCache = nullptr;
     return *this;
 }
 
 SkStrikeCache::ExclusiveStrikePtr::~ExclusiveStrikePtr() {
-    SkStrikeCache::Attach(fNode);
+    if (fNode != nullptr) {
+        fStrikeCache->attachNode(fNode);
+    }
 }
 SkGlyphCache* SkStrikeCache::ExclusiveStrikePtr::get() const {
     return &fNode->fCache;
@@ -84,6 +87,14 @@
     return nullptr == rhs.fNode;
 }
 
+SkStrikeCache* SkStrikeCache::GetGlobalStrikeCache() {
+    static SkOnce once;
+    static SkStrikeCache* globals;
+
+    once([]{ globals = new SkStrikeCache; });
+    return globals;
+}
+
 SkStrikeCache::~SkStrikeCache() {
     Node* node = fHead;
     while (node) {
@@ -93,22 +104,9 @@
     }
 }
 
-void SkStrikeCache::Attach(Node* node) {
-    get_globals().attachNode(node);
-}
 
 SkExclusiveStrikePtr SkStrikeCache::FindStrikeExclusive(const SkDescriptor& desc) {
-    return get_globals().findStrikeExclusive(desc);
-}
-
-bool SkStrikeCache::DesperationSearchForImage(const SkDescriptor& desc, SkGlyph* glyph,
-                                              SkGlyphCache* targetCache) {
-    return get_globals().desperationSearchForImage(desc, glyph, targetCache);
-}
-
-bool SkStrikeCache::DesperationSearchForPath(
-        const SkDescriptor& desc, SkGlyphID glyphID, SkPath* path) {
-    return get_globals().desperationSearchForPath(desc, glyphID, path);
+    return GetGlobalStrikeCache()->findStrikeExclusive(desc);
 }
 
 std::unique_ptr<SkScalerContext> SkStrikeCache::CreateScalerContext(
@@ -131,10 +129,16 @@
 SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeExclusive(
         const SkDescriptor& desc, const SkScalerContextEffects& effects, const SkTypeface& typeface)
 {
-    auto cache = FindStrikeExclusive(desc);
+    return GetGlobalStrikeCache()->findOrCreateStrikeExclusive(desc, effects, typeface);
+}
+
+SkExclusiveStrikePtr SkStrikeCache::findOrCreateStrikeExclusive(
+        const SkDescriptor& desc, const SkScalerContextEffects& effects, const SkTypeface& typeface)
+{
+    auto cache = this->findStrikeExclusive(desc);
     if (cache == nullptr) {
         auto scaler = CreateScalerContext(desc, effects, typeface);
-        cache = CreateStrikeExclusive(desc, std::move(scaler));
+        cache = this->createStrikeExclusive(desc, std::move(scaler));
     }
     return cache;
 }
@@ -162,17 +166,23 @@
 }
 
 void SkStrikeCache::PurgeAll() {
-    get_globals().purgeAll();
+    GetGlobalStrikeCache()->purgeAll();
 }
 
 void SkStrikeCache::Validate() {
 #ifdef SK_DEBUG
-    auto visitor = [](const SkGlyphCache& cache) { cache.forceValidate(); };
-
-    get_globals().forEachStrike(visitor);
+    GetGlobalStrikeCache()->validate();
 #endif
 }
 
+#ifdef SK_DEBUG
+void SkStrikeCache::validate() const {
+    SkAutoExclusive ac(fLock);
+    this->internalValidate();
+}
+#endif
+
+
 void SkStrikeCache::Dump() {
     SkDebugf("GlyphCache [     used    budget ]\n");
     SkDebugf("    bytes  [ %8zu  %8zu ]\n",
@@ -190,7 +200,7 @@
         counter += 1;
     };
 
-    get_globals().forEachStrike(visitor);
+    GetGlobalStrikeCache()->forEachStrike(visitor);
 }
 
 namespace {
@@ -234,7 +244,7 @@
         dump->setMemoryBacking(dumpName.c_str(), "malloc", nullptr);
     };
 
-    get_globals().forEachStrike(visitor);
+    GetGlobalStrikeCache()->forEachStrike(visitor);
 }
 
 
@@ -244,7 +254,7 @@
     }
     SkAutoExclusive ac(fLock);
 
-    this->validate();
+    this->internalValidate();
     node->fCache.validate();
 
     this->internalAttachToHead(node);
@@ -258,11 +268,11 @@
     for (node = internalGetHead(); node != nullptr; node = node->fNext) {
         if (node->fCache.getDescriptor() == desc) {
             this->internalDetachCache(node);
-            return SkExclusiveStrikePtr(node);
+            return SkExclusiveStrikePtr(node, this);
         }
     }
 
-    return SkExclusiveStrikePtr(nullptr);
+    return SkExclusiveStrikePtr();
 }
 
 static bool loose_compare(const SkDescriptor& lhs, const SkDescriptor& rhs) {
@@ -354,6 +364,16 @@
         SkPaint::FontMetrics* maybeMetrics,
         std::unique_ptr<SkStrikePinner> pinner)
 {
+    return GetGlobalStrikeCache()->createStrikeExclusive(
+            desc, std::move(scaler), maybeMetrics, std::move(pinner));
+}
+
+SkExclusiveStrikePtr SkStrikeCache::createStrikeExclusive(
+        const SkDescriptor& desc,
+        std::unique_ptr<SkScalerContext> scaler,
+        SkPaint::FontMetrics* maybeMetrics,
+        std::unique_ptr<SkStrikePinner> pinner)
+{
     SkPaint::FontMetrics fontMetrics;
     if (maybeMetrics != nullptr) {
         fontMetrics = *maybeMetrics;
@@ -361,7 +381,9 @@
         scaler->getFontMetrics(&fontMetrics);
     }
 
-    return SkExclusiveStrikePtr(new Node(desc, std::move(scaler), fontMetrics, std::move(pinner)));
+    return SkExclusiveStrikePtr(
+            new Node(desc, std::move(scaler), fontMetrics, std::move(pinner)),
+            this);
 }
 
 void SkStrikeCache::purgeAll() {
@@ -436,15 +458,13 @@
 void SkStrikeCache::forEachStrike(std::function<void(const SkGlyphCache&)> visitor) const {
     SkAutoExclusive ac(fLock);
 
-    this->validate();
-
     for (Node* node = this->internalGetHead(); node != nullptr; node = node->fNext) {
         visitor(node->fCache);
     }
 }
 
 size_t SkStrikeCache::internalPurge(size_t minBytesNeeded) {
-    this->validate();
+    this->internalValidate();
 
     size_t bytesNeeded = 0;
     if (fTotalMemoryUsed > fCacheSizeLimit) {
@@ -487,7 +507,7 @@
         node = prev;
     }
 
-    this->validate();
+    this->internalValidate();
 
 #ifdef SPEW_PURGE_STATUS
     if (countFreed) {
@@ -534,12 +554,13 @@
 }
 
 #ifdef SK_DEBUG
-void SkStrikeCache::validate() const {
+void SkStrikeCache::internalValidate() const {
     size_t computedBytes = 0;
     int computedCount = 0;
 
     const Node* node = fHead;
     while (node != nullptr) {
+        node->fCache.forceValidate();
         computedBytes += node->fCache.getMemoryUsed();
         computedCount += 1;
         node = node->fNext;
@@ -555,38 +576,38 @@
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 
 size_t SkGraphics::GetFontCacheLimit() {
-    return get_globals().getCacheSizeLimit();
+    return SkStrikeCache::GetGlobalStrikeCache()->getCacheSizeLimit();
 }
 
 size_t SkGraphics::SetFontCacheLimit(size_t bytes) {
-    return get_globals().setCacheSizeLimit(bytes);
+    return SkStrikeCache::GetGlobalStrikeCache()->setCacheSizeLimit(bytes);
 }
 
 size_t SkGraphics::GetFontCacheUsed() {
-    return get_globals().getTotalMemoryUsed();
+    return SkStrikeCache::GetGlobalStrikeCache()->getTotalMemoryUsed();
 }
 
 int SkGraphics::GetFontCacheCountLimit() {
-    return get_globals().getCacheCountLimit();
+    return SkStrikeCache::GetGlobalStrikeCache()->getCacheCountLimit();
 }
 
 int SkGraphics::SetFontCacheCountLimit(int count) {
-    return get_globals().setCacheCountLimit(count);
+    return SkStrikeCache::GetGlobalStrikeCache()->setCacheCountLimit(count);
 }
 
 int SkGraphics::GetFontCacheCountUsed() {
-    return get_globals().getCacheCountUsed();
+    return SkStrikeCache::GetGlobalStrikeCache()->getCacheCountUsed();
 }
 
 int SkGraphics::GetFontCachePointSizeLimit() {
-    return get_globals().getCachePointSizeLimit();
+    return SkStrikeCache::GetGlobalStrikeCache()->getCachePointSizeLimit();
 }
 
 int SkGraphics::SetFontCachePointSizeLimit(int limit) {
-    return get_globals().setCachePointSizeLimit(limit);
+    return SkStrikeCache::GetGlobalStrikeCache()->setCachePointSizeLimit(limit);
 }
 
 void SkGraphics::PurgeFontCache() {
-    get_globals().purgeAll();
+    SkStrikeCache::GetGlobalStrikeCache()->purgeAll();
     SkTypefaceCache::PurgeAll();
 }
diff --git a/src/core/SkStrikeCache.h b/src/core/SkStrikeCache.h
index 05e3aa4..a2b3a8a 100644
--- a/src/core/SkStrikeCache.h
+++ b/src/core/SkStrikeCache.h
@@ -47,7 +47,7 @@
 
     class ExclusiveStrikePtr {
     public:
-        explicit ExclusiveStrikePtr(Node*);
+        explicit ExclusiveStrikePtr(Node*, SkStrikeCache*);
         ExclusiveStrikePtr();
         ExclusiveStrikePtr(const ExclusiveStrikePtr&) = delete;
         ExclusiveStrikePtr& operator = (const ExclusiveStrikePtr&) = delete;
@@ -65,8 +65,10 @@
 
     private:
         Node* fNode;
+        SkStrikeCache* fStrikeCache;
     };
 
+    static SkStrikeCache* GetGlobalStrikeCache();
 
     static ExclusiveStrikePtr FindStrikeExclusive(const SkDescriptor&);
 
@@ -111,6 +113,17 @@
     void attachNode(Node* node);
     ExclusiveStrikePtr findStrikeExclusive(const SkDescriptor&);
 
+    ExclusiveStrikePtr findOrCreateStrikeExclusive(
+            const SkDescriptor& desc,
+            const SkScalerContextEffects& effects,
+            const SkTypeface& typeface);
+
+    ExclusiveStrikePtr createStrikeExclusive(
+            const SkDescriptor& desc,
+            std::unique_ptr<SkScalerContext> scaler,
+            SkPaint::FontMetrics* maybeMetrics = nullptr,
+            std::unique_ptr<SkStrikePinner> = nullptr);
+
     // Routines to find suitable data when working in a remote cache situation. These are
     // suitable as substitutes for similar calls in SkScalerContext.
     bool desperationSearchForImage(const SkDescriptor& desc,
@@ -133,13 +146,13 @@
 
 #ifdef SK_DEBUG
     void validate() const;
+    void internalValidate() const;
 #else
     void validate() const {}
+    void internalValidate() const {}
 #endif
 
 private:
-    static void Attach(Node* node);
-
     // The following methods can only be called when mutex is already held.
     Node* internalGetHead() const { return fHead; }
     Node* internalGetTail() const { return fTail; }
diff --git a/src/core/SkTypeface_remote.cpp b/src/core/SkTypeface_remote.cpp
index 4b10f1e..bc6376d 100644
--- a/src/core/SkTypeface_remote.cpp
+++ b/src/core/SkTypeface_remote.cpp
@@ -19,11 +19,12 @@
         : SkScalerContext{std::move(tf), effects, desc}
         , fDiscardableManager{std::move(manager)} {}
 
-void SkScalerContextProxy::initCache(SkGlyphCache* cache) {
+void SkScalerContextProxy::initCache(SkGlyphCache* cache, SkStrikeCache* strikeCache) {
     SkASSERT(fCache == nullptr);
     SkASSERT(cache != nullptr);
 
     fCache = cache;
+    fStrikeCache = strikeCache;
 }
 
 unsigned SkScalerContextProxy::generateGlyphCount()  {
@@ -57,7 +58,7 @@
         }
 
         // Now check other caches for a desc mismatch.
-        if (SkStrikeCache::DesperationSearchForImage(fCache->getDescriptor(), glyph, fCache)) {
+        if (fStrikeCache->desperationSearchForImage(fCache->getDescriptor(), glyph, fCache)) {
             fDiscardableManager->notifyCacheMiss(
                     SkStrikeClient::CacheMissType::kGlyphMetricsFallback);
             return;
@@ -88,7 +89,7 @@
     // Since the scaler context is being called, we don't have the needed data. Try to find a
     // fallback before failing.
     auto desc = SkScalerContext::DescriptorGivenRecAndEffects(this->getRec(), this->getEffects());
-    bool foundPath = SkStrikeCache::DesperationSearchForPath(*desc, glyphID, path);
+    bool foundPath = fStrikeCache->desperationSearchForPath(*desc, glyphID, path);
     fDiscardableManager->notifyCacheMiss(foundPath
                                                  ? SkStrikeClient::CacheMissType::kGlyphPathFallback
                                                  : SkStrikeClient::CacheMissType::kGlyphPath);
diff --git a/src/core/SkTypeface_remote.h b/src/core/SkTypeface_remote.h
index 88628d1..f4d3f73 100644
--- a/src/core/SkTypeface_remote.h
+++ b/src/core/SkTypeface_remote.h
@@ -18,6 +18,7 @@
 #include "SkTypeface.h"
 
 class SkTypefaceProxy;
+class SkStrikeCache;
 
 class SkScalerContextProxy : public SkScalerContext {
 public:
@@ -26,7 +27,7 @@
                          const SkDescriptor* desc,
                          sk_sp<SkStrikeClient::DiscardableHandleManager> manager);
 
-    void initCache(SkGlyphCache*);
+    void initCache(SkGlyphCache*, SkStrikeCache*);
 
 protected:
     unsigned generateGlyphCount() override;
@@ -41,6 +42,7 @@
 private:
     sk_sp<SkStrikeClient::DiscardableHandleManager> fDiscardableManager;
     SkGlyphCache* fCache = nullptr;
+    SkStrikeCache* fStrikeCache = nullptr;
     typedef SkScalerContext INHERITED;
 };
 
diff --git a/tests/SkRemoteGlyphCacheTest.cpp b/tests/SkRemoteGlyphCacheTest.cpp
index 8bdfb7a..6dc79a7 100644
--- a/tests/SkRemoteGlyphCacheTest.cpp
+++ b/tests/SkRemoteGlyphCacheTest.cpp
@@ -428,6 +428,8 @@
     auto lostGlyphID = SkPackedGlyphID(1, SK_FixedHalf, SK_FixedHalf);
     const uint8_t glyphImage[] = {0xFF, 0xFF};
 
+    SkStrikeCache strikeCache;
+
     // Build a fallback cache.
     {
         SkAutoDescriptor ad;
@@ -437,7 +439,7 @@
         SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
         auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
 
-        auto fallbackCache = SkStrikeCache::FindOrCreateStrikeExclusive(*desc, effects, *clientTf);
+        auto fallbackCache = strikeCache.findOrCreateStrikeExclusive(*desc, effects, *clientTf);
         auto glyph = fallbackCache->getRawGlyphByID(lostGlyphID);
         glyph->fMaskFormat = SkMask::kA8_Format;
         glyph->fHeight = 1;
@@ -454,7 +456,7 @@
         SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
         SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
         auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
-        auto testCache = SkStrikeCache::FindStrikeExclusive(*desc);
+        auto testCache = strikeCache.findStrikeExclusive(*desc);
         REPORTER_ASSERT(reporter, !(testCache == nullptr));
     }
 
@@ -466,11 +468,12 @@
     SkScalerContextFlags flags = SkScalerContextFlags::kNone;
     SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
     auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
-    testCache = SkStrikeCache::FindStrikeExclusive(*desc);
+    testCache = strikeCache.findStrikeExclusive(*desc);
     REPORTER_ASSERT(reporter, testCache == nullptr);
-    testCache = SkStrikeCache::CreateStrikeExclusive(*desc,
+    testCache = strikeCache.createStrikeExclusive(*desc,
                                                      clientTf->createScalerContext(effects, desc));
-    static_cast<SkScalerContextProxy*>(testCache->getScalerContext())->initCache(testCache.get());
+    auto scalerProxy = static_cast<SkScalerContextProxy*>(testCache->getScalerContext());
+    scalerProxy->initCache(testCache.get(), &strikeCache);
 
     // Look for the lost glyph.
     {
@@ -504,7 +507,7 @@
             REPORTER_ASSERT(reporter, discardableManager->cacheMissCount(i) == 0);
         }
     }
-    SkStrikeCache::Validate();
+    strikeCache.internalValidate();
 
     // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
     discardableManager->unlockAndDeleteAll();
@@ -530,6 +533,8 @@
     uint32_t realMask;
     uint32_t fakeMask;
 
+    SkStrikeCache strikeCache;
+
     {
         SkAutoDescriptor ad;
         SkScalerContextRec rec;
@@ -557,7 +562,7 @@
         SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
         auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
 
-        auto fallbackCache = SkStrikeCache::FindOrCreateStrikeExclusive(*desc, effects, *clientTf);
+        auto fallbackCache = strikeCache.findOrCreateStrikeExclusive(*desc, effects, *clientTf);
         auto glyph = fallbackCache->getRawGlyphByID(lostGlyphID);
         fakeMask = (realMask == SkMask::kA8_Format) ? SkMask::kBW_Format : SkMask::kA8_Format;
         glyph->fMaskFormat = fakeMask;
@@ -579,7 +584,9 @@
         std::vector<uint8_t> serverStrikeData;
         server.writeStrikeData(&serverStrikeData);
         REPORTER_ASSERT(reporter,
-                        client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
+                        client.readStrikeData(
+                                serverStrikeData.data(),
+                                serverStrikeData.size()));
     }
 
     {
@@ -591,7 +598,7 @@
         SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
         auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
 
-        auto fallbackCache = SkStrikeCache::FindStrikeExclusive(*desc);
+        auto fallbackCache = strikeCache.findStrikeExclusive(*desc);
         REPORTER_ASSERT(reporter, fallbackCache.get() != nullptr);
         auto glyph = fallbackCache->getRawGlyphByID(lostGlyphID);
         REPORTER_ASSERT(reporter, glyph->fMaskFormat == fakeMask);