Add new SkImage factory to create from GrBackendTexture with SkColorType

Bug: skia:
Change-Id: I46bdc54b6d9cdacc8f5a06644aa6b110837879f0
Reviewed-on: https://skia-review.googlesource.com/84342
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/gm/rectangletexture.cpp b/gm/rectangletexture.cpp
index c71a51c..2fb64be 100644
--- a/gm/rectangletexture.cpp
+++ b/gm/rectangletexture.cpp
@@ -108,11 +108,13 @@
         GrGLTextureInfo info;
         info.fID = id;
         info.fTarget = TARGET;
+        info.fFormat = GR_GL_RGBA8;
 
-        GrBackendTexture rectangleTex(width, height, kRGBA_8888_GrPixelConfig, info);
+        GrBackendTexture rectangleTex(width, height, GrMipMapped::kNo, info);
 
         if (sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(context, rectangleTex,
-                                                                   kTopLeft_GrSurfaceOrigin)) {
+                                                                   kTopLeft_GrSurfaceOrigin,
+                                                                   kRGBA_8888_SkColorType)) {
             return image;
         }
         GR_GL_CALL(gl, DeleteTextures(1, &id));
diff --git a/include/core/SkImage.h b/include/core/SkImage.h
index 03d463d..2a196aa 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -96,6 +96,9 @@
      *  managing the lifetime of the underlying platform texture.
      *
      *  Will return NULL if the specified backend texture is unsupported.
