Lots of progress on switching to SkColorSpace rather than SkColorProfileType

Fixed a bunch of code in Ganesh, as well as usage of SkColorProfileType in most of our tools (DM, SampleApp, Viewer, nanobench, skiaserve, HelloWorld).

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

Committed: https://skia.googlesource.com/skia/+/6a61a875467646f8dbc37cfecf49e12d1f475170
Review-Url: https://codereview.chromium.org/2069173002
diff --git a/tools/flags/SkCommonFlagsConfig.cpp b/tools/flags/SkCommonFlagsConfig.cpp
index 1c7920e..d5c7a1d 100644
--- a/tools/flags/SkCommonFlagsConfig.cpp
+++ b/tools/flags/SkCommonFlagsConfig.cpp
@@ -192,14 +192,14 @@
 SkCommandLineConfigGpu::SkCommandLineConfigGpu(
     const SkString& tag, const SkTArray<SkString>& viaParts,
     ContextType contextType, bool useNVPR, bool useDIText, int samples,
-    SkColorType colorType, SkColorProfileType profileType)
+    SkColorType colorType, sk_sp<SkColorSpace> colorSpace)
         : SkCommandLineConfig(tag, SkString("gpu"), viaParts)
         , fContextType(contextType)
         , fUseNVPR(useNVPR)
         , fUseDIText(useDIText)
         , fSamples(samples)
         , fColorType(colorType)
-        , fProfileType(profileType) {
+        , fColorSpace(std::move(colorSpace)) {
 }
 static bool parse_option_int(const SkString& value, int* outInt) {
     if (value.isEmpty()) {
@@ -276,20 +276,20 @@
 }
 static bool parse_option_gpu_color(const SkString& value,
                                    SkColorType* outColorType,
-                                   SkColorProfileType* outProfileType) {
+                                   sk_sp<SkColorSpace>* outColorSpace) {
     if (value.equals("8888")) {
         *outColorType = kN32_SkColorType;
-        *outProfileType = kLinear_SkColorProfileType;
+        *outColorSpace = nullptr;
         return true;
     }
     if (value.equals("f16")) {
         *outColorType = kRGBA_F16_SkColorType;
-        *outProfileType = kLinear_SkColorProfileType;
+        *outColorSpace = nullptr;
         return true;
     }
     if (value.equals("srgb")) {
         *outColorType = kN32_SkColorType;
-        *outProfileType = kSRGB_SkColorProfileType;
+        *outColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
         return true;
     }
     return false;
@@ -309,7 +309,7 @@
     int samples = 0;
     bool seenColor = false;
     SkColorType colorType = kN32_SkColorType;
-    SkColorProfileType profileType = kLinear_SkColorProfileType;
+    sk_sp<SkColorSpace> colorSpace = nullptr;
 
     SkTArray<SkString> optionParts;
     SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts);
@@ -335,7 +335,7 @@
             valueOk = parse_option_int(value, &samples);
             seenSamples = true;
         } else if (key.equals("color") && !seenColor) {
-            valueOk = parse_option_gpu_color(value, &colorType, &profileType);
+            valueOk = parse_option_gpu_color(value, &colorType, &colorSpace);
             seenColor = true;
         }
         if (!valueOk) {
@@ -343,7 +343,7 @@
         }
     }
     return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText, samples,
-                                      colorType, profileType);
+                                      colorType, colorSpace);
 }
 #endif
 
diff --git a/tools/flags/SkCommonFlagsConfig.h b/tools/flags/SkCommonFlagsConfig.h
index 5d95ef1..dc38977 100644
--- a/tools/flags/SkCommonFlagsConfig.h
+++ b/tools/flags/SkCommonFlagsConfig.h
@@ -53,14 +53,14 @@
     typedef sk_gpu_test::GrContextFactory::ContextType ContextType;
     SkCommandLineConfigGpu(const SkString& tag, const SkTArray<SkString>& viaParts,
                            ContextType contextType, bool useNVPR, bool useDIText, int samples,
-                           SkColorType colorType, SkColorProfileType profileType);
+                           SkColorType colorType, sk_sp<SkColorSpace> colorSpace);
     const SkCommandLineConfigGpu* asConfigGpu() const override { return this; }
     ContextType getContextType() const { return fContextType; }
     bool getUseNVPR() const { return fUseNVPR; }
     bool getUseDIText() const { return fUseDIText; }
     int getSamples() const { return fSamples; }
     SkColorType getColorType() const { return fColorType; }
-    SkColorProfileType getProfileType() const { return fProfileType; }
+    SkColorSpace* getColorSpace() const { return fColorSpace.get(); }
 
   private:
     ContextType fContextType;
@@ -68,7 +68,7 @@
     bool fUseDIText;
     int fSamples;
     SkColorType fColorType;
