Fission GrAtlasGlyphCache in two

This CL splits the old GrAtlasGlyphCache into a GrAtlasGlyphCache and an GrAtlasManager.

The GrAtlasManager itself is split into a rather limited base class (GrRestrictedAtlasManager)
and the all powerful GrAtlasManager. The GrRestrictedAtlasManager is available at op creation
time and provides access to the proxies backing the atlases. The full GrAtlasManager is
only available at flush time and allows instantiation of the proxies and uploading to them.

In the DDL world all of the DDL Contexts will receive a GrRestrictedAtlasManager-version of the
GrAtlasManager in the main thread. This future atlas manager will have had all of its
GrDrawOpAtlases created (but not instantiated) so there should be no race conditions.

Change-Id: I9967d3a4116af50128f390c5039a712b8cd4db08
Reviewed-on: https://skia-review.googlesource.com/108001
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 74fbe10..8ccbb2b 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -77,6 +77,7 @@
     GrDDLContext(GrContextThreadSafeProxy* proxy) : INHERITED(proxy) {}
 
 protected:
+    // DDL TODO: grab a GrRestrictedAtlasManager from the proxy
 
 private:
     typedef GrContext INHERITED;
@@ -218,7 +219,8 @@
     fResourceCache = nullptr;
     fResourceProvider = nullptr;
     fProxyProvider = nullptr;
-    fAtlasGlyphCache = nullptr;
+    fGlyphCache = nullptr;
+    fFullAtlasManager = nullptr;
 }
 
 GrContext::GrContext(GrContextThreadSafeProxy* proxy)
@@ -228,7 +230,8 @@
     fResourceCache = nullptr;
     fResourceProvider = nullptr;
     fProxyProvider = nullptr;
-    fAtlasGlyphCache = nullptr;
+    fGlyphCache = nullptr;
+    fFullAtlasManager = nullptr;
 }
 
 bool GrContext::init(const GrContextOptions& options) {
@@ -293,9 +296,17 @@
     } else {
         allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kYes;
     }
-    fAtlasGlyphCache = new GrAtlasGlyphCache(fProxyProvider, options.fGlyphCacheTextureMaximumBytes,
-                                             allowMultitexturing);
-    this->contextPriv().addOnFlushCallbackObject(fAtlasGlyphCache);
+
+    fGlyphCache = new GrGlyphCache;
+
+    // DDL TODO: in DDL-mode grab a GrRestrictedAtlasManager from the thread-proxy and
+    // do not add an onFlushCB
+    fFullAtlasManager = new GrAtlasManager(fProxyProvider, fGlyphCache,
+                                           options.fGlyphCacheTextureMaximumBytes,
+                                           allowMultitexturing);
+    this->contextPriv().addOnFlushCallbackObject(fFullAtlasManager);
+
+    fGlyphCache->setGlyphSizeLimit(fFullAtlasManager->getGlyphSizeLimit());
 
     fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB,
                                              this, this->uniqueID(), SkToBool(fGpu)));
@@ -327,7 +338,8 @@
     delete fResourceProvider;
     delete fResourceCache;
     delete fProxyProvider;
-    delete fAtlasGlyphCache;
+    delete fGlyphCache;
+    delete fFullAtlasManager;
 }
 
 sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() {
@@ -386,7 +398,8 @@
 
     fGpu->disconnect(GrGpu::DisconnectType::kAbandon);
 
-    fAtlasGlyphCache->freeAll();
+    fGlyphCache->freeAll();
+    fFullAtlasManager->freeAll();
     fTextBlobCache->freeAll();
 }
 
@@ -405,7 +418,8 @@
 
     fGpu->disconnect(GrGpu::DisconnectType::kCleanup);
 
-    fAtlasGlyphCache->freeAll();
+    fGlyphCache->freeAll();
+    fFullAtlasManager->freeAll();
     fTextBlobCache->freeAll();
 }
 
@@ -419,7 +433,8 @@
 
     this->flush();
 
-    fAtlasGlyphCache->freeAll();
+    fGlyphCache->freeAll();
+    fFullAtlasManager->freeAll();
 
     fDrawingManager->freeGpuResources();