/
disable_color_correct_rendering.patch
318 lines (281 loc) · 16.1 KB
/
disable_color_correct_rendering.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Birunthan Mohanathas <birunthan@mohanathas.com>
Date: Fri, 30 Nov 2018 12:44:12 +0200
Subject: Add --disable-color-correct-rendering switch
In Electron 2.0, `--disable-features=ColorCorrectRendering` could be
used to make the app use the display color space (e.g. P3 on Macs)
instead of color correcting to sRGB. Because color correct rendering is
always enabled on Chromium 62 and later and because
`--force-color-profile` has no effect on macOS, apps that need e.g. P3
colors are currently stuck on Electron 2.0.
This restores the functionality removed in
https://chromium-review.googlesource.com/698347 in the form of the
`--disable-color-correct-rendering` switch.
This can be removed once web content (including WebGL) learn how
to deal with color spaces. That is being tracked at
https://crbug.com/634542 and https://crbug.com/711107.
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index 507ece40522fc29a56908d9a6532947a7f67db35..1659c05bfeecbf8ef4264f946aa045d58beb2775 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -1578,6 +1578,10 @@ void LayerTreeHostImpl::SetIsLikelyToRequireADraw(
}
RasterColorSpace LayerTreeHostImpl::GetRasterColorSpace() const {
+ if (!settings_.enable_color_correct_rendering) {
+ return {};
+ }
+
RasterColorSpace result;
// The pending tree will have the most recently updated color space, so
// prefer that.
diff --git a/cc/trees/layer_tree_settings.h b/cc/trees/layer_tree_settings.h
index 736df815a2815484b561bdc4828dbb8592a43d3a..b9b624e475bc244154febb214d88c63aaba5bbab 100644
--- a/cc/trees/layer_tree_settings.h
+++ b/cc/trees/layer_tree_settings.h
@@ -98,6 +98,8 @@ class CC_EXPORT LayerTreeSettings {
bool enable_mask_tiling = true;
+ bool enable_color_correct_rendering = true;
+
// If set to true, the compositor may selectively defer image decodes to the
// Image Decode Service and raster tiles without images until the decode is
// ready.
diff --git a/components/viz/common/display/renderer_settings.h b/components/viz/common/display/renderer_settings.h
index 740cb2ab71cfad11f51418f011ad8a68764c51f4..8c882d58a70a8f6c8f5d4ea861a38b24ffdd4573 100644
--- a/components/viz/common/display/renderer_settings.h
+++ b/components/viz/common/display/renderer_settings.h
@@ -18,6 +18,7 @@ class VIZ_COMMON_EXPORT RendererSettings {
RendererSettings(const RendererSettings& other);
~RendererSettings();
+ bool enable_color_correct_rendering = true;
bool allow_antialiasing = true;
bool force_antialiasing = false;
bool force_blending_with_shaders = false;
diff --git a/components/viz/host/renderer_settings_creation.cc b/components/viz/host/renderer_settings_creation.cc
index eca6020535249e51b428de9dd6454273e6c9dd71..683cf414f98f8a2df5d82904a79c551749fffb67 100644
--- a/components/viz/host/renderer_settings_creation.cc
+++ b/components/viz/host/renderer_settings_creation.cc
@@ -43,6 +43,8 @@ bool GetSwitchValueAsInt(const base::CommandLine* command_line,
RendererSettings CreateRendererSettings() {
RendererSettings renderer_settings;
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ renderer_settings.enable_color_correct_rendering =
+ !command_line->HasSwitch("disable-color-correct-rendering");
renderer_settings.partial_swap_enabled =
!command_line->HasSwitch(switches::kUIDisablePartialSwap);
#if defined(OS_WIN)
diff --git a/components/viz/service/display/gl_renderer.cc b/components/viz/service/display/gl_renderer.cc
index f37adb85d10e344ec9251334b0f46809428cd87a..4d26492492da3ddff0a2529a5e52e5506560a31c 100644
--- a/components/viz/service/display/gl_renderer.cc
+++ b/components/viz/service/display/gl_renderer.cc
@@ -77,6 +77,9 @@
using gpu::gles2::GLES2Interface;
+#define PATCH_CS(color_space) \
+ (settings_->enable_color_correct_rendering ? color_space : gfx::ColorSpace())
+
namespace viz {
namespace {
@@ -516,8 +519,9 @@ void GLRenderer::DoDrawQuad(const DrawQuad* quad,
void GLRenderer::DrawDebugBorderQuad(const DebugBorderDrawQuad* quad) {
SetBlendEnabled(quad->ShouldDrawWithBlending());
- SetUseProgram(ProgramKey::DebugBorder(), gfx::ColorSpace::CreateSRGB(),
- current_frame()->current_render_pass->color_space);
+ SetUseProgram(ProgramKey::DebugBorder(),
+ PATCH_CS(gfx::ColorSpace::CreateSRGB()),
+ PATCH_CS(current_frame()->current_render_pass->color_space));
// Use the full quad_rect for debug quads to not move the edges based on
// partial swaps.
@@ -1289,7 +1293,8 @@ void GLRenderer::ChooseRPDQProgram(DrawRenderPassDrawQuadParams* params,
tex_coord_precision, sampler_type, shader_blend_mode,
params->use_aa ? USE_AA : NO_AA, mask_mode, mask_for_background,
params->use_color_matrix, tint_gl_composited_content_),
- params->contents_and_bypass_color_space, target_color_space);
+ PATCH_CS(params->contents_and_bypass_color_space),
+ PATCH_CS(target_color_space));
}
void GLRenderer::UpdateRPDQUniforms(DrawRenderPassDrawQuadParams* params) {
@@ -1750,8 +1755,8 @@ void GLRenderer::DrawSolidColorQuad(const SolidColorDrawQuad* quad,
gfx::ColorSpace quad_color_space = gfx::ColorSpace::CreateSRGB();
SetUseProgram(ProgramKey::SolidColor(use_aa ? USE_AA : NO_AA,
tint_gl_composited_content_),
- quad_color_space,
- current_frame()->current_render_pass->color_space);
+ PATCH_CS(quad_color_space),
+ PATCH_CS(current_frame()->current_render_pass->color_space));
SetShaderColor(color, opacity);
if (current_program_->tint_color_matrix_location() != -1) {
@@ -1901,8 +1906,8 @@ void GLRenderer::DrawContentQuadAA(const ContentDrawQuadBase* quad,
quad->is_premultiplied ? PREMULTIPLIED_ALPHA
: NON_PREMULTIPLIED_ALPHA,
false, false, tint_gl_composited_content_),
- quad_resource_lock.color_space(),
- current_frame()->current_render_pass->color_space);
+ PATCH_CS(quad_resource_lock.color_space()),
+ PATCH_CS(current_frame()->current_render_pass->color_space));
if (current_program_->tint_color_matrix_location() != -1) {
auto matrix = cc::DebugColors::TintCompositedContentColorTransformMatrix();
@@ -1990,8 +1995,8 @@ void GLRenderer::DrawContentQuadNoAA(const ContentDrawQuadBase* quad,
: NON_PREMULTIPLIED_ALPHA,
!quad->ShouldDrawWithBlending(), has_tex_clamp_rect,
tint_gl_composited_content_),
- quad_resource_lock.color_space(),
- current_frame()->current_render_pass->color_space);
+ PATCH_CS(quad_resource_lock.color_space()),
+ PATCH_CS(current_frame()->current_render_pass->color_space));
if (current_program_->tint_color_matrix_location() != -1) {
auto matrix = cc::DebugColors::TintCompositedContentColorTransformMatrix();
@@ -2086,7 +2091,7 @@ void GLRenderer::DrawYUVVideoQuad(const YUVVideoDrawQuad* quad,
DCHECK_NE(src_color_space, src_color_space.GetAsFullRangeRGB());
gfx::ColorSpace dst_color_space =
- current_frame()->current_render_pass->color_space;
+ PATCH_CS(current_frame()->current_render_pass->color_space);
// Force sRGB output on Windows for overlay candidate video quads to match
// DirectComposition behavior in case these switch between overlays and
// compositing. See https://crbug.com/811118 for details.
@@ -2234,8 +2239,8 @@ void GLRenderer::DrawStreamVideoQuad(const StreamVideoDrawQuad* quad,
quad->resource_id());
SetUseProgram(ProgramKey::VideoStream(tex_coord_precision),
- lock.color_space(),
- current_frame()->current_render_pass->color_space);
+ PATCH_CS(lock.color_space()),
+ PATCH_CS(current_frame()->current_render_pass->color_space));
DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id());
@@ -2287,8 +2292,8 @@ void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) {
draw_cache_.nearest_neighbor ? GL_NEAREST : GL_LINEAR);
// Bind the program to the GL state.
- SetUseProgram(draw_cache_.program_key, locked_quad.color_space(),
- current_frame()->current_render_pass->color_space);
+ SetUseProgram(draw_cache_.program_key, PATCH_CS(locked_quad.color_space()),
+ PATCH_CS(current_frame()->current_render_pass->color_space));
DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
gl_->BindTexture(locked_quad.target(), locked_quad.texture_id());
@@ -2938,7 +2943,9 @@ void GLRenderer::PrepareGeometry(BoundGeometry binding) {
void GLRenderer::SetUseProgram(const ProgramKey& program_key_no_color,
const gfx::ColorSpace& src_color_space,
const gfx::ColorSpace& dst_color_space) {
- DCHECK(dst_color_space.IsValid());
+ if (settings_->enable_color_correct_rendering) {
+ DCHECK(dst_color_space.IsValid());
+ }
ProgramKey program_key = program_key_no_color;
const gfx::ColorTransform* color_transform =
@@ -3306,7 +3313,7 @@ void GLRenderer::CopyRenderPassDrawQuadToOverlayResource(
*overlay_texture = FindOrCreateOverlayTexture(
params.quad->render_pass_id, iosurface_width, iosurface_height,
- current_frame()->root_render_pass->color_space);
+ PATCH_CS(current_frame()->root_render_pass->color_space));
*new_bounds = gfx::RectF(updated_dst_rect.origin(),
gfx::SizeF((*overlay_texture)->texture.size()));
@@ -3511,8 +3518,9 @@ void GLRenderer::FlushOverdrawFeedback(const gfx::Rect& output_rect) {
PrepareGeometry(SHARED_BINDING);
- SetUseProgram(ProgramKey::DebugBorder(), gfx::ColorSpace::CreateSRGB(),
- current_frame()->root_render_pass->color_space);
+ SetUseProgram(ProgramKey::DebugBorder(),
+ PATCH_CS(gfx::ColorSpace::CreateSRGB()),
+ PATCH_CS(current_frame()->root_render_pass->color_space));
gfx::Transform render_matrix;
render_matrix.Translate(0.5 * output_rect.width() + output_rect.x(),
@@ -3671,3 +3679,5 @@ gfx::Size GLRenderer::GetRenderPassBackingPixelSize(
}
} // namespace viz
+
+#undef PATCH_CS
diff --git a/components/viz/service/display/skia_renderer.cc b/components/viz/service/display/skia_renderer.cc
index 0544d031b60d38279104a4ca9c6dc25126dea185..1acb3dfa55f39b8ecb9fccaa4627ac25cac81f1f 100644
--- a/components/viz/service/display/skia_renderer.cc
+++ b/components/viz/service/display/skia_renderer.cc
@@ -584,9 +584,11 @@ void SkiaRenderer::DrawPictureQuad(const PictureDrawQuad* quad) {
std::unique_ptr<SkCanvas> color_transform_canvas;
// TODO(enne): color transform needs to be replicated in gles2_cmd_decoder
- color_transform_canvas = SkCreateColorSpaceXformCanvas(
- current_canvas_, gfx::ColorSpace::CreateSRGB().ToSkColorSpace());
- raster_canvas = color_transform_canvas.get();
+ if (settings_->enable_color_correct_rendering) {
+ color_transform_canvas = SkCreateColorSpaceXformCanvas(
+ current_canvas_, gfx::ColorSpace::CreateSRGB().ToSkColorSpace());
+ raster_canvas = color_transform_canvas.get();
+ }
base::Optional<skia::OpacityFilterCanvas> opacity_canvas;
if (needs_transparency || disable_image_filtering) {
diff --git a/components/viz/service/display/software_renderer.cc b/components/viz/service/display/software_renderer.cc
index b72323450524eb53e2ae1938da4e9410d456417f..bba0fd17ac0f95879e77c8112cb8f4da7b49e3ee 100644
--- a/components/viz/service/display/software_renderer.cc
+++ b/components/viz/service/display/software_renderer.cc
@@ -333,9 +333,11 @@ void SoftwareRenderer::DrawPictureQuad(const PictureDrawQuad* quad) {
std::unique_ptr<SkCanvas> color_transform_canvas;
// TODO(enne): color transform needs to be replicated in gles2_cmd_decoder
- color_transform_canvas = SkCreateColorSpaceXformCanvas(
- current_canvas_, gfx::ColorSpace::CreateSRGB().ToSkColorSpace());
- raster_canvas = color_transform_canvas.get();
+ if (settings_->enable_color_correct_rendering) {
+ color_transform_canvas = SkCreateColorSpaceXformCanvas(
+ current_canvas_, gfx::ColorSpace::CreateSRGB().ToSkColorSpace());
+ raster_canvas = color_transform_canvas.get();
+ }
base::Optional<skia::OpacityFilterCanvas> opacity_canvas;
if (needs_transparency || disable_image_filtering) {
diff --git a/content/browser/gpu/gpu_process_host.cc b/content/browser/gpu/gpu_process_host.cc
index bdecceea7e66605869548efc15181d88cfb8a438..0f0e20308b8a7753ee40e12f8da9bbf0de4aef70 100644
--- a/content/browser/gpu/gpu_process_host.cc
+++ b/content/browser/gpu/gpu_process_host.cc
@@ -192,6 +192,7 @@ GpuTerminationStatus ConvertToGpuTerminationStatus(
// Command-line switches to propagate to the GPU process.
static const char* const kSwitchNames[] = {
+ "disable-color-correct-rendering",
service_manager::switches::kDisableSeccompFilterSandbox,
service_manager::switches::kGpuSandboxAllowSysVShm,
service_manager::switches::kGpuSandboxFailuresFatal,
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index 05e0ee79e5ada8eee03b2bff9c127b4f11610c17..b19d8e8c53db0396b39fed0e2e530705c5337284 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -2779,6 +2779,7 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
// Propagate the following switches to the renderer command line (along
// with any associated values) if present in the browser command line.
static const char* const kSwitchNames[] = {
+ "disable-color-correct-rendering",
network::switches::kNoReferrers,
service_manager::switches::kDisableInProcessStackTraces,
service_manager::switches::kDisableSeccompFilterSandbox,
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index 560c7caaa74c295a203bfa53c1acc63f1eb4283f..39fe8a6696d2cf0201d9b04364ffabab7af50bca 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -2458,6 +2458,9 @@ cc::LayerTreeSettings RenderWidget::GenerateLayerTreeSettings(
settings.main_frame_before_activation_enabled =
cmd.HasSwitch(cc::switches::kEnableMainFrameBeforeActivation);
+ settings.enable_color_correct_rendering =
+ !cmd.HasSwitch("disable-color-correct-rendering");
+
// Checkerimaging is not supported for synchronous single-threaded mode, which
// is what the renderer uses if its not threaded.
settings.enable_checker_imaging =
diff --git a/ui/gfx/mac/io_surface.cc b/ui/gfx/mac/io_surface.cc
index 00ad38db090096645d9ef9e3220a48661b6401df..5c9ae8c36f92b48754dade5baf8f70e7f883eb09 100644
--- a/ui/gfx/mac/io_surface.cc
+++ b/ui/gfx/mac/io_surface.cc
@@ -199,6 +199,11 @@ IOSurfaceRef CreateIOSurface(const gfx::Size& size,
// Ensure that all IOSurfaces start as sRGB.
CGColorSpaceRef color_space = base::mac::GetSRGBColorSpace();
+ auto* cmd_line = base::CommandLine::ForCurrentProcess();
+ if (cmd_line->HasSwitch("disable-color-correct-rendering")) {
+ color_space = base::mac::GetSystemColorSpace();
+ }
+
base::ScopedCFTypeRef<CFDataRef> color_space_icc(
CGColorSpaceCopyICCProfile(color_space));
IOSurfaceSetValue(surface, CFSTR("IOSurfaceColorSpace"), color_space_icc);
@@ -210,6 +215,14 @@ IOSurfaceRef CreateIOSurface(const gfx::Size& size,
void IOSurfaceSetColorSpace(IOSurfaceRef io_surface,
const ColorSpace& color_space) {
+ auto* cmd_line = base::CommandLine::ForCurrentProcess();
+ if (cmd_line->HasSwitch("disable-color-correct-rendering")) {
+ base::ScopedCFTypeRef<CFDataRef> system_icc(
+ CGColorSpaceCopyICCProfile(base::mac::GetSystemColorSpace()));
+ IOSurfaceSetValue(io_surface, CFSTR("IOSurfaceColorSpace"), system_icc);
+ return;
+ }
+
// Special-case sRGB.
if (color_space == ColorSpace::CreateSRGB()) {
base::ScopedCFTypeRef<CFDataRef> srgb_icc(