Remove unneeded test, and support code

The SkRemoteGlyphCache_ReWriteGlyph checked that glyphs of
desparation were not overwritten by glyphs coming from the
Renderer. Since the search of desparation is no longer, this
test is not needed.

In addition:
* Remove unused call prepareForDrawingPathsCPU.
* Cleanup some comments

Change-Id: I1fbc3f84363c9093f5301985e8052f49bbb9356e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270996
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/core/SkGlyph.cpp b/src/core/SkGlyph.cpp
index 4765faf..6336e3d 100644
--- a/src/core/SkGlyph.cpp
+++ b/src/core/SkGlyph.cpp
@@ -68,18 +68,6 @@
                                         : width * format_alignment(format);
 }
 
-SkGlyph::SkGlyph(const SkGlyphPrototype& p)
-    : fWidth{p.width}
-    , fHeight{p.height}
-    , fTop{p.top}
-    , fLeft{p.left}
-    , fAdvanceX{p.advanceX}
-    , fAdvanceY{p.advanceY}
-    , fMaskFormat{(uint8_t)p.maskFormat}
-    , fForceBW{p.forceBW}
-    , fID{p.id}
-    {}
-
 size_t SkGlyph::formatAlignment() const {
     return format_alignment(this->maskFormat());
 }
diff --git a/src/core/SkGlyph.h b/src/core/SkGlyph.h
index 9020f27..048c953 100644
--- a/src/core/SkGlyph.h
+++ b/src/core/SkGlyph.h
@@ -183,7 +183,6 @@
     // SkGlyph() is used for testing.
     constexpr SkGlyph() : fID{SkPackedGlyphID()} { }
     constexpr explicit SkGlyph(SkPackedGlyphID id) : fID{id} { }
-    explicit SkGlyph(const SkGlyphPrototype& p);
 
     SkVector advanceVector() const { return SkVector{fAdvanceX, fAdvanceY}; }
     SkScalar advanceX() const { return fAdvanceX; }
@@ -356,23 +355,4 @@
     const SkPackedGlyphID fID;
 };
 
-struct SkGlyphPrototype {
-    SkPackedGlyphID id;
-
-    float           advanceX = 0,
-                    advanceY = 0;
-
-    // The width and height of the glyph mask.
-    uint16_t        width  = 0,
-                    height = 0;
-
-    // The offset from the glyphs origin on the baseline to the top left of the glyph mask.
-    int16_t         left = 0,
-                    top  = 0;
-
-    SkMask::Format  maskFormat = SkMask::kBW_Format;
-
-    bool            forceBW = false;
-};
-
 #endif
diff --git a/src/core/SkStrike.cpp b/src/core/SkStrike.cpp
index c1b2bc4..2435993 100644
--- a/src/core/SkStrike.cpp
+++ b/src/core/SkStrike.cpp
@@ -63,25 +63,6 @@
     return glyph;
 }
 
-SkGlyph* SkStrike::glyphFromPrototype(const SkGlyphPrototype& p, void* image) {
-    SkAutoMutexExclusive lock{fMu};
-    SkGlyph* glyph = fGlyphMap.findOrNull(p.id);
-    if (glyph == nullptr) {
-        fMemoryUsed += sizeof(SkGlyph);
-        glyph = fAlloc.make<SkGlyph>(p);
-        fGlyphMap.set(glyph);
-    }
-    if (glyph->setImage(&fAlloc, image)) {
-        fMemoryUsed += glyph->imageSize();
-    }
-    return glyph;
-}
-
-SkGlyph* SkStrike::glyphOrNull(SkPackedGlyphID id) const {
-    SkAutoMutexExclusive lock{fMu};
-    return this->internalGlyphOrNull(id);
-}
-
 const SkPath* SkStrike::preparePath(SkGlyph* glyph) {
     if (glyph->setPath(&fAlloc, fScalerContext.get())) {
         fMemoryUsed += glyph->path()->approximateBytesUsed();
@@ -191,18 +172,6 @@
         });
 }
 
