Make asDirectContext return a GrDirectContext

Change-Id: I373658d68582adc9728f3a75d84178a365f5b798
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299877
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Adlai Holler <adlai@google.com>
diff --git a/gm/bitmaptiled.cpp b/gm/bitmaptiled.cpp
index 0982061..6600ef8 100644
--- a/gm/bitmaptiled.cpp
+++ b/gm/bitmaptiled.cpp
@@ -12,6 +12,7 @@
 #include "include/core/SkRect.h"
 #include "include/core/SkTypes.h"
 #include "include/gpu/GrContext.h"
+#include "include/private/GrDirectContext.h"
 #include "include/private/GrRecordingContext.h"
 #include "src/gpu/GrRecordingContextPriv.h"
 
@@ -31,7 +32,7 @@
     const int kBitmapLongEdge = 7 * kTileSize;
     const int kBitmapShortEdge = 1 * kTileSize;
 
-    if (GrContext* direct = context->priv().asDirectContext()) {
+    if (auto direct = context->priv().asDirectContext()) {
         // To trigger tiling, we also need the image to be more than 50% of the cache, so we
         // ensure the cache is sized to make that true.
         const int kBitmapArea = kBitmapLongEdge * kBitmapShortEdge;
diff --git a/gm/crosscontextimage.cpp b/gm/crosscontextimage.cpp
index 9d46d21..5a0ad1e 100644
--- a/gm/crosscontextimage.cpp
+++ b/gm/crosscontextimage.cpp
@@ -17,6 +17,7 @@
 #include "include/core/SkRefCnt.h"
 #include "include/core/SkString.h"
 #include "include/core/SkTypes.h"
+#include "include/private/GrDirectContext.h"
 #include "include/private/GrRecordingContext.h"
 #include "src/gpu/GrRecordingContextPriv.h"
 #include "tools/Resources.h"
@@ -32,7 +33,7 @@
         return skiagm::DrawResult::kFail;
     }
 
-    GrContext* direct = context->priv().asDirectContext();
+    auto direct = context->priv().asDirectContext();
     if (!direct) {
         *errorMsg = "CrossContext image creation requires a direct context.";
         return skiagm::DrawResult::kSkip;
diff --git a/gm/discard.cpp b/gm/discard.cpp
index 86106de..bc9cbcb 100644
--- a/gm/discard.cpp
+++ b/gm/discard.cpp
@@ -17,6 +17,7 @@
 #include "include/core/SkSurface.h"
 #include "include/core/SkTypes.h"
 #include "include/gpu/GrContext.h"
+#include "include/private/GrDirectContext.h"
 #include "include/private/GrRecordingContext.h"
 #include "include/utils/SkRandom.h"
 #include "src/gpu/GrRecordingContextPriv.h"
@@ -34,8 +35,7 @@
 class DiscardGM : public GpuGM {
 
 public:
-    DiscardGM() {
-    }
+    DiscardGM() {}
 
 protected:
     SkString onShortName() override {
diff --git a/gm/fontregen.cpp b/gm/fontregen.cpp
index 9611fe7..de0a08b 100644
--- a/gm/fontregen.cpp
+++ b/gm/fontregen.cpp
@@ -30,6 +30,7 @@
 #include "include/core/SkTypes.h"
 #include "include/gpu/GrContext.h"
 #include "include/gpu/GrContextOptions.h"
+#include "include/private/GrDirectContext.h"
 #include "include/private/GrRecordingContext.h"
 #include "include/private/GrTypesPriv.h"
 #include "include/private/SkTemplates.h"
diff --git a/gm/gpu_blur_utils.cpp b/gm/gpu_blur_utils.cpp
index 7e030ae..2a8fd23 100644
--- a/gm/gpu_blur_utils.cpp
+++ b/gm/gpu_blur_utils.cpp
@@ -8,7 +8,7 @@
 #include "gm/gm.h"
 
 #include "include/effects/SkGradientShader.h"
-#include "include/gpu/GrContext.h"
+#include "include/private/GrDirectContext.h"
 #include "src/core/SkGpuBlurUtils.h"
 #include "src/gpu/GrRecordingContextPriv.h"
 #include "src/gpu/GrStyle.h"
@@ -33,7 +33,7 @@
 };
 
 static void run(GrRecordingContext* ctx, GrRenderTargetContext* rtc, bool subsetSrc, bool ref) {
-    GrContext* direct = ctx->priv().asDirectContext();
+    auto direct = ctx->priv().asDirectContext();
     if (!direct) {
         return;
     }
diff --git a/gm/image.cpp b/gm/image.cpp
index 7f0d56c..39d3ab1 100644
--- a/gm/image.cpp
+++ b/gm/image.cpp
@@ -30,6 +30,7 @@
 #include "include/core/SkSurface.h"
 #include "include/core/SkTypeface.h"
 #include "include/core/SkTypes.h"
+#include "include/private/GrDirectContext.h"
 #include "include/private/SkMalloc.h"
 #include "src/core/SkAutoPixmapStorage.h"
 #include "src/core/SkReadBuffer.h"
@@ -287,7 +288,7 @@
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 DEF_SIMPLE_GPU_GM(new_texture_image, context, rtc, canvas, 280, 60) {
-    GrContext* direct = context->priv().asDirectContext();
+    auto direct = context->priv().asDirectContext();
     if (!direct) {
         return;
     }
diff --git a/gm/textblobrandomfont.cpp b/gm/textblobrandomfont.cpp
index 5665375..2499354 100644
--- a/gm/textblobrandomfont.cpp
+++ b/gm/textblobrandomfont.cpp
@@ -23,7 +23,8 @@
 #include "include/core/SkSurfaceProps.h"
 #include "include/core/SkTextBlob.h"
 #include "include/core/SkTypeface.h"
-#include "include/gpu/GrContext.h"
+#include "include/private/GrDirectContext.h"
+#include "include/private/GrRecordingContext.h"
 #include "src/gpu/GrRecordingContextPriv.h"
 #include "tools/ToolUtils.h"
 #include "tools/fonts/RandomScalerContext.h"
@@ -148,9 +149,9 @@
         surface->draw(canvas, 0, 0, nullptr);
         yOffset += stride;
 
-        if (GrContext* directContext = context->priv().asDirectContext()) {
+        if (auto direct = context->priv().asDirectContext()) {
             // free gpu resources and verify
-            directContext->freeGpuResources();
+            direct->freeGpuResources();
         }
 
         canvas->rotate(-0.05f);
diff --git a/gm/textblobuseaftergpufree.cpp b/gm/textblobuseaftergpufree.cpp
index 63b4f5a..03a7bada3 100644
--- a/gm/textblobuseaftergpufree.cpp
+++ b/gm/textblobuseaftergpufree.cpp
@@ -15,7 +15,7 @@
 #include "include/core/SkString.h"
 #include "include/core/SkTextBlob.h"
 #include "include/core/SkTypeface.h"
-#include "include/gpu/GrContext.h"
+#include "include/private/GrDirectContext.h"
 #include "src/gpu/GrRecordingContextPriv.h"
 #include "tools/ToolUtils.h"
 
@@ -52,8 +52,8 @@
         canvas->drawTextBlob(blob, 20, 60, SkPaint());
 
         // This text should look fine
-        if (GrContext* directContext = context->priv().asDirectContext()) {
-            directContext->freeGpuResources();
+        if (auto direct = context->priv().asDirectContext()) {
+            direct->freeGpuResources();
         }
         canvas->drawTextBlob(blob, 20, 160, SkPaint());
     }
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 15e7e82..41acb6b 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -704,8 +704,6 @@
 
     bool init() override;
 
-    GrContext* asDirectContext() override { return this; }
-
     virtual GrAtlasManager* onGetAtlasManager() = 0;
 
 private:
diff --git a/include/private/GrContext_Base.h b/include/private/GrContext_Base.h
index 326c910..45c2c94 100644
--- a/include/private/GrContext_Base.h
+++ b/include/private/GrContext_Base.h
@@ -15,8 +15,8 @@
 
 class GrBaseContextPriv;
 class GrCaps;
-class GrContext;
 class GrContextThreadSafeProxy;
+class GrDirectContext;
 class GrImageContext;
 class GrRecordingContext;
 
@@ -77,7 +77,7 @@
 
     virtual GrImageContext* asImageContext() { return nullptr; }
     virtual GrRecordingContext* asRecordingContext() { return nullptr; }
-    virtual GrContext* asDirectContext() { return nullptr; }
+    virtual GrDirectContext* asDirectContext() { return nullptr; }
 
     sk_sp<GrContextThreadSafeProxy>         fThreadSafeProxy;
 
diff --git a/include/private/GrDirectContext.h b/include/private/GrDirectContext.h
index 93f077f..c5489b1 100644
--- a/include/private/GrDirectContext.h
+++ b/include/private/GrDirectContext.h
@@ -29,6 +29,8 @@
 
     GrAtlasManager* onGetAtlasManager() override { return fAtlasManager; }
 
+    GrDirectContext* asDirectContext() override { return this; }
+
 private:
     GrAtlasManager* fAtlasManager;
 
diff --git a/src/gpu/GrAHardwareBufferImageGenerator.cpp b/src/gpu/GrAHardwareBufferImageGenerator.cpp
index c5fd646..a8a3f05 100644
--- a/src/gpu/GrAHardwareBufferImageGenerator.cpp
+++ b/src/gpu/GrAHardwareBufferImageGenerator.cpp
@@ -17,8 +17,8 @@
 #include <android/hardware_buffer.h>
 
 #include "include/gpu/GrBackendSurface.h"
-#include "include/gpu/GrContext.h"
 #include "include/gpu/gl/GrGLTypes.h"
+#include "include/private/GrDirectContext.h"
 #include "include/private/GrRecordingContext.h"
 #include "src/core/SkMessageBus.h"
 #include "src/gpu/GrAHardwareBufferUtils.h"
diff --git a/src/gpu/GrBaseContextPriv.h b/src/gpu/GrBaseContextPriv.h
index e564347..8a08d7a 100644
--- a/src/gpu/GrBaseContextPriv.h
+++ b/src/gpu/GrBaseContextPriv.h
@@ -27,7 +27,7 @@
 
     GrImageContext* asImageContext() { return fContext->asImageContext(); }
     GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); }
-    GrContext* asDirectContext() { return fContext->asDirectContext(); }
+    GrDirectContext* asDirectContext() { return fContext->asDirectContext(); }
 
     GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const;
 
diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp
index 6553238..6c5bbff 100644
--- a/src/gpu/GrClipStackClip.cpp
+++ b/src/gpu/GrClipStackClip.cpp
@@ -7,6 +7,7 @@
 
 #include "src/gpu/GrClipStackClip.h"
 
+#include "include/private/GrDirectContext.h"
 #include "include/private/SkTo.h"
 #include "src/core/SkClipOpPriv.h"
 #include "src/core/SkTaskGroup.h"
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index 860c4b5..b17d9da 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -40,7 +40,7 @@
 
     GrImageContext* asImageContext() { return fContext->asImageContext(); }
     GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); }
-    GrContext* asDirectContext() { return fContext->asDirectContext(); }
+    GrDirectContext* asDirectContext() { return fContext->asDirectContext(); }
 
     // from GrImageContext
     GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); }
