Cleanup of code that converts from GPU-backed resources to SkImageInfo

Functions like GrMakeInfoFromTexture encouraged incorrect code to be
written. Similarly, the ability to construct an info from any GrSurface
was never going to be correct. Luckily, the only client of that had all
of the correct parameters much higher on the stack (and dictated or
replaced most of the properties of the returned info anyway).

With this, I can finally remove the color space as an output of the
pixel config -> color type conversion, which was never going to be
correct.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2173513002

Review-Url: https://codereview.chromium.org/2173513002
diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h
index 8c6930a..8e8eb0f 100644
--- a/include/gpu/GrSurface.h
+++ b/include/gpu/GrSurface.h
@@ -137,7 +137,6 @@
 
 protected:
     // Methods made available via GrSurfacePriv
-    SkImageInfo info(SkAlphaType) const;
     bool savePixels(const char* filename);
     bool hasPendingRead() const;
     bool hasPendingWrite() const;
diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h
index 31d53a7..541881d 100644
--- a/include/gpu/SkGr.h
+++ b/include/gpu/SkGr.h
@@ -84,9 +84,4 @@
                                                             const SkMatrix& localM,
                                                             bool* doBicubic);
 
-////////////////////////////////////////////////////////////////////////////////
-
-SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque,
-                                  sk_sp<SkColorSpace> colorSpace = nullptr);
-
 #endif
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 6bb3ea6..5a5173c 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -238,7 +238,7 @@
 bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes,
                           const void* inPixels, size_t outRowBytes, void* outPixels) {
     SkSrcPixelInfo srcPI;
-    if (!GrPixelConfigToColorAndColorSpace(srcConfig, &srcPI.fColorType, nullptr)) {
+    if (!GrPixelConfigToColorType(srcConfig, &srcPI.fColorType)) {
         return false;
     }
     srcPI.fAlphaType = kUnpremul_SkAlphaType;
@@ -509,7 +509,7 @@
     // Perform umpremul conversion if we weren't able to perform it as a draw.
     if (unpremul) {
         SkDstPixelInfo dstPI;
-        if (!GrPixelConfigToColorAndColorSpace(dstConfig, &dstPI.fColorType, nullptr)) {
+        if (!GrPixelConfigToColorType(dstConfig, &dstPI.fColorType)) {
             return false;
         }
         dstPI.fAlphaType = kUnpremul_SkAlphaType;
diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp
index 47fa394..6dc90a3 100644
--- a/src/gpu/GrSurface.cpp
+++ b/src/gpu/GrSurface.cpp
@@ -116,15 +116,6 @@
                                       rowBytes, pixelOpsFlags);
 }
 
-SkImageInfo GrSurface::info(SkAlphaType alphaType) const {
-    SkColorType colorType;
-    sk_sp<SkColorSpace> colorSpace;
-    if (!GrPixelConfigToColorAndColorSpace(this->config(), &colorType, &colorSpace)) {
-        sk_throw();
-    }
-    return SkImageInfo::Make(this->width(), this->height(), colorType, alphaType, colorSpace);
-}
-
 // TODO: This should probably be a non-member helper function. It might only be needed in
 // debug or developer builds.
 bool GrSurface::savePixels(const char* filename) {
diff --git a/src/gpu/GrSurfacePriv.h b/src/gpu/GrSurfacePriv.h
index bff411e..f2ba7ba 100644
--- a/src/gpu/GrSurfacePriv.h
+++ b/src/gpu/GrSurfacePriv.h
@@ -32,11 +32,6 @@
                                       int* left, int* top, int* width, int* height,
                                       const void** data,
                                       size_t* rowBytes);
-    /**
-     * Derive a SkImageInfo from the surface's descriptor. The caller must provide the alpha type as
-     * GrSurface has no equivalent.
-     */
-    SkImageInfo info(SkAlphaType alphaType) const { return fSurface->info(alphaType); }
 
     /**
      * Write the contents of the surface to a PNG. Returns true if successful.
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index 8111759..7e646a1 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -9,6 +9,7 @@
 #define SkGpuDevice_DEFINED
 
 #include "SkGr.h"
+#include "SkGrPriv.h"
 #include "SkBitmap.h"
 #include "SkDevice.h"
 #include "SkPicture.h"
@@ -82,10 +83,13 @@
     GrDrawContext* accessDrawContext() override;
 
     SkImageInfo imageInfo() const override {
-        SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
-        SkImageInfo info = fRenderTarget->surfacePriv().info(at).makeWH(fSize.fWidth, 
-                                                                        fSize.fHeight);
-        return info;
+        SkColorType colorType;
+        if (!GrPixelConfigToColorType(fRenderTarget->config(), &colorType)) {
+            colorType = kUnknown_SkColorType;
+        }
+        return SkImageInfo::Make(fSize.fWidth, fSize.fHeight, colorType,
+                                 fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType,
+                                 sk_ref_sp(fDrawContext->getColorSpace()));
     }
 
     void drawPaint(const SkDraw&, const SkPaint& paint) override;
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index ef3a39b..452218f 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -462,10 +462,8 @@
     return kUnknown_GrPixelConfig;
 }
 
-bool GrPixelConfigToColorAndColorSpace(GrPixelConfig config, SkColorType* ctOut,
-                                       sk_sp<SkColorSpace>* csOut) {
+bool GrPixelConfigToColorType(GrPixelConfig config, SkColorType* ctOut) {
     SkColorType ct;
-    sk_sp<SkColorSpace> cs = nullptr;
     switch (config) {
         case kAlpha_8_GrPixelConfig:
             ct = kAlpha_8_SkColorType;
@@ -487,11 +485,9 @@
             break;
         case kSRGBA_8888_GrPixelConfig:
             ct = kRGBA_8888_SkColorType;
-            cs = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
             break;
         case kSBGRA_8888_GrPixelConfig:
             ct = kBGRA_8888_SkColorType;
-            cs = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
             break;
         case kRGBA_half_GrPixelConfig:
             ct = kRGBA_F16_SkColorType;
@@ -502,9 +498,6 @@
     if (ctOut) {
         *ctOut = ct;
     }
-    if (csOut) {
-        *csOut = cs;
-    }
     return true;
 }
 
@@ -741,22 +734,6 @@
 
 ////////////////////////////////////////////////////////////////////////////////////////////////
 
-SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque,
-                                  sk_sp<SkColorSpace> colorSpace) {
-#ifdef SK_DEBUG
-    const GrSurfaceDesc& desc = tex->desc();
-    SkASSERT(w <= desc.fWidth);
-    SkASSERT(h <= desc.fHeight);
-#endif
-    const GrPixelConfig config = tex->config();
-    SkColorType ct = kUnknown_SkColorType;
-    SkAlphaType at = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
-    if (!GrPixelConfigToColorAndColorSpace(config, &ct, nullptr)) {
-        ct = kUnknown_SkColorType;
-    }
-    return SkImageInfo::Make(w, h, ct, at, std::move(colorSpace));
-}
-
 GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality,
                                                             const SkMatrix& viewM,
                                                             const SkMatrix& localM,
diff --git a/src/gpu/SkGrPriv.h b/src/gpu/SkGrPriv.h
index ab77dc1..7188856 100644
--- a/src/gpu/SkGrPriv.h
+++ b/src/gpu/SkGrPriv.h
@@ -102,7 +102,7 @@
 
 GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo&, const GrCaps&);
 
-bool GrPixelConfigToColorAndColorSpace(GrPixelConfig, SkColorType*, sk_sp<SkColorSpace>*);
+bool GrPixelConfigToColorType(GrPixelConfig, SkColorType*);
 
 /**
  *  If the compressed data in the SkData is supported (as a texture format, this returns
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index fa697cd..c331a29 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -43,6 +43,14 @@
     }
 }
 
+SkImageInfo SkImage_Gpu::onImageInfo() const {
+    SkColorType ct;
+    if (!GrPixelConfigToColorType(fTexture->config(), &ct)) {
+        ct = kUnknown_SkColorType;
+    }
+    return SkImageInfo::Make(fTexture->width(), fTexture->height(), ct, fAlphaType, fColorSpace);
+}
+
 static SkImageInfo make_info(int w, int h, bool isOpaque, sk_sp<SkColorSpace> colorSpace) {
     return SkImageInfo::MakeN32(w, h, isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType,
                                 std::move(colorSpace));
@@ -316,17 +324,10 @@
 }
 
 sk_sp<SkImage> SkImage::makeNonTextureImage() const {
-    GrTexture* texture = as_IB(this)->peekTexture();
-    if (!texture) {
+    if (!this->isTextureBacked()) {
         return sk_ref_sp(const_cast<SkImage*>(this));
     }
-    SkColorType ct;
-    sk_sp<SkColorSpace> cs;
-    if (!GrPixelConfigToColorAndColorSpace(texture->config(), &ct, &cs)) {
-        return nullptr;
-    }
-    SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
-    auto info = SkImageInfo::Make(this->width(), this->height(), ct, at, cs);
+    SkImageInfo info = as_IB(this)->onImageInfo();
     size_t rowBytes = info.minRowBytes();
     size_t size = info.getSafeSize(rowBytes);
     auto data = SkData::MakeUninitialized(size);
diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h
index 0e9169d..5faaa75 100644
--- a/src/image/SkImage_Gpu.h
+++ b/src/image/SkImage_Gpu.h
@@ -27,10 +27,7 @@
                 SkBudgeted);
     ~SkImage_Gpu() override;
 
-    SkImageInfo onImageInfo() const override {
-        return GrMakeInfoFromTexture(fTexture, fTexture->width(), fTexture->height(), isOpaque(),
-                                     fColorSpace);
-    }
+    SkImageInfo onImageInfo() const override;
 
     void applyBudgetDecision() const {
         if (SkBudgeted::kYes == fBudgeted) {