-    SkColorProfileType fProfileType;
+    sk_sp<SkColorSpace> fColorSpace;
 };
 #endif
 
diff --git a/tools/picture_utils.cpp b/tools/picture_utils.cpp
index 63a48ce..a6803c6 100644
--- a/tools/picture_utils.cpp
+++ b/tools/picture_utils.cpp
@@ -80,8 +80,9 @@
 
         SkAutoTMalloc<uint32_t> rgba(w*h);
 
-        if (bitmap.  colorType() ==  kN32_SkColorType &&
-            bitmap.profileType() == kSRGB_SkColorProfileType) {
+        auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+        if (bitmap. colorType() ==  kN32_SkColorType &&
+            bitmap.colorSpace() == srgbColorSpace.get()) {
             // These are premul sRGB 8-bit pixels in SkPMColor order.
             // We want unpremul sRGB 8-bit pixels in RGBA order.  We'll get there via floats.
             bitmap.lockPixels();
diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp
index c3eaaff..756f70e 100644
--- a/tools/skiaserve/Request.cpp
+++ b/tools/skiaserve/Request.cpp
@@ -159,14 +159,14 @@
 
 struct ColorAndProfile {
     SkColorType fColorType;
-    SkColorProfileType fProfileType;
+    bool fSRGB;
     bool fGammaCorrect;
 };
 
 ColorAndProfile ColorModes[] = {
-    { kN32_SkColorType, kLinear_SkColorProfileType, false },
-    { kN32_SkColorType, kSRGB_SkColorProfileType, true },
-    { kRGBA_F16_SkColorType, kLinear_SkColorProfileType, true },
+    { kN32_SkColorType,      false, false },
+    { kN32_SkColorType,       true, true },
+    { kRGBA_F16_SkColorType, false, true },
 };
 
 }
@@ -174,8 +174,9 @@
 SkSurface* Request::createCPUSurface() {
     SkIRect bounds = this->getBounds();
     ColorAndProfile cap = ColorModes[fColorMode];
+    auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
     SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fColorType,
-                                         kPremul_SkAlphaType, cap.fProfileType);
+                                         kPremul_SkAlphaType, cap.fSRGB ? srgbColorSpace : nullptr);
     uint32_t flags = cap.fGammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag : 0;
     SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
     return SkSurface::MakeRaster(info, &props).release();
@@ -185,8 +186,9 @@
     GrContext* context = this->getContext();
     SkIRect bounds = this->getBounds();
     ColorAndProfile cap = ColorModes[fColorMode];
+    auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
     SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fColorType,