diff --git a/src/gpu/GrDDLContext.cpp b/src/gpu/GrDDLContext.cpp
index 72e893a..20b844d 100644
--- a/src/gpu/GrDDLContext.cpp
+++ b/src/gpu/GrDDLContext.cpp
@@ -44,7 +44,7 @@
 private:
     // TODO: Here we're pretending this isn't derived from GrContext. Switch this to be derived from
     // GrRecordingContext!
-    GrContext* asDirectContext() override { return nullptr; }
+    GrDirectContext* asDirectContext() override { return nullptr; }
 
     bool init() override {
         if (!INHERITED::init()) {
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index a19518f..f61fedf 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -9,6 +9,7 @@
 
 #include "include/core/SkDeferredDisplayList.h"
 #include "include/gpu/GrBackendSemaphore.h"
+#include "include/private/GrDirectContext.h"
 #include "include/private/GrRecordingContext.h"
 #include "src/core/SkDeferredDisplayListPriv.h"
 #include "src/core/SkTTopoSort.h"
diff --git a/src/gpu/GrImageContextPriv.h b/src/gpu/GrImageContextPriv.h
index ec11464..50b7a62 100644
--- a/src/gpu/GrImageContextPriv.h
+++ b/src/gpu/GrImageContextPriv.h
@@ -27,7 +27,7 @@
 
     GrImageContext* asImageContext() { return fContext->asImageContext(); }
     GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); }