+     *
+     *  DEPRECATED: This factory is deprecated and clients should use the factory below which takes
+     *  an SkColorType.
      */
     static sk_sp<SkImage> MakeFromTexture(GrContext* context,
                                           const GrBackendTexture& backendTexture,
@@ -112,6 +115,9 @@
      *  no longer is holding a reference to it.
      *
      *  Will return NULL if the specified backend texture is unsupported.
+     *
+     *  DEPRECATED: This factory is deprecated and clients should use the factory below which takes
+     *  an SkColorType.
      */
     static sk_sp<SkImage> MakeFromTexture(GrContext* context,
                                           const GrBackendTexture& backendTexture,
@@ -122,6 +128,46 @@
                                           ReleaseContext releaseContext);
 
     /**
+     *  Create a new image from the specified descriptor. Note - the caller is responsible for
+     *  managing the lifetime of the underlying platform texture.
+     *
+     *  The GrBackendTexture mush have a valid backed format supplied (GrGLTextureInfo::fFormat,
+     *  GrVkImageInfo::fFormat, etc.) in it. The passed in SkColorType informs skia how it should
+     *  interpret the backend format supplied by the GrBackendTexture. If the format in the
+     *  GrBackendTexture is not compitable with the SkColorType, SkAlphaType, and SkColorSpace we
+     *  will return nullptr.
+     */
+    static sk_sp<SkImage> MakeFromTexture(GrContext* context,
+                                          const GrBackendTexture& backendTexture,
+                                          GrSurfaceOrigin origin,
+                                          SkColorType colorType,
+                                          SkAlphaType alphaType,
+                                          sk_sp<SkColorSpace> colorSpace) {
+        return MakeFromTexture(context, backendTexture, origin, colorType, alphaType, colorSpace,
+                               nullptr, nullptr);
+    }
+
+    /**
+     *  Create a new image from the GrBackendTexture. The underlying platform texture must stay
+     *  valid and unaltered until the specified release-proc is invoked, indicating that Skia
+     *  no longer is holding a reference to it.
+     *
+     *  The GrBackendTexture mush have a valid backed format supplied (GrGLTextureInfo::fFormat,
+     *  GrVkImageInfo::fFormat, etc.) in it. The passed in SkColorType informs skia how it should
+     *  interpret the backend format supplied by the GrBackendTexture. If the format in the
+     *  GrBackendTexture is not compitable with the SkColorType, SkAlphaType, and SkColorSpace we
+     *  will return nullptr.
+     */
+    static sk_sp<SkImage> MakeFromTexture(GrContext* context,
+                                          const GrBackendTexture& backendTexture,
+                                          GrSurfaceOrigin origin,
+                                          SkColorType colorType,
+                                          SkAlphaType alphaType,
+                                          sk_sp<SkColorSpace> colorSpace,
+                                          TextureReleaseProc textureReleaseProc,
+                                          ReleaseContext releaseContext);
+
+    /**
      *  Decodes and uploads the encoded data to a GPU backed image using the supplied GrContext.
      *  That image can be safely used by other GrContexts, across thread boundaries. The GrContext
      *  used here, and the ones used to draw this image later must be in the same GL share group,
@@ -158,6 +204,9 @@
      *  texture when the image is released.
      *
      *  Will return NULL if the specified backend texture is unsupported.
+     *
+     *  DEPRECATED: This factory is deprecated and clients should use the factory below which takes
+     *  an SkColorType.
      */
     static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context,
                                                  const GrBackendTexture& backendTexture,
@@ -166,6 +215,23 @@
                                                  sk_sp<SkColorSpace> colorSpace = nullptr);
 
     /**
+     *  Create a new image from the specified descriptor. Note - Skia will delete or recycle the
+     *  texture when the image is released.
+     *
+     *  The GrBackendTexture mush have a valid backed format supplied (GrGLTextureInfo::fFormat,
+     *  GrVkImageInfo::fFormat, etc.) in it. The passed in SkColorType informs skia how it should
+     *  interpret the backend format supplied by the GrBackendTexture. If the format in the
+     *  GrBackendTexture is not compitable with the SkColorType, SkAlphaType, and SkColorSpace we
+     *  will return nullptr.
+     */
+    static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context,
+                                                 const GrBackendTexture& backendTexture,
+                                                 GrSurfaceOrigin surfaceOrigin,
+                                                 SkColorType colorType,
+                                                 SkAlphaType alphaType = kPremul_SkAlphaType,
+                                                 sk_sp<SkColorSpace> colorSpace = nullptr);
+
+    /**
      *  Create a new image by copying the pixels from the specified y, u, v textures. The data
      *  from the textures is immediately ingested into the image and the textures can be modified or
      *  deleted after the function returns. The image will have the dimensions of the y texture.
diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h
index 1eab357..9f77155 100644
--- a/include/gpu/GrBackendSurface.h
+++ b/include/gpu/GrBackendSurface.h
@@ -84,8 +84,11 @@
 private:
     // Friending for access to the GrPixelConfig
     friend class SkSurface;
+    friend class GrCaps;
     friend class GrGpu;
+    friend class GrGLCaps;
     friend class GrGLGpu;
+    friend class GrVkCaps;
     friend class GrVkGpu;
     GrPixelConfig config() const { return fConfig; }
 
@@ -146,8 +149,11 @@
 private:
     // Friending for access to the GrPixelConfig
     friend class SkSurface;
+    friend class GrCaps;
     friend class GrGpu;
+    friend class GrGLCaps;
     friend class GrGLGpu;
+    friend class GrVkCaps;
     friend class GrVkGpu;
     GrPixelConfig config() const { return fConfig; }
 
diff --git a/include/gpu/GrCaps.h b/include/gpu/GrCaps.h
index 6cdc0e3..59e0528 100644
--- a/include/gpu/GrCaps.h
+++ b/include/gpu/GrCaps.h
@@ -11,9 +11,11 @@
 #include "../private/GrTypesPriv.h"
 #include "GrBlend.h"
 #include "GrShaderCaps.h"
+#include "SkImageInfo.h"
 #include "SkRefCnt.h"
 #include "SkString.h"
 
+class GrBackendTexture;
 struct GrContextOptions;
 class GrRenderTargetProxy;
 class SkJSONWriter;
@@ -170,6 +172,13 @@
     virtual bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
                                     bool* rectsMustMatch, bool* disallowSubrect) const = 0;
 
+    /**
+     * Returns true if the GrBackendTexutre can we used with the supplied SkColorType. If it is
+     * compatible, the GrPixelConfig on the GrBackendTexture will be set to a config that matches
+     * the backend format and requested SkColorType.
+     */
+    bool validateBackendTexture(GrBackendTexture* tex, SkColorType ct) const;
+
 protected:
     /** Subclasses must call this at the end of their constructors in order to apply caps
         overrides requested by the client. Note that overrides will only reduce the caps never
@@ -229,6 +238,7 @@
     int fMaxClipAnalyticFPs;
 
 private:
+    virtual bool onValidateBackendTexture(GrBackendTexture* tex, SkColorType ct) const = 0;
     virtual void onApplyOptionsOverrides(const GrContextOptions&) {}
     virtual void onDumpJSON(SkJSONWriter*) const {}
 
diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp
index 2c83cc3..8f6d27d 100644
--- a/src/gpu/GrCaps.cpp
+++ b/src/gpu/GrCaps.cpp
@@ -6,6 +6,8 @@
  */
 
 #include "GrCaps.h"
