Add GrContext::defaultBackendFormat

TBR=bsalomon@google.com
Bug: 987392
Change-Id: I38ff649b25e78c0a02a8fd20f513db4be62abf43
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/229919
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index a1e3eba..63a7780 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -343,7 +343,7 @@
 }
 
 GrBackendTexture GrContext::createBackendTexture(int width, int height,
-                                                 SkColorType colorType,
+                                                 SkColorType skColorType,
                                                  GrMipMapped mipMapped,
                                                  GrRenderable renderable,
                                                  GrProtected isProtected) {
@@ -355,8 +355,7 @@
         return GrBackendTexture();
     }
 
-    GrBackendFormat format =
-            this->caps()->getBackendFormatFromColorType(SkColorTypeToGrColorType(colorType));
+    const GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable);
     if (!format.isValid()) {
         return GrBackendTexture();
     }
@@ -384,8 +383,7 @@
         return {};
     }
 
-    const GrBackendFormat format =
-            caps->getBackendFormatFromColorType(SkColorTypeToGrColorType(c.colorType()));
+    const GrBackendFormat format = this->defaultBackendFormat(c.colorType(), GrRenderable::kYes);
     if (!format.isValid()) {
         return GrBackendTexture();
     }
@@ -404,8 +402,6 @@
 
 GrBackendTexture GrContext::createBackendTexture(const SkSurfaceCharacterization& c,
                                                  const SkColor4f& color) {
-    const GrCaps* caps = this->caps();
-
     if (!this->asDirectContext() || !c.isValid()) {
         return GrBackendTexture();
     }
@@ -423,13 +419,12 @@
         return {};
     }
 
-    const GrBackendFormat format =
-            caps->getBackendFormatFromColorType(SkColorTypeToGrColorType(c.colorType()));
+    const GrBackendFormat format = this->defaultBackendFormat(c.colorType(), GrRenderable::kYes);
     if (!format.isValid()) {
         return GrBackendTexture();
     }
 
-    if (!SkSurface_Gpu::Valid(caps, format)) {
+    if (!SkSurface_Gpu::Valid(this->caps(), format)) {
         return GrBackendTexture();
     }
 
@@ -466,7 +461,7 @@
 }
 
 GrBackendTexture GrContext::createBackendTexture(int width, int height,
-                                                 SkColorType colorType,
+                                                 SkColorType skColorType,
                                                  const SkColor4f& color,
                                                  GrMipMapped mipMapped,
                                                  GrRenderable renderable,
@@ -479,12 +474,13 @@
         return GrBackendTexture();
     }
 
-    GrColorType ct = SkColorTypeToGrColorType(colorType);
-    GrBackendFormat format = this->caps()->getBackendFormatFromColorType(ct);
+    GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable);
     if (!format.isValid()) {
         return GrBackendTexture();
     }
-    SkColor4f swizzledColor = this->caps()->getOutputSwizzle(format, ct).applyTo(color);
+
+    GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
+    SkColor4f swizzledColor = this->caps()->getOutputSwizzle(format, grColorType).applyTo(color);
 
     return this->createBackendTexture(width, height, format, swizzledColor, mipMapped, renderable,
                                       isProtected);