-    GrContext* asDirectContext() { return fContext->asDirectContext(); }
+    GrDirectContext* asDirectContext() { return fContext->asDirectContext(); }
 
     // from GrImageContext
     GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); }
diff --git a/src/gpu/GrOnFlushResourceProvider.cpp b/src/gpu/GrOnFlushResourceProvider.cpp
index 93bf9db..538b0f4 100644
--- a/src/gpu/GrOnFlushResourceProvider.cpp
+++ b/src/gpu/GrOnFlushResourceProvider.cpp
@@ -7,6 +7,7 @@
 
 #include "src/gpu/GrOnFlushResourceProvider.h"
 
+#include "include/private/GrDirectContext.h"
 #include "include/private/GrRecordingContext.h"
 #include "src/gpu/GrContextPriv.h"
 #include "src/gpu/GrDrawingManager.h"
diff --git a/src/gpu/GrPathRendererChain.cpp b/src/gpu/GrPathRendererChain.cpp
index cf7e271..37610bb 100644
--- a/src/gpu/GrPathRendererChain.cpp
+++ b/src/gpu/GrPathRendererChain.cpp
@@ -8,7 +8,7 @@
 
 #include "src/gpu/GrPathRendererChain.h"
 
-#include "include/gpu/GrContext.h"
+#include "include/private/GrDirectContext.h"
 #include "include/private/GrRecordingContext.h"
 #include "src/gpu/GrCaps.h"
 #include "src/gpu/GrContextPriv.h"
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index e2bfd76..6e98c7b 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -9,7 +9,7 @@
 
 #include "include/core/SkBitmap.h"
 #include "include/core/SkImage.h"