+
+#include "GrBackendSurface.h"
 #include "GrContextOptions.h"
 #include "GrWindowRectangles.h"
 #include "SkJSONWriter.h"
@@ -212,3 +214,12 @@
 
     writer->endObject();
 }
+
+bool GrCaps::validateBackendTexture(GrBackendTexture* tex, SkColorType ct) const {
+    if (!this->onValidateBackendTexture(tex, ct)) {
+        return false;
+    }
+    return this->isConfigTexturable(tex->fConfig);
+}
+
+
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index efc6628..05e3268 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -2361,3 +2361,58 @@
     return fConfigTable[config].fColorSampleCounts[count-1];
 }
 
+bool GrGLCaps::onValidateBackendTexture(GrBackendTexture* tex, SkColorType ct) const {
+    const GrGLTextureInfo* texInfo = tex->getGLTextureInfo();
+    if (!texInfo) {
+        return false;
+    }
+    GrGLenum format = texInfo->fFormat;
+    tex->fConfig = kUnknown_GrPixelConfig;
+
+    switch (ct) {
+        case kUnknown_SkColorType:
+            return false;
+        case kAlpha_8_SkColorType:
+            if (GR_GL_ALPHA8 == format) {
+                tex->fConfig = kAlpha_8_as_Alpha_GrPixelConfig;
+            } else if (GR_GL_R8 == format) {
+                tex->fConfig = kAlpha_8_as_Red_GrPixelConfig;
+            }
+            break;
+        case kRGB_565_SkColorType:
+            if (GR_GL_RGB565 == format) {
+                tex->fConfig = kRGB_565_GrPixelConfig;
+            }
+            break;
+        case kARGB_4444_SkColorType:
+            if (GR_GL_RGBA4 == format) {
+                tex->fConfig = kRGBA_4444_GrPixelConfig;
+            }
+            break;
+        case kRGBA_8888_SkColorType:
+            if (GR_GL_RGBA8 == format) {
+                tex->fConfig = kRGBA_8888_GrPixelConfig;
+            }
+            break;
+        case kBGRA_8888_SkColorType:
+            if (GR_GL_BGRA8 == format) {
+                tex->fConfig = kBGRA_8888_GrPixelConfig;
+            }
+            break;
+        case kGray_8_SkColorType:
+            if (GR_GL_LUMINANCE8 == format) {
+                tex->fConfig = kGray_8_as_Lum_GrPixelConfig;
+            } else if (GR_GL_R8 == format) {
+                tex->fConfig = kGray_8_as_Red_GrPixelConfig;
+            }
+            break;
+        case kRGBA_F16_SkColorType:
+            if (GR_GL_RGBA16F == format) {
+                tex->fConfig = kRGBA_half_GrPixelConfig;
+            }
+            break;
+    }
+
+    return kUnknown_GrPixelConfig != tex->fConfig;
+}
+
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 3a50e8a..38cbfe8 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -416,6 +416,8 @@
     }
 
 private:
+    bool onValidateBackendTexture(GrBackendTexture*, SkColorType) const override;
+
     enum ExternalFormatUsage {
         kTexImage_ExternalFormatUsage,
         kOther_ExternalFormatUsage,
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 95eb339..7b66bcc 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -4421,6 +4421,8 @@
         return GrBackendTexture();  // invalid
     }
 
+    info.fFormat = this->glCaps().configSizedInternalFormat(config);
+
     this->unbindCpuToGpuXferBuffer();
 
     // Figure out the number of mip levels.
@@ -4447,7 +4449,7 @@
         height = SkTMax(1, height / 2);
     }
 
-    return GrBackendTexture(w, h, config, mipMapped, info);
+    return GrBackendTexture(w, h, mipMapped, info);
 }
 
 bool GrGLGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const {
diff --git a/src/gpu/mock/GrMockCaps.h b/src/gpu/mock/GrMockCaps.h
index 47a5002..37bde82 100644
--- a/src/gpu/mock/GrMockCaps.h
+++ b/src/gpu/mock/GrMockCaps.h
@@ -52,6 +52,10 @@
     }
 
 private:
+    bool onValidateBackendTexture(GrBackendTexture* tex, SkColorType ct) const override {
+        return SkToBool(tex->getMockTextureInfo());
+    }
+
     GrMockOptions fOptions;
     typedef GrCaps INHERITED;
 };
diff --git a/src/gpu/mtl/GrMtlCaps.h b/src/gpu/mtl/GrMtlCaps.h
index 3f2adf8..bc8aac9 100644
--- a/src/gpu/mtl/GrMtlCaps.h
+++ b/src/gpu/mtl/GrMtlCaps.h
@@ -57,6 +57,10 @@
     }
 
 private:
+    bool onValidateBackendTexture(GrBackendTexture* tex, SkColorType ct) const override {
+        return false;
+    }
+
     void initFeatureSet(MTLFeatureSet featureSet);
 
     void initGrCaps(const id<MTLDevice> device);
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index 9e48983..17253a0 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -6,6 +6,8 @@
  */
 
 #include "GrVkCaps.h"
+
+#include "GrBackendSurface.h"
 #include "GrRenderTargetProxy.h"
 #include "GrShaderCaps.h"
 #include "GrVkUtil.h"
@@ -413,3 +415,55 @@
     return fConfigTable[config].fColorSampleCounts[count-1];
 }
 
+bool GrVkCaps::onValidateBackendTexture(GrBackendTexture* tex, SkColorType ct) const {
+    const GrVkImageInfo* imageInfo = tex->getVkImageInfo();
+    if (!imageInfo) {
+        return false;
+    }
+    VkFormat format = imageInfo->fFormat;
+    tex->fConfig = kUnknown_GrPixelConfig;
+
+    switch (ct) {
+        case kUnknown_SkColorType:
+            return false;
+        case kAlpha_8_SkColorType:
+            if (VK_FORMAT_R8_UNORM == format) {
+                tex->fConfig = kAlpha_8_as_Red_GrPixelConfig;
+            }
+            break;
+        case kRGB_565_SkColorType:
+            if (VK_FORMAT_R5G6B5_UNORM_PACK16 == format) {
+                tex->fConfig = kRGB_565_GrPixelConfig;
+            }
+            break;
+        case kARGB_4444_SkColorType:
+            if (VK_FORMAT_B4G4R4A4_UNORM_PACK16 == format) {
+                tex->fConfig = kRGBA_4444_GrPixelConfig;
+            }
+            break;
+        case kRGBA_8888_SkColorType:
+            if (VK_FORMAT_R8G8B8A8_UNORM == format) {
+                tex->fConfig = kRGBA_8888_GrPixelConfig;
+            }
+            break;
+        case kBGRA_8888_SkColorType:
+            if (VK_FORMAT_B8G8R8A8_UNORM == format) {
+                tex->fConfig = kBGRA_8888_GrPixelConfig;
+            }
+            break;
+        case kGray_8_SkColorType:
+            if (VK_FORMAT_R8_UNORM == format) {
+                tex->fConfig = kGray_8_as_Red_GrPixelConfig;
+            }
+            break;
+        case kRGBA_F16_SkColorType:
+            if (VK_FORMAT_R16G16B16A16_SFLOAT == format) {
+                tex->fConfig = kRGBA_half_GrPixelConfig;
+            }
+            break;
+    }
+
+    return kUnknown_GrPixelConfig != tex->fConfig;
+}
+
+
diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h
index 1a6e1bd..8d0ab5d 100644
--- a/src/gpu/vk/GrVkCaps.h
+++ b/src/gpu/vk/GrVkCaps.h
@@ -112,6 +112,8 @@
                             bool* rectsMustMatch, bool* disallowSubrect) const override;
 
 private:
