Add GrCaps::isFormatCompressed

This is part of trying to remove uses of GrPixelConfig from the proxy provider

Change-Id: I12d085cfbff86d0e44829ce3ee36744b937b804e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/230576
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrCaps.h b/src/gpu/GrCaps.h
index cdc8ca7..53bae23 100644
--- a/src/gpu/GrCaps.h
+++ b/src/gpu/GrCaps.h
@@ -156,6 +156,7 @@
     }
 
     virtual bool isFormatSRGB(const GrBackendFormat&) const = 0;
+    virtual bool isFormatCompressed(const GrBackendFormat&) const = 0;
 
     virtual bool isFormatTexturable(GrColorType, const GrBackendFormat&) const = 0;
     virtual bool isConfigTexturable(GrPixelConfig) const = 0;
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index 6051cc1..48a24fe 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -440,12 +440,13 @@
                                                    SkBudgeted budgeted,
                                                    GrProtected isProtected,
                                                    GrInternalSurfaceFlags surfaceFlags) {
-    if (GrPixelConfigIsCompressed(desc.fConfig)) {
+    const GrCaps* caps = this->caps();
+
+    if (caps->isFormatCompressed(format)) {
         // Deferred proxies for compressed textures are not supported.
         return nullptr;
     }
 
-    const GrCaps* caps = this->caps();
     GrColorType colorType = GrPixelConfigToColorType(desc.fConfig);
 
     SkASSERT(GrCaps::AreConfigsCompatible(desc.fConfig,
@@ -483,14 +484,16 @@
 sk_sp<GrTextureProxy> GrProxyProvider::createCompressedTextureProxy(
         int width, int height, SkBudgeted budgeted, SkImage::CompressionType compressionType,
         sk_sp<SkData> data) {
-    GrBackendFormat format = this->caps()->getBackendFormatFromCompressionType(compressionType);
 
     GrSurfaceDesc desc;
     desc.fConfig = GrCompressionTypePixelConfig(compressionType);
     desc.fWidth = width;
     desc.fHeight = height;
 
-    if (!this->caps()->isConfigTexturable(desc.fConfig)) {
+    GrColorType grColorType = GrCompressionTypeClosestColorType(compressionType);
+    GrBackendFormat format = this->caps()->getBackendFormatFromCompressionType(compressionType);
+
+    if (!this->caps()->isFormatTexturable(grColorType, format)) {
         return nullptr;
     }
 
diff --git a/src/gpu/dawn/GrDawnCaps.cpp b/src/gpu/dawn/GrDawnCaps.cpp
index 9e8954b..c9381bc 100644
--- a/src/gpu/dawn/GrDawnCaps.cpp
+++ b/src/gpu/dawn/GrDawnCaps.cpp
@@ -18,6 +18,10 @@
     return false;
 }
 
+bool GrDawnCaps::isFormatCompressed(const GrBackendFormat& format) const {
+    return false;
+}
+
 bool GrDawnCaps::isConfigTexturable(GrPixelConfig config) const {
     switch (config) {
         case kRGBA_8888_GrPixelConfig:
diff --git a/src/gpu/dawn/GrDawnCaps.h b/src/gpu/dawn/GrDawnCaps.h
index 734422a..f975990 100644
--- a/src/gpu/dawn/GrDawnCaps.h
+++ b/src/gpu/dawn/GrDawnCaps.h
@@ -17,7 +17,9 @@
 public:
     GrDawnCaps(const GrContextOptions& contextOptions);
 
-    bool isFormatSRGB(const GrBackendFormat& format) const override;
+    bool isFormatSRGB(const GrBackendFormat&) const override;
+    bool isFormatCompressed(const GrBackendFormat&) const override;
+
     bool isFormatTexturable(GrColorType, const GrBackendFormat& format) const override;
     bool isFormatCopyable(GrColorType, const GrBackendFormat& format) const override;
 
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index dba4fe9..d781865 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -3777,6 +3777,13 @@
     return GrGLBackendFormatToGLFormat(format) == GrGLFormat::kSRGB8_ALPHA8;
 }
 
+bool GrGLCaps::isFormatCompressed(const GrBackendFormat& format) const {
+    GrGLFormat grGLFormat = GrGLBackendFormatToGLFormat(format);
+
+    return grGLFormat == GrGLFormat::kCOMPRESSED_RGB8_ETC2 ||
+           grGLFormat == GrGLFormat::kCOMPRESSED_ETC1_RGB8;
+}
+
 bool GrGLCaps::isFormatTexturable(GrColorType ct, GrGLFormat format) const {
     const FormatInfo& info = this->getFormatInfo(format);
     // Currently we conflate texturable to mean the format itself is texturable in a draw and that
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index b8782ac..f4fa5e1 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -108,7 +108,8 @@
     GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
              const GrGLInterface* glInterface);
 
-    bool isFormatSRGB(const GrBackendFormat& format) const override;
+    bool isFormatSRGB(const GrBackendFormat&) const override;
+    bool isFormatCompressed(const GrBackendFormat&) const override;
 
     bool isFormatTexturable(GrColorType, const GrBackendFormat&) const override;
 
diff --git a/src/gpu/mock/GrMockCaps.h b/src/gpu/mock/GrMockCaps.h
index b244c0d..73f3611 100644
--- a/src/gpu/mock/GrMockCaps.h
+++ b/src/gpu/mock/GrMockCaps.h
@@ -46,6 +46,11 @@
         return *format.getMockColorType() == GrColorType::kRGBA_8888_SRGB;
     }
 
+    // Mock caps doesn't support any compressed formats right now
+    bool isFormatCompressed(const GrBackendFormat&) const override {
+        return false;
+    }
+
     bool isFormatTexturable(GrColorType, const GrBackendFormat& format) const override {
         if (!format.getMockColorType()) {
             return false;
diff --git a/src/gpu/mtl/GrMtlCaps.h b/src/gpu/mtl/GrMtlCaps.h
index d3f39e5..f982c02 100644
--- a/src/gpu/mtl/GrMtlCaps.h
+++ b/src/gpu/mtl/GrMtlCaps.h
@@ -26,7 +26,8 @@
     GrMtlCaps(const GrContextOptions& contextOptions, id<MTLDevice> device,
               MTLFeatureSet featureSet);
 
-    bool isFormatSRGB(const GrBackendFormat& format) const override;
+    bool isFormatSRGB(const GrBackendFormat&) const override;
+    bool isFormatCompressed(const GrBackendFormat&) const override;
 
     bool isFormatTexturable(GrColorType, const GrBackendFormat&) const override;
     bool isConfigTexturable(GrPixelConfig config) const override;
diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm
index 558fc3f..af94b4d 100644
--- a/src/gpu/mtl/GrMtlCaps.mm
+++ b/src/gpu/mtl/GrMtlCaps.mm
@@ -274,6 +274,20 @@
     return format_is_srgb(static_cast<MTLPixelFormat>(*format.getMtlFormat()));
 }
 
+bool GrMtlCaps::isFormatCompressed(const GrBackendFormat& format) const {
+#ifdef SK_BUILD_FOR_MAC
+    return false;
+#else
+    if (!format.getMtlFormat()) {
+        return false;
+    }
+
+    MTLPixelFormat mtlFormat = static_cast<MTLPixelFormat>(*format.getMtlFormat());
+
+    return mtlFormat == MTLPixelFormatETC2_RGB8;
+#endif
+}
+
 bool GrMtlCaps::isFormatTexturable(GrColorType, const GrBackendFormat& format) const {
     if (!format.getMtlFormat()) {
         return false;
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index 2f98524..3ee070b 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -778,6 +778,17 @@
     return format_is_srgb(*format.getVkFormat());
 }
 
+bool GrVkCaps::isFormatCompressed(const GrBackendFormat& format) const {
+    if (!format.getVkFormat()) {
+        return false;
+    }
+
+    VkFormat vkFormat = *format.getVkFormat();
+    SkASSERT(GrVkFormatIsSupported(vkFormat));
+
+    return vkFormat == VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
+}
+
 bool GrVkCaps::isFormatTexturable(GrColorType, const GrBackendFormat& format) const {
     if (!format.getVkFormat()) {
         return false;
diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h
index ceadd68..af1bfd3 100644
--- a/src/gpu/vk/GrVkCaps.h
+++ b/src/gpu/vk/GrVkCaps.h
@@ -32,7 +32,9 @@
              uint32_t instanceVersion, uint32_t physicalDeviceVersion,
              const GrVkExtensions& extensions, GrProtected isProtected = GrProtected::kNo);
 
-    bool isFormatSRGB(const GrBackendFormat& format) const override;
+    bool isFormatSRGB(const GrBackendFormat&) const override;
+    bool isFormatCompressed(const GrBackendFormat&) const override;
+
 
     bool isFormatTexturable(GrColorType, const GrBackendFormat&) const override;
     bool isVkFormatTexturable(VkFormat) const;
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
index 09eef93..47e5b13 100644
--- a/tests/GrSurfaceTest.cpp
+++ b/tests/GrSurfaceTest.cpp
@@ -116,8 +116,8 @@
         GrPixelConfig config = static_cast<GrPixelConfig>(c);
 
         // We don't round trip correctly going from pixelConfig to colorType to
-        // backendFormat with the RGBX config.
-        if (config == kRGB_888X_GrPixelConfig) {
+        // backendFormat with the RGBX and ETC1 configs.
+        if (config == kRGB_888X_GrPixelConfig || config == kRGB_ETC1_GrPixelConfig) {
             continue;
         }