Move DrawingManager to RecordingContext

This CL does make use of a new GrRecordingContextPriv backdoor to break CL deadlocks. This occurs when this CL tries to create GrContext-dependent objects outside its scope.

Change-Id: I278fe9d321f8e0a4f5e9b489b1a5cc01b8974521
Reviewed-on: https://skia-review.googlesource.com/c/191287
Reviewed-by: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 71b82f9..09f3ca4 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -23,7 +23,6 @@
 class GrCaps;
 class GrContextPriv;
 class GrContextThreadSafeProxy;
-class GrDrawingManager;
 class GrFragmentProcessor;
 struct GrGLInterface;
 class GrGpu;
@@ -293,9 +292,6 @@
 
     virtual GrAtlasManager* onGetAtlasManager() = 0;
 
-    // CONTEXT TODO: move GrDrawingManager to GrRecordingContext for real
-    GrDrawingManager* drawingManager() override;
-
     sk_sp<GrContextThreadSafeProxy>         fThreadSafeProxy;
 
 private:
@@ -312,8 +308,6 @@
     // true if the PM/UPM conversion succeeded; false otherwise
     bool                                    fPMUPMConversionsRoundTrip;
 
-    std::unique_ptr<GrDrawingManager>       fDrawingManager;
-
     GrContextOptions::PersistentCache*      fPersistentCache;
 
     // TODO: have the GrClipStackClip use renderTargetContexts and rm this friending
diff --git a/include/private/GrRecordingContext.h b/include/private/GrRecordingContext.h
index 014d655..251ff7b 100644
--- a/include/private/GrRecordingContext.h
+++ b/include/private/GrRecordingContext.h
@@ -10,6 +10,7 @@
 
 #include "GrAuditTrail.h"
 #include "GrImageContext.h"
+#include "SkRefCnt.h"
 
 class GrDrawingManager;
 class GrOnFlushCallbackObject;
@@ -34,8 +35,7 @@
 
     void abandonContext() override;
 
-    // CONTEXT TODO: move GrDrawingManager to GrRecordingContext for real
-    virtual GrDrawingManager* drawingManager() = 0;
+    GrDrawingManager* drawingManager();
 
     sk_sp<GrOpMemoryPool> refOpMemoryPool();
     GrOpMemoryPool* opMemoryPool();
@@ -105,6 +105,7 @@
     GrRecordingContext* asRecordingContext() override { return this; }
 
 private:
+    std::unique_ptr<GrDrawingManager> fDrawingManager;
     // All the GrOp-derived classes use this pool.
     sk_sp<GrOpMemoryPool>             fOpMemoryPool;
 
diff --git a/src/atlastext/SkAtlasTextTarget.cpp b/src/atlastext/SkAtlasTextTarget.cpp
index 68dc6fa..1ba6c12 100644
--- a/src/atlastext/SkAtlasTextTarget.cpp
+++ b/src/atlastext/SkAtlasTextTarget.cpp
@@ -154,7 +154,7 @@
     fColor = color;
 
     SkSurfaceProps props(SkSurfaceProps::kUseDistanceFieldFonts_Flag, kUnknown_SkPixelGeometry);
-    auto* grContext = this->context()->internal().grContext();
+    auto grContext = this->context()->internal().grContext();
     auto atlasTextContext = grContext->priv().drawingManager()->getTextContext();
     SkGlyphRunBuilder builder;
     builder.drawGlyphsWithPositions(paint, font.makeFont(),
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index 2105e94..b5a3606 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -8,8 +8,11 @@
 #include "SkGlyphRunPainter.h"
 
 #if SK_SUPPORT_GPU
+#include "GrCaps.h"
 #include "GrColorSpaceInfo.h"
 #include "GrContextPriv.h"
+#include "GrRecordingContext.h"
+#include "GrRecordingContextPriv.h"
 #include "GrRenderTargetContext.h"
 #include "SkGr.h"
 #include "text/GrTextBlobCache.h"
@@ -516,7 +519,7 @@
 }
 
 void GrTextContext::drawGlyphRunList(
-        GrContext* context, GrTextTarget* target, const GrClip& clip,
+        GrRecordingContext* context, GrTextTarget* target, const GrClip& clip,
         const SkMatrix& viewMatrix, const SkSurfaceProps& props,
         const SkGlyphRunList& glyphRunList) {
     SkPoint origin = glyphRunList.origin();
@@ -528,7 +531,7 @@
     GrColor color = generate_filtered_color(listPaint, target->colorSpaceInfo()).toBytes_RGBA();
 
     // If we have been abandoned, then don't draw
-    if (context->abandoned()) {
+    if (context->priv().abandoned()) {
         return;
     }
 
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp
index 103fa73..46d1afd 100644
--- a/src/gpu/GrBlurUtils.cpp
+++ b/src/gpu/GrBlurUtils.cpp
@@ -8,7 +8,6 @@
 #include "GrBlurUtils.h"
 
 #include "GrCaps.h"
-#include "GrContextPriv.h"
 #include "GrFixedClip.h"
 #include "GrProxyProvider.h"
 #include "GrRecordingContext.h"
@@ -442,7 +441,7 @@
                                 viewMatrix, as_MFB(mf), shape);
 }
 