-                                         kPremul_SkAlphaType, cap.fProfileType);
+                                         kPremul_SkAlphaType, cap.fSRGB ? srgbColorSpace : nullptr);
     uint32_t flags = cap.fGammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag : 0;
     SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
     SkSurface* surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0,
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 43697f8..9aec01f 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -122,8 +122,8 @@
     });
     fCommands.addCommand('c', "Modes", "Toggle sRGB color mode", [this]() {
         DisplayParams params = fWindow->getDisplayParams();
-        params.fProfileType = (kLinear_SkColorProfileType == params.fProfileType)
-            ? kSRGB_SkColorProfileType : kLinear_SkColorProfileType;
+        params.fColorSpace = (nullptr == params.fColorSpace)
+            ? SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr;
         fWindow->setDisplayParams(params);
         this->updateTitle();
         fWindow->inval();
@@ -266,7 +266,9 @@
 void Viewer::updateTitle() {
     SkString title("Viewer: ");
     title.append(fSlides[fCurrentSlide]->getName());
-    if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) {
+
+    // TODO: For now, any color-space on the window means sRGB
+    if (fWindow->getDisplayParams().fColorSpace) {
         title.append(" sRGB");
     }
     title.append(kBackendTypeStrings[fBackendType]);
diff --git a/tools/viewer/sk_app/DisplayParams.h b/tools/viewer/sk_app/DisplayParams.h
index 8756ff0..b9a23f3 100644
--- a/tools/viewer/sk_app/DisplayParams.h
+++ b/tools/viewer/sk_app/DisplayParams.h
@@ -14,14 +14,14 @@
 struct DisplayParams {
     DisplayParams()
         : fColorType(kN32_SkColorType)
-        , fProfileType(kLinear_SkColorProfileType)
+        , fColorSpace(nullptr)
         , fMSAASampleCount(0)
         , fDeepColor(false) {}
 
-    SkColorType        fColorType;
-    SkColorProfileType fProfileType;
-    int                fMSAASampleCount;
-    bool               fDeepColor;
+    SkColorType         fColorType;
+    sk_sp<SkColorSpace> fColorSpace;
+    int                 fMSAASampleCount;
+    bool                fDeepColor;
 };
 
 }   // namespace sk_app
diff --git a/tools/viewer/sk_app/GLWindowContext.cpp b/tools/viewer/sk_app/GLWindowContext.cpp
index a491321..b960da4 100644
--- a/tools/viewer/sk_app/GLWindowContext.cpp
+++ b/tools/viewer/sk_app/GLWindowContext.cpp
@@ -47,8 +47,8 @@
     // ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conversion on write,
     // so pretend that it's non-sRGB 8888:
     fPixelConfig = fContext->caps()->srgbSupport() &&
-                   SkColorAndProfileAreGammaCorrect(fDisplayParams.fColorType,
-                                                    fDisplayParams.fProfileType) &&
+                   SkColorAndColorSpaceAreGammaCorrect(fDisplayParams.fColorType,
+                                                       fDisplayParams.fColorSpace.get()) &&
                    (fColorBits != 30) ? kSkiaGamma8888_GrPixelConfig : kSkia8888_GrPixelConfig;
 }
 
diff --git a/tools/viewer/sk_app/VulkanWindowContext.cpp b/tools/viewer/sk_app/VulkanWindowContext.cpp
index 9bcf6ca..d892cd4 100644
--- a/tools/viewer/sk_app/VulkanWindowContext.cpp
+++ b/tools/viewer/sk_app/VulkanWindowContext.cpp
@@ -173,7 +173,8 @@
     // Pick our surface format. For now, just make sure it matches our sRGB request:
     VkFormat surfaceFormat = VK_FORMAT_UNDEFINED;
     VkColorSpaceKHR colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
-    bool wantSRGB = kSRGB_SkColorProfileType == params.fProfileType;
+    auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+    bool wantSRGB = srgbColorSpace == params.fColorSpace;
     for (uint32_t i = 0; i < surfaceFormatCount; ++i) {
         GrPixelConfig config;
         if (GrVkFormatToPixelConfig(surfaceFormats[i].format, &config) &&
diff --git a/tools/viewer/sk_app/WindowContext.cpp b/tools/viewer/sk_app/WindowContext.cpp
index 41bbd14..ecac2cc 100755
--- a/tools/viewer/sk_app/WindowContext.cpp
+++ b/tools/viewer/sk_app/WindowContext.cpp
@@ -36,7 +36,7 @@
         SkImageInfo info = SkImageInfo::Make(fWidth, fHeight,
                                              fDisplayParams.fColorType,
                                              kUnknown_SkAlphaType,
-                                             fDisplayParams.fProfileType);
+                                             fDisplayParams.fColorSpace);
         return SkSurface::MakeRenderTarget(fContext, SkBudgeted::kNo, info,
                                            fDisplayParams.fMSAASampleCount, &props);
     } else {
@@ -52,7 +52,7 @@
         SkImageInfo info = SkImageInfo::Make(fWidth, fHeight,
                                              fDisplayParams.fColorType,
                                              kUnknown_SkAlphaType,
-                                             fDisplayParams.fProfileType);
+                                             fDisplayParams.fColorSpace);
         SkBitmap bm;
         bm.allocPixels(info);
         renderSurface->getCanvas()->readPixels(&bm, 0, 0);
diff --git a/tools/viewer/sk_app/android/GLWindowContext_android.cpp b/tools/viewer/sk_app/android/GLWindowContext_android.cpp
index 79425b4..be62ab2 100644
--- a/tools/viewer/sk_app/android/GLWindowContext_android.cpp
+++ b/tools/viewer/sk_app/android/GLWindowContext_android.cpp
@@ -99,7 +99,8 @@
         EGL_NONE,
     };
     const EGLint* windowAttribs = nullptr;
-    if (kSRGB_SkColorProfileType == params.fProfileType && majorVersion == 1 && minorVersion >= 2) {
+    auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+    if (srgbColorSpace == params.fColorSpace && majorVersion == 1 && minorVersion >= 2) {
         windowAttribs = srgbWindowAttribs;
     }
 
diff --git a/tools/viewer/sk_app/android/RasterWindowContext_android.cpp b/tools/viewer/sk_app/android/RasterWindowContext_android.cpp
index 5e1e351..a5f9a65 100644
--- a/tools/viewer/sk_app/android/RasterWindowContext_android.cpp
+++ b/tools/viewer/sk_app/android/RasterWindowContext_android.cpp
@@ -68,7 +68,7 @@
         SkImageInfo info = SkImageInfo::Make(fWidth, fHeight,
                                              fDisplayParams.fColorType,
                                              kOpaque_SkAlphaType,
-                                             fDisplayParams.fProfileType);
+                                             fDisplayParams.fColorSpace);
         fBackbufferSurface = SkSurface::MakeRasterDirect(
                 info, fBuffer.bits, fBuffer.stride * bytePerPixel, nullptr);
     }