-#include "include/gpu/GrContext.h"
+#include "include/private/GrDirectContext.h"
 #include "include/private/GrImageContext.h"
 #include "include/private/GrResourceKey.h"
 #include "include/private/GrSingleOwner.h"
@@ -58,7 +58,7 @@
 
 #ifdef SK_DEBUG
     {
-        GrContext* direct = fImageContext->priv().asDirectContext();
+        auto direct = fImageContext->priv().asDirectContext();
         if (direct) {
             GrResourceCache* resourceCache = direct->priv().getResourceCache();
             // If there is already a GrResource with this key then the caller has violated the
@@ -127,7 +127,7 @@
     if (this->isAbandoned()) {
         return nullptr;
     }
-    GrContext* direct = fImageContext->priv().asDirectContext();
+    auto direct = fImageContext->priv().asDirectContext();
     if (!direct) {
         return nullptr;
     }
@@ -212,7 +212,7 @@
         return result;
     }
 
-    GrContext* direct = fImageContext->priv().asDirectContext();
+    auto direct = fImageContext->priv().asDirectContext();
     if (!direct) {
         return nullptr;
     }
@@ -296,7 +296,7 @@
         return nullptr;
     }
 
-    GrContext* direct = fImageContext->priv().asDirectContext();
+    auto direct = fImageContext->priv().asDirectContext();
     if (direct) {
         GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
 
@@ -474,7 +474,7 @@
         return nullptr;
     }
 
