reorganize GrAtlasTextOp creation

Break the GrAtlasTextOp ctor into a mask version, and an SDFT version.
Reorganize geometry creation to allow more of the GrAtlasSubRun API
to be private.

Change-Id: Ic29d4026a15386d135e0fabc4f270810d1638b2d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/303262
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp
index 55ce686..f527bc5 100644
--- a/src/gpu/ops/GrAtlasTextOp.cpp
+++ b/src/gpu/ops/GrAtlasTextOp.cpp
@@ -35,40 +35,52 @@
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 GrAtlasTextOp::GrAtlasTextOp(MaskType maskType,
+                             bool needsTransform,
+                             int glyphCount,
+                             SkRect deviceRect,
                              GrPaint&& paint,
-                             GrAtlasSubRun* subrun,
-                             const SkMatrix& drawMatrix,
-                             SkPoint drawOrigin,
-                             const SkIRect& clipRect,
-                             const SkPMColor4f& filteredColor,
+                             Geometry&& geo)
+         : INHERITED{ClassID()}
+         , fMaskType{maskType}
+         , fNeedsGlyphTransform{needsTransform}
+         , fLuminanceColor{0}
+         , fUseGammaCorrectDistanceTable{false}
+         , fDFGPFlags{0}
+         , fGeoDataAllocSize{kMinGeometryAllocated}
+         , fProcessors{std::move(paint)}
+         , fNumGlyphs{glyphCount} {
+    fGeoData[0] = std::move(geo);
+    fGeoCount = 1;
+
+    // We don't have tight bounds on the glyph paths in device space. For the purposes of bounds
+    // we treat this as a set of non-AA rects rendered with a texture.
+    this->setBounds(deviceRect, HasAABloat::kNo, IsHairline::kNo);
+}
+
+GrAtlasTextOp::GrAtlasTextOp(MaskType maskType,
+                             bool needsTransform,
+                             int glyphCount,
+                             SkRect deviceRect,
                              SkColor luminanceColor,
                              bool useGammaCorrectDistanceTable,
-                             uint32_t DFGPFlags)
-        : INHERITED(ClassID())
+                             uint32_t DFGPFlags,
+                             GrPaint&& paint,
+                             Geometry&& geo)
+        : INHERITED{ClassID()}
         , fMaskType{maskType}
-        , fNeedsGlyphTransform{subrun->needsTransform()}
+        , fNeedsGlyphTransform{needsTransform}
         , fLuminanceColor{luminanceColor}
         , fUseGammaCorrectDistanceTable{useGammaCorrectDistanceTable}
         , fDFGPFlags{DFGPFlags}
         , fGeoDataAllocSize{kMinGeometryAllocated}
         , fProcessors{std::move(paint)}
-        , fNumGlyphs{subrun->glyphCount()} {
-    GrAtlasTextOp::Geometry& geometry = fGeoData[0];
-
-    // Unref handled in ~GrAtlasTextOp().
-    geometry.fBlob = SkRef(subrun->fBlob);
-    geometry.fSubRunPtr = subrun;
-    geometry.fDrawMatrix = drawMatrix;
-    geometry.fDrawOrigin = drawOrigin;
-    geometry.fClipRect = clipRect;
-    geometry.fColor = subrun->maskFormat() == kARGB_GrMaskFormat ? SK_PMColor4fWHITE
-                                                                 : filteredColor;
+        , fNumGlyphs{glyphCount} {
+    fGeoData[0] = std::move(geo);
     fGeoCount = 1;
 
-    SkRect bounds = subrun->deviceRect(drawMatrix, drawOrigin);
     // We don't have tight bounds on the glyph paths in device space. For the purposes of bounds
     // we treat this as a set of non-AA rects rendered with a texture.
-    this->setBounds(bounds, HasAABloat::kNo, IsHairline::kNo);
+    this->setBounds(deviceRect, HasAABloat::kNo, IsHairline::kNo);
 }
 
 void GrAtlasTextOp::Geometry::fillVertexData(void *dst, int offset, int count) const {
diff --git a/src/gpu/ops/GrAtlasTextOp.h b/src/gpu/ops/GrAtlasTextOp.h
index 2c53998..44c6377 100644
--- a/src/gpu/ops/GrAtlasTextOp.h
+++ b/src/gpu/ops/GrAtlasTextOp.h
@@ -27,11 +27,11 @@
     static const int kIndicesPerGlyph = 6;
 
     struct Geometry {
-        SkMatrix       fDrawMatrix;
-        SkIRect        fClipRect;
         GrTextBlob*    fBlob;
-        SkPoint        fDrawOrigin;
         GrAtlasSubRun* fSubRunPtr;
+        SkMatrix       fDrawMatrix;
+        SkPoint        fDrawOrigin;
+        SkIRect        fClipRect;
         SkPMColor4f    fColor;
 
         void fillVertexData(void* dst, int offset, int count) const;
@@ -79,15 +79,21 @@
     static constexpr auto kMinGeometryAllocated = 12;
 
     GrAtlasTextOp(MaskType maskType,
+                  bool needsTransform,
+                  int glyphCount,
+                  SkRect deviceRect,
                   GrPaint&& paint,
-                  GrAtlasSubRun* subrun,
-                  const SkMatrix& drawMatrix,
-                  SkPoint drawOrigin,
-                  const SkIRect& clipRect,
-                  const SkPMColor4f& filteredColor,
+                  Geometry&& geo);
+
+    GrAtlasTextOp(MaskType maskType,
+                  bool needsTransform,
+                  int glyphCount,
+                  SkRect deviceRect,
                   SkColor luminanceColor,
                   bool useGammaCorrectDistanceTable,
-                  uint32_t DFGPFlags);
+                  uint32_t DFGPFlags,
+                  GrPaint&& paint,
+                  Geometry&& geo);
 
     struct FlushInfo {
         sk_sp<const GrBuffer> fVertexBuffer;
diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp
index 0c04419..345f219 100644
--- a/src/gpu/text/GrTextBlob.cpp
+++ b/src/gpu/text/GrTextBlob.cpp
@@ -161,13 +161,14 @@
     const GrColorInfo& colorInfo = rtc->colorInfo();
 
     // This is the color the op will use to draw.
-    SkPMColor4f drawingColor = generate_filtered_color(drawPaint, colorInfo);
-
+    SkPMColor4f drawingColor;
     GrPaint grPaint;
     if (this->maskFormat() == kARGB_GrMaskFormat) {
+        drawingColor = SK_PMColor4fWHITE;
         SkPaintToGrPaintWithPrimitiveColor(
                 context, colorInfo, drawPaint, viewMatrix, &grPaint);
     } else {
+        drawingColor = generate_filtered_color(drawPaint, colorInfo);
         SkPaintToGrPaint(context, colorInfo, drawPaint, viewMatrix, &grPaint);
     }
 
@@ -210,16 +211,21 @@
             }
         }();
 
+        GrAtlasTextOp::Geometry geometry = {
+                SkRef(fBlob),
+                this,
+                drawMatrix,
+                drawOrigin,
+                clipRect,
+                drawingColor
+        };
+
         op = pool->allocate<GrAtlasTextOp>(maskType,
+                                           this->needsTransform(),
+                                           this->glyphCount(),
+                                           this->deviceRect(drawMatrix, drawOrigin),
                                            std::move(grPaint),
-                                           this,
-                                           drawMatrix,
-                                           drawOrigin,
-                                           clipRect,
-                                           drawingColor,
-                                           0,
-                                           false,
-                                           0);
+                                           std::move(geometry));
     } else {
         const SkSurfaceProps& props = rtc->surfaceProps();
         bool isBGR = SkPixelGeometryIsBGR(props.pixelGeometry());
@@ -244,16 +250,24 @@
                          kBGR_DistanceFieldEffectFlag : 0;
         }
 
