Make defaultBackendFormat callable from anywhere in the GrContext hierarchy

This is probably overkill but yields an officially thread-safe means of calling defaultBackendFormat.

Change-Id: Ibf344acf11102d938e335e9ea38bfaee575e00c5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/234324
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 db45689..76c8a70 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -351,7 +351,9 @@
      *
      * The caller should check that the returned format is valid.
      */
-    using GrRecordingContext::defaultBackendFormat;
+    GrBackendFormat defaultBackendFormat(SkColorType ct, GrRenderable renderable) const {
+        return INHERITED::defaultBackendFormat(ct, renderable);
+    }
 
    /*
     * The explicitly allocated backend texture API allows clients to use Skia to create backend
diff --git a/include/gpu/GrContextThreadSafeProxy.h b/include/gpu/GrContextThreadSafeProxy.h
index 8dc68fd..b329da0 100644
--- a/include/gpu/GrContextThreadSafeProxy.h
+++ b/include/gpu/GrContextThreadSafeProxy.h
@@ -65,6 +65,17 @@
                                   bool isTextureable = true,
                                   GrProtected isProtected = GrProtected::kNo);
 
+    /*
+     * Retrieve the default GrBackendFormat for a given SkColorType and renderability.
+     * It is guaranteed that this backend format will be the one used by the following
+     * SkColorType and SkSurfaceCharacterization-based createBackendTexture methods.
+     *
+     * The caller should check that the returned format is valid.
+     */
+    GrBackendFormat defaultBackendFormat(SkColorType ct, GrRenderable renderable) const {
+        return INHERITED::defaultBackendFormat(ct, renderable);
+    }
+
     bool operator==(const GrContextThreadSafeProxy& that) const {
         // Each GrContext should only ever have a single thread-safe proxy.
         SkASSERT((this == &that) == (this->contextID() == that.contextID()));
diff --git a/include/private/GrContext_Base.h b/include/private/GrContext_Base.h
index c66ab85..58fb9bb 100644
--- a/include/private/GrContext_Base.h
+++ b/include/private/GrContext_Base.h
@@ -9,6 +9,7 @@
 #define GrContext_Base_DEFINED
 
 #include "include/core/SkRefCnt.h"
+#include "include/gpu/GrBackendSurface.h"
 #include "include/gpu/GrContextOptions.h"
 #include "include/gpu/GrTypes.h"
 
@@ -28,6 +29,15 @@
      */
     GrBackendApi backend() const { return fBackend; }
 
+    /*
+     * Retrieve the default GrBackendFormat for a given SkColorType and renderability.
+     * It is guaranteed that this backend format will be the one used by the GrContext
+     * SkColorType and SkSurfaceCharacterization-based createBackendTexture methods.
+     *
+     * The caller should check that the returned format is valid.
+     */
+    GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const;
+
     // Provides access to functions that aren't part of the public API.
     GrBaseContextPriv priv();
     const GrBaseContextPriv priv() const;
diff --git a/include/private/GrImageContext.h b/include/private/GrImageContext.h
index 04659be..40f6178 100644
--- a/include/private/GrImageContext.h
+++ b/include/private/GrImageContext.h
@@ -18,6 +18,10 @@
 public:
     ~GrImageContext() override;
 
+    GrBackendFormat defaultBackendFormat(SkColorType ct, GrRenderable renderable) const {
+        return INHERITED::defaultBackendFormat(ct, renderable);
+    }
+
     // Provides access to functions that aren't part of the public API.
     GrImageContextPriv priv();
     const GrImageContextPriv priv() const;
diff --git a/include/private/GrRecordingContext.h b/include/private/GrRecordingContext.h
index f48eec9..51c52d9 100644
--- a/include/private/GrRecordingContext.h
+++ b/include/private/GrRecordingContext.h
@@ -27,14 +27,9 @@
 public:
     ~GrRecordingContext() override;
 
-    /*
-     * Retrieve the default GrBackendFormat for a given SkColorType and renderability.
-     * It is guaranteed that this backend format will be the one used by the GrContext
-     * SkColorType and SkSurfaceCharacterization-based createBackendTexture methods.
-     *
-     * The caller should check that the returned format is valid.
-     */
-    GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const;
+    GrBackendFormat defaultBackendFormat(SkColorType ct, GrRenderable renderable) const {
+        return INHERITED::defaultBackendFormat(ct, renderable);
+    }
 
     // Provides access to functions that aren't part of the public API.
     GrRecordingContextPriv priv();
diff --git a/src/gpu/GrContext_Base.cpp b/src/gpu/GrContext_Base.cpp
index 31e7ff1..aba1b82 100644
--- a/src/gpu/GrContext_Base.cpp
+++ b/src/gpu/GrContext_Base.cpp
@@ -43,6 +43,24 @@
 
 sk_sp<GrSkSLFPFactoryCache> GrContext_Base::fpFactoryCache() { return fFPFactoryCache; }
 
+GrBackendFormat GrContext_Base::defaultBackendFormat(SkColorType skColorType,
+                                                     GrRenderable renderable) const {
+    const GrCaps* caps = this->caps();
+
+    GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
+
+    GrBackendFormat format = caps->getDefaultBackendFormat(grColorType, renderable);
+    if (!format.isValid()) {
+        return GrBackendFormat();
+    }
+
+    SkASSERT(caps->isFormatTexturable(grColorType, format));
+    SkASSERT(renderable == GrRenderable::kNo ||
+             caps->isFormatAsColorTypeRenderable(grColorType, format));
+
+    return format;
+}
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 sk_sp<const GrCaps> GrBaseContextPriv::refCaps() const {
     return fContext->refCaps();
diff --git a/src/gpu/GrRecordingContext.cpp b/src/gpu/GrRecordingContext.cpp
index 577d03c..01ed9b1 100644
--- a/src/gpu/GrRecordingContext.cpp
+++ b/src/gpu/GrRecordingContext.cpp
@@ -396,27 +396,3 @@
 GrContext* GrRecordingContextPriv::backdoor() {
     return (GrContext*) fContext;
 }
-
-GrBackendFormat GrRecordingContext::defaultBackendFormat(SkColorType skColorType,
-                                                         GrRenderable renderable) const {
-    TRACE_EVENT0("skia.gpu", TRACE_FUNC);
-
-    if (this->abandoned()) {
-        return GrBackendFormat();
-    }
-
-    const GrCaps* caps = this->caps();
-
-    GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
-
-    GrBackendFormat format = caps->getDefaultBackendFormat(grColorType, renderable);
-    if (!format.isValid()) {
-        return GrBackendFormat();
-    }
-
-    SkASSERT(caps->isFormatTexturable(grColorType, format));
-    SkASSERT(renderable == GrRenderable::kNo ||
-             caps->isFormatAsColorTypeRenderable(grColorType, format));
-
-    return format;
-}