-    GrContext* direct = fImageContext->priv().asDirectContext();
+    auto direct = fImageContext->priv().asDirectContext();
     if (direct) {
         GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
         // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however
@@ -498,7 +498,7 @@
     }
 
     // This is only supported on a direct GrContext.
-    GrContext* direct = fImageContext->priv().asDirectContext();
+    auto direct = fImageContext->priv().asDirectContext();
     if (!direct) {
         return nullptr;
     }
@@ -533,7 +533,7 @@
     }
 
     // This is only supported on a direct GrContext.
-    GrContext* direct = fImageContext->priv().asDirectContext();
+    auto direct = fImageContext->priv().asDirectContext();
     if (!direct) {
         return nullptr;
     }
@@ -569,7 +569,7 @@
     }
 
     // This is only supported on a direct GrContext.
-    GrContext* direct = fImageContext->priv().asDirectContext();
+    auto direct = fImageContext->priv().asDirectContext();
     if (!direct) {
         return nullptr;
     }
@@ -607,7 +607,7 @@
     }
 
     // This is only supported on a direct GrContext.
-    GrContext* direct = fImageContext->priv().asDirectContext();
+    auto direct = fImageContext->priv().asDirectContext();
     if (!direct) {
         return nullptr;
     }
@@ -638,7 +638,7 @@
     }
 
     // This is only supported on a direct GrContext.
-    GrContext* direct = fImageContext->priv().asDirectContext();
+    auto direct = fImageContext->priv().asDirectContext();
     if (!direct) {
         return nullptr;
     }
@@ -665,7 +665,7 @@
     }
 
     // This is only supported on a direct GrContext.
-    GrContext* direct = fImageContext->priv().asDirectContext();
+    auto direct = fImageContext->priv().asDirectContext();
     if (!direct) {
         return nullptr;
     }
@@ -845,7 +845,7 @@
     // proxy's unique key. We must do it in this order because 'key' may alias the proxy's key.
     sk_sp<GrGpuResource> invalidGpuResource;
     if (InvalidateGPUResource::kYes == invalidateGPUResource) {
-        GrContext* direct = fImageContext->priv().asDirectContext();
+        auto direct = fImageContext->priv().asDirectContext();
         if (direct) {
             GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
             invalidGpuResource = resourceProvider->findByUniqueKey<GrGpuResource>(key);
diff --git a/src/gpu/GrRecordingContextPriv.h b/src/gpu/GrRecordingContextPriv.h
index 4e3e9a7..bec89b5 100644
--- a/src/gpu/GrRecordingContextPriv.h
+++ b/src/gpu/GrRecordingContextPriv.h
@@ -28,7 +28,7 @@
 
     GrImageContext* asImageContext() { return fContext->asImageContext(); }
     GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); }
-    GrContext* asDirectContext() { return fContext->asDirectContext(); }
+    GrDirectContext* asDirectContext() { return fContext->asDirectContext(); }
 
     // from GrImageContext
     GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); }
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index e5c7bac..bf6906f 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -10,6 +10,7 @@
 #include "include/core/SkDrawable.h"
 #include "include/core/SkVertices.h"
 #include "include/gpu/GrBackendSemaphore.h"
+#include "include/private/GrDirectContext.h"
 #include "include/private/GrImageContext.h"
 #include "include/private/GrRecordingContext.h"
 #include "include/private/SkShadowFlags.h"
diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp
index 95ab059..b79f3f2 100644
--- a/src/gpu/GrSoftwarePathRenderer.cpp
+++ b/src/gpu/GrSoftwarePathRenderer.cpp
@@ -7,6 +7,7 @@
 
 #include "src/gpu/GrSoftwarePathRenderer.h"
 
+#include "include/private/GrDirectContext.h"
 #include "include/private/SkSemaphore.h"
 #include "src/core/SkTaskGroup.h"
 #include "src/core/SkTraceEvent.h"
diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp
index ff0f930..655eab4 100644
--- a/src/gpu/GrSurfaceContext.cpp
+++ b/src/gpu/GrSurfaceContext.cpp
@@ -7,6 +7,7 @@
 
 #include "src/gpu/GrSurfaceContext.h"
 
+#include "include/private/GrDirectContext.h"
 #include "include/private/GrRecordingContext.h"
 #include "src/core/SkAutoPixmapStorage.h"
 #include "src/core/SkYUVMath.h"
@@ -131,7 +132,7 @@
 #endif
 
 bool GrSurfaceContext::readPixels(const GrImageInfo& origDstInfo, void* dst, size_t rowBytes,
-                                  SkIPoint pt, GrContext* direct) {
+                                  SkIPoint pt, GrDirectContext* direct) {
     ASSERT_SINGLE_OWNER
     RETURN_FALSE_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
@@ -289,7 +290,7 @@
 }
 
 bool GrSurfaceContext::writePixels(const GrImageInfo& origSrcInfo, const void* src, size_t rowBytes,
-                                   SkIPoint pt, GrContext* direct) {
+                                   SkIPoint pt, GrDirectContext* direct) {
     ASSERT_SINGLE_OWNER
     RETURN_FALSE_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
diff --git a/src/gpu/GrSurfaceContext.h b/src/gpu/GrSurfaceContext.h
index 1571f4e..82307b5 100644
--- a/src/gpu/GrSurfaceContext.h
+++ b/src/gpu/GrSurfaceContext.h
@@ -83,7 +83,7 @@
      *                      is a GrDirectContext and fail otherwise.
      */
     bool readPixels(const GrImageInfo& dstInfo, void* dst, size_t rowBytes, SkIPoint srcPt,
-                    GrContext* direct = nullptr);
+                    GrDirectContext* direct = nullptr);
 
     using ReadPixelsCallback = SkImage::ReadPixelsCallback;
     using ReadPixelsContext  = SkImage::ReadPixelsContext;
@@ -118,7 +118,7 @@
      *                      is a GrDirectContext and fail otherwise.
      */
     bool writePixels(const GrImageInfo& srcInfo, const void* src, size_t rowBytes, SkIPoint dstPt,
-                     GrContext* direct = nullptr);
+                     GrDirectContext* direct = nullptr);
 
     GrSurfaceProxy* asSurfaceProxy() { return fReadView.proxy(); }
     const GrSurfaceProxy* asSurfaceProxy() const { return fReadView.proxy(); }
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index 07b8b8a..4597d36 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -10,6 +10,7 @@
 #include "include/core/SkPromiseImageTexture.h"
 #include "include/gpu/GrBackendSurface.h"
 #include "include/gpu/GrContext.h"
+#include "include/private/GrDirectContext.h"
 #include "include/private/GrRecordingContext.h"
 #include "src/core/SkBitmapCache.h"
 #include "src/core/SkTLList.h"
diff --git a/tests/FloatingPointTextureTest.cpp b/tests/FloatingPointTextureTest.cpp
index 5d42bc1..a3f3630 100644
--- a/tests/FloatingPointTextureTest.cpp
+++ b/tests/FloatingPointTextureTest.cpp
@@ -14,7 +14,7 @@
 
 #include "tests/Test.h"
 
-#include "include/gpu/GrContext.h"
+#include "include/private/GrDirectContext.h"
 #include "include/private/SkHalf.h"
 #include "src/gpu/GrContextPriv.h"
 #include "src/gpu/GrImageInfo.h"
@@ -28,7 +28,8 @@
 static const int DEV_W = 100, DEV_H = 100;
 
 template <typename T>