+        GrAtlasTextOp::Geometry geometry = {
+                SkRef(fBlob),
+                this,
+                drawMatrix,
+                drawOrigin,
+                SkIRect::MakeEmpty(),
+                drawingColor
+        };
+
         op = pool->allocate<GrAtlasTextOp>(maskType,
-                                           std::move(grPaint),
-                                           this,
-                                           drawMatrix,
-                                           drawOrigin,
-                                           SkIRect::MakeEmpty(),
-                                           drawingColor,
+                                           this->needsTransform(),
+                                           this->glyphCount(),
+                                           this->deviceRect(drawMatrix, drawOrigin),
                                            SkPaintPriv::ComputeLuminanceColor(drawPaint),
                                            useGammaCorrectDistanceTable,
-                                           DFGPFlags);
+                                           DFGPFlags,
+                                           std::move(grPaint),
+                                           std::move(geometry));
     }
 
     return {clip, std::move(op)};
diff --git a/src/gpu/text/GrTextBlob.h b/src/gpu/text/GrTextBlob.h
index 9e3c539..865b16c 100644
--- a/src/gpu/text/GrTextBlob.h
+++ b/src/gpu/text/GrTextBlob.h
@@ -266,9 +266,6 @@
 
     std::tuple<bool, int> regenerateAtlas(int begin, int end, GrMeshDrawOp::Target* target);
 
-    GrMaskFormat maskFormat() const;
-    bool needsTransform() const;
-
     size_t vertexStride() const;
     size_t quadOffset(size_t index) const;
     void fillVertexData(
@@ -281,9 +278,6 @@
     // Acquire a GrTextStrike and convert the SkPackedGlyphIDs to GrGlyphs for this run
     void prepareGrGlyphs(GrStrikeCache*);
 
-    // 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;
 
     const SkStrikeSpec& strikeSpec() const;
@@ -306,8 +300,6 @@
                                          GrTextBlob* blob,
                                          SkArenaAlloc* alloc);
 
-    GrTextBlob* fBlob;
-
 private:
     struct AtlasPt {
         uint16_t u;
@@ -352,6 +344,12 @@
     bool hasUseLCDText() const;
     bool isAntiAliased() const;
 
+    GrMaskFormat maskFormat() const;
+
+    // The rectangle that surrounds all the glyph bounding boxes in device space.
+    SkRect deviceRect(const SkMatrix& drawMatrix, SkPoint drawOrigin) const;
+
+    bool needsTransform() const;
     bool drawAsDistanceFields() const;
     bool needsPadding() const;
     int atlasPadding() const;
@@ -363,6 +361,7 @@
     void resetBulkUseToken();
     GrDrawOpAtlas::BulkUseTokenUpdater* bulkUseToken();
 
+    GrTextBlob* fBlob;
     const SubRunType fType;
     const GrMaskFormat fMaskFormat;
     bool fUseLCDText{false};