-void GrBlurUtils::drawShapeWithMaskFilter(GrContext* context,
+void GrBlurUtils::drawShapeWithMaskFilter(GrRecordingContext* context,
                                           GrRenderTargetContext* renderTargetContext,
                                           const GrClip& clip,
                                           const SkPaint& paint,
diff --git a/src/gpu/GrBlurUtils.h b/src/gpu/GrBlurUtils.h
index bb7adbf..7e10edc 100644
--- a/src/gpu/GrBlurUtils.h
+++ b/src/gpu/GrBlurUtils.h
@@ -33,7 +33,7 @@
     /**
      * Draw a shape handling the mask filter if present.
      */
-    void drawShapeWithMaskFilter(GrContext*,
+    void drawShapeWithMaskFilter(GrRecordingContext*,
                                  GrRenderTargetContext*,
                                  const GrClip&,
                                  const SkPaint&,
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 95c0c62..ce5e766 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -70,6 +70,7 @@
         return false;
     }
 
+    SkASSERT(this->drawingManager());
     SkASSERT(this->caps());
     SkASSERT(this->getGlyphCache());
     SkASSERT(this->getTextBlobCache());
@@ -86,41 +87,6 @@
 
     fDidTestPMConversions = false;
 
-    GrPathRendererChain::Options prcOptions;
-    prcOptions.fAllowPathMaskCaching = this->options().fAllowPathMaskCaching;
-#if GR_TEST_UTILS
-    prcOptions.fGpuPathRenderers = this->options().fGpuPathRenderers;
-#endif
-    if (this->options().fDisableCoverageCountingPaths) {
-        prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kCoverageCounting;
-    }
-    if (this->options().fDisableDistanceFieldPaths) {
-        prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall;
-    }
-
-    if (!fResourceCache) {
-        // DDL TODO: remove this crippling of the path renderer chain
-        // Disable the small path renderer bc of the proxies in the atlas. They need to be
-        // unified when the opLists are added back to the destination drawing manager.
-        prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall;
-    }
-
-    GrTextContext::Options textContextOptions;
-    textContextOptions.fMaxDistanceFieldFontSize = this->options().fGlyphsAsPathsFontSize;
-    textContextOptions.fMinDistanceFieldFontSize = this->options().fMinDistanceFieldFontSize;
-    textContextOptions.fDistanceFieldVerticesAlwaysHaveW = false;
-#if SK_SUPPORT_ATLAS_TEXT
-    if (GrContextOptions::Enable::kYes == this->options().fDistanceFieldGlyphVerticesAlwaysHaveW) {
-        textContextOptions.fDistanceFieldVerticesAlwaysHaveW = true;
-    }
-#endif
-
-    fDrawingManager.reset(new GrDrawingManager(this, prcOptions, textContextOptions,
-                                               this->singleOwner(),
-                                               this->explicitlyAllocateGPUResources(),
-                                               this->options().fSortRenderTargets,
-                                               this->options().fReduceOpListSplitting));
-
     // DDL TODO: we need to think through how the task group & persistent cache
     // get passed on to/shared between all the DDLRecorders created with this context.
     if (this->options().fExecutor) {
@@ -136,10 +102,6 @@
     return fThreadSafeProxy;
 }
 
-GrDrawingManager* GrContext::drawingManager() {
-    return fDrawingManager.get();
-}
-
 //////////////////////////////////////////////////////////////////////////////
 
 void GrContext::abandonContext() {
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index 3172207..24f3e2a 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -61,8 +61,6 @@
     SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } )
 
     // from GrRecordingContext
-
-    // CONTEXT TODO: move GrDrawingManager to GrRecordingContext for real
     GrDrawingManager* drawingManager() { return fContext->drawingManager(); }
 
     sk_sp<GrOpMemoryPool> refOpMemoryPool();
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index e3fcdf6..5cc3ccf 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -6,13 +6,15 @@
  */
 
 #include "GrDrawingManager.h"
+
 #include "GrBackendSemaphore.h"
-#include "GrContext.h"
 #include "GrContextPriv.h"
 #include "GrGpu.h"
 #include "GrMemoryPool.h"
 #include "GrOnFlushResourceProvider.h"
 #include "GrOpList.h"
+#include "GrRecordingContext.h"
+#include "GrRecordingContextPriv.h"
 #include "GrRenderTargetContext.h"
 #include "GrRenderTargetProxy.h"
 #include "GrResourceAllocator.h"
@@ -145,7 +147,7 @@
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-GrDrawingManager::GrDrawingManager(GrContext* context,
+GrDrawingManager::GrDrawingManager(GrRecordingContext* context,
                                    const GrPathRendererChain::Options& optionsForPathRendererChain,
                                    const GrTextContext::Options& optionsForTextContext,
                                    GrSingleOwner* singleOwner,
@@ -290,8 +292,7 @@
     bool flushed = false;
 
     {
-        GrResourceAllocator alloc(fContext->priv().resourceProvider(),
-                                  flushState.deinstantiateProxyTracker());
+        GrResourceAllocator alloc(resourceProvider, flushState.deinstantiateProxyTracker());
         for (int i = 0; i < fDAG.numOpLists(); ++i) {
             if (fDAG.opList(i)) {
                 fDAG.opList(i)->gatherProxyIntervals(&alloc);
@@ -376,7 +377,7 @@
         return false;
     }
 
-    GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
+    auto resourceProvider = direct->priv().resourceProvider();
     bool anyOpListsExecuted = false;
 
     for (int i = startIndex; i < stopIndex; ++i) {
diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h
index 793a97c..1048405 100644
--- a/src/gpu/GrDrawingManager.h
+++ b/src/gpu/GrDrawingManager.h
@@ -16,10 +16,10 @@
 #include "SkTArray.h"
 #include "text/GrTextContext.h"
 
-class GrContext;
 class GrCoverageCountingPathRenderer;
 class GrOnFlushCallbackObject;
 class GrOpFlushState;
+class GrRecordingContext;
 class GrRenderTargetContext;
 class GrRenderTargetProxy;
 class GrSingleOWner;
@@ -53,7 +53,7 @@
     sk_sp<GrRenderTargetOpList> newRTOpList(GrRenderTargetProxy* rtp, bool managedOpList);
     sk_sp<GrTextureOpList> newTextureOpList(GrTextureProxy* textureProxy);
 
-    GrContext* getContext() { return fContext; }
+    GrRecordingContext* getContext() { return fContext; }
 
     GrTextContext* getTextContext();
 
@@ -134,7 +134,7 @@
         bool                      fSortOpLists;
     };
 
-    GrDrawingManager(GrContext*, const GrPathRendererChain::Options&,
+    GrDrawingManager(GrRecordingContext*, const GrPathRendererChain::Options&,
                      const GrTextContext::Options&, GrSingleOwner*,
                      bool explicitlyAllocating, GrContextOptions::Enable sortRenderTargets,
                      GrContextOptions::Enable reduceOpListSplitting);
@@ -152,14 +152,15 @@
 
     SkDEBUGCODE(void validate() const);
 
-    friend class GrContext;  // for access to: ctor, abandon, reset & flush
+    friend class GrContext; // access to: flush & cleanup
     friend class GrContextPriv; // access to: flush
     friend class GrOnFlushResourceProvider; // this is just a shallow wrapper around this class
+    friend class GrRecordingContext;  // access to: ctor
 
     static const int kNumPixelGeometries = 5; // The different pixel geometries
     static const int kNumDFTOptions = 2;      // DFT or no DFT
 
-    GrContext*                        fContext;
+    GrRecordingContext*               fContext;
     GrPathRendererChain::Options      fOptionsForPathRendererChain;
     GrTextContext::Options            fOptionsForTextContext;
     // This cache is used by both the vertex and index pools. It reuses memory across multiple
diff --git a/src/gpu/GrOnFlushResourceProvider.cpp b/src/gpu/GrOnFlushResourceProvider.cpp
index 13fd60f..40dc68a 100644
--- a/src/gpu/GrOnFlushResourceProvider.cpp
+++ b/src/gpu/GrOnFlushResourceProvider.cpp
@@ -6,10 +6,12 @@
  */
 
 #include "GrOnFlushResourceProvider.h"
-#include "GrContext.h"
+
 #include "GrContextPriv.h"
 #include "GrDrawingManager.h"
 #include "GrProxyProvider.h"
+#include "GrRecordingContext.h"
+#include "GrRecordingContextPriv.h"
 #include "GrRenderTargetContext.h"
 #include "GrSurfaceProxy.h"
 
diff --git a/src/gpu/GrPathRendererChain.cpp b/src/gpu/GrPathRendererChain.cpp
index ca2a7f0..93f3f11 100644
--- a/src/gpu/GrPathRendererChain.cpp
+++ b/src/gpu/GrPathRendererChain.cpp
@@ -7,11 +7,14 @@
 
 
 #include "GrPathRendererChain.h"
+
 #include "GrCaps.h"
-#include "GrShaderCaps.h"
 #include "GrContext.h"
 #include "GrContextPriv.h"
 #include "GrGpu.h"
+#include "GrRecordingContext.h"
+#include "GrRecordingContextPriv.h"
+#include "GrShaderCaps.h"
 #include "ccpr/GrCoverageCountingPathRenderer.h"
 #include "ops/GrAAConvexPathRenderer.h"
 #include "ops/GrAAHairLinePathRenderer.h"
@@ -22,7 +25,7 @@
 #include "ops/GrStencilAndCoverPathRenderer.h"
 #include "ops/GrTessellatingPathRenderer.h"
 
-GrPathRendererChain::GrPathRendererChain(GrContext* context, const Options& options) {
+GrPathRendererChain::GrPathRendererChain(GrRecordingContext* context, const Options& options) {
     const GrCaps& caps = *context->priv().caps();
     if (options.fGpuPathRenderers & GpuPathRenderers::kDashLine) {
         fChain.push_back(sk_make_sp<GrDashLinePathRenderer>());
diff --git a/src/gpu/GrPathRendererChain.h b/src/gpu/GrPathRendererChain.h
index e368450..3542ec4 100644
--- a/src/gpu/GrPathRendererChain.h
+++ b/src/gpu/GrPathRendererChain.h
@@ -30,7 +30,7 @@
         bool fAllowPathMaskCaching = false;
         GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kAll;
     };
-    GrPathRendererChain(GrContext* context, const Options&);
+    GrPathRendererChain(GrRecordingContext* context, const Options&);
 
     /** Documents how the caller plans to use a GrPathRenderer to draw a path. It affects the PR
         returned by getPathRenderer */
diff --git a/src/gpu/GrRecordingContext.cpp b/src/gpu/GrRecordingContext.cpp
index ebd9373..7384e3c 100644
--- a/src/gpu/GrRecordingContext.cpp
+++ b/src/gpu/GrRecordingContext.cpp
@@ -60,6 +60,42 @@
     fTextBlobCache.reset(new GrTextBlobCache(textblobcache_overbudget_CB, this,
                                              this->contextID()));
 
+    GrPathRendererChain::Options prcOptions;
+    prcOptions.fAllowPathMaskCaching = this->options().fAllowPathMaskCaching;
+#if GR_TEST_UTILS
+    prcOptions.fGpuPathRenderers = this->options().fGpuPathRenderers;
+#endif
+    if (this->options().fDisableCoverageCountingPaths) {
+        prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kCoverageCounting;
+    }
+    if (this->options().fDisableDistanceFieldPaths) {
+        prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall;
+    }
+
+    if (!this->proxyProvider()->renderingDirectly()) {
+        // DDL TODO: remove this crippling of the path renderer chain
+        // Disable the small path renderer bc of the proxies in the atlas. They need to be
+        // unified when the opLists are added back to the destination drawing manager.
+        prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall;
+    }
+
+    GrTextContext::Options textContextOptions;
+    textContextOptions.fMaxDistanceFieldFontSize = this->options().fGlyphsAsPathsFontSize;
+    textContextOptions.fMinDistanceFieldFontSize = this->options().fMinDistanceFieldFontSize;
+    textContextOptions.fDistanceFieldVerticesAlwaysHaveW = false;
+#if SK_SUPPORT_ATLAS_TEXT
+    if (GrContextOptions::Enable::kYes == this->options().fDistanceFieldGlyphVerticesAlwaysHaveW) {
+        textContextOptions.fDistanceFieldVerticesAlwaysHaveW = true;
+    }
+#endif
+
+    fDrawingManager.reset(new GrDrawingManager(this,
+                                               prcOptions,
+                                               textContextOptions,
+                                               this->singleOwner(),
+                                               this->explicitlyAllocateGPUResources(),
+                                               this->options().fSortRenderTargets,
+                                               this->options().fReduceOpListSplitting));
     return true;
 }
 
@@ -70,6 +106,10 @@
     fTextBlobCache->freeAll();
 }
 
+GrDrawingManager* GrRecordingContext::drawingManager() {
+    return fDrawingManager.get();
+}
+
 sk_sp<GrOpMemoryPool> GrRecordingContext::refOpMemoryPool() {
     if (!fOpMemoryPool) {
         // DDL TODO: should the size of the memory pool be decreased in DDL mode? CPU-side memory
@@ -177,7 +217,6 @@
         return nullptr;
     }
 
-    // CONTEXT TODO: move GrDrawingManager to GrRecordingContext for real
     auto drawingManager = this->drawingManager();
 
     sk_sp<GrRenderTargetContext> renderTargetContext =
diff --git a/src/gpu/GrRecordingContextPriv.h b/src/gpu/GrRecordingContextPriv.h
index 8d64f1c..879b56e 100644
--- a/src/gpu/GrRecordingContextPriv.h
+++ b/src/gpu/GrRecordingContextPriv.h
@@ -45,8 +45,6 @@
     SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } )
 
     // from GrRecordingContext
-
-    // CONTEXT TODO: move GrDrawingManager to GrRecordingContext for real
     GrDrawingManager* drawingManager() { return fContext->drawingManager(); }
 
     sk_sp<GrOpMemoryPool> refOpMemoryPool();
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 910fcdb..063b72b 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -11,6 +11,7 @@
 #include "GrAppliedClip.h"
 #include "GrBackendSemaphore.h"
 #include "GrBlurUtils.h"
+#include "GrCaps.h"
 #include "GrColor.h"
 #include "GrContextPriv.h"
 #include "GrDrawingManager.h"
@@ -20,6 +21,8 @@
 #include "GrOpList.h"
 #include "GrPathRenderer.h"
 #include "GrQuad.h"
+#include "GrRecordingContext.h"
+#include "GrRecordingContextPriv.h"
 #include "GrRenderTarget.h"
 #include "GrRenderTargetContextPriv.h"
 #include "GrResourceProvider.h"
@@ -80,7 +83,7 @@
 
     void makeGrPaint(GrMaskFormat maskFormat, const SkPaint& skPaint, const SkMatrix& viewMatrix,
                      GrPaint* grPaint) override {
-        GrContext* context = fRenderTargetContext->fContext;
+        auto context = fRenderTargetContext->fContext;
         const GrColorSpaceInfo& colorSpaceInfo = fRenderTargetContext->colorSpaceInfo();
         if (kARGB_GrMaskFormat == maskFormat) {
             SkPaintToGrPaintWithPrimitiveColor(context, colorSpaceInfo, skPaint, grPaint);
@@ -89,7 +92,7 @@
         }
     }
 
-    GrContext* getContext() override {
+    GrRecordingContext* getContext() override {
         return fRenderTargetContext->fContext;
     }
 
@@ -108,11 +111,11 @@
     SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
 #define ASSERT_SINGLE_OWNER_PRIV \
     SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());)
-#define RETURN_IF_ABANDONED        if (fContext->abandoned()) { return; }
-#define RETURN_IF_ABANDONED_PRIV   if (fRenderTargetContext->fContext->abandoned()) { return; }
-#define RETURN_FALSE_IF_ABANDONED  if (fContext->abandoned()) { return false; }
-#define RETURN_FALSE_IF_ABANDONED_PRIV  if (fRenderTargetContext->fContext->abandoned()) { return false; }
-#define RETURN_NULL_IF_ABANDONED   if (fContext->abandoned()) { return nullptr; }
+#define RETURN_IF_ABANDONED        if (fContext->priv().abandoned()) { return; }
+#define RETURN_IF_ABANDONED_PRIV   if (fRenderTargetContext->fContext->priv().abandoned()) { return; }
+#define RETURN_FALSE_IF_ABANDONED  if (fContext->priv().abandoned()) { return false; }
+#define RETURN_FALSE_IF_ABANDONED_PRIV  if (fRenderTargetContext->fContext->priv().abandoned()) { return false; }
+#define RETURN_NULL_IF_ABANDONED   if (fContext->priv().abandoned()) { return nullptr; }
 
 //////////////////////////////////////////////////////////////////////////////
 
@@ -156,7 +159,7 @@
 // GrOpLists to be picked up and added to by renderTargetContexts lower in the call
 // stack. When this occurs with a closed GrOpList, a new one will be allocated
 // when the renderTargetContext attempts to use it (via getOpList).
-GrRenderTargetContext::GrRenderTargetContext(GrContext* context,
+GrRenderTargetContext::GrRenderTargetContext(GrRecordingContext* context,
                                              GrDrawingManager* drawingMgr,
                                              sk_sp<GrRenderTargetProxy> rtp,
                                              sk_sp<SkColorSpace> colorSpace,
@@ -2030,7 +2033,7 @@
 void GrRenderTargetContext::addDrawOp(const GrClip& clip, std::unique_ptr<GrDrawOp> op,
                                       const std::function<WillAddOpFn>& willAddFn) {
     ASSERT_SINGLE_OWNER
-    if (fContext->abandoned()) {
+    if (fContext->priv().abandoned()) {
         fContext->priv().opMemoryPool()->release(std::move(op));
         return;
     }
diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h
index d21af5a..8f344cd 100644
--- a/src/gpu/GrRenderTargetContext.h
+++ b/src/gpu/GrRenderTargetContext.h
@@ -454,7 +454,7 @@
     bool isWrapped_ForTesting() const;
 
 protected:
-    GrRenderTargetContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTargetProxy>,
+    GrRenderTargetContext(GrRecordingContext*, GrDrawingManager*, sk_sp<GrRenderTargetProxy>,
                           sk_sp<SkColorSpace>, const SkSurfaceProps*, GrAuditTrail*,
                           GrSingleOwner*, bool managedOpList = true);
 
diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp
index a573a36..2d85a11 100644
--- a/src/gpu/GrSurfaceContext.cpp
+++ b/src/gpu/GrSurfaceContext.cpp
@@ -9,18 +9,20 @@
 #include "GrContextPriv.h"
 #include "GrDrawingManager.h"
 #include "GrOpList.h"
+#include "GrRecordingContext.h"
+#include "GrRecordingContextPriv.h"
 #include "SkGr.h"
 #include "../private/GrAuditTrail.h"
 
 #define ASSERT_SINGLE_OWNER \
     SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
-#define RETURN_FALSE_IF_ABANDONED  if (this->fContext->abandoned()) { return false; }
+#define RETURN_FALSE_IF_ABANDONED  if (this->fContext->priv().abandoned()) { return false; }
 
 // In MDB mode the reffing of the 'getLastOpList' call's result allows in-progress
 // GrOpLists to be picked up and added to by renderTargetContexts lower in the call
 // stack. When this occurs with a closed GrOpList, a new one will be allocated
 // when the renderTargetContext attempts to use it (via getOpList).
-GrSurfaceContext::GrSurfaceContext(GrContext* context,
+GrSurfaceContext::GrSurfaceContext(GrRecordingContext* context,
                                    GrDrawingManager* drawingMgr,
                                    GrPixelConfig config,
                                    sk_sp<SkColorSpace> colorSpace,
diff --git a/src/gpu/GrSurfaceContext.h b/src/gpu/GrSurfaceContext.h
index c499d09..9d60689 100644
--- a/src/gpu/GrSurfaceContext.h
+++ b/src/gpu/GrSurfaceContext.h
@@ -16,6 +16,7 @@
 class GrContext;
 class GrDrawingManager;
 class GrOpList;
+class GrRecordingContext;
 class GrRenderTargetContext;
 class GrRenderTargetProxy;
 class GrSingleOwner;
@@ -111,7 +112,7 @@
 protected:
     friend class GrSurfaceContextPriv;
 
-    GrSurfaceContext(GrContext*, GrDrawingManager*, GrPixelConfig, sk_sp<SkColorSpace>,
+    GrSurfaceContext(GrRecordingContext*, GrDrawingManager*, GrPixelConfig, sk_sp<SkColorSpace>,
                      GrAuditTrail*, GrSingleOwner*);
 
     GrDrawingManager* drawingManager() { return fDrawingManager; }
@@ -122,13 +123,13 @@
 
     SkDEBUGCODE(GrSingleOwner* singleOwner() { return fSingleOwner; })
 
-    GrContext* fContext;
-    GrAuditTrail* fAuditTrail;
+    GrRecordingContext* fContext;
+    GrAuditTrail*       fAuditTrail;
 
 private:
-    GrColorSpaceInfo fColorSpaceInfo;
+    GrColorSpaceInfo    fColorSpaceInfo;
 
-    GrDrawingManager* fDrawingManager;
+    GrDrawingManager*   fDrawingManager;
 
     // In debug builds we guard against improper thread handling
     SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;)
diff --git a/src/gpu/GrSurfaceContextPriv.h b/src/gpu/GrSurfaceContextPriv.h
index 4a45f8f..0749d3d 100644
--- a/src/gpu/GrSurfaceContextPriv.h
+++ b/src/gpu/GrSurfaceContextPriv.h
@@ -15,7 +15,7 @@
     additional data members or virtual methods. */
 class GrSurfaceContextPriv {
 public:
-    GrContext* getContext() { return fSurfaceContext->fContext; }
+    GrRecordingContext* getContext() { return fSurfaceContext->fContext; }
 
 private:
     explicit GrSurfaceContextPriv(GrSurfaceContext* surfaceContext)
diff --git a/src/gpu/GrTextureContext.cpp b/src/gpu/GrTextureContext.cpp
index c5b3203..e4434a2 100644
--- a/src/gpu/GrTextureContext.cpp
+++ b/src/gpu/GrTextureContext.cpp
@@ -17,7 +17,7 @@
     SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
 #define RETURN_FALSE_IF_ABANDONED  if (this->drawingManager()->wasAbandoned()) { return false; }
 
-GrTextureContext::GrTextureContext(GrContext* context,
+GrTextureContext::GrTextureContext(GrRecordingContext* context,
                                    GrDrawingManager* drawingMgr,
                                    sk_sp<GrTextureProxy> textureProxy,
                                    sk_sp<SkColorSpace> colorSpace,
diff --git a/src/gpu/GrTextureContext.h b/src/gpu/GrTextureContext.h
index f083e71..70603a2 100644
--- a/src/gpu/GrTextureContext.h
+++ b/src/gpu/GrTextureContext.h
@@ -39,7 +39,7 @@
     sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() override;
 
 protected:
-    GrTextureContext(GrContext*, GrDrawingManager*, sk_sp<GrTextureProxy>,
+    GrTextureContext(GrRecordingContext*, GrDrawingManager*, sk_sp<GrTextureProxy>,
                      sk_sp<SkColorSpace>, GrAuditTrail*, GrSingleOwner*);
 
     SkDEBUGCODE(void validate() const override;)
diff --git a/src/gpu/text/GrTextContext.h b/src/gpu/text/GrTextContext.h
index 7eca8b7..5c359fa 100644
--- a/src/gpu/text/GrTextContext.h
+++ b/src/gpu/text/GrTextContext.h
@@ -45,7 +45,7 @@
 
     static std::unique_ptr<GrTextContext> Make(const Options& options);
 
-    void drawGlyphRunList(GrContext*, GrTextTarget*, const GrClip&,
+    void drawGlyphRunList(GrRecordingContext*, GrTextTarget*, const GrClip&,
                           const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkGlyphRunList&);
 
     std::unique_ptr<GrDrawOp> createOp_TestingOnly(GrRecordingContext*,
diff --git a/src/gpu/text/GrTextTarget.h b/src/gpu/text/GrTextTarget.h
index 1742f59..9ad9a7c 100644
--- a/src/gpu/text/GrTextTarget.h
+++ b/src/gpu/text/GrTextTarget.h
@@ -14,6 +14,7 @@
 class GrAtlasTextOp;
 class GrClip;
 class GrPaint;
+class GrRecordingContext;
 class GrShape;
 class SkGlyphRunListPainter;
 class SkMatrix;
@@ -37,7 +38,7 @@
     virtual void makeGrPaint(GrMaskFormat, const SkPaint&, const SkMatrix& viewMatrix,
                              GrPaint*) = 0;
 
-    virtual GrContext* getContext() = 0;
+    virtual GrRecordingContext* getContext() = 0;
 
     virtual SkGlyphRunListPainter* glyphPainter() = 0;
 
diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp
index e9f286f..ce6122a 100644
--- a/tests/RectangleTextureTest.cpp
+++ b/tests/RectangleTextureTest.cpp
@@ -165,8 +165,7 @@
 
         test_read_pixels(reporter, rectContext.get(), refPixels, "RectangleTexture-read");
 
-        test_copy_to_surface(reporter, context->priv().proxyProvider(),
-                              rectContext.get(), "RectangleTexture-copy-to");
+        test_copy_to_surface(reporter, context, rectContext.get(), "RectangleTexture-copy-to");
 
         test_write_pixels(reporter, rectContext.get(), true, "RectangleTexture-write");
 
diff --git a/tests/TestUtils.cpp b/tests/TestUtils.cpp
index 62b651d..560894f 100644
--- a/tests/TestUtils.cpp
+++ b/tests/TestUtils.cpp
@@ -7,7 +7,7 @@
 
 #include "TestUtils.h"
 
-#include "GrProxyProvider.h"
+#include "GrContextPriv.h"
 #include "GrSurfaceContext.h"
 #include "GrSurfaceContextPriv.h"
 #include "GrSurfaceProxy.h"
@@ -94,8 +94,10 @@
     }
 }
 
-void test_copy_to_surface(skiatest::Reporter* reporter, GrProxyProvider* proxyProvider,
-                          GrSurfaceContext* dstContext, const char* testName) {
+void test_copy_to_surface(skiatest::Reporter* reporter,
+                          GrContext* context,
+                          GrSurfaceContext* dstContext,
+                          const char* testName) {
 
     int pixelCnt = dstContext->width() * dstContext->height();
     SkAutoTMalloc<uint32_t> pixels(pixelCnt);
@@ -109,7 +111,7 @@
     for (auto isRT : {false, true}) {
         for (auto origin : {kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
             auto src = sk_gpu_test::MakeTextureProxyFromData(
-                    dstContext->surfPriv().getContext(), isRT, dstContext->width(),
+                    context, isRT, dstContext->width(),
                     dstContext->height(), GrColorType::kRGBA_8888, origin, pixels.get(), 0);
             dstContext->copy(src.get());
             test_read_pixels(reporter, dstContext, pixels.get(), testName);
diff --git a/tests/TestUtils.h b/tests/TestUtils.h
index 5fc9afd..1e0c1e7 100644
--- a/tests/TestUtils.h
+++ b/tests/TestUtils.h
@@ -29,7 +29,7 @@
                             bool onlyTestRTConfig, const char* testName);
 
 // Ensure that RGBA 8888 pixels can be copied into 'dstContext'
-void test_copy_to_surface(skiatest::Reporter*, GrProxyProvider*,
+void test_copy_to_surface(skiatest::Reporter*, GrContext*,
                           GrSurfaceContext* dstContext, const char* testName);
 
 // Fills data with a red-green gradient
diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
index a068e76..2de8e6a 100644
--- a/tools/gpu/GrTest.cpp
+++ b/tools/gpu/GrTest.cpp
@@ -14,6 +14,8 @@
 #include "GrGpu.h"
 #include "GrGpuResourceCacheAccess.h"
 #include "GrMemoryPool.h"
+#include "GrRecordingContext.h"
+#include "GrRecordingContextPriv.h"
 #include "GrRenderTargetContext.h"
 #include "GrRenderTargetContextPriv.h"
 #include "GrRenderTargetProxy.h"
@@ -188,7 +190,7 @@
 DRAW_OP_TEST_EXTERN(TextureOp);
 
 void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) {
-    GrContext* context = renderTargetContext->surfPriv().getContext();
+    auto context = renderTargetContext->surfPriv().getContext();
     using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*,
                                                    GrRecordingContext*, GrFSAAType);
     static constexpr MakeDrawOpFn* gFactories[] = {
diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp
index 31b9ddd..8167264 100644
--- a/tools/gpu/ProxyUtils.cpp
+++ b/tools/gpu/ProxyUtils.cpp
@@ -14,11 +14,12 @@
 
 namespace sk_gpu_test {
 
-sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context, bool isRT, int width, int height,
+sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context, bool isRT,
+                                               int width, int height,
                                                GrColorType colorType, GrSRGBEncoded srgbEncoded,
                                                GrSurfaceOrigin origin, const void* data,
                                                size_t rowBytes) {
-    if (context->abandoned()) {
+    if (context->priv().abandoned()) {
         return nullptr;
     }
 
diff --git a/tools/gpu/ProxyUtils.h b/tools/gpu/ProxyUtils.h
index 6dfcd71..3ad23ae 100644
--- a/tools/gpu/ProxyUtils.h
+++ b/tools/gpu/ProxyUtils.h
@@ -14,12 +14,13 @@
 namespace sk_gpu_test {
 
 /** Makes a texture proxy containing the passed in color data. */
-sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context, bool isRT, int width, int height,
+sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext*, bool isRT, int width, int height,
                                                GrColorType, GrSRGBEncoded, GrSurfaceOrigin,
                                                const void* data, size_t rowBytes);
 
 /** Version that assumes GrSRGBEncoded::kNo. */
-inline sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context, bool isRT, int width,
+inline sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context,
+                                                      bool isRT, int width,
                                                       int height, GrColorType ct,
                                                       GrSurfaceOrigin origin, const void* data,
                                                       size_t rowBytes) {
@@ -28,7 +29,8 @@
 }
 
 /** Version that takes SkColorType rather than GrColorType and assumes GrSRGBEncoded::kNo. */
-inline sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context, bool isRT, int width,
+inline sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context,
+                                                      bool isRT, int width,
                                                       int height, SkColorType ct,
                                                       GrSurfaceOrigin origin, const void* data,
                                                       size_t rowBytes) {