+    bool onValidateBackendTexture(GrBackendTexture*, SkColorType) const override;
+
     enum VkVendor {
         kAMD_VkVendor = 4098,
         kImagination_VkVendor = 4112,
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index 5fdf58e..baf0221 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -2200,3 +2200,4 @@
     // The image layout change serves as a barrier, so no semaphore is needed
     return nullptr;
 }
+
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 09796cd..6b35a12 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -364,6 +364,13 @@
     return nullptr;
 }
 
+sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx,
+                                        const GrBackendTexture& tex, GrSurfaceOrigin origin,
+                                        SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs,
+                                        TextureReleaseProc releaseP, ReleaseContext releaseC) {
+    return nullptr;
+}
+
 bool SkImage::MakeBackendTextureFromSkImage(GrContext*,
                                             sk_sp<SkImage>,
                                             GrBackendTexture*,
@@ -377,6 +384,13 @@
     return nullptr;
 }
 
+sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx,
+                                               const GrBackendTexture& tex, GrSurfaceOrigin origin,
+                                               SkColorType ct, SkAlphaType at,
+                                               sk_sp<SkColorSpace> cs) {
+    return nullptr;
+}
+
 sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace space,
                                                 const GrBackendObject yuvTextureHandles[3],
                                                 const SkISize yuvSizes[3],
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 8766dad..bf80ac0 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -301,6 +301,29 @@
                                       releaseP, releaseC);
 }
 
+bool validate_backend_texture(GrContext* ctx, GrBackendTexture* tex,
+                              SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs) {
+    // TODO: Create a SkImageColorInfo struct for color, alpha, and color space so we don't need to
+    // create a fake image info here.
+    SkImageInfo info = SkImageInfo::Make(1, 1, ct, at, cs);
+    if (!SkImageInfoIsValidAllowNumericalCS(info)) {
+        return false;
+    }
+
+    return ctx->caps()->validateBackendTexture(tex, ct);
+}
+
+sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx,
+                                        const GrBackendTexture& tex, GrSurfaceOrigin origin,
+                                        SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs,
+                                        TextureReleaseProc releaseP, ReleaseContext releaseC) {
+    GrBackendTexture texCopy = tex;
+    if (!validate_backend_texture(ctx, &texCopy, ct, at, cs)) {
+        return nullptr;
+    }
+    return MakeFromTexture(ctx, texCopy, origin, at, cs, releaseP, releaseC);
+}
+
 sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx,
                                                const GrBackendTexture& tex, GrSurfaceOrigin origin,
                                                SkAlphaType at, sk_sp<SkColorSpace> cs) {
@@ -308,6 +331,17 @@
                                       nullptr, nullptr);
 }
 
+sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx,
+                                               const GrBackendTexture& tex, GrSurfaceOrigin origin,
+                                               SkColorType ct, SkAlphaType at,
+                                               sk_sp<SkColorSpace> cs) {
+    GrBackendTexture texCopy = tex;
+    if (!validate_backend_texture(ctx, &texCopy, ct, at, cs)) {
+        return nullptr;
+    }
+    return MakeFromAdoptedTexture(ctx, texCopy, origin, at, cs);
+}
+
 static GrBackendTexture make_backend_texture_from_handle(GrBackend backend,
                                                          int width, int height,
                                                          GrPixelConfig config,
diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp
index 58faec4..91fba5f 100644
--- a/tests/GrMipMappedTest.cpp
+++ b/tests/GrMipMappedTest.cpp
@@ -61,7 +61,9 @@
             } else {
                 image = SkImage::MakeFromTexture(context, backendTex,
                                                  kTopLeft_GrSurfaceOrigin,
-                                                 kPremul_SkAlphaType, nullptr);
+                                                 kRGBA_8888_SkColorType,
+                                                 kPremul_SkAlphaType, nullptr,
+                                                 nullptr, nullptr);
                 proxy = as_IB(image)->asTextureProxyRef();
             }
             REPORTER_ASSERT(reporter, proxy);
@@ -108,7 +110,9 @@
 
             sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backendTex,
                                                             kTopLeft_GrSurfaceOrigin,
-                                                            kPremul_SkAlphaType, nullptr);
+                                                            kRGBA_8888_SkColorType,
+                                                            kPremul_SkAlphaType, nullptr,
+                                                            nullptr, nullptr);
 
             GrTextureProxy* proxy = as_IB(image)->peekProxy();
             REPORTER_ASSERT(reporter, proxy);
diff --git a/tests/ImageFilterCacheTest.cpp b/tests/ImageFilterCacheTest.cpp
index bcd4511..fb9d04b 100644
--- a/tests/ImageFilterCacheTest.cpp
+++ b/tests/ImageFilterCacheTest.cpp
@@ -221,7 +221,9 @@
     sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(context,
                                                      backendTex,
                                                      texOrigin,
-                                                     kPremul_SkAlphaType, nullptr));
+                                                     kRGBA_8888_SkColorType,
+                                                     kPremul_SkAlphaType, nullptr,
+                                                     nullptr, nullptr));
     if (!srcImage) {
         return;
     }
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 1415bcb..ff058f2 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -730,7 +730,8 @@
     TextureReleaseChecker releaseChecker;
     GrSurfaceOrigin texOrigin = kBottomLeft_GrSurfaceOrigin;
     sk_sp<SkImage> refImg(
-        SkImage::MakeFromTexture(ctx, backendTex, texOrigin, kPremul_SkAlphaType, nullptr,
+        SkImage::MakeFromTexture(ctx, backendTex, texOrigin, kRGBA_8888_SkColorType,
+                                 kPremul_SkAlphaType, nullptr,
                                  TextureReleaseChecker::Release, &releaseChecker));
 
     GrSurfaceOrigin readBackOrigin;
diff --git a/tests/SurfaceSemaphoreTest.cpp b/tests/SurfaceSemaphoreTest.cpp
index 8ae0953..b4f63fe 100644
--- a/tests/SurfaceSemaphoreTest.cpp
+++ b/tests/SurfaceSemaphoreTest.cpp
@@ -83,7 +83,10 @@
     sk_sp<SkImage> childImage = SkImage::MakeFromTexture(childCtx,
                                                          backendTexture,
                                                          kTopLeft_GrSurfaceOrigin,
+                                                         kRGBA_8888_SkColorType,
                                                          kPremul_SkAlphaType,
+                                                         nullptr,
+                                                         nullptr,
                                                          nullptr);
 
     SkCanvas* childCanvas = childSurface->getCanvas();
diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
index 552dd8a..f511574 100644
--- a/tools/gpu/GrTest.cpp
+++ b/tools/gpu/GrTest.cpp
@@ -67,7 +67,8 @@
 #endif
         case kOpenGL_GrBackend: {
             GrGLTextureInfo* glInfo = (GrGLTextureInfo*)(handle);
-            return GrBackendTexture(width, height, config, mipMapped, *glInfo);
+            SkASSERT(glInfo->fFormat);
+            return GrBackendTexture(width, height, mipMapped, *glInfo);
         }
         case kMock_GrBackend: {
             GrMockTextureInfo* mockInfo = (GrMockTextureInfo*)(handle);