Reland "Remove more GrContext imports & usage"

This reverts commit 75c5168b41c312f5df009cf004f04c1aada1d859.

Reason for revert: Reverted image-cacherator test, for now

Original change's description:
> Revert "Remove more GrContext imports & usage"
>
> This reverts commit dd1395526df7fa346fe9d21ef8c9b41b2c0ef748.
>
> Reason for revert: Broke chrome roll
>
> Original change's description:
> > Remove more GrContext imports & usage
> >
> > Sanity is coming soon!
> >
> > Change-Id: I109ebeef9efd7dbf4d76a13e1c05df36d59affbc
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/303661
> > Commit-Queue: Adlai Holler <adlai@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
>
> TBR=robertphillips@google.com,adlai@google.com
>
> Change-Id: I20d770058d4b54193b6cd2fdc9ca5a1e09f84309
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304056
> Reviewed-by: Adlai Holler <adlai@google.com>
> Commit-Queue: Adlai Holler <adlai@google.com>

TBR=robertphillips@google.com,adlai@google.com


Change-Id: I940b9f74f7caaa8b4201c241f2a6242b7a24d2a4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304062
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
diff --git a/src/gpu/GrAHardwareBufferUtils.cpp b/src/gpu/GrAHardwareBufferUtils.cpp
index badb8ee..f2137f3 100644
--- a/src/gpu/GrAHardwareBufferUtils.cpp
+++ b/src/gpu/GrAHardwareBufferUtils.cpp
@@ -19,7 +19,7 @@
 #include <GLES/gl.h>
 #include <GLES/glext.h>
 
-#include "include/gpu/GrContext.h"
+#include "include/gpu/GrDirectContext.h"
 #include "include/gpu/gl/GrGLTypes.h"
 #include "src/gpu/GrContextPriv.h"
 #include "src/gpu/gl/GrGLDefines.h"