-void runFPTest(skiatest::Reporter* reporter, GrContext* context, T min, T max, T epsilon, T maxInt,
+void runFPTest(skiatest::Reporter* reporter, GrDirectContext* context,
+               T min, T max, T epsilon, T maxInt,
                int arraySize, GrColorType colorType) {
     if (0 != arraySize % 4) {
         REPORT_FAILURE(reporter, "(0 != arraySize % 4)",
@@ -76,7 +77,9 @@
 static const SkHalf kMaxIntegerRepresentableInHalfFloatingPoint = 0x6800;  // 2 ^ 11
 
 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(HalfFloatAlphaTextureTest, reporter, ctxInfo) {
-    runFPTest<SkHalf>(reporter, ctxInfo.grContext(), SK_HalfMin, SK_HalfMax, SK_HalfEpsilon,
+    auto direct = ctxInfo.grContext()->priv().asDirectContext();
+
+    runFPTest<SkHalf>(reporter, direct, SK_HalfMin, SK_HalfMax, SK_HalfEpsilon,
                       kMaxIntegerRepresentableInHalfFloatingPoint, HALF_ALPHA_CONTROL_ARRAY_SIZE,
                       GrColorType::kAlpha_F16);
 }
@@ -84,7 +87,9 @@
 static const int HALF_RGBA_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 4 /*RGBA*/;
 
 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(HalfFloatRGBATextureTest, reporter, ctxInfo) {
-    runFPTest<SkHalf>(reporter, ctxInfo.grContext(), SK_HalfMin, SK_HalfMax, SK_HalfEpsilon,
+    auto direct = ctxInfo.grContext()->priv().asDirectContext();
+
+    runFPTest<SkHalf>(reporter, direct, SK_HalfMin, SK_HalfMax, SK_HalfEpsilon,
                       kMaxIntegerRepresentableInHalfFloatingPoint, HALF_RGBA_CONTROL_ARRAY_SIZE,
                       GrColorType::kRGBA_F16);
 }
diff --git a/tests/GrTestingBackendTextureUploadTest.cpp b/tests/GrTestingBackendTextureUploadTest.cpp
index 9b8f250..8f31e89 100644
--- a/tests/GrTestingBackendTextureUploadTest.cpp
+++ b/tests/GrTestingBackendTextureUploadTest.cpp
@@ -5,6 +5,7 @@
  * found in the LICENSE file.
  */
 
+#include "include/private/GrDirectContext.h"
 #include "src/core/SkAutoPixmapStorage.h"
 #include "src/gpu/GrContextPriv.h"
 #include "src/gpu/GrImageInfo.h"
@@ -15,6 +16,10 @@
 
 void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColorType ct,
                                GrRenderable renderable, bool doDataUpload, GrMipMapped mipMapped) {
+    auto direct = context->priv().asDirectContext();
+    if (!direct) {
+        return;
+    }
 
     const int kWidth = 16;
     const int kHeight = 16;
@@ -25,11 +30,11 @@
     expectedPixels.alloc(ii);
     actualPixels.alloc(ii);
 
-    const GrCaps* caps = context->priv().caps();
+    const GrCaps* caps = direct->priv().caps();
 
     GrColorType grCT = SkColorTypeToGrColorType(ct);
 
-    GrBackendFormat backendFormat = context->defaultBackendFormat(ct, renderable);
+    GrBackendFormat backendFormat = direct->defaultBackendFormat(ct, renderable);
     if (!backendFormat.isValid()) {
         return;
     }
@@ -41,11 +46,11 @@
 
         FillPixelData(kWidth, kHeight, expectedPixels.writable_addr32(0, 0));
 
-        backendTex = context->createBackendTexture(&expectedPixels, 1,
-                                                   renderable, GrProtected::kNo);
+        backendTex = direct->createBackendTexture(&expectedPixels, 1,
+                                                  renderable, GrProtected::kNo);
     } else {
-        backendTex = context->createBackendTexture(kWidth, kHeight, ct, SkColors::kTransparent,
-                                                   mipMapped, renderable, GrProtected::kNo);
+        backendTex = direct->createBackendTexture(kWidth, kHeight, ct, SkColors::kTransparent,
+                                                  mipMapped, renderable, GrProtected::kNo);
 
         size_t allocSize = SkAutoPixmapStorage::AllocSize(ii, nullptr);
         // createBackendTexture will fill the texture with 0's if no data is provided, so
@@ -64,23 +69,23 @@
 
     sk_sp<GrTextureProxy> wrappedProxy;
     if (GrRenderable::kYes == renderable) {
-        wrappedProxy = context->priv().proxyProvider()->wrapRenderableBackendTexture(
+        wrappedProxy = direct->priv().proxyProvider()->wrapRenderableBackendTexture(
                 backendTex, 1, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, nullptr);
     } else {
-        wrappedProxy = context->priv().proxyProvider()->wrapBackendTexture(
+        wrappedProxy = direct->priv().proxyProvider()->wrapBackendTexture(
                 backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, GrIOType::kRW_GrIOType);
     }
     REPORTER_ASSERT(reporter, wrappedProxy);
 
-    GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(wrappedProxy->backendFormat(), grCT);
+    GrSwizzle swizzle = direct->priv().caps()->getReadSwizzle(wrappedProxy->backendFormat(), grCT);
     GrSurfaceProxyView view(std::move(wrappedProxy), kTopLeft_GrSurfaceOrigin, swizzle);
-    auto surfaceContext = GrSurfaceContext::Make(context, std::move(view), grCT,
+    auto surfaceContext = GrSurfaceContext::Make(direct, std::move(view), grCT,
                                                  kPremul_SkAlphaType, nullptr);
     REPORTER_ASSERT(reporter, surfaceContext);
 
     bool result = surfaceContext->readPixels({grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight},
                                              actualPixels.writable_addr(), actualPixels.rowBytes(),
-                                             {0, 0}, context);
+                                             {0, 0}, direct);
 
     REPORTER_ASSERT(reporter, result);
     REPORTER_ASSERT(reporter,
diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp
index 633467c..1347c1b 100644
--- a/tools/gpu/ProxyUtils.cpp
+++ b/tools/gpu/ProxyUtils.cpp
@@ -7,6 +7,7 @@
 
 #include "include/core/SkColor.h"
 #include "include/gpu/GrBackendSurface.h"
+#include "include/private/GrDirectContext.h"
 #include "src/gpu/GrContextPriv.h"
 #include "src/gpu/GrDrawingManager.h"
 #include "src/gpu/GrGpu.h"
@@ -30,7 +31,12 @@
         return nullptr;
     }
 
-    const GrCaps* caps = context->priv().caps();
+    auto direct = context->priv().asDirectContext();
+    if (!direct) {
+        return nullptr;
+    }
+
+    const GrCaps* caps = direct->priv().caps();
 
     const GrBackendFormat format = caps->getDefaultBackendFormat(imageInfo.colorType(), renderable);
     if (!format.isValid()) {
@@ -39,19 +45,19 @@
     GrSwizzle swizzle = caps->getReadSwizzle(format, imageInfo.colorType());
 
     sk_sp<GrTextureProxy> proxy;
-    proxy = context->priv().proxyProvider()->createProxy(format, imageInfo.dimensions(), renderable,
-                                                         1, GrMipMapped::kNo, SkBackingFit::kExact,
-                                                         SkBudgeted::kYes, GrProtected::kNo);
+    proxy = direct->priv().proxyProvider()->createProxy(format, imageInfo.dimensions(), renderable,
+                                                        1, GrMipMapped::kNo, SkBackingFit::kExact,
+                                                        SkBudgeted::kYes, GrProtected::kNo);
     if (!proxy) {
         return nullptr;
     }
     GrSurfaceProxyView view(proxy, origin, swizzle);
-    auto sContext = GrSurfaceContext::Make(context, std::move(view), imageInfo.colorType(),
+    auto sContext = GrSurfaceContext::Make(direct, std::move(view), imageInfo.colorType(),
                                            imageInfo.alphaType(), imageInfo.refColorSpace());
     if (!sContext) {
         return nullptr;
     }
-    if (!sContext->writePixels(imageInfo, data, rowBytes, {0, 0}, context)) {
+    if (!sContext->writePixels(imageInfo, data, rowBytes, {0, 0}, direct)) {
         return nullptr;
     }
     return proxy;