Split getOrCreateCache into a SkFont and descriptor based calles

Change-Id: Ie4724137baf3d355b94bd9966cc381a688c465fb
Reviewed-on: https://skia-review.googlesource.com/c/190671
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp
index e33f3a5..64ef769 100644
--- a/src/core/SkRemoteGlyphCache.cpp
+++ b/src/core/SkRemoteGlyphCache.cpp
@@ -309,14 +309,19 @@
     SkAutoDescriptor descStorage;
     auto desc = create_descriptor(paint, font, matrix, props, flags, &descStorage, effects);
 
-    SkTypeface* typeface = font.getTypefaceOrDefault();
+    return this->getOrCreateCache(*desc, *font.getTypefaceOrDefault(), *effects);
+
+}
+
+SkStrikeServer::SkGlyphCacheState* SkStrikeServer::getOrCreateCache(
+        const SkDescriptor& desc, const SkTypeface& typeface, SkScalerContextEffects effects) {
 
     // In cases where tracing is turned off, make sure not to get an unused function warning.
     // Lambdaize the function.
     TRACE_EVENT1("skia", "RecForDesc", "rec",
             TRACE_STR_COPY(
-                    [desc](){
-                        auto ptr = desc->findEntry(kRec_SkDescriptorTag, nullptr);
+                    [&desc](){
+                        auto ptr = desc.findEntry(kRec_SkDescriptorTag, nullptr);
                         SkScalerContextRec rec;
                         std::memcpy(&rec, ptr, sizeof(rec));
                         return rec.dump();
@@ -325,22 +330,22 @@
     );
 
     // Already locked.
-    if (fLockedDescs.find(desc) != fLockedDescs.end()) {
-        auto it = fRemoteGlyphStateMap.find(desc);
+    if (fLockedDescs.find(&desc) != fLockedDescs.end()) {
+        auto it = fRemoteGlyphStateMap.find(&desc);
         SkASSERT(it != fRemoteGlyphStateMap.end());
         SkGlyphCacheState* cache = it->second.get();
-        cache->setTypefaceAndEffects(typeface, *effects);
+        cache->setTypefaceAndEffects(&typeface, effects);
         return cache;
     }
 
     // Try to lock.
-    auto it = fRemoteGlyphStateMap.find(desc);
+    auto it = fRemoteGlyphStateMap.find(&desc);
     if (it != fRemoteGlyphStateMap.end()) {
         SkGlyphCacheState* cache = it->second.get();
         bool locked = fDiscardableHandleManager->lockHandle(it->second->discardableHandleId());
         if (locked) {
             fLockedDescs.insert(it->first);
-            cache->setTypefaceAndEffects(typeface, *effects);
+            cache->setTypefaceAndEffects(&typeface, effects);
             return cache;
         }
 
@@ -349,21 +354,20 @@
         fRemoteGlyphStateMap.erase(it);
     }
 
-    const SkFontID typefaceId = typeface->uniqueID();
+    const SkFontID typefaceId = typeface.uniqueID();
     if (!fCachedTypefaces.contains(typefaceId)) {
         fCachedTypefaces.add(typefaceId);
-        fTypefacesToSend.emplace_back(typefaceId,
-                                      typeface->countGlyphs(),
-                                      typeface->fontStyle(),
-                                      typeface->isFixedPitch());
+        fTypefacesToSend.emplace_back(typefaceId, typeface.countGlyphs(),
+                                      typeface.fontStyle(),
+                                      typeface.isFixedPitch());
     }
 
-    auto context = typeface->createScalerContext(*effects, desc);
+    auto context = typeface.createScalerContext(effects, &desc);
 
     // Create a new cache state and insert it into the map.
     auto newHandle = fDiscardableHandleManager->createHandle();
     auto cacheState = skstd::make_unique<SkGlyphCacheState>(
-            *desc, std::move(context), newHandle);
+            desc, std::move(context), newHandle);
 
     auto* cacheStatePtr = cacheState.get();
 
@@ -372,7 +376,7 @@
 
     checkForDeletedEntries();
 
-    cacheStatePtr->setTypefaceAndEffects(typeface, *effects);
+    cacheStatePtr->setTypefaceAndEffects(&typeface, effects);
     return cacheStatePtr;
 }
 
diff --git a/src/core/SkRemoteGlyphCache.h b/src/core/SkRemoteGlyphCache.h
index 701375a..3c9bfc5 100644
--- a/src/core/SkRemoteGlyphCache.h
+++ b/src/core/SkRemoteGlyphCache.h
@@ -132,6 +132,10 @@
                                         SkScalerContextFlags flags,
                                         SkScalerContextEffects* effects);
 
+    SkGlyphCacheState* getOrCreateCache(const SkDescriptor& desc,
+                                        const SkTypeface& typeface,
+                                        SkScalerContextEffects effects);
+
     void setMaxEntriesInDescriptorMapForTesting(size_t count) {
         fMaxEntriesInDescriptorMap = count;
     }