Move more atlas functionality from GrSmallPathRenderer to GrSmallPathAtlasMgr

After this CL the GrSmallPathAtlasMgr is almost all ready to be moved
to be a flush-time entity.

This is pulled out of the omnibus CL:
https://skia-review.googlesource.com/c/skia/+/307776 (Split the small path renderer into record-time and flush-time pieces)

Change-Id: Ie6a2196a640ce9be7a1e1c6d7bbdfd41413c42d0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308977
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrPathRendererChain.cpp b/src/gpu/GrPathRendererChain.cpp
index 33b63f3..337f7cd 100644
--- a/src/gpu/GrPathRendererChain.cpp
+++ b/src/gpu/GrPathRendererChain.cpp
@@ -16,6 +16,7 @@
 #include "src/gpu/GrRecordingContextPriv.h"
 #include "src/gpu/GrShaderCaps.h"
 #include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
+#include "src/gpu/geometry/GrStyledShape.h"
 #include "src/gpu/ops/GrAAConvexPathRenderer.h"
 #include "src/gpu/ops/GrAAHairLinePathRenderer.h"
 #include "src/gpu/ops/GrAALinearizingConvexPathRenderer.h"
@@ -59,7 +60,7 @@
     }
     if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) {
         auto spr = sk_make_sp<GrSmallPathRenderer>();
-        context->priv().addOnFlushCallbackObject(spr.get());
+        spr->addToOnFlushCallbacks(context);
         fChain.push_back(std::move(spr));
     }
     if (options.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) {
diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp
index 8d22b9d..3670728 100644
--- a/src/gpu/ops/GrSmallPathRenderer.cpp
+++ b/src/gpu/ops/GrSmallPathRenderer.cpp
@@ -45,9 +45,14 @@
 static constexpr SkScalar kMinSize = SK_ScalarHalf;
 static constexpr SkScalar kMaxSize = 2*kMaxMIP;
 
-class GrSmallPathAtlasMgr {
+#include "src/gpu/GrDrawOpAtlas.h"
+#include "src/gpu/GrOnFlushResourceProvider.h"
+
+class GrSmallPathAtlasMgr : public GrOnFlushCallbackObject,
+                            public GrDrawOpAtlas::EvictionCallback,
+                            public GrDrawOpAtlas::GenerationCounter{
 public:
-    ~GrSmallPathAtlasMgr() {
+    ~GrSmallPathAtlasMgr() override {
         ShapeDataList::Iter iter;
         iter.init(fShapeList, ShapeDataList::Iter::kHead_IterStart);
         GrSmallPathShapeData* shapeData;
@@ -61,9 +66,7 @@
 #endif
     }
 
-    bool initAtlas(GrProxyProvider* proxyProvider, const GrCaps* caps,
-                   GrDrawOpAtlas::GenerationCounter* generationCounter,
-                   GrDrawOpAtlas::EvictionCallback* evictor) {
+    bool initAtlas(GrProxyProvider* proxyProvider, const GrCaps* caps) {
         if (fAtlas) {
             return true;
         }
@@ -79,8 +82,8 @@
         SkISize size = atlasConfig.atlasDimensions(kA8_GrMaskFormat);
         fAtlas = GrDrawOpAtlas::Make(proxyProvider, format,
                                      GrColorType::kAlpha_8, size.width(), size.height(),
-                                     kPlotWidth, kPlotHeight, generationCounter,
-                                     GrDrawOpAtlas::AllowMultitexturing::kYes, evictor);
+                                     kPlotWidth, kPlotHeight, this,
+                                     GrDrawOpAtlas::AllowMultitexturing::kYes, this);
 
         return SkToBool(fAtlas);
     }
@@ -96,22 +99,29 @@
          fAtlas->setLastUseToken(shapeData->fAtlasLocator, token);
     }
 
+
+    // GrOnFlushCallbackObject overrides
+    //
+    // Note: because this class is associated with a path renderer we want it to be removed from
+    // the list of active OnFlushBackkbackObjects in an freeGpuResources call (i.e., we accept the
+    // default retainOnFreeGpuResources implementation).
+
     void preFlush(GrOnFlushResourceProvider* onFlushRP,
-                  const uint32_t* /*opsTaskIDs*/, int /*numOpsTaskIDs*/) {
+                  const uint32_t* /*opsTaskIDs*/, int /*numOpsTaskIDs*/) override {
         if (fAtlas) {
             fAtlas->instantiate(onFlushRP);
         }
     }
 
     void postFlush(GrDeferredUploadToken startTokenForNextFlush,
-                   const uint32_t* /*opsTaskIDs*/, int /*numOpsTaskIDs*/) {
+                   const uint32_t* /*opsTaskIDs*/, int /*numOpsTaskIDs*/) override {
         if (fAtlas) {
             fAtlas->compact(startTokenForNextFlush);
         }
     }
 
     // Callback to clear out internal path cache when eviction occurs
-    void evict(GrDrawOpAtlas::PlotLocator plotLocator) {
+    void evict(GrDrawOpAtlas::PlotLocator plotLocator) override {
         // remove any paths that use this plot
         ShapeDataList::Iter iter;
         iter.init(fShapeList, ShapeDataList::Iter::kHead_IterStart);
@@ -155,30 +165,20 @@
     using ShapeCache = SkTDynamicHash<GrSmallPathShapeData, GrSmallPathShapeDataKey>;
     typedef SkTInternalLList<GrSmallPathShapeData> ShapeDataList;
 
-    std::unique_ptr<GrDrawOpAtlas>     fAtlas;
-    GrSmallPathRenderer::ShapeCache    fShapeCache;
-    GrSmallPathRenderer::ShapeDataList fShapeList;
+    std::unique_ptr<GrDrawOpAtlas> fAtlas;
+    ShapeCache                     fShapeCache;
+    ShapeDataList                  fShapeList;
 };
 
-void GrSmallPathRenderer::preFlush(GrOnFlushResourceProvider* onFlushRP,
-                                   const uint32_t* opsTaskIDs, int numOpsTaskIDs) {
-    fAtlasMgr->preFlush(onFlushRP, opsTaskIDs, numOpsTaskIDs);
-}
-
-void GrSmallPathRenderer::postFlush(GrDeferredUploadToken startTokenForNextFlush,
-                                    const uint32_t* opsTaskIDs, int numOpsTaskIDs) {
-    fAtlasMgr->postFlush(startTokenForNextFlush, opsTaskIDs, numOpsTaskIDs);
-}
-
-void GrSmallPathRenderer::evict(GrDrawOpAtlas::PlotLocator plotLocator) {
-    fAtlasMgr->evict(plotLocator);
-}
-
 ////////////////////////////////////////////////////////////////////////////////
 GrSmallPathRenderer::GrSmallPathRenderer() : fAtlasMgr(new GrSmallPathAtlasMgr) {}
 
 GrSmallPathRenderer::~GrSmallPathRenderer() { }
 
+void GrSmallPathRenderer::addToOnFlushCallbacks(GrRecordingContext* rContext) {
+    rContext->priv().addOnFlushCallbackObject(fAtlasMgr.get());
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 GrPathRenderer::CanDrawPath GrSmallPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
     if (!args.fCaps->shaderCaps()->shaderDerivativeSupport()) {
@@ -233,9 +233,6 @@
 public:
     DEFINE_OP_CLASS_ID
 
-    using ShapeCache = SkTDynamicHash<GrSmallPathShapeData, GrSmallPathShapeDataKey>;
-    using ShapeDataList = GrSmallPathRenderer::ShapeDataList;
-
     static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context,
                                           GrPaint&& paint,
                                           const GrStyledShape& shape,
@@ -827,11 +824,12 @@
     GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
                               "GrSmallPathRenderer::onDrawPath");
 
+    const GrCaps* caps = args.fContext->priv().caps();
+
     // we've already bailed on inverse filled paths, so this is safe
     SkASSERT(!args.fShape->isEmpty());
     SkASSERT(args.fShape->hasUnstyledKey());
-    if (!fAtlasMgr->initAtlas(args.fContext->priv().proxyProvider(), args.fContext->priv().caps(),
-                               this, this)) {
+    if (!fAtlasMgr->initAtlas(args.fContext->priv().proxyProvider(), caps)) {
         return false;
     }
 
@@ -847,14 +845,9 @@
 
 #if GR_TEST_UTILS
 
-struct GrSmallPathRenderer::PathTestStruct : public GrDrawOpAtlas::EvictionCallback,
-                                             public GrDrawOpAtlas::GenerationCounter {
+struct GrSmallPathRenderer::PathTestStruct {
     PathTestStruct() : fContextID(SK_InvalidGenID) {}
-    ~PathTestStruct() override { }
-
-    void evict(GrDrawOpAtlas::PlotLocator plotLocator) override {
-        fAtlasMgr->evict(plotLocator);
-    }
+    ~PathTestStruct() { }
 
     uint32_t fContextID;
     std::unique_ptr<GrSmallPathAtlasMgr> fAtlasMgr;
@@ -875,15 +868,13 @@
 }
 
 GR_DRAW_OP_TEST_DEFINE(SmallPathOp) {
-    using PathTestStruct = GrSmallPathRenderer::PathTestStruct;
-    static PathTestStruct gTestStruct;
+    static GrSmallPathRenderer::PathTestStruct gTestStruct;
 
     if (context->priv().contextID() != gTestStruct.fContextID) {
         gTestStruct.fContextID = context->priv().contextID();
         gTestStruct.fAtlasMgr = std::make_unique<GrSmallPathAtlasMgr>();
         gTestStruct.fAtlasMgr->initAtlas(context->priv().proxyProvider(),
-                                         context->priv().caps(),
-                                         &gTestStruct, &gTestStruct);
+                                         context->priv().caps());
     }
 
     SkMatrix viewMatrix = GrTest::TestMatrix(random);
diff --git a/src/gpu/ops/GrSmallPathRenderer.h b/src/gpu/ops/GrSmallPathRenderer.h
index c5935c1..e0a45a7 100644
--- a/src/gpu/ops/GrSmallPathRenderer.h
+++ b/src/gpu/ops/GrSmallPathRenderer.h
@@ -8,42 +8,21 @@
 #ifndef GrSmallPathRenderer_DEFINED
 #define GrSmallPathRenderer_DEFINED
 
-#include "src/gpu/GrDrawOpAtlas.h"
-#include "src/gpu/GrOnFlushResourceProvider.h"
 #include "src/gpu/GrPathRenderer.h"
-#include "src/gpu/geometry/GrRect.h"
-#include "src/gpu/geometry/GrStyledShape.h"
 
-#include "src/core/SkTDynamicHash.h"
-
+class GrDrawOp;
 class GrRecordingContext;
 class GrSmallPathAtlasMgr;
-class GrSmallPathShapeData;
-class GrSmallPathShapeDataKey;
+class GrStyledShape;
 
-class GrSmallPathRenderer : public GrPathRenderer,
-                            public GrOnFlushCallbackObject,
-                            public GrDrawOpAtlas::EvictionCallback,
-                            public GrDrawOpAtlas::GenerationCounter {
+class GrSmallPathRenderer : public GrPathRenderer {
 public:
     GrSmallPathRenderer();
     ~GrSmallPathRenderer() override;
 
     const char* name() const final { return "Small"; }
 
-    // GrOnFlushCallbackObject overrides
-    //
-    // Note: because this class is associated with a path renderer we want it to be removed from
-    // the list of active OnFlushBackkbackObjects in an freeGpuResources call (i.e., we accept the
-    // default retainOnFreeGpuResources implementation).
-
-    void preFlush(GrOnFlushResourceProvider* onFlushRP,
-                  const uint32_t* /*opsTaskIDs*/, int /*numOpsTaskIDs*/) override;
-    void postFlush(GrDeferredUploadToken startTokenForNextFlush,
-                   const uint32_t* /*opsTaskIDs*/, int /*numOpsTaskIDs*/) override;
-
-    using ShapeCache = SkTDynamicHash<GrSmallPathShapeData, GrSmallPathShapeDataKey>;
-    typedef SkTInternalLList<GrSmallPathShapeData> ShapeDataList;
+    void addToOnFlushCallbacks(GrRecordingContext*);
 
     static std::unique_ptr<GrDrawOp> createOp_TestingOnly(GrRecordingContext*,
                                                           GrPaint&&,
@@ -65,8 +44,6 @@
 
     bool onDrawPath(const DrawPathArgs&) override;
 
-    void evict(GrDrawOpAtlas::PlotLocator) override;
-
     std::unique_ptr<GrSmallPathAtlasMgr> fAtlasMgr;
 
     typedef GrPathRenderer INHERITED;
diff --git a/src/gpu/ops/GrSmallPathShapeData.h b/src/gpu/ops/GrSmallPathShapeData.h
index 34628eb..c5ddbf1 100644
--- a/src/gpu/ops/GrSmallPathShapeData.h
+++ b/src/gpu/ops/GrSmallPathShapeData.h
@@ -9,6 +9,7 @@
 #define GrSmallPathShapeData_DEFINED
 
 #include "src/core/SkOpts.h"
+#include "src/gpu/geometry/GrStyledShape.h"
 
 class GrSmallPathShapeDataKey  {
 public: