Isolate fGlyphs in SubRun

Add glyphCount to return the number of glyphs and
grGlyph to return a grGlyph from fGlyphs.

Bug: skia:10251

Change-Id: I15f77a032b9eb9aa736ccd810900f2425fc4c059
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290296
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/atlastext/SkAtlasTextTarget.cpp b/src/atlastext/SkAtlasTextTarget.cpp
index d541f38..4e6c197 100644
--- a/src/atlastext/SkAtlasTextTarget.cpp
+++ b/src/atlastext/SkAtlasTextTarget.cpp
@@ -245,7 +245,7 @@
         subRun->updateVerticesColorIfNeeded(fGeoData[i].fColor.toBytes_RGBA());
         subRun->translateVerticesIfNeeded(fGeoData[i].fDrawMatrix, fGeoData[i].fDrawOrigin);
         GrTextBlob::VertexRegenerator regenerator(resourceProvider, subRun, &context, atlasManager);
-        int subRunEnd = subRun->fGlyphs.count();
+        int subRunEnd = subRun->glyphCount();
         for (int subRunIndex = 0; subRunIndex < subRunEnd;) {
             auto [ok, glyphsRegenerated] = regenerator.regenerate(subRunIndex, subRunEnd);
             if (!ok) {
diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp
index 80a34c6..cc7611f 100644
--- a/src/gpu/ops/GrAtlasTextOp.cpp
+++ b/src/gpu/ops/GrAtlasTextOp.cpp
@@ -43,7 +43,7 @@
         , fDFGPFlags{DFGPFlags}
         , fGeoDataAllocSize{kMinGeometryAllocated}
         , fProcessors{std::move(paint)}
-        , fNumGlyphs{SkTo<int>(subrun->fGlyphs.size())} {
+        , fNumGlyphs{subrun->glyphCount()} {
     GrAtlasTextOp::Geometry& geometry = fGeoData[0];
 
     // Unref handled in ~GrAtlasTextOp().
@@ -390,7 +390,7 @@
 
         // Where the subRun begins and ends relative to totalGlyphsRegened.
         int subRunBegin = totalGlyphsRegened;
-        int subRunEnd = subRunBegin + subRun->fGlyphs.count();
+        int subRunEnd = subRunBegin + subRun->glyphCount();
 
         // Draw all the glyphs in the subRun.
         while (totalGlyphsRegened < subRunEnd) {
diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp
index 8d8e898..d4eaa8a 100644
--- a/src/gpu/text/GrTextBlob.cpp
+++ b/src/gpu/text/GrTextBlob.cpp
@@ -46,12 +46,12 @@
         : fType{type}
         , fBlob{textBlob}
         , fMaskFormat{format}
-        , fGlyphs{glyphs}
         , fVertexData{vertexData}
         , fStrikeSpec{strikeSpec}
         , fCurrentColor{textBlob->fColor}
         , fCurrentOrigin{0,0}
-        , fCurrentMatrix{textBlob->fInitialMatrix} {
+        , fCurrentMatrix{textBlob->fInitialMatrix}
+        , fGlyphs{glyphs} {
     SkASSERT(type != kTransformedPath);
     textBlob->insertSubRun(this);
 }
@@ -60,11 +60,11 @@
         : fType{kTransformedPath}
         , fBlob{textBlob}
         , fMaskFormat{kA8_GrMaskFormat}
-        , fGlyphs{SkSpan<PackedGlyphIDorGrGlyph>{}}
         , fVertexData{SkSpan<char>{}}
         , fStrikeSpec{strikeSpec}
         , fCurrentColor{textBlob->fColor}
-        , fPaths{} {
+        , fPaths{}
+        , fGlyphs{SkSpan<PackedGlyphIDorGrGlyph>{}} {
     textBlob->insertSubRun(this);
 }
 
@@ -177,6 +177,10 @@
     return index * kVerticesPerGlyph * this->vertexStride();
 }
 
+int GrTextBlob::SubRun::glyphCount() const {
+    return fGlyphs.count();
+}
+
 void GrTextBlob::SubRun::joinGlyphBounds(const SkRect& glyphBounds) {
     fVertexBounds.joinNonEmptyArg(glyphBounds);
 }
@@ -308,6 +312,10 @@
     return outBounds;
 }
 
+GrGlyph* GrTextBlob::SubRun::grGlyph(int i) const {
+    return fGlyphs[i].fGrGlyph;
+}
+
 void GrTextBlob::SubRun::setUseLCDText(bool useLCDText) { fFlags.useLCDText = useLCDText; }
 bool GrTextBlob::SubRun::hasUseLCDText() const { return fFlags.useLCDText; }
 void GrTextBlob::SubRun::setAntiAliased(bool antiAliased) { fFlags.antiAliased = antiAliased; }
@@ -544,7 +552,7 @@
                 }
             }
         } else {
-            int glyphCount = subRun->fGlyphs.count();
+            int glyphCount = subRun->glyphCount();
             if (0 == glyphCount) {
                 continue;
             }
@@ -937,7 +945,7 @@
     auto tokenTracker = fUploadTarget->tokenTracker();
     int i = begin;
     for (; i < end; i++) {
-        GrGlyph* grGlyph = fSubRun->fGlyphs[i].fGrGlyph;
+        GrGlyph* grGlyph = fSubRun->grGlyph(i);
         SkASSERT(grGlyph);
 
         if (!fFullAtlasManager->hasGlyph(fSubRun->maskFormat(), grGlyph)) {
@@ -974,7 +982,7 @@
         auto [success, glyphsPlacedInAtlas] = this->updateTextureCoordinates(begin, end);
 
         // Update atlas generation if there are no more glyphs to put in the atlas.
-        if (success && begin + glyphsPlacedInAtlas == fSubRun->fGlyphs.count()) {
+        if (success && begin + glyphsPlacedInAtlas == fSubRun->glyphCount()) {
             // Need to get the freshest value of the atlas' generation because
             // updateTextureCoordinates may have changed it.
             fSubRun->fAtlasGeneration = fFullAtlasManager->atlasGeneration(fSubRun->maskFormat());
@@ -982,7 +990,7 @@
         return {success, glyphsPlacedInAtlas};
     } else {
         // The atlas hasn't changed, so our texture coordinates are still valid.
-        if (end == fSubRun->fGlyphs.count()) {
+        if (end == fSubRun->glyphCount()) {
             // The atlas hasn't changed and the texture coordinates are all still valid. Update
             // all the plots used to the new use token.
             fFullAtlasManager->setUseTokenBulk(*fSubRun->bulkUseToken(),
diff --git a/src/gpu/text/GrTextBlob.h b/src/gpu/text/GrTextBlob.h
index c9b56d8..71f860f 100644
--- a/src/gpu/text/GrTextBlob.h
+++ b/src/gpu/text/GrTextBlob.h
@@ -351,6 +351,8 @@
     char* quadStart(size_t index) const;
     size_t quadOffset(size_t index) const;
 
+    int glyphCount() const;
+
     void joinGlyphBounds(const SkRect& glyphBounds);
 
     bool drawAsDistanceFields() const;
@@ -370,6 +372,8 @@
     // The rectangle that surrounds all the glyph bounding boxes in device space.
     SkRect deviceRect(const SkMatrix& drawMatrix, SkPoint drawOrigin) const;
 
+    GrGlyph* grGlyph(int i) const;
+
     // df properties
     void setUseLCDText(bool useLCDText);
     bool hasUseLCDText() const;
@@ -382,7 +386,6 @@
     const SubRunType fType;
     GrTextBlob* const fBlob;
     const GrMaskFormat fMaskFormat;
-    const SkSpan<PackedGlyphIDorGrGlyph> fGlyphs;
     const SkSpan<char> fVertexData;
     const SkStrikeSpec fStrikeSpec;
     sk_sp<GrTextStrike> fStrike;
@@ -398,13 +401,13 @@
     SkPoint fCurrentOrigin;
     SkMatrix fCurrentMatrix;
     std::vector<PathGlyph> fPaths;
-
 private:
+    bool hasW() const;
+
+    const SkSpan<PackedGlyphIDorGrGlyph> fGlyphs;
     // The vertex bounds in device space if needsTransform() is false, otherwise the bounds in
     // source space. The bounds are the joined rectangles of all the glyphs.
     SkRect fVertexBounds = SkRectPriv::MakeLargestInverted();
-    bool hasW() const;
-
 };  // SubRun
 
 #endif  // GrTextBlob_DEFINED