Change SkSpecialImage::makeSurface and makeTightSurface to take output
properties (color space), bounds, and (optional) alphaType.

We were being pretty inconsistent before. Raster was honoring all
components of the info. GPU was using the supplied color type, but
propagating the source's color space. All call sites were saying N32.

What we want to do is propagate the original device's color space, and
pick a good format from that. Rather than force all the clients to
jump through hoops constructing an SkImageInfo that meets our criteria,
just have them supply the few bits we care about, and do everything else
internally.

This also lets us always use RGBA on GPU, but N32 on raster.

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

Committed: https://skia.googlesource.com/skia/+/53c38087949252d27cde668368a3eeb59cc2eb00
Review-Url: https://codereview.chromium.org/2349373004
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index 240d469..5d62c6b 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -52,11 +52,13 @@
 
     virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0;
 
-    virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const = 0;
+    virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties& outProps,
+                                                  const SkISize& size, SkAlphaType at) const = 0;
 
     virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0;
 
-    virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const = 0;
+    virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps,
+                                                const SkISize& size, SkAlphaType at) const = 0;
 
 private:
     typedef SkSpecialImage INHERITED;
@@ -151,12 +153,14 @@
 }
 #endif
 
-sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) const {
-    return as_SIB(this)->onMakeSurface(info);
+sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageFilter::OutputProperties& outProps,
+                                                    const SkISize& size, SkAlphaType at) const {
+    return as_SIB(this)->onMakeSurface(outProps, size, at);
 }
 
-sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageInfo& info) const {
-    return as_SIB(this)->onMakeTightSurface(info);
+sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageFilter::OutputProperties& outProps,
+                                                  const SkISize& size, SkAlphaType at) const {
+    return as_SIB(this)->onMakeTightSurface(outProps, size, at);
 }
 
 sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const {
@@ -252,7 +256,22 @@
     }
 #endif
 
-    sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override {
+// TODO: The raster implementations of image filters all currently assume that the pixels are
+// legacy N32. Until they actually check the format and operate on sRGB or F16 data appropriately,
+// we can't enable this. (They will continue to produce incorrect results, but less-so).
+#define RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16 0
+
+    sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties& outProps,
+                                          const SkISize& size, SkAlphaType at) const override {
+#if RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16
+        SkColorSpace* colorSpace = outProps.colorSpace();
+#else
+        SkColorSpace* colorSpace = nullptr;
+#endif
+        SkColorType colorType = colorSpace && colorSpace->gammaIsLinear()
+            ? kRGBA_F16_SkColorType : kN32_SkColorType;
+        SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, at,
+                                             sk_ref_sp(colorSpace));
         return SkSpecialSurface::MakeRaster(info, nullptr);
     }
 
@@ -278,7 +297,17 @@
         return SkImage::MakeFromBitmap(subsetBM);
     }
 
-    sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override {
+    sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps,
+                                        const SkISize& size, SkAlphaType at) const override {
+#if RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16
+        SkColorSpace* colorSpace = outProps.colorSpace();
+#else
+        SkColorSpace* colorSpace = nullptr;
+#endif
+        SkColorType colorType = colorSpace && colorSpace->gammaIsLinear()
+            ? kRGBA_F16_SkColorType : kN32_SkColorType;
+        SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, at,
+                                             sk_ref_sp(colorSpace));
         return SkSurface::MakeRaster(info);
     }
 
@@ -382,16 +411,16 @@
         return fColorSpace.get();
     }
 
-    sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override {
+    sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties& outProps,
+                                          const SkISize& size, SkAlphaType at) const override {
         if (!fTexture->getContext()) {
             return nullptr;
         }
 
-        GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fTexture->getContext()->caps());
-
-        return SkSpecialSurface::MakeRenderTarget(fTexture->getContext(),
-                                                  info.width(), info.height(),
-                                                  config, sk_ref_sp(info.colorSpace()));
+        SkColorSpace* colorSpace = outProps.colorSpace();
+        return SkSpecialSurface::MakeRenderTarget(
+            fTexture->getContext(), size.width(), size.height(),
+            GrRenderableConfigForColorSpace(colorSpace), sk_ref_sp(colorSpace));
     }
 
     sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override {
@@ -428,7 +457,13 @@
                                        fAlphaType, subTx.get(), fColorSpace, SkBudgeted::kYes);
     }
 
-    sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override {
+    sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps,
+                                        const SkISize& size, SkAlphaType at) const override {
+        SkColorSpace* colorSpace = outProps.colorSpace();
+        SkColorType colorType = colorSpace && colorSpace->gammaIsLinear()
+            ? kRGBA_F16_SkColorType : kRGBA_8888_SkColorType;
+        SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, at,
+                                             sk_ref_sp(colorSpace));
         return SkSurface::MakeRenderTarget(fTexture->getContext(), SkBudgeted::kYes, info);
     }