Make rest of GrGpu::wrapBackend* methods take a GrColorType

This CL is intended to further wean Ganesh off of using the GrBackendTexture's pixel config

Bug: skia:6718
Change-Id: I593c0c73922fb76045e379214e20adb1f17ea215
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/227780
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrAHardwareBufferImageGenerator.cpp b/src/gpu/GrAHardwareBufferImageGenerator.cpp
index 9008436..e5a2b3b 100644
--- a/src/gpu/GrAHardwareBufferImageGenerator.cpp
+++ b/src/gpu/GrAHardwareBufferImageGenerator.cpp
@@ -95,8 +95,9 @@
                                                                              fBufferFormat,
                                                                              false);
 
-    GrPixelConfig pixelConfig = context->priv().caps()->getConfigFromBackendFormat(
-            backendFormat, SkColorTypeToGrColorType(this->getInfo().colorType()));
+    GrColorType grColorType = SkColorTypeToGrColorType(this->getInfo().colorType());
+    GrPixelConfig pixelConfig = context->priv().caps()->getConfigFromBackendFormat(backendFormat,
+                                                                                   grColorType);
 
     if (pixelConfig == kUnknown_GrPixelConfig) {
         return nullptr;
@@ -150,7 +151,7 @@
 
     sk_sp<GrTextureProxy> texProxy = proxyProvider->createLazyProxy(
             [direct, buffer = AutoAHBRelease(hardwareBuffer), width, height, pixelConfig,
-             isProtectedContent, backendFormat](GrResourceProvider* resourceProvider)
+             isProtectedContent, backendFormat, grColorType](GrResourceProvider* resourceProvider)
                     -> GrSurfaceProxy::LazyInstantiationResult {
                 GrAHardwareBufferUtils::DeleteImageProc deleteImageProc = nullptr;
                 GrAHardwareBufferUtils::DeleteImageCtx deleteImageCtx = nullptr;
@@ -173,7 +174,8 @@
                 // is invoked. We know the owning SkIamge will send an invalidation message when the
                 // image is destroyed, so the texture will be removed at that time.
                 sk_sp<GrTexture> tex = resourceProvider->wrapBackendTexture(
-                        backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kYes, kRead_GrIOType);
+                        backendTex, grColorType, kBorrow_GrWrapOwnership, GrWrapCacheable::kYes,
+                        kRead_GrIOType);
                 if (!tex) {
                     deleteImageProc(deleteImageCtx);
                     return {};
diff --git a/src/gpu/GrBackendTextureImageGenerator.cpp b/src/gpu/GrBackendTextureImageGenerator.cpp
index a62dfab..56e91a2 100644
--- a/src/gpu/GrBackendTextureImageGenerator.cpp
+++ b/src/gpu/GrBackendTextureImageGenerator.cpp
@@ -51,15 +51,20 @@
     context->priv().getResourceCache()->insertDelayedResourceUnref(texture.get());
 
     GrBackendTexture backendTexture = texture->getBackendTexture();
-    GrBackendFormat backendFormat = backendTexture.getBackendFormat();
-    if (!backendFormat.isValid()) {
-        return nullptr;
-    }
-    backendTexture.fConfig =
-            context->priv().caps()->getConfigFromBackendFormat(backendFormat,
-                                                               SkColorTypeToGrColorType(colorType));
-    if (backendTexture.fConfig == kUnknown_GrPixelConfig) {
-        return nullptr;
+
+    // TODO: delete this block
+    {
+        GrBackendFormat backendFormat = backendTexture.getBackendFormat();
+        if (!backendFormat.isValid()) {
+            return nullptr;
+        }
+
+        backendTexture.fConfig = context->priv().caps()->getConfigFromBackendFormat(
+                                                            backendFormat,
+                                                            SkColorTypeToGrColorType(colorType));
+        if (backendTexture.fConfig == kUnknown_GrPixelConfig) {
+            return nullptr;
+        }
     }
 
     SkImageInfo info = SkImageInfo::Make(texture->width(), texture->height(), colorType, alphaType,
@@ -79,7 +84,6 @@
         , fRefHelper(new RefHelper(texture, owningContextID))
         , fSemaphore(std::move(semaphore))
         , fBackendTexture(backendTex)
-        , fConfig(backendTex.config())
         , fSurfaceOrigin(origin) {}
 
 GrBackendTextureImageGenerator::~GrBackendTextureImageGenerator() {
@@ -110,6 +114,7 @@
     }
 
     auto proxyProvider = context->priv().proxyProvider();
+    const GrCaps* caps = context->priv().caps();
 
     fBorrowingMutex.acquire();
     sk_sp<GrRefCntedCallback> releaseProcHelper;
@@ -141,20 +146,32 @@
 
     SkASSERT(fRefHelper->fBorrowingContextID == context->priv().contextID());
 
+
+    GrBackendFormat backendFormat = fBackendTexture.getBackendFormat();
+    SkASSERT(backendFormat.isValid());
+
+    GrColorType grColorType = SkColorTypeToGrColorType(info.colorType());
+
+    GrPixelConfig config = caps->getConfigFromBackendFormat(backendFormat, grColorType);
+    if (kUnknown_GrPixelConfig == config) {
+        return nullptr;
+    }
+
+    SkASSERT(GrCaps::AreConfigsCompatible(fBackendTexture.config(),
+                                          caps->getConfigFromBackendFormat(backendFormat,
+                                                                           grColorType)));
+
     GrSurfaceDesc desc;
     desc.fWidth = fBackendTexture.width();
     desc.fHeight = fBackendTexture.height();
-    desc.fConfig = fConfig;
+    desc.fConfig = config;
     GrMipMapped mipMapped = fBackendTexture.hasMipMaps() ? GrMipMapped::kYes : GrMipMapped::kNo;
 
-    GrBackendFormat format = fBackendTexture.getBackendFormat();
-    SkASSERT(format.isValid());
-
     // Must make copies of member variables to capture in the lambda since this image generator may
     // be deleted before we actually execute the lambda.
     sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
             [refHelper = fRefHelper, releaseProcHelper, semaphore = fSemaphore,
-             backendTexture = fBackendTexture](GrResourceProvider* resourceProvider)
+             backendTexture = fBackendTexture, grColorType](GrResourceProvider* resourceProvider)
                     -> GrSurfaceProxy::LazyInstantiationResult {
                 if (semaphore) {
                     resourceProvider->priv().gpu()->waitSemaphore(semaphore);
@@ -180,8 +197,8 @@
                     // ever see the original texture, so this should be safe.
                     // We make the texture uncacheable so that the release proc is called ASAP.
                     tex = resourceProvider->wrapBackendTexture(
-                            backendTexture, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
-                            kRead_GrIOType);
+                            backendTexture, grColorType, kBorrow_GrWrapOwnership,
+                            GrWrapCacheable::kNo, kRead_GrIOType);
                     if (!tex) {
                         return {};
                     }
@@ -192,9 +209,8 @@
                 // unrelated to the whatever SkImage key may be assigned to the proxy.
                 return {std::move(tex), GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced};
             },
-            format, desc, GrRenderable::kNo, fSurfaceOrigin, mipMapped,
+            backendFormat, desc, GrRenderable::kNo, fSurfaceOrigin, mipMapped,
             GrInternalSurfaceFlags::kReadOnly, SkBackingFit::kExact, SkBudgeted::kNo);
-
     if (!proxy) {
         return nullptr;
     }
diff --git a/src/gpu/GrBackendTextureImageGenerator.h b/src/gpu/GrBackendTextureImageGenerator.h
index 13616a3..8a82c5c 100644
--- a/src/gpu/GrBackendTextureImageGenerator.h
+++ b/src/gpu/GrBackendTextureImageGenerator.h
@@ -80,7 +80,6 @@
     sk_sp<GrSemaphore>   fSemaphore;
 
     GrBackendTexture     fBackendTexture;
-    GrPixelConfig        fConfig;
     GrSurfaceOrigin      fSurfaceOrigin;
 
     typedef SkImageGenerator INHERITED;
diff --git a/src/gpu/GrCaps.h b/src/gpu/GrCaps.h
index 8c23ece..3410a49 100644
--- a/src/gpu/GrCaps.h
+++ b/src/gpu/GrCaps.h
@@ -395,7 +395,8 @@
      * Special method only for YUVA images. Returns a config that matches the backend format or
      * kUnknown if a config could not be determined.
      */
-    virtual GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat& format) const = 0;
+    virtual GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const = 0;
+    virtual GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat&) const = 0;
 
     /** These are used when creating a new texture internally. */
     virtual GrBackendFormat getBackendFormatFromColorType(GrColorType ct) const = 0;
diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp
index ad6d8ab..721f02d 100644
--- a/src/gpu/GrContextPriv.cpp
+++ b/src/gpu/GrContextPriv.cpp
@@ -106,7 +106,7 @@
     ASSERT_SINGLE_OWNER
 
     sk_sp<GrSurfaceProxy> proxy = this->proxyProvider()->wrapBackendTexture(
-            tex, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
+            tex, colorType, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
     if (!proxy) {
         return nullptr;
     }
@@ -149,7 +149,7 @@
     ASSERT_SINGLE_OWNER
 
     sk_sp<GrSurfaceProxy> proxy = this->proxyProvider()->wrapBackendRenderTarget(
-            backendRT, origin, releaseProc, releaseCtx);
+            backendRT, colorType, origin, releaseProc, releaseCtx);
     if (!proxy) {
         return nullptr;
     }
@@ -168,7 +168,8 @@
     ASSERT_SINGLE_OWNER
     SkASSERT(sampleCnt > 0);
     sk_sp<GrSurfaceProxy> proxy(
-            this->proxyProvider()->wrapBackendTextureAsRenderTarget(tex, origin, sampleCnt));
+            this->proxyProvider()->wrapBackendTextureAsRenderTarget(tex, colorType,
+                                                                    origin, sampleCnt));
     if (!proxy) {
         return nullptr;
     }
