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

Review-Url: https://codereview.chromium.org/2069173002
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index a894f98..2759a3e 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -213,7 +213,7 @@
 
     SkColorType ct = origInfo.colorType();
     SkAlphaType at = origInfo.alphaType();
-    SkColorProfileType pt = origInfo.profileType();
+    SkColorSpace* cs = origInfo.colorSpace();
     if (kRGB_565_SkColorType == ct || kGray_8_SkColorType == ct) {
         at = kOpaque_SkAlphaType;  // force this setting
     }
@@ -221,13 +221,13 @@
         at = kPremul_SkAlphaType;  // force this setting
     }
 
-    GrPixelConfig origConfig = SkImageInfo2GrPixelConfig(ct, at, pt, *context->caps());
+    GrPixelConfig origConfig = SkImageInfo2GrPixelConfig(ct, at, cs, *context->caps());
     if (!context->caps()->isConfigRenderable(origConfig, sampleCount > 0)) {
         // Fall back from whatever ct was to default of kRGBA or kBGRA which is aliased as kN32
         ct = kN32_SkColorType;
     }
 
-    GrPixelConfig config = SkImageInfo2GrPixelConfig(ct, at, pt, *context->caps());
+    GrPixelConfig config = SkImageInfo2GrPixelConfig(ct, at, cs, *context->caps());
 
     return context->newDrawContext(SkBackingFit::kExact,               // Why exact?
                                    origInfo.width(), origInfo.height(),
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index c2e2841..45100f09 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -243,7 +243,7 @@
     GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(pixmap.info(), *caps);
 
     if (caps->srgbSupport() && !GrPixelConfigIsSRGB(desc.fConfig) &&
-        kSRGB_SkColorProfileType == pixmap.info().profileType()) {
+        pixmap.info().colorSpace() && pixmap.info().colorSpace()->gammaCloseToSRGB()) {
         // We were supplied sRGB as the profile type, but we don't have a suitable pixel config.
         // Convert to 8888 sRGB so we can handle the data correctly. The raster backend doesn't
         // handle sRGB Index8 -> sRGB 8888 correctly (yet), so lie about both the source and
@@ -418,7 +418,7 @@
 
 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass
 // alpha info, that will be considered.
-GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProfileType pt,
+GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, const SkColorSpace* cs,
                                         const GrCaps& caps) {
     // We intentionally ignore profile type for non-8888 formats. Anything we can't support
     // in hardware will be expanded to sRGB 8888 in GrUploadPixmapToTexture.
@@ -432,10 +432,10 @@
         case kARGB_4444_SkColorType:
             return kRGBA_4444_GrPixelConfig;
         case kRGBA_8888_SkColorType:
-            return (kSRGB_SkColorProfileType == pt && caps.srgbSupport())
+            return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB())
                    ? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig;
         case kBGRA_8888_SkColorType:
-            return (kSRGB_SkColorProfileType == pt && caps.srgbSupport())
+            return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB())
                    ? kSBGRA_8888_GrPixelConfig : kBGRA_8888_GrPixelConfig;
         case kIndex_8_SkColorType:
             return kIndex_8_GrPixelConfig;
diff --git a/src/gpu/SkGrPixelRef.cpp b/src/gpu/SkGrPixelRef.cpp
index df720da..df23003 100644
--- a/src/gpu/SkGrPixelRef.cpp
+++ b/src/gpu/SkGrPixelRef.cpp
@@ -50,7 +50,7 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorType dstCT,
-                                                  SkColorProfileType dstPT, const SkIRect* subset) {
+                                                  SkColorSpace* dstCS, const SkIRect* subset) {
     if (nullptr == texture || kUnknown_SkColorType == dstCT) {
         return nullptr;
     }
@@ -74,7 +74,7 @@
         srcRect = *subset;
     }
     desc.fFlags = kRenderTarget_GrSurfaceFlag;
-    desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType, dstPT, *context->caps());
+    desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType, dstCS, *context->caps());
     desc.fIsMipMapped = false;
 
     GrTexture* dst = context->textureProvider()->createTexture(desc, SkBudgeted::kNo, nullptr, 0);
@@ -89,7 +89,7 @@
     context->flushSurfaceWrites(dst);
 
     SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPremul_SkAlphaType,
-                                         dstPT);
+                                         sk_ref_sp(dstCS));
     SkGrPixelRef* pixelRef = new SkGrPixelRef(info, dst);
     SkSafeUnref(dst);
     return pixelRef;
@@ -130,8 +130,7 @@
     }
 }
 
-SkPixelRef* SkGrPixelRef::deepCopy(SkColorType dstCT, SkColorProfileType dstPT,
-                                   const SkIRect* subset) {
+SkPixelRef* SkGrPixelRef::deepCopy(SkColorType dstCT, SkColorSpace* dstCS, const SkIRect* subset) {
     if (nullptr == fSurface) {
         return nullptr;
     }
@@ -142,7 +141,7 @@
     // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live
     // independently of that texture.  Texture-backed pixel refs, on the other
     // hand, own their GrTextures, and are thus self-contained.
-    return copy_to_new_texture_pixelref(fSurface->asTexture(), dstCT, dstPT, subset);
+    return copy_to_new_texture_pixelref(fSurface->asTexture(), dstCT, dstCS, subset);
 }
 
 static bool tryAllocBitmapPixels(SkBitmap* bitmap) {
@@ -183,7 +182,7 @@
         SkBitmap cachedBitmap;
         cachedBitmap.setInfo(SkImageInfo::Make(bounds.width(), bounds.height(), colorType,
                                                this->info().alphaType(),
-                                               this->info().profileType()));
+                                               sk_ref_sp(this->info().colorSpace())));
 
         // If we can't alloc the pixels, then fail
         if (!tryAllocBitmapPixels(&cachedBitmap)) {