Remove PackedID from the strike call chain

By removing the PackedID from the call chain, all the information
needed to lookup glyphs is gathered from the SkGlyph. I added some
code to allow this corrispondence between the SkGlyph and the PackedID.
But, in the next CL all that code will be removed as PackeID becomes
SkPackedGlyphID.

Remove unneeded inlines
Remove unused maskFormat parameter to getGlyph

Change-Id: Id6d876d7ad3f1b4303f8b9ecfc38f499fbedcf73
Reviewed-on: https://skia-review.googlesource.com/c/179640
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index 94551ca..414be8f 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -633,11 +633,7 @@
                                   const SkGlyph& skGlyph, GrGlyph::MaskStyle maskStyle,
                                   SkPoint origin, SkScalar textRatio, bool needsTransform) {
 
-    GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(),
-                                         skGlyph.getSubXFixed(),
-                                         skGlyph.getSubYFixed(),
-                                         maskStyle);
-    GrGlyph* glyph = strike->getGlyph(skGlyph, id);
+    GrGlyph* glyph = strike->getGlyph(skGlyph);
     if (!glyph) {
         return;
     }
@@ -667,7 +663,6 @@
     }
 }
 
-
 void GrTextBlob::generateFromGlyphRunList(GrGlyphCache* glyphCache,
                                           const GrShaderCaps& shaderCaps,
                                           const GrTextContext::Options& options,
diff --git a/src/gpu/GrGlyph.h b/src/gpu/GrGlyph.h
index 1671d93..ed0090b 100644
--- a/src/gpu/GrGlyph.h
+++ b/src/gpu/GrGlyph.h
@@ -37,8 +37,7 @@
                                    SkTo<uint16_t>(rect.height()));
     }
 
-    GrGlyph(
-            GrGlyph::PackedID packed, const SkIRect& bounds, GrMaskFormat format, MaskStyle style)
+    GrGlyph(GrGlyph::PackedID packed, const SkIRect& bounds, GrMaskFormat format, MaskStyle style)
         : fPackedID{packed}
         , fMaskFormat{format}
         , fMaskStyle{style}
@@ -51,7 +50,6 @@
     SkIPoint16             fAtlasLocation{0, 0};
     GrDrawOpAtlas::AtlasID fID{GrDrawOpAtlas::kInvalidAtlasID};
 
-
     int width() const { return fBounds.width(); }
     int height() const { return fBounds.height(); }
     bool isEmpty() const { return fBounds.isEmpty(); }
@@ -61,35 +59,47 @@
 
     ///////////////////////////////////////////////////////////////////////////
 
-    static inline unsigned ExtractSubPixelBitsFromFixed(SkFixed pos) {
+    static unsigned ExtractSubPixelBitsFromFixed(SkFixed pos) {
         // two most significant fraction bits from fixed-point
         return (pos >> 14) & 3;
     }
 
-    static inline PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y, MaskStyle ms) {
+    static PackedID FromSkGlyph(const SkGlyph& skGlyph) {
+        GrGlyph::MaskStyle maskStyle = (SkMask::Format)skGlyph.fMaskFormat == SkMask::kSDF_Format
+                                       ? GrGlyph::MaskStyle::kDistance_MaskStyle
+                                       : GrGlyph::MaskStyle::kCoverage_MaskStyle;
+        SkPackedGlyphID skPackedID = skGlyph.getPackedID();
+        GrGlyph::PackedID packedID = GrGlyph::Pack(skPackedID.code(),
+                                                   skPackedID.getSubXFixed(),
+                                                   skPackedID.getSubYFixed(),
+                                                   maskStyle);
+        return packedID;
+    }
+
+    static PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y, MaskStyle ms) {
         x = ExtractSubPixelBitsFromFixed(x);
         y = ExtractSubPixelBitsFromFixed(y);
         int dfFlag = (ms == kDistance_MaskStyle) ? 0x1 : 0x0;
         return (dfFlag << 20) | (x << 18) | (y << 16) | glyphID;
     }
 