@@ -62,7 +62,13 @@
 
 GrBackendFormat GetBackendFormat(GrContext* context, AHardwareBuffer* hardwareBuffer,
                                  uint32_t bufferFormat, bool requireKnownFormat) {
-    GrBackendApi backend = context->backend();
+    // CONTEXT TODO: Elevate direct context requirement to Android API.
+    auto dContext = GrAsDirectContext(context);
+    if (!dContext) {
+        SkDEBUGFAIL("Requires direct context.");
+        return GrBackendFormat();
+    }
+    GrBackendApi backend = dContext->backend();
 
     if (backend == GrBackendApi::kOpenGL) {
         switch (bufferFormat) {
@@ -104,7 +110,7 @@
                 if (requireKnownFormat) {
                     return GrBackendFormat();
                 } else {
-                    GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
+                    GrVkGpu* gpu = static_cast<GrVkGpu*>(dContext->priv().getGpu());
                     SkASSERT(gpu);
                     VkDevice device = gpu->device();
 
@@ -169,7 +175,7 @@
         // eglDestroyImageKHR will remove a ref from the AHardwareBuffer
         eglDestroyImageKHR(fDisplay, fImage);
     }
-    void rebind(GrContext* grContext);
+    void rebind(GrDirectContext*);
 
 private:
     GrGLuint    fTexID;
@@ -178,7 +184,7 @@
     GrGLuint    fTexTarget;
 };
 
-void GLTextureHelper::rebind(GrContext* grContext) {
+void GLTextureHelper::rebind(GrDirectContext* dContext) {
     glBindTexture(fTexTarget, fTexID);
     GLenum status = GL_NO_ERROR;
     if ((status = glGetError()) != GL_NO_ERROR) {
@@ -191,7 +197,7 @@
         SkDebugf("glEGLImageTargetTexture2DOES failed (%#x)", (int) status);
         return;
     }
-    grContext->resetContext(kTextureBinding_GrGLBackendState);
+    dContext->resetContext(kTextureBinding_GrGLBackendState);
 }
 
 void delete_gl_texture(void* context) {
@@ -200,12 +206,18 @@
 }
 
 void update_gl_texture(void* context, GrContext* grContext) {
+    // CONTEXT TODO: Elevate direct context requirement to Android API.
+    auto dContext = GrAsDirectContext(grContext);
+    if (!dContext) {
+        SkDEBUGFAIL("Direct context required.");
+        return;
+    }
     GLTextureHelper* cleanupHelper = static_cast<GLTextureHelper*>(context);
-    cleanupHelper->rebind(grContext);
+    cleanupHelper->rebind(dContext);
 }
 
 static GrBackendTexture make_gl_backend_texture(
-        GrContext* context, AHardwareBuffer* hardwareBuffer,
+        GrDirectContext* dContext, AHardwareBuffer* hardwareBuffer,
         int width, int height,
         DeleteImageProc* deleteProc,
         UpdateImageProc* updateProc,
@@ -253,7 +265,7 @@
         eglDestroyImageKHR(display, image);
         return GrBackendTexture();
     }
-    context->resetContext(kTextureBinding_GrGLBackendState);
+    dContext->resetContext(kTextureBinding_GrGLBackendState);
 
     GrGLTextureInfo textureInfo;
     textureInfo.fID = texID;
@@ -295,11 +307,13 @@
 }
 
 void update_vk_image(void* context, GrContext* grContext) {
+    // CONTEXT TODO: Elevate direct context requirement to Android API.
+    SkASSERT(GrAsDirectContext(grContext));
     // no op
 }
 
 static GrBackendTexture make_vk_backend_texture(
-        GrContext* context, AHardwareBuffer* hardwareBuffer,
+        GrDirectContext* dContext, AHardwareBuffer* hardwareBuffer,
         int width, int height,
         DeleteImageProc* deleteProc,
         UpdateImageProc* updateProc,
@@ -307,8 +321,8 @@
         bool isProtectedContent,
         const GrBackendFormat& backendFormat,
         bool isRenderable) {
-    SkASSERT(context->backend() == GrBackendApi::kVulkan);
-    GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
+    SkASSERT(dContext->backend() == GrBackendApi::kVulkan);
+    GrVkGpu* gpu = static_cast<GrVkGpu*>(dContext->priv().getGpu());
 
     VkPhysicalDevice physicalDevice = gpu->physicalDevice();
     VkDevice device = gpu->device();
@@ -510,8 +524,8 @@
     return equal || atStart || atEnd || inMiddle;
 }
 
-static bool can_import_protected_content(GrContext* context) {
-    if (GrBackendApi::kOpenGL == context->backend()) {
+static bool can_import_protected_content(GrDirectContext* dContext) {
+    if (GrBackendApi::kOpenGL == dContext->backend()) {
         // Only compute whether the extension is present once the first time this
         // function is called.
         static bool hasIt = can_import_protected_content_eglimpl();
@@ -528,21 +542,24 @@
                                     bool isProtectedContent,
                                     const GrBackendFormat& backendFormat,
                                     bool isRenderable) {
-    if (context->abandoned()) {
+    // CONTEXT TODO: Elevate direct context requirement to Android API.
+    auto dContext = GrAsDirectContext(context);
+    SkASSERT(dContext);
+    if (!dContext || dContext->abandoned()) {
         return GrBackendTexture();
     }
-    bool createProtectedImage = isProtectedContent && can_import_protected_content(context);
+    bool createProtectedImage = isProtectedContent && can_import_protected_content(dContext);
 
-    if (GrBackendApi::kOpenGL == context->backend()) {
-        return make_gl_backend_texture(context, hardwareBuffer, width, height, deleteProc,
+    if (GrBackendApi::kOpenGL == dContext->backend()) {
+        return make_gl_backend_texture(dContext, hardwareBuffer, width, height, deleteProc,
                                        updateProc, imageCtx, createProtectedImage, backendFormat,
                                        isRenderable);
     } else {
-        SkASSERT(GrBackendApi::kVulkan == context->backend());
+        SkASSERT(GrBackendApi::kVulkan == dContext->backend());
 #ifdef SK_VULKAN
         // Currently we don't support protected images on vulkan
         SkASSERT(!createProtectedImage);
-        return make_vk_backend_texture(context, hardwareBuffer, width, height, deleteProc,
+        return make_vk_backend_texture(dContext, hardwareBuffer, width, height, deleteProc,
                                        updateProc, imageCtx, createProtectedImage, backendFormat,
                                        isRenderable);
 #else