diff --git a/src/gpu/GrDataUtils.cpp b/src/gpu/GrDataUtils.cpp
index 0ac04f8..0bfb27d 100644
--- a/src/gpu/GrDataUtils.cpp
+++ b/src/gpu/GrDataUtils.cpp
@@ -581,3 +581,19 @@
     }
     return true;
 }
+
+
+GrColorType SkColorTypeAndFormatToGrColorType(const GrCaps* caps,
+                                              SkColorType skCT,
+                                              const GrBackendFormat& format) {
+    GrColorType grCT = SkColorTypeToGrColorType(skCT);
+    // Until we support SRGB in the SkColorType we have to do this manual check here to make sure
+    // we use the correct GrColorType.
+    if (caps->isFormatSRGB(format)) {
+        if (grCT != GrColorType::kRGBA_8888) {
+            return GrColorType::kUnknown;
+        }
+        grCT = GrColorType::kRGBA_8888_SRGB;
+    }
+    return grCT;
+}
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index ce2c840..6664ca1 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -221,19 +221,29 @@
 }
 
 sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex,
+                                           GrColorType colorType,
                                            GrWrapOwnership ownership, GrWrapCacheable cacheable,
                                            GrIOType ioType) {
     SkASSERT(ioType != kWrite_GrIOType);
     this->handleDirtyContext();
-    SkASSERT(this->caps());
-    if (!this->caps()->isConfigTexturable(backendTex.config())) {
+
+    const GrCaps* caps = this->caps();
+    SkASSERT(caps);
+
+    if (!caps->isFormatTexturable(colorType, backendTex.getBackendFormat())) {
         return nullptr;
     }
-    if (backendTex.width() > this->caps()->maxTextureSize() ||
-        backendTex.height() > this->caps()->maxTextureSize()) {
+    if (backendTex.width() > caps->maxTextureSize() ||
+        backendTex.height() > caps->maxTextureSize()) {
         return nullptr;
     }
-    return this->onWrapBackendTexture(backendTex, ownership, cacheable, ioType);
+
+    SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
+                                          caps->getConfigFromBackendFormat(
+                                                                     backendTex.getBackendFormat(),
+                                                                     colorType)));
+
+    return this->onWrapBackendTexture(backendTex, colorType, ownership, cacheable, ioType);
 }
 
 sk_sp<GrTexture> GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& backendTex,
@@ -267,25 +277,47 @@
     return tex;
 }
 
-sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget& backendRT) {
-    if (0 == this->caps()->getRenderTargetSampleCount(backendRT.sampleCnt(), backendRT.config())) {
+sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget& backendRT,
+                                                     GrColorType colorType) {
+    this->handleDirtyContext();
+
+    const GrCaps* caps = this->caps();
+
+    SkASSERT(GrCaps::AreConfigsCompatible(backendRT.config(),
+                                          caps->getConfigFromBackendFormat(
+                                                                     backendRT.getBackendFormat(),
+                                                                     colorType)));
+
+    if (0 == caps->getRenderTargetSampleCount(backendRT.sampleCnt(), colorType,
+                                              backendRT.getBackendFormat())) {
         return nullptr;
     }
-    this->handleDirtyContext();
-    return this->onWrapBackendRenderTarget(backendRT);
+
+    return this->onWrapBackendRenderTarget(backendRT, colorType);
 }
 
-sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
-                                                              int sampleCnt) {
-    if (0 == this->caps()->getRenderTargetSampleCount(sampleCnt, tex.config())) {
-        return nullptr;
-    }
-    int maxSize = this->caps()->maxTextureSize();
-    if (tex.width() > maxSize || tex.height() > maxSize) {
-        return nullptr;
-    }
+sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& backendTex,
+                                                              int sampleCnt,
+                                                              GrColorType colorType) {
     this->handleDirtyContext();
-    return this->onWrapBackendTextureAsRenderTarget(tex, sampleCnt);
+
+    const GrCaps* caps = this->caps();
+
+    int maxSize = caps->maxTextureSize();
+    if (backendTex.width() > maxSize || backendTex.height() > maxSize) {
+        return nullptr;
+    }
+
+    SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
+                                          caps->getConfigFromBackendFormat(
+                                                                     backendTex.getBackendFormat(),
+                                                                     colorType)));
+
+    if (0 == caps->getRenderTargetSampleCount(sampleCnt, colorType,
+                                              backendTex.getBackendFormat())) {
+        return nullptr;
+    }
+    return this->onWrapBackendTextureAsRenderTarget(backendTex, sampleCnt, colorType);
 }
 
 sk_sp<GrRenderTarget> GrGpu::wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo& imageInfo,
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index 27a1941..7d6b7ec 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -118,8 +118,8 @@
     /**
      * Implements GrResourceProvider::wrapBackendTexture
      */
-    sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
-                                        GrIOType);
+    sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture&, GrColorType,
+                                        GrWrapOwnership, GrWrapCacheable, GrIOType);
 
     /**
      * Implements GrResourceProvider::wrapRenderableBackendTexture
@@ -130,13 +130,15 @@
     /**
      * Implements GrResourceProvider::wrapBackendRenderTarget
      */
-    sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&);
+    sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&,
+                                                  GrColorType colorType);
 
     /**
      * Implements GrResourceProvider::wrapBackendTextureAsRenderTarget
      */
     sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTexture&,
-                                                           int sampleCnt);
+                                                           int sampleCnt,
+                                                           GrColorType colorType);
 
     /**
      * Implements GrResourceProvider::wrapVulkanSecondaryCBAsRenderTarget
@@ -532,14 +534,16 @@
     virtual sk_sp<GrTexture> onCreateCompressedTexture(int width, int height,
                                                        SkImage::CompressionType, SkBudgeted,
                                                        const void* data) = 0;
-    virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership,
-                                                  GrWrapCacheable, GrIOType) = 0;
+    virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType,
+                                                  GrWrapOwnership, GrWrapCacheable, GrIOType) = 0;
     virtual sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
                                                             GrColorType, GrWrapOwnership,
                                                             GrWrapCacheable) = 0;
-    virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) = 0;
+    virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
+                                                            GrColorType) = 0;
     virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
-                                                                     int sampleCnt) = 0;
+                                                                     int sampleCnt,
+                                                                     GrColorType) = 0;
     virtual sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
                                                                         const GrVkDrawableInfo&);
 
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index 5e0fd0e..d4b811b 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -521,6 +521,7 @@
 }
 
 sk_sp<GrTextureProxy> GrProxyProvider::wrapBackendTexture(const GrBackendTexture& backendTex,
+                                                          GrColorType grColorType,
                                                           GrSurfaceOrigin origin,
                                                           GrWrapOwnership ownership,
                                                           GrWrapCacheable cacheable,
@@ -538,13 +539,21 @@
         return nullptr;
     }
 
-    SkASSERT(validate_backend_format_and_config(this->caps(), backendTex.getBackendFormat(),
-                                                backendTex.config()));
+    const GrCaps* caps = this->caps();
+
+    SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
+                                          caps->getConfigFromBackendFormat(
+                                                                     backendTex.getBackendFormat(),
+                                                                     grColorType)));
+
+    SkASSERT(validate_backend_format_and_colortype(caps, grColorType,
+                                                   backendTex.getBackendFormat()));
 
     GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
 
     sk_sp<GrTexture> tex =
-            resourceProvider->wrapBackendTexture(backendTex, ownership, cacheable, ioType);
+            resourceProvider->wrapBackendTexture(backendTex, grColorType,
+                                                 ownership, cacheable, ioType);
     if (!tex) {
         return nullptr;
     }
@@ -557,8 +566,7 @@
     // Make sure we match how we created the proxy with SkBudgeted::kNo
     SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType());
 
-    GrColorType colorType = GrPixelConfigToColorType(tex->config());
-    GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(tex->backendFormat(), colorType);
+    GrSwizzle texSwizzle = caps->getTextureSwizzle(tex->backendFormat(), grColorType);
 
     return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(tex), origin, texSwizzle));
 }
@@ -616,8 +624,8 @@
 }
 
 sk_sp<GrSurfaceProxy> GrProxyProvider::wrapBackendRenderTarget(
-        const GrBackendRenderTarget& backendRT, GrSurfaceOrigin origin, ReleaseProc releaseProc,
-        ReleaseContext releaseCtx) {
+        const GrBackendRenderTarget& backendRT, GrColorType grColorType,
+        GrSurfaceOrigin origin, ReleaseProc releaseProc, ReleaseContext releaseCtx) {
     if (this->isAbandoned()) {
         return nullptr;
     }
@@ -628,16 +636,15 @@
         return nullptr;
     }
 
-    GrColorType colorType = GrPixelConfigToColorType(backendRT.config());
 #ifdef SK_DEBUG
     GrPixelConfig testConfig =
-            this->caps()->validateBackendRenderTarget(backendRT, colorType);
+            this->caps()->validateBackendRenderTarget(backendRT, grColorType);
     SkASSERT(testConfig != kUnknown_GrPixelConfig);
 #endif
 
     GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
 
-    sk_sp<GrRenderTarget> rt = resourceProvider->wrapBackendRenderTarget(backendRT);
+    sk_sp<GrRenderTarget> rt = resourceProvider->wrapBackendRenderTarget(backendRT, grColorType);
     if (!rt) {
         return nullptr;
     }
@@ -651,15 +658,16 @@
     // Make sure we match how we created the proxy with SkBudgeted::kNo
     SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType());
 
-    GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(rt->backendFormat(), colorType);
-    GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(rt->backendFormat(), colorType);
+    GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(rt->backendFormat(), grColorType);
+    GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(rt->backendFormat(), grColorType);
 
     return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(std::move(rt), origin, texSwizzle,
                                                               outSwizzle));
 }
 
 sk_sp<GrSurfaceProxy> GrProxyProvider::wrapBackendTextureAsRenderTarget(
-        const GrBackendTexture& backendTex, GrSurfaceOrigin origin, int sampleCnt) {
+        const GrBackendTexture& backendTex, GrColorType grColorType,
+        GrSurfaceOrigin origin, int sampleCnt) {
     if (this->isAbandoned()) {
         return nullptr;
     }
@@ -670,13 +678,20 @@
         return nullptr;
     }
 
-    SkASSERT(validate_backend_format_and_config(this->caps(), backendTex.getBackendFormat(),
-                                                backendTex.config()));
+    const GrCaps* caps = this->caps();
+
+    SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
+                                          caps->getConfigFromBackendFormat(
+                                                                     backendTex.getBackendFormat(),
+                                                                     grColorType)));
+
+    SkASSERT(validate_backend_format_and_colortype(caps, grColorType,
+                                                   backendTex.getBackendFormat()));
 
     GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
 
     sk_sp<GrRenderTarget> rt =
-            resourceProvider->wrapBackendTextureAsRenderTarget(backendTex, sampleCnt);
+            resourceProvider->wrapBackendTextureAsRenderTarget(backendTex, sampleCnt, grColorType);
     if (!rt) {
         return nullptr;
     }
@@ -685,9 +700,8 @@
     // This proxy should be unbudgeted because we're just wrapping an external resource
     SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType());
 
-    GrColorType colorType = GrPixelConfigToColorType(rt->config());
-    GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(rt->backendFormat(), colorType);
-    GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(rt->backendFormat(), colorType);
+    GrSwizzle texSwizzle = caps->getTextureSwizzle(rt->backendFormat(), grColorType);
+    GrSwizzle outSwizzle = caps->getOutputSwizzle(rt->backendFormat(), grColorType);
 
     return sk_sp<GrSurfaceProxy>(new GrRenderTargetProxy(std::move(rt), origin, texSwizzle,
                                                          outSwizzle));
diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h
index a4b07f9..d216aab 100644
--- a/src/gpu/GrProxyProvider.h
+++ b/src/gpu/GrProxyProvider.h
@@ -110,7 +110,7 @@
      * Create a texture proxy that wraps a (non-renderable) backend texture. GrIOType must be
      * kRead or kRW.
      */
-    sk_sp<GrTextureProxy> wrapBackendTexture(const GrBackendTexture&, GrSurfaceOrigin,
+    sk_sp<GrTextureProxy> wrapBackendTexture(const GrBackendTexture&, GrColorType, GrSurfaceOrigin,
                                              GrWrapOwnership, GrWrapCacheable, GrIOType,
                                              ReleaseProc = nullptr, ReleaseContext = nullptr);
 
@@ -126,14 +126,16 @@
     /*
      * Create a render target proxy that wraps a backend render target
      */
-    sk_sp<GrSurfaceProxy> wrapBackendRenderTarget(const GrBackendRenderTarget&, GrSurfaceOrigin,
+    sk_sp<GrSurfaceProxy> wrapBackendRenderTarget(const GrBackendRenderTarget&, GrColorType,
+                                                  GrSurfaceOrigin,
                                                   ReleaseProc = nullptr, ReleaseContext = nullptr);
 
     /*
      * Create a render target proxy that wraps a backend texture
      */
-    sk_sp<GrSurfaceProxy> wrapBackendTextureAsRenderTarget(const GrBackendTexture& backendTex,
-                                                           GrSurfaceOrigin origin,
+    sk_sp<GrSurfaceProxy> wrapBackendTextureAsRenderTarget(const GrBackendTexture&,
+                                                           GrColorType,
+                                                           GrSurfaceOrigin,
                                                            int sampleCnt);
 
     sk_sp<GrRenderTargetProxy> wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index d49721c..b80f9f1 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -334,6 +334,7 @@
 }
 
 sk_sp<GrTexture> GrResourceProvider::wrapBackendTexture(const GrBackendTexture& tex,
+                                                        GrColorType colorType,
                                                         GrWrapOwnership ownership,
                                                         GrWrapCacheable cacheable,
                                                         GrIOType ioType) {
@@ -341,7 +342,7 @@
     if (this->isAbandoned()) {
         return nullptr;
     }
-    return fGpu->wrapBackendTexture(tex, ownership, cacheable, ioType);
+    return fGpu->wrapBackendTexture(tex, colorType, ownership, cacheable, ioType);
 }
 
 sk_sp<GrTexture> GrResourceProvider::wrapRenderableBackendTexture(const GrBackendTexture& tex,
@@ -357,10 +358,10 @@
 }
 
 sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendRenderTarget(
-        const GrBackendRenderTarget& backendRT)
+        const GrBackendRenderTarget& backendRT, GrColorType colorType)
 {
     ASSERT_SINGLE_OWNER
-    return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(backendRT);
+    return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(backendRT, colorType);
 }
 
 sk_sp<GrRenderTarget> GrResourceProvider::wrapVulkanSecondaryCBAsRenderTarget(
@@ -533,12 +534,12 @@
 }
 
 sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendTextureAsRenderTarget(
-        const GrBackendTexture& tex, int sampleCnt)
+        const GrBackendTexture& tex, int sampleCnt, GrColorType colorType)
 {
     if (this->isAbandoned()) {
         return nullptr;
     }
-    return fGpu->wrapBackendTextureAsRenderTarget(tex, sampleCnt);
+    return fGpu->wrapBackendTextureAsRenderTarget(tex, sampleCnt, colorType);
 }
 
 sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT GrResourceProvider::makeSemaphore(bool isOwned) {
diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h
index 3447fd4..c0b0219 100644
--- a/src/gpu/GrResourceProvider.h
+++ b/src/gpu/GrResourceProvider.h
@@ -109,7 +109,7 @@
      *
      * @return GrTexture object or NULL on failure.
      */
-    sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture& tex, GrWrapOwnership,
+    sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture& tex, GrColorType, GrWrapOwnership,
                                         GrWrapCacheable, GrIOType);
 
     /**
@@ -132,7 +132,8 @@
      *
      * @return GrRenderTarget object or NULL on failure.
      */
-    sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&);
+    sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&,
+                                                  GrColorType colorType);
 
     sk_sp<GrRenderTarget> wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
                                                               const GrVkDrawableInfo&);
@@ -228,7 +229,8 @@
       * @return GrRenderTarget object or NULL on failure.
       */
      sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTexture&,