-    static inline SkFixed UnpackFixedX(PackedID packed) {
+    static SkFixed UnpackFixedX(PackedID packed) {
         return ((packed >> 18) & 3) << 14;
     }
 
-    static inline SkFixed UnpackFixedY(PackedID packed) {
+    static SkFixed UnpackFixedY(PackedID packed) {
         return ((packed >> 16) & 3) << 14;
     }
 
-    static inline uint16_t UnpackID(PackedID packed) {
+    static uint16_t UnpackID(PackedID packed) {
         return (uint16_t)packed;
     }
 
-    static inline const GrGlyph::PackedID& GetKey(const GrGlyph& glyph) {
+    static const GrGlyph::PackedID& GetKey(const GrGlyph& glyph) {
         return glyph.fPackedID;
     }
 
-    static inline uint32_t Hash(GrGlyph::PackedID key) {
+    static uint32_t Hash(GrGlyph::PackedID key) {
         return SkChecksum::Mix(key);
     }
 };
diff --git a/src/gpu/text/GrGlyphCache.cpp b/src/gpu/text/GrGlyphCache.cpp
index c574cf4..f9a8540 100644
--- a/src/gpu/text/GrGlyphCache.cpp
+++ b/src/gpu/text/GrGlyphCache.cpp
@@ -192,7 +192,7 @@
 GrTextStrike::GrTextStrike(const SkDescriptor& key)
     : fFontScalerKey(key) {}
 
-GrGlyph* GrTextStrike::generateGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed) {
+GrGlyph* GrTextStrike::generateGlyph(const SkGlyph& skGlyph) {
     SkIRect bounds;
 
     bounds.setXYWH(skGlyph.fLeft, skGlyph.fTop, skGlyph.fWidth, skGlyph.fHeight);
@@ -202,7 +202,8 @@
     GrGlyph::MaskStyle maskStyle = (SkMask::Format)skGlyph.fMaskFormat == SkMask::kSDF_Format
                                    ? GrGlyph::MaskStyle::kDistance_MaskStyle
                                    : GrGlyph::MaskStyle::kCoverage_MaskStyle;
-    GrGlyph* glyph = fAlloc.make<GrGlyph>(packed, bounds, format, maskStyle);
+    GrGlyph* glyph = fAlloc.make<GrGlyph>(
+            GrGlyph::FromSkGlyph(skGlyph), bounds, format, maskStyle);
     fCache.add(glyph);
     return glyph;
 }
diff --git a/src/gpu/text/GrGlyphCache.h b/src/gpu/text/GrGlyphCache.h
index 59e8520..835d484 100644
--- a/src/gpu/text/GrGlyphCache.h
+++ b/src/gpu/text/GrGlyphCache.h
@@ -30,10 +30,11 @@
 public:
     GrTextStrike(const SkDescriptor& fontScalerKey);
 
-    GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed) {
+    GrGlyph* getGlyph(const SkGlyph& skGlyph) {
+        GrGlyph::PackedID packed = GrGlyph::FromSkGlyph(skGlyph);
         GrGlyph* glyph = fCache.find(packed);
         if (!glyph) {
-            glyph = this->generateGlyph(skGlyph, packed);
+            glyph = this->generateGlyph(skGlyph);
         }
         return glyph;
     }
@@ -43,7 +44,6 @@
     // draw a clear square.
     // skbug:4143 crbug:510931
     GrGlyph* getGlyph(GrGlyph::PackedID packed,
-                      GrMaskFormat expectedMaskFormat,
                       SkGlyphCache* cache) {
         GrGlyph* glyph = fCache.find(packed);
         if (!glyph) {
@@ -51,7 +51,7 @@
             // potentially little benefit(ie, if the glyph is not in our font cache, then its not
             // in the atlas and we're going to be doing a texture upload anyways).
             const SkGlyph& skGlyph = GrToSkGlyph(cache, packed);
-            glyph = this->generateGlyph(skGlyph, packed);
+            glyph = this->generateGlyph(skGlyph);
         }
         return glyph;
     }
@@ -95,7 +95,7 @@
                                         GrGlyph::UnpackFixedY(id));
     }
 
-    GrGlyph* generateGlyph(const SkGlyph&, GrGlyph::PackedID);
+    GrGlyph* generateGlyph(const SkGlyph&);
 
     friend class GrGlyphCache;
 };
diff --git a/src/gpu/text/GrTextBlobVertexRegenerator.cpp b/src/gpu/text/GrTextBlobVertexRegenerator.cpp
index e994ce9..6b6beb3 100644
--- a/src/gpu/text/GrTextBlobVertexRegenerator.cpp
+++ b/src/gpu/text/GrTextBlobVertexRegenerator.cpp
@@ -270,8 +270,7 @@
                 // Get the id from the old glyph, and use the new strike to lookup
                 // the glyph.
                 GrGlyph::PackedID id = fBlob->fGlyphs[glyphOffset]->fPackedID;
-                fBlob->fGlyphs[glyphOffset] =
-                        strike->getGlyph(id, fSubRun->maskFormat(), fLazyCache->get());
+                fBlob->fGlyphs[glyphOffset] = strike->getGlyph(id, fLazyCache->get());
                 SkASSERT(id == fBlob->fGlyphs[glyphOffset]->fPackedID);
             }
             glyph = fBlob->fGlyphs[glyphOffset];