-void SkStrike::prepareForDrawingPathsCPU(SkDrawableGlyphBuffer* drawables) {
-    SkAutoMutexExclusive lock{fMu};
-    this->commonFilterLoop(drawables,
-        [&](size_t i, SkGlyph* glyph, SkPoint pos) SK_REQUIRES(fMu) {
-            const SkPath* path = this->preparePath(glyph);
-            // The glyph my not have a path.
-            if (path != nullptr) {
-                drawables->push_back(path, i);
-            }
-        });
-}
-
 // Note: this does not actually fill out the image. That happens at atlas building time.
 void SkStrike::prepareForMaskDrawing(
         SkDrawableGlyphBuffer* drawables, SkSourceGlyphBuffer* rejects) {
diff --git a/src/core/SkStrike.h b/src/core/SkStrike.h
index 638e5a4..e468ff2 100644
--- a/src/core/SkStrike.h
+++ b/src/core/SkStrike.h
@@ -20,31 +20,15 @@
 #include "src/core/SkStrikeForGPU.h"
 #include <memory>
 
-/** \class SkGlyphCache
+// This class represents a strike: a specific combination of typeface, size, matrix, etc., and
+// holds the glyphs for that strike.
 
-    This class represents a strike: a specific combination of typeface, size, matrix, etc., and
-    holds the glyphs for that strike. Calling any of the getGlyphID... methods will
-    return the requested glyph, either instantly if it is already cached, or by first generating
-    it and then adding it to the strike.
-
-    The strikes are held in a global list, available to all threads. To interact with one, call
-    either Find{OrCreate}Exclusive().
-
-    The Find*Exclusive() method returns SkExclusiveStrikePtr, which releases exclusive ownership
-    when they go out of scope.
-*/
 class SkStrike final : public SkStrikeForGPU {
 public:
     SkStrike(const SkDescriptor& desc,
              std::unique_ptr<SkScalerContext> scaler,
              const SkFontMetrics* metrics = nullptr);
 
-    // Return a glyph.  Create it if it doesn't exist, and initialize with the prototype.
-    SkGlyph* glyphFromPrototype(const SkGlyphPrototype& p, void* image = nullptr) SK_EXCLUDES(fMu);
-
-    // Return a glyph or nullptr if it does not exits in the strike.
-    SkGlyph* glyphOrNull(SkPackedGlyphID id) const SK_EXCLUDES(fMu);
-
     // Lookup (or create if needed) the toGlyph using toID. If that glyph is not initialized with
     // an image, then use the information in from to initialize the width, height top, left,
     // format and image of the toGlyph. This is mainly used preserving the glyph if it was
@@ -63,9 +47,6 @@
     void findIntercepts(const SkScalar bounds[2], SkScalar scale, SkScalar xPos,
                         SkGlyph* , SkScalar* array, int* count) SK_EXCLUDES(fMu);
 
-
-    /** Return the vertical metrics for this strike.
-    */
     const SkFontMetrics& getFontMetrics() const {
         return fFontMetrics;
     }
@@ -87,8 +68,6 @@
 
     void prepareForDrawingMasksCPU(SkDrawableGlyphBuffer* drawables) SK_EXCLUDES(fMu);
 
-    void prepareForDrawingPathsCPU(SkDrawableGlyphBuffer* drawables) SK_EXCLUDES(fMu);
-
     void prepareForMaskDrawing(
             SkDrawableGlyphBuffer* drawables, SkSourceGlyphBuffer* rejects) override SK_EXCLUDES(fMu);
 
diff --git a/tests/SkRemoteGlyphCacheTest.cpp b/tests/SkRemoteGlyphCacheTest.cpp
index 64a6823..64cc8b3 100644
--- a/tests/SkRemoteGlyphCacheTest.cpp
+++ b/tests/SkRemoteGlyphCacheTest.cpp
@@ -821,115 +821,3 @@
     discardableManager->unlockAndDeleteAll();
 }
 
-DEF_TEST(SkRemoteGlyphCache_ReWriteGlyph, reporter) {
-    // Build proxy typeface on the client for initializing the cache.
-    sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
-    SkStrikeServer server(discardableManager.get());
-    SkStrikeClient client(discardableManager, false);
-
-    auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());
-    auto tfData = server.serializeTypeface(serverTf.get());
-    auto clientTf = client.deserializeTypeface(tfData->data(), tfData->size());
-    REPORTER_ASSERT(reporter, clientTf);
-
-    SkFont font;
-    font.setEdging(SkFont::Edging::kAntiAlias);
-    SkPaint paint;
-    paint.setColor(SK_ColorRED);
-
-    SkPoint glyphPos = {0.5f, 0.5f};
-    SkIPoint glyphIPos = {SkScalarToFixed(glyphPos.x()), SkScalarToFixed(glyphPos.y())};
-    auto lostGlyphID = SkPackedGlyphID(1, glyphIPos.x(), glyphIPos.y());
-    const uint8_t glyphImage[] = {0xFF, 0xFF};
-    SkMask::Format realMask;
-    SkMask::Format fakeMask;
-
-    SkStrikeCache strikeCache;
-
-    {
-        SkAutoDescriptor ad;
-        SkScalerContextRec rec;
-        SkScalerContextEffects effects;
-        SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
-        font.setTypeface(serverTf);
-        SkScalerContext::MakeRecAndEffects(
-                font, paint, SkSurfacePropsCopyOrDefault(nullptr), flags,
-                SkMatrix::I(), &rec, &effects);
-        auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
-
-        auto context = serverTf->createScalerContext(effects, desc);
-        SkGlyph glyph{lostGlyphID};
-        context->getMetrics(&glyph);
-        realMask = glyph.maskFormat();
-    }
-
-    // Build a fallback cache.
-    {
-        SkAutoDescriptor ad;
-        SkScalerContextRec rec;
-        SkScalerContextEffects effects;
-        SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
-        font.setTypeface(clientTf);
-        SkScalerContext::MakeRecAndEffects(
-                font, paint, SkSurfacePropsCopyOrDefault(nullptr), flags,
-                SkMatrix::I(), &rec, &effects);
-        auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
-
-        auto fallbackCache = strikeCache.findOrCreateStrikeExclusive(*desc, effects, *clientTf);
-        fakeMask = (realMask == SkMask::kA8_Format) ? SkMask::kBW_Format : SkMask::kA8_Format;
-        SkGlyphPrototype proto = {lostGlyphID, 0.f, 0.f, 2, 1, 0, 0, fakeMask, false};
-        fallbackCache->glyphFromPrototype(proto, (void *)glyphImage);
-    }
-
-    // Send over the real glyph and make sure the client cache stays intact.
-    {
-        SkAutoDescriptor ad;
-        SkScalerContextEffects effects;
-        SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
-        font.setTypeface(serverTf);
-        auto* cacheState = server.getOrCreateCache(
-                paint, font, SkSurfacePropsCopyOrDefault(nullptr),
-                SkMatrix::I(), flags, &effects);
-        SkGlyphID glyphID = lostGlyphID.glyphID();
-        SkZip<const SkGlyphID, const SkPoint> source{1, &glyphID, &glyphPos};
-        SkSourceGlyphBuffer rejects;
-        SkDrawableGlyphBuffer drawables;
-        drawables.ensureSize(source.size());
-        rejects.setSource(source);
-        drawables.startSource(rejects.source(), {0, 0});
-        SkStrikeServer::AddGlyphForTesting(cacheState, &drawables, &rejects);
-        std::vector<uint8_t> serverStrikeData;
-        server.writeStrikeData(&serverStrikeData);
-        REPORTER_ASSERT(reporter, !serverStrikeData.empty());
-        REPORTER_ASSERT(reporter,
-                        client.readStrikeData(
-                                serverStrikeData.data(),
-                                serverStrikeData.size()));
-    }
-
-    {
-        SkAutoDescriptor ad;
-        SkScalerContextRec rec;
-        SkScalerContextEffects effects;
-        SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
-        font.setTypeface(clientTf);
-        SkScalerContext::MakeRecAndEffects(
-                font, paint, SkSurfaceProps(0, kUnknown_SkPixelGeometry), flags,
-                SkMatrix::I(), &rec, &effects);
-        auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
-
-        auto fallbackCache = strikeCache.findStrikeExclusive(*desc);
-        REPORTER_ASSERT(reporter, fallbackCache.get() != nullptr);
-        auto glyph = fallbackCache->glyphOrNull(lostGlyphID);
-        REPORTER_ASSERT(reporter, glyph && glyph->maskFormat() == fakeMask);
-        if (glyph) {
-            REPORTER_ASSERT(reporter,
-                            memcmp(glyph->image(), glyphImage, glyph->imageSize()) == 0);
-        }
-    }
-
-    strikeCache.validateGlyphCacheDataSize();
-
-    // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
-    discardableManager->unlockAndDeleteAll();
-}