-                                                            int sampleCnt);
+                                                            int sampleCnt,
+                                                            GrColorType);
 
     /**
      * Assigns a unique key to a resource. If the key is associated with another resource that
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index d54595d..9803efa 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -3643,6 +3643,29 @@
     return get_yuva_config(*glFormat);
 }
 
+GrColorType GrGLCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format) const {
+    GrGLFormat grGLFormat = GrGLBackendFormatToGLFormat(format);
+
+    switch (grGLFormat) {
+        case GrGLFormat::kALPHA8:   // fall through
+        case GrGLFormat::kR8:       return GrColorType::kAlpha_8;
+        case GrGLFormat::kRG8:      return GrColorType::kRG_88;
+        case GrGLFormat::kRGBA8:    return GrColorType::kRGBA_8888;
+        case GrGLFormat::kRGB8:     return GrColorType::kRGB_888x;
+        case GrGLFormat::kBGRA8:    return GrColorType::kBGRA_8888;
+        case GrGLFormat::kRGB10_A2: return GrColorType::kRGBA_1010102;
+        case GrGLFormat::kR16F:     return GrColorType::kAlpha_F16;
+        case GrGLFormat::kR16:      return GrColorType::kR_16;
+        case GrGLFormat::kRG16:     return GrColorType::kRG_1616;
+        // Experimental (for Y416 and mutant P016/P010)
+        case GrGLFormat::kRGBA16:   return GrColorType::kRGBA_16161616;
+        case GrGLFormat::kRG16F:    return GrColorType::kRG_F16;
+        default: return GrColorType::kUnknown;
+    }
+
+    SkUNREACHABLE;
+}
+
 GrBackendFormat GrGLCaps::getBackendFormatFromColorType(GrColorType ct) const {
     auto format = this->getFormatFromColorType(ct);
     if (format == GrGLFormat::kUnknown) {
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 051870e..64c95aa 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -447,6 +447,7 @@
                                               GrColorType) const override;
 
     GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override;
+    GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat&) const override;
 
     GrBackendFormat getBackendFormatFromColorType(GrColorType ct) const override;
     GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override;
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 4508af7..0d4f666 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -680,8 +680,8 @@
 }
 
 sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTex,
-                                               GrWrapOwnership ownership, GrWrapCacheable cacheable,
-                                               GrIOType ioType) {
+                                               GrColorType grColorType, GrWrapOwnership ownership,
+                                               GrWrapCacheable cacheable, GrIOType ioType) {
     GrGLTexture::IDDesc idDesc;
     if (!check_backend_texture(backendTex, this->glCaps(), &idDesc)) {
         return nullptr;
@@ -695,10 +695,14 @@
         idDesc.fOwnership = GrBackendObjectOwnership::kOwned;
     }
 
+    GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendTex.getBackendFormat(),
+                                                                    grColorType);
+    SkASSERT(kUnknown_GrPixelConfig != config);
+
     GrSurfaceDesc surfDesc;
     surfDesc.fWidth = backendTex.width();
     surfDesc.fHeight = backendTex.height();
-    surfDesc.fConfig = backendTex.config();
+    surfDesc.fConfig = config;
     surfDesc.fSampleCnt = 1;
 
     GrMipMapsStatus mipMapsStatus = backendTex.hasMipMaps() ? GrMipMapsStatus::kValid
@@ -737,10 +741,14 @@
 
     const GrCaps* caps = this->caps();
 
+    GrPixelConfig config = caps->getConfigFromBackendFormat(backendTex.getBackendFormat(),
+                                                            colorType);
+    SkASSERT(kUnknown_GrPixelConfig != config);
+
     GrSurfaceDesc surfDesc;
     surfDesc.fWidth = backendTex.width();
     surfDesc.fHeight = backendTex.height();
-    surfDesc.fConfig = backendTex.config();
+    surfDesc.fConfig = config;
     surfDesc.fSampleCnt = caps->getRenderTargetSampleCount(sampleCnt, colorType,
                                                            backendTex.getBackendFormat());
     if (surfDesc.fSampleCnt < 1) {
@@ -764,7 +772,8 @@
     return std::move(texRT);
 }
 
-sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT) {
+sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT,
+                                                         GrColorType grColorType) {
     GrGLFramebufferInfo info;
     if (!backendRT.getGLFramebufferInfo(&info)) {
         return nullptr;
@@ -776,18 +785,23 @@
     idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID;
     idDesc.fRTFBOOwnership = GrBackendObjectOwnership::kBorrowed;
 
+    GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendRT.getBackendFormat(),
+                                                                    grColorType);
+    SkASSERT(kUnknown_GrPixelConfig != config);
+
     GrSurfaceDesc desc;
     desc.fWidth = backendRT.width();
     desc.fHeight = backendRT.height();
-    desc.fConfig = backendRT.config();
-    desc.fSampleCnt =
-            this->caps()->getRenderTargetSampleCount(backendRT.sampleCnt(), backendRT.config());
+    desc.fConfig = config;
+    desc.fSampleCnt = this->caps()->getRenderTargetSampleCount(backendRT.sampleCnt(), grColorType,
+                                                               backendRT.getBackendFormat());
 
     return GrGLRenderTarget::MakeWrapped(this, desc, info.fFormat, idDesc, backendRT.stencilBits());
 }
 
 sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
-                                                                  int sampleCnt) {
+                                                                  int sampleCnt,
+                                                                  GrColorType grColorType) {
     GrGLTextureInfo info;
     if (!tex.getGLTextureInfo(&info) || !info.fID) {
         return nullptr;
@@ -801,11 +815,16 @@
         return nullptr;
     }
 
+    GrPixelConfig config = this->caps()->getConfigFromBackendFormat(tex.getBackendFormat(),
+                                                                    grColorType);
+    SkASSERT(kUnknown_GrPixelConfig != config);
+
     GrSurfaceDesc surfDesc;
     surfDesc.fWidth = tex.width();
     surfDesc.fHeight = tex.height();
-    surfDesc.fConfig = tex.config();
-    surfDesc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, tex.config());
+    surfDesc.fConfig = config;
+    surfDesc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, grColorType,
+                                                                   tex.getBackendFormat());
 
     GrGLRenderTarget::IDDesc rtIDDesc;
     if (!this->createRenderTargetObjects(surfDesc, info, &rtIDDesc)) {
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index fb5c196..42b657f 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -200,14 +200,15 @@
     sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType intendedType, GrAccessPattern,
                                       const void* data) override;
 
-    sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
-                                          GrIOType) override;
+    sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType, GrWrapOwnership,
+                                          GrWrapCacheable, GrIOType) override;
     sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
                                                     GrColorType, GrWrapOwnership,
                                                     GrWrapCacheable) override;
-    sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
+    sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
+                                                    GrColorType) override;
     sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
-                                                             int sampleCnt) override;
+                                                             int sampleCnt, GrColorType) override;
 
     // Given a GL format return the index into the stencil format array on GrGLCaps to a
     // compatible stencil format, or negative if there is no compatible stencil format.
diff --git a/src/gpu/mock/GrMockCaps.h b/src/gpu/mock/GrMockCaps.h
index 4e82f19..1f9e2d2 100644
--- a/src/gpu/mock/GrMockCaps.h
+++ b/src/gpu/mock/GrMockCaps.h
@@ -137,6 +137,14 @@
         return GrColorTypeToPixelConfig(*format.getMockColorType());
     }
 
+    GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format) const override {
+        if (!format.getMockColorType()) {
+            return GrColorType::kUnknown;
+        }
+
+        return *format.getMockColorType();
+    }
+
     GrBackendFormat getBackendFormatFromColorType(GrColorType ct) const override {
         return GrBackendFormat::MakeMock(ct);
     }
diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp
index e6f0a62..4c9f5c0 100644
--- a/src/gpu/mock/GrMockGpu.cpp
+++ b/src/gpu/mock/GrMockGpu.cpp
@@ -114,21 +114,23 @@
     return nullptr;
 }
 
-sk_sp<GrTexture> GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex,
+sk_sp<GrTexture> GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex, GrColorType colorType,
                                                  GrWrapOwnership ownership,
                                                  GrWrapCacheable wrapType, GrIOType ioType) {
-    GrMockTextureInfo info;
-    SkAssertResult(tex.getMockTextureInfo(&info));
+    GrMockTextureInfo texInfo;
+    SkAssertResult(tex.getMockTextureInfo(&texInfo));
 
+    SkASSERT(colorType == texInfo.fColorType);
     GrSurfaceDesc desc;
     desc.fWidth = tex.width();
     desc.fHeight = tex.height();
-    desc.fConfig = info.pixelConfig();
+    desc.fConfig = texInfo.pixelConfig();
 
     GrMipMapsStatus mipMapsStatus = tex.hasMipMaps() ? GrMipMapsStatus::kValid
                                                      : GrMipMapsStatus::kNotAllocated;
 
-    return sk_sp<GrTexture>(new GrMockTexture(this, desc, mipMapsStatus, info, wrapType, ioType));
+    return sk_sp<GrTexture>(new GrMockTexture(this, desc, mipMapsStatus, texInfo,
+                                              wrapType, ioType));
 }
 
 sk_sp<GrTexture> GrMockGpu::onWrapRenderableBackendTexture(const GrBackendTexture& tex,
@@ -155,10 +157,12 @@
             new GrMockTextureRenderTarget(this, desc, mipMapsStatus, texInfo, rtInfo, cacheable));
 }
 
-sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& rt) {
+sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& rt,
+                                                           GrColorType colorType) {
     GrMockRenderTargetInfo info;
     SkAssertResult(rt.getMockRenderTargetInfo(&info));
 
+    SkASSERT(colorType == info.colorType());
     GrSurfaceDesc desc;
     desc.fWidth = rt.width();
     desc.fHeight = rt.height();
@@ -169,10 +173,12 @@
 }
 
 sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
-                                                                    int sampleCnt) {
+                                                                    int sampleCnt,
+                                                                    GrColorType colorType) {
     GrMockTextureInfo texInfo;
     SkAssertResult(tex.getMockTextureInfo(&texInfo));
 
+    SkASSERT(colorType == texInfo.fColorType);
     GrSurfaceDesc desc;
     desc.fWidth = tex.width();
     desc.fHeight = tex.height();
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index 1459637..9bdd28f 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -69,8 +69,8 @@
     sk_sp<GrTexture> onCreateCompressedTexture(int width, int height, SkImage::CompressionType,
                                                SkBudgeted, const void* data) override;
 
-    sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
-                                          GrIOType) override;
+    sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType, GrWrapOwnership,
+                                          GrWrapCacheable, GrIOType) override;
 
     sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
                                                     int sampleCnt,
@@ -78,10 +78,11 @@
                                                     GrWrapOwnership,
                                                     GrWrapCacheable) override;
 
-    sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
+    sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
+                                                    GrColorType) override;
 
     sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
-                                                             int sampleCnt) override;
+                                                             int sampleCnt, GrColorType) override;
 
     sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern,
                                       const void*) override;
diff --git a/src/gpu/mtl/GrMtlCaps.h b/src/gpu/mtl/GrMtlCaps.h
index d11aa29..2e981ab 100644
--- a/src/gpu/mtl/GrMtlCaps.h
+++ b/src/gpu/mtl/GrMtlCaps.h
@@ -72,6 +72,7 @@
                                               GrColorType) const override;
 
     GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override;
+    GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat&) const override;
 
     GrBackendFormat getBackendFormatFromColorType(GrColorType ct) const override;
     GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override;
diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm
index 6c080d3..cc1c728 100644
--- a/src/gpu/mtl/GrMtlCaps.mm
+++ b/src/gpu/mtl/GrMtlCaps.mm
@@ -696,6 +696,32 @@
     return get_yuva_config(*mtlFormat);
 }
 
+GrColorType GrMtlCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format) const {
+    const GrMTLPixelFormat* grMtlFormat = format.getMtlFormat();
+    if (!grMtlFormat) {
+        return GrColorType::kUnknown;
+    }
+
+    MTLPixelFormat mtlFormat = static_cast<MTLPixelFormat>(*grMtlFormat);
+
+    switch (mtlFormat) {
+        case MTLPixelFormatA8Unorm:           // fall through
+        case MTLPixelFormatR8Unorm:           return GrColorType::kAlpha_8;
+        case MTLPixelFormatRG8Unorm:          return GrColorType::kRG_88;
+        case MTLPixelFormatRGBA8Unorm:        return GrColorType::kRGBA_8888;
+        case MTLPixelFormatBGRA8Unorm:        return GrColorType::kBGRA_8888;
+        case MTLPixelFormatRGB10A2Unorm:      return GrColorType::kRGBA_1010102;
+        case MTLPixelFormatR16Unorm:          return GrColorType::kR_16;
+        case MTLPixelFormatRG16Unorm:         return GrColorType::kRG_1616;
+        // Experimental (for Y416 and mutant P016/P010)
+        case MTLPixelFormatRGBA16Unorm:       return GrColorType::kRGBA_16161616;
+        case MTLPixelFormatRG16Float:         return GrColorType::kRG_F16;
+        default:                              return GrColorType::kUnknown;
+    }
+
+    SkUNREACHABLE;
+}
+
 GrBackendFormat GrMtlCaps::getBackendFormatFromColorType(GrColorType ct) const {
     GrPixelConfig config = GrColorTypeToPixelConfig(ct);
     if (config == kUnknown_GrPixelConfig) {
diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h
index 16f35fc..15ae380 100644
--- a/src/gpu/mtl/GrMtlGpu.h
+++ b/src/gpu/mtl/GrMtlGpu.h
@@ -142,17 +142,19 @@
         return nullptr;
     }
 
-    sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
-                                          GrIOType) override;
+    sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType,
+                                          GrWrapOwnership, GrWrapCacheable, GrIOType) override;
 
     sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
                                                     GrColorType, GrWrapOwnership,
                                                     GrWrapCacheable) override;
 
-    sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
+    sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
+                                                    GrColorType) override;
 
     sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
-                                                             int sampleCnt) override;
+                                                             int sampleCnt,
+                                                             GrColorType) override;
 
     sk_sp<GrGpuBuffer> onCreateBuffer(size_t, GrGpuBufferType, GrAccessPattern,
                                       const void*) override;
diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm
index 2e6c3df..6d8b9af 100644
--- a/src/gpu/mtl/GrMtlGpu.mm
+++ b/src/gpu/mtl/GrMtlGpu.mm
@@ -516,6 +516,7 @@
 }
 
 sk_sp<GrTexture> GrMtlGpu::onWrapBackendTexture(const GrBackendTexture& backendTex,
+                                                GrColorType grColorType,
                                                 GrWrapOwnership,
                                                 GrWrapCacheable cacheable, GrIOType ioType) {
     id<MTLTexture> mtlTexture = get_texture_from_backend(backendTex);
@@ -523,8 +524,12 @@
         return nullptr;
     }
 
+    GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendTex.getBackendFormat(),
+                                                                    grColorType);
+    SkASSERT(kUnknown_GrPixelConfig != config);
+
     GrSurfaceDesc surfDesc;
-    init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kNo, backendTex.config());
+    init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kNo, config);
 
     return GrMtlTexture::MakeWrappedTexture(this, surfDesc, mtlTexture, cacheable, ioType);
 }
@@ -539,11 +544,17 @@
         return nullptr;
     }
 
-    GrSurfaceDesc surfDesc;
-    init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kYes, backendTex.config());
+    const GrCaps* caps = this->caps();
 
-    surfDesc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, colorType,
-                                                                   backendTex.getBackendFormat());
+    GrPixelConfig config = caps->getConfigFromBackendFormat(backendTex.getBackendFormat(),
+                                                            colorType);
+    SkASSERT(kUnknown_GrPixelConfig != config);
+
+    GrSurfaceDesc surfDesc;
+    init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kYes, config);
+
+    surfDesc.fSampleCnt = caps->getRenderTargetSampleCount(sampleCnt, colorType,
+                                                           backendTex.getBackendFormat());
     if (!surfDesc.fSampleCnt) {
         return nullptr;
     }
@@ -552,7 +563,8 @@
                                                                     cacheable);
 }
 
-sk_sp<GrRenderTarget> GrMtlGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT) {
+sk_sp<GrRenderTarget> GrMtlGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT,
+                                                          GrColorType grColorType) {
     // TODO: Revisit this when the Metal backend is completed. It may support MSAA render targets.
     if (backendRT.sampleCnt() > 1) {
         return nullptr;
@@ -562,22 +574,31 @@
         return nullptr;
     }
 
+    GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendRT.getBackendFormat(),
+                                                                    grColorType);
+    SkASSERT(kUnknown_GrPixelConfig != config);
+
     GrSurfaceDesc surfDesc;
-    init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kYes, backendRT.config());
+    init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kYes, config);
 
     return GrMtlRenderTarget::MakeWrappedRenderTarget(this, surfDesc, mtlTexture);
 }
 
 sk_sp<GrRenderTarget> GrMtlGpu::onWrapBackendTextureAsRenderTarget(
-        const GrBackendTexture& backendTex, int sampleCnt) {
+        const GrBackendTexture& backendTex, int sampleCnt, GrColorType grColorType) {
     id<MTLTexture> mtlTexture = get_texture_from_backend(backendTex);
     if (!mtlTexture) {
         return nullptr;
     }
 
+    GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendTex.getBackendFormat(),
+                                                                    grColorType);
+    SkASSERT(kUnknown_GrPixelConfig != config);
+
     GrSurfaceDesc surfDesc;
-    init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kYes, backendTex.config());
-    surfDesc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, surfDesc.fConfig);
+    init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kYes, config);
+    surfDesc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, grColorType,
+                                                                   backendTex.getBackendFormat());
     if (!surfDesc.fSampleCnt) {
         return nullptr;
     }
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index 568df88..3da7ad5 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -1118,6 +1118,30 @@
     return get_yuva_config(*vkFormat);
 }
 
+GrColorType GrVkCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format) const {
+    const VkFormat* vkFormat = format.getVkFormat();
+    if (!vkFormat) {
+        return GrColorType::kUnknown;
+    }
+
+    switch (*vkFormat) {
+        case VK_FORMAT_R8_UNORM:                 return GrColorType::kAlpha_8;
+        case VK_FORMAT_R8G8B8A8_UNORM:           return GrColorType::kRGBA_8888;
+        case VK_FORMAT_R8G8B8_UNORM:             return GrColorType::kRGB_888x;
+        case VK_FORMAT_R8G8_UNORM:               return GrColorType::kRG_88;
+        case VK_FORMAT_B8G8R8A8_UNORM:           return GrColorType::kBGRA_8888;
+        case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return GrColorType::kRGBA_1010102;
+        case VK_FORMAT_R16_UNORM:                return GrColorType::kR_16;
+        case VK_FORMAT_R16G16_UNORM:             return GrColorType::kRG_1616;
+        // Experimental (for Y416 and mutant P016/P010)
+        case VK_FORMAT_R16G16B16A16_UNORM:       return GrColorType::kRGBA_16161616;
+        case VK_FORMAT_R16G16_SFLOAT:            return GrColorType::kRG_F16;
+        default:                                 return GrColorType::kUnknown;
+    }
+
+    SkUNREACHABLE;
+}
+
 GrBackendFormat GrVkCaps::getBackendFormatFromColorType(GrColorType ct) const {
     GrPixelConfig config = GrColorTypeToPixelConfig(ct);
     if (config == kUnknown_GrPixelConfig) {
diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h
index cca10b0..1a89a89 100644
--- a/src/gpu/vk/GrVkCaps.h
+++ b/src/gpu/vk/GrVkCaps.h
@@ -166,6 +166,7 @@
                                               GrColorType) const override;
 
     GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override;
+    GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat&) const override;
 
     GrBackendFormat getBackendFormatFromColorType(GrColorType ct) const override;
     GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override;
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index c62a033..9a8aeb8 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -1120,7 +1120,7 @@
 
 static bool check_image_info(const GrVkCaps& caps,
                              const GrVkImageInfo& info,
-                             GrPixelConfig config,
+                             GrColorType colorType,
                              bool needsAllocation) {
     if (VK_NULL_HANDLE == info.fImage) {
         return false;
@@ -1140,7 +1140,7 @@
         return false;
     }
 
-    SkASSERT(GrVkFormatPixelConfigPairIsValid(info.fFormat, config));
+    SkASSERT(GrVkFormatColorTypePairIsValid(info.fFormat, colorType));
     return true;
 }
 
@@ -1166,14 +1166,14 @@
 }
 
 sk_sp<GrTexture> GrVkGpu::onWrapBackendTexture(const GrBackendTexture& backendTex,
-                                               GrWrapOwnership ownership, GrWrapCacheable cacheable,
-                                               GrIOType ioType) {
+                                               GrColorType colorType, GrWrapOwnership ownership,
+                                               GrWrapCacheable cacheable, GrIOType ioType) {
     GrVkImageInfo imageInfo;
     if (!backendTex.getVkImageInfo(&imageInfo)) {
         return nullptr;
     }
 
-    if (!check_image_info(this->vkCaps(), imageInfo, backendTex.config(),
+    if (!check_image_info(this->vkCaps(), imageInfo, colorType,
                           kAdopt_GrWrapOwnership == ownership)) {
         return nullptr;
     }
@@ -1185,10 +1185,14 @@
         return nullptr;
     }
 
+    GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendTex.getBackendFormat(),
+                                                                    colorType);
+    SkASSERT(kUnknown_GrPixelConfig != config);
+
     GrSurfaceDesc surfDesc;
     surfDesc.fWidth = backendTex.width();
     surfDesc.fHeight = backendTex.height();
-    surfDesc.fConfig = backendTex.config();
+    surfDesc.fConfig = config;
     surfDesc.fSampleCnt = 1;
     surfDesc.fIsProtected = backendTex.isProtected() ? GrProtected::kYes : GrProtected::kNo;
 
@@ -1208,7 +1212,7 @@
         return nullptr;
     }
 
-    if (!check_image_info(this->vkCaps(), imageInfo, backendTex.config(),
+    if (!check_image_info(this->vkCaps(), imageInfo, colorType,
                           kAdopt_GrWrapOwnership == ownership)) {
         return nullptr;
     }
@@ -1223,16 +1227,16 @@
         return nullptr;
     }
 
-    SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
-                                          this->caps()->getConfigFromBackendFormat(
-                                                        backendTex.getBackendFormat(),
-                                                        colorType)));
+
+    GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendTex.getBackendFormat(),
+                                                                    colorType);
+    SkASSERT(kUnknown_GrPixelConfig != config);
 
     GrSurfaceDesc surfDesc;
     surfDesc.fWidth = backendTex.width();
     surfDesc.fHeight = backendTex.height();
     surfDesc.fIsProtected = backendTex.isProtected() ? GrProtected::kYes : GrProtected::kNo;
-    surfDesc.fConfig = backendTex.config();
+    surfDesc.fConfig = config;
     surfDesc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, colorType,
                                                                    backendTex.getBackendFormat());
 
@@ -1243,7 +1247,8 @@
             this, surfDesc, ownership, cacheable, imageInfo, std::move(layout));
 }
 
-sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT){
+sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT,
+                                                         GrColorType colorType) {
     // Currently the Vulkan backend does not support wrapping of msaa render targets directly. In
     // general this is not an issue since swapchain images in vulkan are never multisampled. Thus if
     // you want a multisampled RT it is best to wrap the swapchain images and then let Skia handle
@@ -1257,7 +1262,11 @@
         return nullptr;
     }
 
-    if (!check_image_info(this->vkCaps(), info, backendRT.config(), false)) {
+    GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendRT.getBackendFormat(),
+                                                                    colorType);
+    SkASSERT(kUnknown_GrPixelConfig != config);
+
+    if (!check_image_info(this->vkCaps(), info, colorType, false)) {
         return nullptr;
     }
     if (!check_rt_image_info(this->vkCaps(), info)) {
@@ -1272,7 +1281,7 @@
     desc.fWidth = backendRT.width();
     desc.fHeight = backendRT.height();
     desc.fIsProtected = backendRT.isProtected() ? GrProtected::kYes : GrProtected::kNo;
-    desc.fConfig = backendRT.config();
+    desc.fConfig = config;
     desc.fSampleCnt = 1;
 
     sk_sp<GrVkImageLayout> layout = backendRT.getGrVkImageLayout();
@@ -1290,13 +1299,14 @@
 }
 
 sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
-                                                                  int sampleCnt) {
+                                                                  int sampleCnt,
+                                                                  GrColorType grColorType) {
 
     GrVkImageInfo imageInfo;
     if (!tex.getVkImageInfo(&imageInfo)) {
         return nullptr;
     }
-    if (!check_image_info(this->vkCaps(), imageInfo, tex.config(), false)) {
+    if (!check_image_info(this->vkCaps(), imageInfo, grColorType, false)) {
         return nullptr;
     }
     if (!check_rt_image_info(this->vkCaps(), imageInfo)) {
@@ -1307,12 +1317,17 @@
         return nullptr;
     }
 
+    GrPixelConfig config = this->caps()->getConfigFromBackendFormat(tex.getBackendFormat(),
+                                                                    grColorType);
+    SkASSERT(kUnknown_GrPixelConfig != config);
+
     GrSurfaceDesc desc;
     desc.fWidth = tex.width();
     desc.fHeight = tex.height();
     desc.fIsProtected = tex.isProtected() ? GrProtected::kYes : GrProtected::kNo;
-    desc.fConfig = tex.config();
-    desc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, tex.config());
+    desc.fConfig = config;
+    desc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, grColorType,
+                                                               tex.getBackendFormat());
     if (!desc.fSampleCnt) {
         return nullptr;
     }
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index 45b0090..6b1c3f3 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -196,17 +196,18 @@
     sk_sp<GrTexture> onCreateCompressedTexture(int width, int height, SkImage::CompressionType,
                                                SkBudgeted, const void* data) override;
 
-    sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
-                                          GrIOType) override;
+    sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType, GrWrapOwnership,
+                                          GrWrapCacheable, GrIOType) override;
     sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
                                                     int sampleCnt,
                                                     GrColorType colorType,
                                                     GrWrapOwnership,
                                                     GrWrapCacheable) override;
-    sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
+    sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
+                                                    GrColorType) override;
 
     sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
-                                                             int sampleCnt) override;
+                                                             int sampleCnt, GrColorType) override;
 
     sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
                                                                 const GrVkDrawableInfo&) override;
diff --git a/src/gpu/vk/GrVkUtil.cpp b/src/gpu/vk/GrVkUtil.cpp
index 7101201..205f44c 100644
--- a/src/gpu/vk/GrVkUtil.cpp
+++ b/src/gpu/vk/GrVkUtil.cpp
@@ -97,56 +97,35 @@
 }
 
 #ifdef SK_DEBUG
-bool GrVkFormatPixelConfigPairIsValid(VkFormat format, GrPixelConfig config) {
+bool GrVkFormatColorTypePairIsValid(VkFormat format, GrColorType colorType) {
     switch (format) {
-        case VK_FORMAT_R8G8B8A8_UNORM:
-            return kRGBA_8888_GrPixelConfig == config ||
-                   kRGB_888X_GrPixelConfig == config;
-        case VK_FORMAT_B8G8R8A8_UNORM:
-            return kBGRA_8888_GrPixelConfig == config;
-        case VK_FORMAT_R8G8B8A8_SRGB:
-            return kSRGBA_8888_GrPixelConfig == config;
-        case VK_FORMAT_R8G8B8_UNORM:
-            return kRGB_888_GrPixelConfig == config;
-        case VK_FORMAT_R8G8_UNORM:
-            return kRG_88_GrPixelConfig == config;
-        case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
-            return kRGBA_1010102_GrPixelConfig == config;
-        case VK_FORMAT_R5G6B5_UNORM_PACK16:
-            return kRGB_565_GrPixelConfig == config;
-        case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
-            // R4G4B4A4 is not required to be supported so we actually
-            // store RGBA_4444 data as B4G4R4A4.
-            return kRGBA_4444_GrPixelConfig == config;
-        case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
-            return kRGBA_4444_GrPixelConfig == config;
-        case VK_FORMAT_R8_UNORM:
-            return kAlpha_8_GrPixelConfig == config ||
-                   kAlpha_8_as_Red_GrPixelConfig == config ||
-                   kGray_8_GrPixelConfig == config ||
-                   kGray_8_as_Red_GrPixelConfig == config;
-        case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
-            return kRGB_ETC1_GrPixelConfig == config;
-        case VK_FORMAT_R32G32B32A32_SFLOAT:
-            return kRGBA_float_GrPixelConfig == config;
-        case VK_FORMAT_R16G16B16A16_SFLOAT:
-            return kRGBA_half_GrPixelConfig == config ||
-                   kRGBA_half_Clamped_GrPixelConfig == config;
-        case VK_FORMAT_R16_SFLOAT:
-            return kAlpha_half_GrPixelConfig == config ||
-                   kAlpha_half_as_Red_GrPixelConfig == config;
-        case VK_FORMAT_R16_UNORM:
-            return kR_16_GrPixelConfig == config;
-        case VK_FORMAT_R16G16_UNORM:
-            return kRG_1616_GrPixelConfig == config;
+        case VK_FORMAT_R8G8B8A8_UNORM:           return GrColorType::kRGBA_8888 == colorType ||
+                                                        GrColorType::kRGB_888x == colorType;
+        case VK_FORMAT_B8G8R8A8_UNORM:           return GrColorType::kBGRA_8888 == colorType;
+        case VK_FORMAT_R8G8B8A8_SRGB:            return GrColorType::kRGBA_8888_SRGB == colorType;
+        case VK_FORMAT_R8G8B8_UNORM:             return GrColorType::kRGB_888x == colorType;
+        case VK_FORMAT_R8G8_UNORM:               return GrColorType::kRG_88 == colorType;
+        case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return GrColorType::kRGBA_1010102 == colorType;
+        case VK_FORMAT_R5G6B5_UNORM_PACK16:      return GrColorType::kBGR_565 == colorType;
+        // R4G4B4A4 is not required to be supported so we actually
+        // store RGBA_4444 data as B4G4R4A4.
+        case VK_FORMAT_B4G4R4A4_UNORM_PACK16:    return GrColorType::kABGR_4444 == colorType;
+        case VK_FORMAT_R4G4B4A4_UNORM_PACK16:    return GrColorType::kABGR_4444 == colorType;
+        case VK_FORMAT_R8_UNORM:                 return GrColorType::kAlpha_8 == colorType ||
+                                                        GrColorType::kGray_8 == colorType;
+        case VK_FORMAT_R32G32B32A32_SFLOAT:      return GrColorType::kRGBA_F32 == colorType;
+        case VK_FORMAT_R16G16B16A16_SFLOAT:      return GrColorType::kRGBA_F16 == colorType ||
+                                                        GrColorType::kRGBA_F16_Clamped == colorType;
+        case VK_FORMAT_R16_SFLOAT:               return GrColorType::kAlpha_F16 == colorType;
+        case VK_FORMAT_R16_UNORM:                return GrColorType::kR_16 == colorType;
+        case VK_FORMAT_R16G16_UNORM:             return GrColorType::kRG_1616 == colorType;
         // Experimental (for Y416 and mutant P016/P010)
-        case VK_FORMAT_R16G16B16A16_UNORM:
-            return kRGBA_16161616_GrPixelConfig == config;
-        case VK_FORMAT_R16G16_SFLOAT:
-            return kRG_half_GrPixelConfig == config;
-        default:
-            return false;
+        case VK_FORMAT_R16G16B16A16_UNORM:       return GrColorType::kRGBA_16161616 == colorType;
+        case VK_FORMAT_R16G16_SFLOAT:            return GrColorType::kRG_F16 == colorType;
+        default:                                 return false;
     }
+
+    SkUNREACHABLE;
 }
 #endif
 
diff --git a/src/gpu/vk/GrVkUtil.h b/src/gpu/vk/GrVkUtil.h
index 6c77c74..04c1acd 100644
--- a/src/gpu/vk/GrVkUtil.h
+++ b/src/gpu/vk/GrVkUtil.h
@@ -38,9 +38,9 @@
 
 #ifdef SK_DEBUG
 /**
- * Returns true if the passed in VkFormat and GrPixelConfig are compatible with each other.
+ * Returns true if the passed in VkFormat and GrColorType are compatible with each other.
  */
