Give GrResourceAllocator a GrDirectContext

This allows it to access the resource cache as well as the provider,
and paves the way for memory budgeting inside the resource allocator.

Bug: skia:10877
Change-Id: I01e9c02e445494ac431b288f41006ae7360ff791
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/394116
Auto-Submit: Adlai Holler <adlai@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index 6d822cd..512911a 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -117,18 +117,18 @@
         }
     }
 
-    auto direct = fContext->asDirectContext();
-    SkASSERT(direct);
-    direct->priv().clientMappedBufferManager()->process();
+    auto dContext = fContext->asDirectContext();
+    SkASSERT(dContext);
+    dContext->priv().clientMappedBufferManager()->process();
 
-    GrGpu* gpu = direct->priv().getGpu();
+    GrGpu* gpu = dContext->priv().getGpu();
     // We have a non abandoned and direct GrContext. It must have a GrGpu.
     SkASSERT(gpu);
 
     fFlushing = true;
 
-    auto resourceProvider = direct->priv().resourceProvider();
-    auto resourceCache = direct->priv().getResourceCache();
+    auto resourceProvider = dContext->priv().resourceProvider();
+    auto resourceCache = dContext->priv().getResourceCache();
 
     // Semi-usually the GrRenderTasks are already closed at this point, but sometimes Ganesh needs
     // to flush mid-draw. In that case, the SkGpuDevice's opsTasks won't be closed but need to be
@@ -205,7 +205,7 @@
     bool flushed = false;
 
     {
-        GrResourceAllocator alloc(resourceProvider SkDEBUGCODE(, fDAG.count()));
+        GrResourceAllocator alloc(dContext SkDEBUGCODE(, fDAG.count()));
         for (const auto& task : fDAG) {
             SkASSERT(task);
             task->gatherProxyIntervals(&alloc);
diff --git a/src/gpu/GrResourceAllocator.cpp b/src/gpu/GrResourceAllocator.cpp
index f5a48fa..9efdebf 100644
--- a/src/gpu/GrResourceAllocator.cpp
+++ b/src/gpu/GrResourceAllocator.cpp
@@ -7,6 +7,7 @@
 
 #include "src/gpu/GrResourceAllocator.h"
 
+#include "src/gpu/GrDirectContextPriv.h"
 #include "src/gpu/GrGpuResourcePriv.h"
 #include "src/gpu/GrOpsTask.h"
 #include "src/gpu/GrRenderTargetProxy.h"
@@ -56,7 +57,8 @@
     // recycled. We don't need to assign a texture to it and no other proxy can be instantiated
     // with the same texture.
     if (proxy->readOnly()) {
-        if (proxy->isLazy() && !proxy->priv().doLazyInstantiation(fResourceProvider)) {
+        auto resourceProvider = fDContext->priv().resourceProvider();
+        if (proxy->isLazy() && !proxy->priv().doLazyInstantiation(resourceProvider)) {
             fFailedInstantiation = true;
         } else {
             // Since we aren't going to add an interval we won't revisit this proxy in assign(). So
@@ -262,7 +264,7 @@
 
     // Then look in the free pool
     GrScratchKey scratchKey;
-    proxy->priv().computeScratchKey(*fResourceProvider->caps(), &scratchKey);
+    proxy->priv().computeScratchKey(*fDContext->priv().caps(), &scratchKey);
 
     auto filter = [] (const Register* r) {
         return true;
@@ -282,7 +284,7 @@
         SkASSERT(!intvl->next());
 
         Register* r = intvl->getRegister();
-        if (r && r->isRecyclable(*fResourceProvider->caps(), intvl->proxy(), intvl->uses())) {
+        if (r && r->isRecyclable(*fDContext->priv().caps(), intvl->proxy(), intvl->uses())) {
 #if GR_ALLOCATION_SPEW
             SkDebugf("putting register %d back into pool\n", r->uniqueID());
 #endif
@@ -337,6 +339,7 @@
     // instantiating anything.
 
     // Instantiate surfaces
+    auto resourceProvider = fDContext->priv().resourceProvider();
     while (Interval* cur = fFinishedIntvls.popHead()) {
         if (fFailedInstantiation) {
             break;
@@ -345,12 +348,12 @@
             continue;
         }
         if (cur->proxy()->isLazy()) {
-            fFailedInstantiation = !cur->proxy()->priv().doLazyInstantiation(fResourceProvider);
+            fFailedInstantiation = !cur->proxy()->priv().doLazyInstantiation(resourceProvider);
             continue;
         }
         Register* r = cur->getRegister();
         SkASSERT(r);
-        fFailedInstantiation = !r->instantiateSurface(cur->proxy(), fResourceProvider);
+        fFailedInstantiation = !r->instantiateSurface(cur->proxy(), resourceProvider);
     }
     return !fFailedInstantiation;
 }
diff --git a/src/gpu/GrResourceAllocator.h b/src/gpu/GrResourceAllocator.h
index 286bd2a..6bc5a3b 100644
--- a/src/gpu/GrResourceAllocator.h
+++ b/src/gpu/GrResourceAllocator.h
@@ -10,15 +10,14 @@
 
 #include "include/private/SkTHash.h"
 
-#include "src/gpu/GrGpuResourcePriv.h"
 #include "src/gpu/GrHashMapWithCache.h"
 #include "src/gpu/GrSurface.h"
-#include "src/gpu/GrSurfaceProxyPriv.h"
+#include "src/gpu/GrSurfaceProxy.h"
 
 #include "src/core/SkArenaAlloc.h"
 #include "src/core/SkTMultiMap.h"
 
-class GrResourceProvider;
+class GrDirectContext;
 
 // Print out explicit allocation information
 #define GR_ALLOCATION_SPEW 0
@@ -69,8 +68,8 @@
  */
 class GrResourceAllocator {
 public:
-    GrResourceAllocator(GrResourceProvider* resourceProvider SkDEBUGCODE(, int numOpsTasks))
-            : fResourceProvider(resourceProvider) {}
+    GrResourceAllocator(GrDirectContext* dContext SkDEBUGCODE(, int numOpsTasks))
+            : fDContext(dContext) {}
 
     ~GrResourceAllocator();
 
@@ -252,7 +251,7 @@
     // Compositing use cases can create > 80 intervals.
     static const int kInitialArenaSize = 128 * sizeof(Interval);
 
-    GrResourceProvider*          fResourceProvider;
+    GrDirectContext*             fDContext;
     FreePoolMultiMap             fFreePool;          // Recently created/used GrSurfaces
     IntvlHash                    fIntvlHash;         // All the intervals, hashed by proxyID