Better encapsulate the GrDrawOpAtlas w/in the GrSmallPathAtlasMgr

This brings the GrSmallPathAtlasMgr into closer correspondence with
the GrAtlasMgr.

It also centralizes where we update the GrSmallPathShapeData's
atlas information.

Change-Id: I892be262a85b3878dbd7f71b0503208943203d46
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/310476
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/ops/GrSmallPathAtlasMgr.cpp b/src/gpu/ops/GrSmallPathAtlasMgr.cpp
index ca9b5bf..633e411 100644
--- a/src/gpu/ops/GrSmallPathAtlasMgr.cpp
+++ b/src/gpu/ops/GrSmallPathAtlasMgr.cpp
@@ -101,6 +101,13 @@
     return this->findOrCreate(key);
 }
 
+GrDrawOpAtlas::ErrorCode GrSmallPathAtlasMgr::addToAtlas(GrResourceProvider* resourceProvider,
+                                                         GrDeferredUploadTarget* target,
+                                                         int width, int height, const void* image,
+                                                         GrDrawOpAtlas::AtlasLocator* locator) {
+    return fAtlas->addToAtlas(resourceProvider, target, width, height, image, locator);
+}
+
 void GrSmallPathAtlasMgr::setUseToken(GrSmallPathShapeData* shapeData,
                                       GrDeferredUploadToken token) {
     fAtlas->setLastUseToken(shapeData->fAtlasLocator, token);
diff --git a/src/gpu/ops/GrSmallPathAtlasMgr.h b/src/gpu/ops/GrSmallPathAtlasMgr.h
index 17ab571..86fec24 100644
--- a/src/gpu/ops/GrSmallPathAtlasMgr.h
+++ b/src/gpu/ops/GrSmallPathAtlasMgr.h
@@ -36,11 +36,14 @@
 
     bool initAtlas(GrProxyProvider*, const GrCaps*);
 
-    GrDrawOpAtlas* atlas() { return fAtlas.get(); }
-
     GrSmallPathShapeData* findOrCreate(const GrStyledShape&, int desiredDimension);
     GrSmallPathShapeData* findOrCreate(const GrStyledShape&, const SkMatrix& ctm);
 
+    GrDrawOpAtlas::ErrorCode addToAtlas(GrResourceProvider*,
+                                        GrDeferredUploadTarget*,
+                                        int width, int height, const void* image,
+                                        GrDrawOpAtlas::AtlasLocator*);
+
     void setUseToken(GrSmallPathShapeData*, GrDeferredUploadToken);
 
     // GrOnFlushCallbackObject overrides
diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp
index f3ac7c9..c3a7d72 100644
--- a/src/gpu/ops/GrSmallPathRenderer.cpp
+++ b/src/gpu/ops/GrSmallPathRenderer.cpp
@@ -315,7 +315,7 @@
 
                     if (!this->addDFPathToAtlas(target,
                                                 &flushInfo,
-                                                atlasMgr->atlas(),
+                                                atlasMgr,
                                                 shapeData,
                                                 args.fShape,
                                                 ceilDesiredDimension,
@@ -330,7 +330,7 @@
                 if (!shapeData->fAtlasLocator.plotLocator().isValid()) {
                     if (!this->addBMPathToAtlas(target,
                                                 &flushInfo,
-                                                atlasMgr->atlas(),
+                                                atlasMgr,
                                                 shapeData,
                                                 args.fShape,
                                                 args.fViewMatrix)) {
@@ -351,16 +351,17 @@
         this->flush(target, &flushInfo);
     }
 
-    bool addToAtlas(GrMeshDrawOp::Target* target, FlushInfo* flushInfo, GrDrawOpAtlas* atlas,
-                    int width, int height, const void* image,
-                    GrDrawOpAtlas::AtlasLocator* atlasLocator) const {
-        SkASSERT(atlas);
-
+    bool addToAtlasWithRetry(GrMeshDrawOp::Target* target,
+                             FlushInfo* flushInfo,
+                             GrSmallPathAtlasMgr* atlasMgr,
+                             int width, int height, const void* image,
+                             const SkRect& bounds, int srcInset,
+                             GrSmallPathShapeData* shapeData) const {
         auto resourceProvider = target->resourceProvider();
         auto uploadTarget = target->deferredUploadTarget();
 
-        GrDrawOpAtlas::ErrorCode code = atlas->addToAtlas(resourceProvider, uploadTarget,
-                                                          width, height, image, atlasLocator);
+        auto code = atlasMgr->addToAtlas(resourceProvider, uploadTarget, width, height,
+                                         image, &shapeData->fAtlasLocator);
         if (GrDrawOpAtlas::ErrorCode::kError == code) {
             return false;
         }
@@ -368,17 +369,19 @@
         if (GrDrawOpAtlas::ErrorCode::kTryAgain == code) {
             this->flush(target, flushInfo);
 
-            code = atlas->addToAtlas(resourceProvider, uploadTarget, width, height,
-                                     image, atlasLocator);
+            code = atlasMgr->addToAtlas(resourceProvider, uploadTarget, width, height,
+                                        image, &shapeData->fAtlasLocator);
         }
 
+        shapeData->fAtlasLocator.insetSrc(srcInset);
+        shapeData->fBounds = bounds;
+
         return GrDrawOpAtlas::ErrorCode::kSucceeded == code;
     }
 
     bool addDFPathToAtlas(GrMeshDrawOp::Target* target, FlushInfo* flushInfo,
-                          GrDrawOpAtlas* atlas, GrSmallPathShapeData* shapeData,
+                          GrSmallPathAtlasMgr* atlasMgr, GrSmallPathShapeData* shapeData,
                           const GrStyledShape& shape, uint32_t dimension, SkScalar scale) const {
-        SkASSERT(atlas);
 
         const SkRect& bounds = shape.bounds();
 
@@ -457,28 +460,20 @@
                                                dst.width(), dst.height(), dst.rowBytes());
         }
 
-        // add to atlas
-        if (!this->addToAtlas(target, flushInfo, atlas, width, height, dfStorage.get(),
-                              &shapeData->fAtlasLocator)) {
-            return false;
-        }
+        SkRect drawBounds = SkRect::Make(devPathBounds).makeOffset(-translateX, -translateY);
+        drawBounds.fLeft /= scale;
+        drawBounds.fTop /= scale;
+        drawBounds.fRight /= scale;
+        drawBounds.fBottom /= scale;
 
-        shapeData->fAtlasLocator.insetSrc(SK_DistanceFieldPad);
-
-        shapeData->fBounds = SkRect::Make(devPathBounds);
-        shapeData->fBounds.offset(-translateX, -translateY);
-        shapeData->fBounds.fLeft /= scale;
-        shapeData->fBounds.fTop /= scale;
-        shapeData->fBounds.fRight /= scale;
-        shapeData->fBounds.fBottom /= scale;
-        return true;
+        return this->addToAtlasWithRetry(target, flushInfo, atlasMgr,
+                                         width, height, dfStorage.get(),
+                                         drawBounds, SK_DistanceFieldPad, shapeData);
     }
 
     bool addBMPathToAtlas(GrMeshDrawOp::Target* target, FlushInfo* flushInfo,
-                          GrDrawOpAtlas* atlas, GrSmallPathShapeData* shapeData,
+                          GrSmallPathAtlasMgr* atlasMgr, GrSmallPathShapeData* shapeData,
                           const GrStyledShape& shape, const SkMatrix& ctm) const {
-        SkASSERT(atlas);
-
         const SkRect& bounds = shape.bounds();
         if (bounds.isEmpty()) {
             return false;
@@ -536,15 +531,11 @@
 
         draw.drawPathCoverage(path, paint);
 
-        // add to atlas
-        if (!this->addToAtlas(target, flushInfo, atlas, dst.width(), dst.height(), dst.addr(),
-                              &shapeData->fAtlasLocator)) {
-            return false;
-        }
+        SkRect drawBounds = SkRect::Make(devPathBounds).makeOffset(-translateX, -translateY);
 
-        shapeData->fBounds = SkRect::Make(devPathBounds);
-        shapeData->fBounds.offset(-translateX, -translateY);
-        return true;
+        return this->addToAtlasWithRetry(target, flushInfo, atlasMgr,
+                                         dst.width(), dst.height(), dst.addr(),
+                                         drawBounds, 0, shapeData);
     }
 
     void writePathVertices(GrVertexWriter& vertices,