-bool GrVkFormatPixelConfigPairIsValid(VkFormat, GrPixelConfig);
+bool GrVkFormatColorTypePairIsValid(VkFormat, GrColorType);
 #endif
 
 bool GrSampleCountToVkSampleCount(uint32_t samples, VkSampleCountFlagBits* vkSamples);
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 70b36c7..011a6de 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -116,7 +116,7 @@
 
 static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx,
                                                  const GrBackendTexture& backendTex,
-                                                 GrSurfaceOrigin origin,
+                                                 GrColorType colorType, GrSurfaceOrigin origin,
                                                  SkAlphaType at, sk_sp<SkColorSpace> colorSpace,
                                                  GrWrapOwnership ownership,
                                                  SkImage::TextureReleaseProc releaseProc,
@@ -127,8 +127,9 @@
 
     GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
     sk_sp<GrTextureProxy> proxy =
-            proxyProvider->wrapBackendTexture(backendTex, origin, ownership, GrWrapCacheable::kNo,
-                                              kRead_GrIOType, releaseProc, releaseCtx);
+            proxyProvider->wrapBackendTexture(backendTex, colorType, origin, ownership,
+                                              GrWrapCacheable::kNo, kRead_GrIOType,
+                                              releaseProc, releaseCtx);
     if (!proxy) {
         return nullptr;
     }
