Remove GrTextBlobCache/GrAtlasTextBlob friendliness

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1686113002

Review URL: https://codereview.chromium.org/1686113002
diff --git a/src/gpu/text/GrAtlasTextBlob.cpp b/src/gpu/text/GrAtlasTextBlob.cpp
index cac1e53..2775098 100644
--- a/src/gpu/text/GrAtlasTextBlob.cpp
+++ b/src/gpu/text/GrAtlasTextBlob.cpp
@@ -17,6 +17,38 @@
 #include "SkTextBlobRunIterator.h"
 #include "batches/GrAtlasTextBatch.h"
 
+GrAtlasTextBlob* GrAtlasTextBlob::Create(GrMemoryPool* pool, int glyphCount, int runCount) {
+    // We allocate size for the GrAtlasTextBlob itself, plus size for the vertices array,
+    // and size for the glyphIds array.
+    size_t verticesCount = glyphCount * kVerticesPerGlyph * kMaxVASize;
+    size_t size = sizeof(GrAtlasTextBlob) +
+                  verticesCount +
+                  glyphCount * sizeof(GrGlyph**) +
+                  sizeof(GrAtlasTextBlob::Run) * runCount;
+
+    void* allocation = pool->allocate(size);
+    if (CACHE_SANITY_CHECK) {
+        sk_bzero(allocation, size);
+    }
+
+    GrAtlasTextBlob* cacheBlob = new (allocation) GrAtlasTextBlob;
+    cacheBlob->fSize = size;
+
+    // setup offsets for vertices / glyphs
+    cacheBlob->fVertices = sizeof(GrAtlasTextBlob) + reinterpret_cast<unsigned char*>(cacheBlob);
+    cacheBlob->fGlyphs = reinterpret_cast<GrGlyph**>(cacheBlob->fVertices + verticesCount);
+    cacheBlob->fRuns = reinterpret_cast<GrAtlasTextBlob::Run*>(cacheBlob->fGlyphs + glyphCount);
+
+    // Initialize runs
+    for (int i = 0; i < runCount; i++) {
+        new (&cacheBlob->fRuns[i]) GrAtlasTextBlob::Run;
+    }
+    cacheBlob->fRunCount = runCount;
+    cacheBlob->fPool = pool;
+    return cacheBlob;
+}
+
+
 SkGlyphCache* GrAtlasTextBlob::setupCache(int runIndex,
                                           const SkSurfaceProps& props,
                                           const SkPaint& skPaint,
diff --git a/src/gpu/text/GrAtlasTextBlob.h b/src/gpu/text/GrAtlasTextBlob.h
index 4351aae..68cba3d 100644
--- a/src/gpu/text/GrAtlasTextBlob.h
+++ b/src/gpu/text/GrAtlasTextBlob.h
@@ -18,6 +18,7 @@
 #include "SkTInternalLList.h"
 
 struct GrDistanceFieldAdjustTable;
+class GrMemoryPool;
 class GrTextContext;
 class SkDrawFilter;
 class SkTextBlob;
@@ -45,16 +46,7 @@
 public:
     SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrAtlasTextBlob);
 
-    GrAtlasTextBlob()
-        : fMaxMinScale(-SK_ScalarMax)
-        , fMinMaxScale(SK_ScalarMax)
-        , fTextType(0) {}
-
-    ~GrAtlasTextBlob() {
-        for (int i = 0; i < fRunCount; i++) {
-            fRuns[i].~Run();
-        }
-    }
+    static GrAtlasTextBlob* Create(GrMemoryPool* pool, int glyphCount, int runCount);
 
     struct Key {
         Key() {
@@ -75,6 +67,20 @@
         }
     };
 
+    void setupKey(const GrAtlasTextBlob::Key& key,
+                  const SkMaskFilter::BlurRec& blurRec,
+                  const SkPaint& paint) {
+        fKey = key;
+        if (key.fHasBlur) {
+            fBlurRec = blurRec;
+        }
+        if (key.fStyle != SkPaint::kFill_Style) {
+            fStrokeInfo.fFrameWidth = paint.getStrokeWidth();
+            fStrokeInfo.fMiterLimit = paint.getStrokeMiter();
+            fStrokeInfo.fJoin = paint.getStrokeJoin();
+        }
+    }
+
     static const Key& GetKey(const GrAtlasTextBlob& blob) {
         return blob.fKey;
     }
@@ -198,6 +204,7 @@
     static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16);
     static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16);
     static const size_t kLCDTextVASize = kGrayTextVASize;
+    static const size_t kMaxVASize = kGrayTextVASize;
     static const int kVerticesPerGlyph = 4;
 
     static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&);
@@ -220,7 +227,20 @@
                                   const GrDistanceFieldAdjustTable* distanceAdjustTable,
                                   GrBatchFontCache* cache);
 
