From 071c5dd51013464961a9b420675ac5779c71edf4 Mon Sep 17 00:00:00 2001 From: Biru Mohanathas Date: Thu, 28 May 2020 16:51:13 +0300 Subject: [PATCH] fix: Make the `--disable-color-correct-rendering` switch work again (8-x-y) Backport of #23787 See that PR for details. Notes: Fix disabling color correct rendering with `--disable-color-correct-rendering` --- .../disable_color_correct_rendering.patch | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/patches/chromium/disable_color_correct_rendering.patch b/patches/chromium/disable_color_correct_rendering.patch index 82835661dfbb5..902b098cefe5b 100644 --- a/patches/chromium/disable_color_correct_rendering.patch +++ b/patches/chromium/disable_color_correct_rendering.patch @@ -310,7 +310,7 @@ index a947db5fb562fb4ccbfb94df88f460f1da9451f4..77c816b2c5e98a4546c74d9358dfcf3f gfx::ColorSpace::TransferID transfer_id = diff --git a/ui/gfx/mac/io_surface.cc b/ui/gfx/mac/io_surface.cc -index c383d42c986aa29fcdfc2009901ed452ef480b55..1b8d0818155a407eb42c3f785e9609fe7bfa3dc7 100644 +index c383d42c986aa29fcdfc2009901ed452ef480b55..cdc87912b7d646a95796c84b76d583033c64c4dc 100644 --- a/ui/gfx/mac/io_surface.cc +++ b/ui/gfx/mac/io_surface.cc @@ -16,6 +16,7 @@ @@ -321,33 +321,37 @@ index c383d42c986aa29fcdfc2009901ed452ef480b55..1b8d0818155a407eb42c3f785e9609fe namespace gfx { -@@ -261,6 +262,11 @@ IOSurfaceRef CreateIOSurface(const gfx::Size& size, - IOSurfaceSetValue(surface, CFSTR("IOSurfaceColorSpace"), kCGColorSpaceSRGB); - } else { - CGColorSpaceRef color_space = base::mac::GetSRGBColorSpace(); -+ auto* cmd_line = base::CommandLine::ForCurrentProcess(); -+ if (cmd_line->HasSwitch(switches::kDisableColorCorrectRendering)) { -+ color_space = base::mac::GetSystemColorSpace(); -+ } -+ - base::ScopedCFTypeRef color_space_icc( - CGColorSpaceCopyICCProfile(color_space)); - IOSurfaceSetValue(surface, CFSTR("IOSurfaceColorSpace"), color_space_icc); -@@ -277,6 +283,14 @@ bool IOSurfaceCanSetColorSpace(const ColorSpace& color_space) { - - void IOSurfaceSetColorSpace(IOSurfaceRef io_surface, +@@ -126,6 +127,14 @@ void IOSurfaceMachPortTraits::Release(mach_port_t port) { + // Common method used by IOSurfaceSetColorSpace and IOSurfaceCanSetColorSpace. + bool IOSurfaceSetColorSpace(IOSurfaceRef io_surface, const ColorSpace& color_space) { + auto* cmd_line = base::CommandLine::ForCurrentProcess(); + if (cmd_line->HasSwitch(switches::kDisableColorCorrectRendering)) { + base::ScopedCFTypeRef system_icc( + CGColorSpaceCopyICCProfile(base::mac::GetSystemColorSpace())); + IOSurfaceSetValue(io_surface, CFSTR("IOSurfaceColorSpace"), system_icc); -+ return; ++ return true; + } + - if (!internal::IOSurfaceSetColorSpace(io_surface, color_space)) { - DLOG(ERROR) << "Failed to set color space for IOSurface: " - << color_space.ToString(); + // Allow but ignore invalid color spaces. + if (!color_space.IsValid()) + return true; +@@ -256,6 +265,15 @@ IOSurfaceRef CreateIOSurface(const gfx::Size& size, + DCHECK_EQ(kIOReturnSuccess, r); + } + ++ auto* cmd_line = base::CommandLine::ForCurrentProcess(); ++ if (cmd_line->HasSwitch(switches::kDisableColorCorrectRendering)) { ++ CGColorSpaceRef color_space = base::mac::GetSystemColorSpace(); ++ base::ScopedCFTypeRef color_space_icc( ++ CGColorSpaceCopyICCProfile(color_space)); ++ IOSurfaceSetValue(surface, CFSTR("IOSurfaceColorSpace"), color_space_icc); ++ return surface; ++ } ++ + // Ensure that all IOSurfaces start as sRGB. + if (__builtin_available(macos 10.12, *)) { + IOSurfaceSetValue(surface, CFSTR("IOSurfaceColorSpace"), kCGColorSpaceSRGB); diff --git a/ui/gfx/switches.cc b/ui/gfx/switches.cc index ba3dbf23d1df7a3b0cc199054f36a88014daa0e7..f8a563a78cee2856da0f2ad556beba19b01a2e59 100644 --- a/ui/gfx/switches.cc