@@ -143,11 +144,20 @@
     if (!ctx) {
         return nullptr;
     }
-    GrBackendTexture texCopy = tex;
-    if (!SkImage_GpuBase::ValidateBackendTexture(ctx, texCopy, &texCopy.fConfig, ct, at, cs)) {
+
+    GrColorType grColorType = SkColorTypeAndFormatToGrColorType(ctx->priv().caps(), ct,
+                                                                tex.getBackendFormat());
+    if (GrColorType::kUnknown == grColorType) {
         return nullptr;
     }
-    return new_wrapped_texture_common(ctx, texCopy, origin, at, std::move(cs),
+
+    GrBackendTexture texCopy = tex;
+    if (!SkImage_GpuBase::ValidateBackendTexture(ctx, texCopy, &texCopy.fConfig, grColorType,
+                                                 ct, at, cs)) {
+        return nullptr;
+    }
+
+    return new_wrapped_texture_common(ctx, texCopy, grColorType, origin, at, std::move(cs),
                                       kBorrow_GrWrapOwnership, releaseP, releaseC);
 }
 
@@ -159,11 +169,20 @@
         // We have a DDL context and we don't support adopted textures for them.
         return nullptr;
     }
-    GrBackendTexture texCopy = tex;
-    if (!SkImage_GpuBase::ValidateBackendTexture(ctx, texCopy, &texCopy.fConfig, ct, at, cs)) {
+
+    GrColorType grColorType = SkColorTypeAndFormatToGrColorType(ctx->priv().caps(), ct,
+                                                                tex.getBackendFormat());
+    if (GrColorType::kUnknown == grColorType) {
         return nullptr;
     }
-    return new_wrapped_texture_common(ctx, texCopy, origin, at, std::move(cs),
+
+    GrBackendTexture texCopy = tex;
+    if (!SkImage_GpuBase::ValidateBackendTexture(ctx, texCopy, &texCopy.fConfig, grColorType,
+                                                 ct, at, cs)) {
+        return nullptr;
+    }
+
+    return new_wrapped_texture_common(ctx, texCopy, grColorType, origin, at, std::move(cs),
                                       kAdopt_GrWrapOwnership, nullptr, nullptr);
 }
 
@@ -243,11 +262,18 @@
         GrSurfaceOrigin imageOrigin,
         const GrBackendTexture& backendTexture,
         sk_sp<SkColorSpace> imageColorSpace) {
-    GrBackendTexture backendTextureCopy = backendTexture;
 
+    GrColorType grColorType = SkColorTypeAndFormatToGrColorType(ctx->priv().caps(),
+                                                                kRGBA_8888_SkColorType,
+                                                                backendTexture.getBackendFormat());
+    if (GrColorType::kUnknown == grColorType) {
+        return nullptr;
+    }
+
+    GrBackendTexture backendTextureCopy = backendTexture;
     SkAlphaType at = SkImage_GpuBase::GetAlphaTypeFromYUVAIndices(yuvaIndices);
     if (!SkImage_Gpu::ValidateBackendTexture(ctx, backendTextureCopy, &backendTextureCopy.fConfig,
-                                             kRGBA_8888_SkColorType, at, nullptr)) {
+                                             grColorType, kRGBA_8888_SkColorType, at, nullptr)) {
         return nullptr;
     }
 