+    const Key& key() const { return fKey; }
+
+    ~GrAtlasTextBlob() {
+        for (int i = 0; i < fRunCount; i++) {
+            fRuns[i].~Run();
+        }
+    }
+
 private:
+    GrAtlasTextBlob()
+        : fMaxMinScale(-SK_ScalarMax)
+        , fMinMaxScale(SK_ScalarMax)
+        , fTextType(0) {}
+
     void appendLargeGlyph(GrGlyph* glyph, GrFontScaler* scaler, const SkGlyph& skGlyph,
                           SkScalar x, SkScalar y, SkScalar scale, bool applyVM);
 
@@ -456,7 +476,6 @@
     uint8_t fTextType;
 
     friend class GrAtlasTextBatch; // We might be able to get rid of this friending
-    friend class GrTextBlobCache; // Needs to access the key
 };
 
 #endif
diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp
index 91fa658..9e30476 100644
--- a/src/gpu/text/GrAtlasTextContext.cpp
+++ b/src/gpu/text/GrAtlasTextContext.cpp
@@ -150,8 +150,7 @@
             // TODO we could probably get away reuse most of the time if the pointer is unique,
             // but we'd have to clear the subrun information
             fCache->remove(cacheBlob);
-            cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint,
-                                                           GrAtlasTextBlob::kGrayTextVASize)));
+            cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint)));
             this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMatrix,
                                      blob, x, y, drawFilter);
         } else {
@@ -161,9 +160,8 @@
                 int glyphCount = 0;
                 int runCount = 0;
                 GrTextBlobCache::BlobGlyphCount(&glyphCount, &runCount, blob);
-                SkAutoTUnref<GrAtlasTextBlob> sanityBlob(
-                    fCache->createBlob(glyphCount, runCount, GrAtlasTextBlob::kGrayTextVASize));
-                GrTextBlobCache::SetupCacheBlobKey(sanityBlob, key, blurRec, skPaint);
+                SkAutoTUnref<GrAtlasTextBlob> sanityBlob(fCache->createBlob(glyphCount, runCount));
+                sanityBlob->setupKey(key, blurRec, skPaint);
                 this->regenerateTextBlob(sanityBlob, skPaint, grPaint.getColor(), viewMatrix,
                                          blob, x, y, drawFilter);
                 GrAtlasTextBlob::AssertEqual(*sanityBlob, *cacheBlob);
@@ -171,10 +169,9 @@
         }
     } else {
         if (canCache) {
-            cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint,
-                                                           GrAtlasTextBlob::kGrayTextVASize)));
+            cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint)));
         } else {
-            cacheBlob.reset(fCache->createBlob(blob, GrAtlasTextBlob::kGrayTextVASize));
+            cacheBlob.reset(fCache->createBlob(blob));
         }
         this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMatrix,
                                  blob, x, y, drawFilter);
@@ -278,7 +275,7 @@
                                        SkScalar x, SkScalar y) {
     int glyphCount = skPaint.countText(text, byteLength);
 
-    GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASize);
+    GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1);
     blob->initThrowawayBlob(viewMatrix, x, y);
 
     if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps,
@@ -301,7 +298,7 @@
                                           const SkPoint& offset) {
     int glyphCount = skPaint.countText(text, byteLength);
 
-    GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASize);
+    GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1);
     blob->initThrowawayBlob(viewMatrix, offset.x(), offset.y());
 
     if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps,
diff --git a/src/gpu/text/GrTextBlobCache.cpp b/src/gpu/text/GrTextBlobCache.cpp
index 7fa2d1a..ce74977 100644
--- a/src/gpu/text/GrTextBlobCache.cpp
+++ b/src/gpu/text/GrTextBlobCache.cpp
@@ -7,43 +7,10 @@
 
 #include "GrTextBlobCache.h"
 
-static const int kVerticesPerGlyph = 4;
-
 GrTextBlobCache::~GrTextBlobCache() {
     this->freeAll();
 }
 