@@ -255,7 +281,7 @@
     // in order to draw to it for the yuv->rgb conversion.
     sk_sp<GrRenderTargetContext> renderTargetContext(
             ctx->priv().makeBackendTextureRenderTargetContext(backendTextureCopy, imageOrigin, 1,
-                                                              GrColorType::kRGBA_8888,
+                                                              grColorType,
                                                               std::move(imageColorSpace)));
 
     if (!renderTargetContext) {
@@ -414,15 +440,16 @@
         return nullptr;
     }
 
-    GrPixelConfig config =
-            context->priv().caps()->getConfigFromBackendFormat(backendFormat,
-                                                               SkColorTypeToGrColorType(colorType));
-    if (config == kUnknown_GrPixelConfig) {
+    GrColorType grColorType = SkColorTypeAndFormatToGrColorType(context->priv().caps(),
+                                                                colorType,
+                                                                backendFormat);
+    if (GrColorType::kUnknown == grColorType) {
         return nullptr;
     }
 
     callDone.clear();
-    auto proxy = MakePromiseImageLazyProxy(context, width, height, origin, config, backendFormat,
+    auto proxy = MakePromiseImageLazyProxy(context, width, height, origin,
+                                           grColorType, backendFormat,
                                            mipMapped, textureFulfillProc, textureReleaseProc,
                                            textureDoneProc, textureContext, version);
     if (!proxy) {
@@ -601,8 +628,9 @@
     SkColorType colorType =
             GrAHardwareBufferUtils::GetSkColorTypeFromBufferFormat(bufferDesc.format);
 
+    GrColorType grColorType = SkColorTypeToGrColorType(colorType);
     backendTexture.fConfig = context->priv().caps()->getConfigFromBackendFormat(
-            backendFormat, SkColorTypeToGrColorType(colorType));
+            backendFormat, grColorType);
 
     GrProxyProvider* proxyProvider = context->priv().proxyProvider();
     if (!proxyProvider) {
@@ -611,7 +639,7 @@
     }
 
     sk_sp<GrTextureProxy> proxy =
-            proxyProvider->wrapBackendTexture(backendTexture, surfaceOrigin,
+            proxyProvider->wrapBackendTexture(backendTexture, grColorType, surfaceOrigin,
                                               kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
                                               kRW_GrIOType, deleteImageProc, deleteImageCtx);
     if (!proxy) {
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index efce01d..595ca3c 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -39,7 +39,8 @@
 #endif
 
 bool SkImage_GpuBase::ValidateBackendTexture(GrContext* ctx, const GrBackendTexture& tex,
-                                             GrPixelConfig* config, SkColorType ct, SkAlphaType at,
+                                             GrPixelConfig* config, GrColorType grCT,
+                                             SkColorType ct, SkAlphaType at,
                                              sk_sp<SkColorSpace> cs) {
     if (!tex.isValid()) {
         return false;
@@ -55,16 +56,6 @@
         return false;
     }
 
-    GrColorType grCT = SkColorTypeToGrColorType(ct);
-    // Until we support SRGB in the SkColorType we have to do this manual check here to make sure
-    // we use the correct GrColorType.
-    if (ctx->priv().caps()->isFormatSRGB(backendFormat)) {
-        if (grCT != GrColorType::kRGBA_8888) {
-            return false;
-        }
-        grCT = GrColorType::kRGBA_8888_SRGB;
-    }
-
     *config = ctx->priv().caps()->getConfigFromBackendFormat(backendFormat, grCT);
     return *config != kUnknown_GrPixelConfig;
 }
@@ -247,6 +238,7 @@
                                              GrSurfaceOrigin imageOrigin,
                                              sk_sp<GrTextureProxy> tempTextureProxies[4]) {
     GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
+    const GrCaps* caps = ctx->priv().caps();
 
     // We need to make a copy of the input backend textures because we need to preserve the result
     // of validate_backend_texture.
@@ -258,39 +250,46 @@
             return false;
         }
         yuvaTexturesCopy[textureIndex].fConfig =
-                ctx->priv().caps()->getYUVAConfigFromBackendFormat(backendFormat);
+                caps->getYUVAConfigFromBackendFormat(backendFormat);
         if (yuvaTexturesCopy[textureIndex].fConfig == kUnknown_GrPixelConfig) {
             return false;
         }
+        GrColorType grColorType = caps->getYUVAColorTypeFromBackendFormat(backendFormat);
+        if (GrColorType::kUnknown == grColorType) {
+            return false;
+        }
+
         SkASSERT(yuvaTexturesCopy[textureIndex].isValid());
 
         tempTextureProxies[textureIndex] = proxyProvider->wrapBackendTexture(
-                yuvaTexturesCopy[textureIndex], imageOrigin, kBorrow_GrWrapOwnership,
+                yuvaTexturesCopy[textureIndex], grColorType, imageOrigin, kBorrow_GrWrapOwnership,
                 GrWrapCacheable::kNo, kRead_GrIOType);
         if (!tempTextureProxies[textureIndex]) {
             return false;
         }
 
         // Check that each texture contains the channel data for the corresponding YUVA index
-        GrPixelConfig config = yuvaTexturesCopy[textureIndex].fConfig;
+        auto componentFlags = GrColorTypeComponentFlags(grColorType);
         for (int yuvaIndex = 0; yuvaIndex < SkYUVAIndex::kIndexCount; ++yuvaIndex) {
             if (yuvaIndices[yuvaIndex].fIndex == textureIndex) {
                 switch (yuvaIndices[yuvaIndex].fChannel) {
                     case SkColorChannel::kR:
-                        if (kAlpha_8_as_Alpha_GrPixelConfig == config) {
+                        if (!(kRed_SkColorTypeComponentFlag & componentFlags)) {
                             return false;
                         }
                         break;
                     case SkColorChannel::kG:
+                        if (!(kGreen_SkColorTypeComponentFlag & componentFlags)) {
+                            return false;
+                        }
+                        break;
                     case SkColorChannel::kB:
-                        if (kAlpha_8_as_Alpha_GrPixelConfig == config ||
-                            kAlpha_8_as_Red_GrPixelConfig == config) {
+                        if (!(kBlue_SkColorTypeComponentFlag & componentFlags)) {
                             return false;
                         }
                         break;
                     case SkColorChannel::kA:
-                    default:
-                        if (kRGB_888_GrPixelConfig == config) {
+                        if (!(kAlpha_SkColorTypeComponentFlag & componentFlags)) {
                             return false;
                         }
                         break;
@@ -327,7 +326,7 @@
 }
 
 sk_sp<GrTextureProxy> SkImage_GpuBase::MakePromiseImageLazyProxy(
-        GrContext* context, int width, int height, GrSurfaceOrigin origin, GrPixelConfig config,
+        GrContext* context, int width, int height, GrSurfaceOrigin origin, GrColorType colorType,
         GrBackendFormat backendFormat, GrMipMapped mipMapped,
         PromiseImageTextureFulfillProc fulfillProc,
         PromiseImageTextureReleaseProc releaseProc,
@@ -337,7 +336,7 @@
     SkASSERT(context);
     SkASSERT(width > 0 && height > 0);
     SkASSERT(doneProc);
-    SkASSERT(config != kUnknown_GrPixelConfig);
+    SkASSERT(colorType != GrColorType::kUnknown);
 
     if (!fulfillProc || !releaseProc) {
         doneProc(textureContext);
@@ -372,11 +371,11 @@
                                        PromiseImageTextureReleaseProc releaseProc,
                                        PromiseImageTextureDoneProc doneProc,
                                        PromiseImageTextureContext context,
-                                       GrPixelConfig config,
+                                       GrColorType colorType,
                                        PromiseImageApiVersion version)
                 : fFulfillProc(fulfillProc)
                 , fReleaseProc(releaseProc)
-                , fConfig(config)
+                , fColorType(colorType)
                 , fVersion(version) {
             fDoneCallback = sk_make_sp<GrRefCntedCallback>(doneProc, context);
         }
@@ -409,7 +408,7 @@
             // Fulfill once. So return our cached result.
             if (fTexture) {
                 return {sk_ref_sp(fTexture), kKeySyncMode};
-            } else if (fConfig == kUnknown_GrPixelConfig) {
+            } else if (fColorType == GrColorType::kUnknown) {
                 // We've already called fulfill and it failed. Our contract says that we should only
                 // call each callback once.
                 return {};
@@ -422,22 +421,30 @@
             auto releaseCallback = sk_make_sp<GrRefCntedCallback>(fReleaseProc, textureContext);
             if (!promiseTexture) {
                 // This records that we have failed.
-                fConfig = kUnknown_GrPixelConfig;
+                fColorType = GrColorType::kUnknown;
                 return {};
             }
 
             auto backendTexture = promiseTexture->backendTexture();
-            backendTexture.fConfig = fConfig;
             if (!backendTexture.isValid()) {
                 return {};
             }
 
+            // TODO: delete this block
+            {
+                GrPixelConfig config = resourceProvider->caps()->getConfigFromBackendFormat(
+                                                                backendTexture.getBackendFormat(),
+                                                                fColorType);
+                SkASSERT(kUnknown_GrPixelConfig != config);
+                backendTexture.fConfig = config;
+            }
+
             sk_sp<GrTexture> tex;
             static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
             GrUniqueKey key;
             GrUniqueKey::Builder builder(&key, kDomain, 2, "promise");
             builder[0] = promiseTexture->uniqueID();
-            builder[1] = fConfig;
+            builder[1] = (uint32_t) fColorType;
             builder.finish();
             // A texture with this key may already exist from a different instance of this lazy
             // callback. This could happen if the client fulfills a promise image with a texture
@@ -447,8 +454,8 @@
                 SkASSERT(tex);
             } else {
                 if ((tex = resourceProvider->wrapBackendTexture(
-                             backendTexture, kBorrow_GrWrapOwnership, GrWrapCacheable::kYes,
-                             kRead_GrIOType))) {
+                             backendTexture, fColorType, kBorrow_GrWrapOwnership,
+                             GrWrapCacheable::kYes, kRead_GrIOType))) {
                     tex->resourcePriv().setUniqueKey(key);
                 } else {
                     return {};
@@ -477,12 +484,16 @@
         sk_sp<GrRefCntedCallback> fDoneCallback;
         GrTexture* fTexture = nullptr;
         uint32_t fTextureContextID = SK_InvalidUniqueID;
-        GrPixelConfig fConfig;
+        GrColorType fColorType;
         PromiseImageApiVersion fVersion;
-    } callback(fulfillProc, releaseProc, doneProc, textureContext, config, version);
+    } callback(fulfillProc, releaseProc, doneProc, textureContext, colorType, version);
 
     GrProxyProvider* proxyProvider = context->priv().proxyProvider();
 
+    GrPixelConfig config = context->priv().caps()->getConfigFromBackendFormat(
+                                                                     backendFormat,
+                                                                     colorType);
+
     GrSurfaceDesc desc;
     desc.fWidth = width;
     desc.fHeight = height;
diff --git a/src/image/SkImage_GpuBase.h b/src/image/SkImage_GpuBase.h
index c48c48e..6a3c516 100644
--- a/src/image/SkImage_GpuBase.h
+++ b/src/image/SkImage_GpuBase.h
@@ -58,7 +58,8 @@
 #endif
 
     static bool ValidateBackendTexture(GrContext* ctx, const GrBackendTexture& tex,
-                                       GrPixelConfig* config, SkColorType ct, SkAlphaType at,
+                                       GrPixelConfig* config, GrColorType grCT,
+                                       SkColorType ct, SkAlphaType at,
                                        sk_sp<SkColorSpace> cs);
     static bool MakeTempTextureProxies(GrContext* ctx, const GrBackendTexture yuvaTextures[],
                                        int numTextures, const SkYUVAIndex [4],
@@ -84,7 +85,7 @@
     // proxy along with the TextureFulfillProc and TextureReleaseProc. PromiseDoneProc must not
     // be null.
     static sk_sp<GrTextureProxy> MakePromiseImageLazyProxy(
-            GrContext*, int width, int height, GrSurfaceOrigin, GrPixelConfig, GrBackendFormat,
+            GrContext*, int width, int height, GrSurfaceOrigin, GrColorType, GrBackendFormat,
             GrMipMapped, PromiseImageTextureFulfillProc, PromiseImageTextureReleaseProc,
             PromiseImageTextureDoneProc, PromiseImageTextureContext, PromiseImageApiVersion);
 
diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp
index 7b938dd..7eef716 100644
--- a/src/image/SkImage_GpuYUVA.cpp
+++ b/src/image/SkImage_GpuYUVA.cpp
@@ -354,15 +354,16 @@
     // Get lazy proxies
     sk_sp<GrTextureProxy> proxies[4];
     for (int texIdx = 0; texIdx < numTextures; ++texIdx) {
-        GrPixelConfig config =
-                context->priv().caps()->getYUVAConfigFromBackendFormat(yuvaFormats[texIdx]);
-        if (config == kUnknown_GrPixelConfig) {
+        GrColorType colorType = context->priv().caps()->getYUVAColorTypeFromBackendFormat(
+                                                                            yuvaFormats[texIdx]);
+        if (GrColorType::kUnknown == colorType) {
             return nullptr;
         }
+
         proxies[texIdx] = MakePromiseImageLazyProxy(
-                context, yuvaSizes[texIdx].width(), yuvaSizes[texIdx].height(), imageOrigin, config,
-                yuvaFormats[texIdx], GrMipMapped::kNo, textureFulfillProc, textureReleaseProc,
-                promiseDoneProc, textureContexts[texIdx], version);
+                context, yuvaSizes[texIdx].width(), yuvaSizes[texIdx].height(), imageOrigin,
+                colorType, yuvaFormats[texIdx], GrMipMapped::kNo, textureFulfillProc,
+                textureReleaseProc, promiseDoneProc, textureContexts[texIdx], version);
         ++proxiesCreated;
         if (!proxies[texIdx]) {
             return nullptr;
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 6bc6d3d..1487328 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -426,21 +426,6 @@
     return true;
 }
 
-static GrColorType get_grcolortype_from_skcolortype_and_format(const GrCaps* caps,
-                                                               SkColorType skCT,
-                                                               const GrBackendFormat& format) {
-    GrColorType grCT = SkColorTypeToGrColorType(skCT);
-    // Until we support SRGB in the SkColorType we have to do this manual check here to make sure
-    // we use the correct GrColorType.
-    if (caps->isFormatSRGB(format)) {
-        if (grCT != GrColorType::kRGBA_8888) {
-            return GrColorType::kUnknown;
-        }
-        grCT = GrColorType::kRGBA_8888_SRGB;
-    }
-    return grCT;
-}
-
 sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context,
                                                    const SkSurfaceCharacterization& c,
                                                    const GrBackendTexture& backendTexture,
@@ -459,8 +444,8 @@
         return nullptr;
     }
 
-    GrColorType grCT = get_grcolortype_from_skcolortype_and_format(
-            context->priv().caps(), c.colorType(), backendTexture.getBackendFormat());
+    GrColorType grCT = SkColorTypeAndFormatToGrColorType(context->priv().caps(), c.colorType(),
+                                                         backendTexture.getBackendFormat());
     if (grCT == GrColorType::kUnknown) {
         return nullptr;
     }
@@ -551,8 +536,8 @@
     }
     sampleCnt = SkTMax(1, sampleCnt);
 
-    GrColorType grColorType = get_grcolortype_from_skcolortype_and_format(
-            context->priv().caps(), colorType, tex.getBackendFormat());
+    GrColorType grColorType = SkColorTypeAndFormatToGrColorType(context->priv().caps(), colorType,
+                                                                tex.getBackendFormat());
     if (grColorType == GrColorType::kUnknown) {
         return nullptr;
     }
@@ -672,8 +657,8 @@
         return nullptr;
     }
 
-    GrColorType grColorType = get_grcolortype_from_skcolortype_and_format(
-            context->priv().caps(), colorType, rt.getBackendFormat());
+    GrColorType grColorType = SkColorTypeAndFormatToGrColorType(context->priv().caps(), colorType,
+                                                                rt.getBackendFormat());
     if (grColorType == GrColorType::kUnknown) {
         return nullptr;
     }
@@ -718,8 +703,8 @@
     }
 
     sampleCnt = SkTMax(1, sampleCnt);
-    GrColorType grColorType = get_grcolortype_from_skcolortype_and_format(
-            context->priv().caps(), colorType, tex.getBackendFormat());
+    GrColorType grColorType = SkColorTypeAndFormatToGrColorType(context->priv().caps(), colorType,
+                                                                tex.getBackendFormat());
     if (grColorType == GrColorType::kUnknown) {
         return nullptr;
     }