-GrAtlasTextBlob* GrTextBlobCache::createBlob(int glyphCount, int runCount, size_t maxVASize) {
-    // We allocate size for the GrAtlasTextBlob itself, plus size for the vertices array,
-    // and size for the glyphIds array.
-    size_t verticesCount = glyphCount * kVerticesPerGlyph * maxVASize;
-    size_t size = sizeof(GrAtlasTextBlob) +
-                  verticesCount +
-                  glyphCount * sizeof(GrGlyph**) +
-                  sizeof(GrAtlasTextBlob::Run) * runCount;
-
-    void* allocation = fPool.allocate(size);
-    if (CACHE_SANITY_CHECK) {
-        sk_bzero(allocation, size);
-    }
-
-    GrAtlasTextBlob* cacheBlob = new (allocation) GrAtlasTextBlob;
-    cacheBlob->fSize = size;
-
-    // setup offsets for vertices / glyphs
-    cacheBlob->fVertices = sizeof(GrAtlasTextBlob) + reinterpret_cast<unsigned char*>(cacheBlob);
-    cacheBlob->fGlyphs = reinterpret_cast<GrGlyph**>(cacheBlob->fVertices + verticesCount);
-    cacheBlob->fRuns = reinterpret_cast<GrAtlasTextBlob::Run*>(cacheBlob->fGlyphs + glyphCount);
-
-    // Initialize runs
-    for (int i = 0; i < runCount; i++) {
-        new (&cacheBlob->fRuns[i]) GrAtlasTextBlob::Run;
-    }
-    cacheBlob->fRunCount = runCount;
-    cacheBlob->fPool = &fPool;
-    return cacheBlob;
-}
-
 void GrTextBlobCache::freeAll() {
     SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key>::Iter iter(&fCache);
     while (!iter.done()) {
diff --git a/src/gpu/text/GrTextBlobCache.h b/src/gpu/text/GrTextBlobCache.h
index 8eee9d1..e3b2ca7 100644
--- a/src/gpu/text/GrTextBlobCache.h
+++ b/src/gpu/text/GrTextBlobCache.h
@@ -30,40 +30,26 @@
     ~GrTextBlobCache();
 
     // creates an uncached blob
-    GrAtlasTextBlob* createBlob(int glyphCount, int runCount, size_t maxVASize);
-    GrAtlasTextBlob* createBlob(const SkTextBlob* blob, size_t maxVAStride) {
+    GrAtlasTextBlob* createBlob(int glyphCount, int runCount) {
+        return GrAtlasTextBlob::Create(&fPool, glyphCount, runCount);
+    }
+    GrAtlasTextBlob* createBlob(const SkTextBlob* blob) {
         int glyphCount = 0;
         int runCount = 0;
         BlobGlyphCount(&glyphCount, &runCount, blob);
-        GrAtlasTextBlob* cacheBlob = this->createBlob(glyphCount, runCount, maxVAStride);
+        GrAtlasTextBlob* cacheBlob = GrAtlasTextBlob::Create(&fPool, glyphCount, runCount);
         return cacheBlob;
     }
 
-    static void SetupCacheBlobKey(GrAtlasTextBlob* cacheBlob,
-                                  const GrAtlasTextBlob::Key& key,
-                                  const SkMaskFilter::BlurRec& blurRec,
-                                  const SkPaint& paint) {
-        cacheBlob->fKey = key;
-        if (key.fHasBlur) {
-            cacheBlob->fBlurRec = blurRec;
-        }
-        if (key.fStyle != SkPaint::kFill_Style) {
-            cacheBlob->fStrokeInfo.fFrameWidth = paint.getStrokeWidth();
-            cacheBlob->fStrokeInfo.fMiterLimit = paint.getStrokeMiter();
-            cacheBlob->fStrokeInfo.fJoin = paint.getStrokeJoin();
-        }
-    }
-
     GrAtlasTextBlob* createCachedBlob(const SkTextBlob* blob,
                                       const GrAtlasTextBlob::Key& key,
                                       const SkMaskFilter::BlurRec& blurRec,
-                                      const SkPaint& paint,
-                                      size_t maxVAStride) {
+                                      const SkPaint& paint) {
         int glyphCount = 0;
         int runCount = 0;
         BlobGlyphCount(&glyphCount, &runCount, blob);
-        GrAtlasTextBlob* cacheBlob = this->createBlob(glyphCount, runCount, maxVAStride);
-        SetupCacheBlobKey(cacheBlob, key, blurRec, paint);
+        GrAtlasTextBlob* cacheBlob = GrAtlasTextBlob::Create(&fPool, glyphCount, runCount);
+        cacheBlob->setupKey(key, blurRec, paint);
         this->add(cacheBlob);
         return cacheBlob;
     }
@@ -73,7 +59,7 @@
     }
 
     void remove(GrAtlasTextBlob* blob) {
-        fCache.remove(blob->fKey);
+        fCache.remove(blob->key());
         fBlobList.remove(blob);
         blob->unref();
     }
@@ -119,7 +105,7 @@
             iter.init(fBlobList, BitmapBlobList::Iter::kTail_IterStart);
             GrAtlasTextBlob* lruBlob = nullptr;
             while (fPool.size() > fBudget && (lruBlob = iter.get()) && lruBlob != blob) {
-                fCache.remove(lruBlob->fKey);
+                fCache.remove(lruBlob->key());
 
                 // Backup the iterator before removing and unrefing the blob
                 iter.prev();