x11: Support the CTM (color transform matrix) RandR property

When supported, this property allows the window system to apply a 3x3 color
correction matrix in order to transform colors from the window system's native
color space to the measured color space of a display device.

Query for this property and set the 'supports-color-transform' property in the
GetResource reply. Add support for the SetOutputCTM DBus method and plumb that
through to the server's CTM property.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1048>
This commit is contained in:
Aaron Plattner
2020-02-04 16:41:34 -08:00
committed by Marge Bot
parent bd15cfc94b
commit e88467f9d7
7 changed files with 156 additions and 0 deletions

View File

@ -8,6 +8,7 @@
* Copyright (C) 2003 Rob Adams
* Copyright (C) 2004-2006 Elijah Newren
* Copyright (C) 2013 Red Hat Inc.
* Copyright (C) 2020 NVIDIA CORPORATION
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@ -1001,6 +1002,13 @@ meta_monitor_manager_xrandr_get_default_layout_mode (MetaMonitorManager *manager
return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
}
static void
meta_monitor_manager_xrandr_set_output_ctm (MetaOutput *output,
const MetaOutputCtm *ctm)
{
meta_output_xrandr_set_ctm (META_OUTPUT_XRANDR (output), ctm);
}
static void
meta_monitor_manager_xrandr_constructed (GObject *object)
{
@ -1086,6 +1094,7 @@ meta_monitor_manager_xrandr_class_init (MetaMonitorManagerXrandrClass *klass)
manager_class->get_capabilities = meta_monitor_manager_xrandr_get_capabilities;
manager_class->get_max_screen_size = meta_monitor_manager_xrandr_get_max_screen_size;
manager_class->get_default_layout_mode = meta_monitor_manager_xrandr_get_default_layout_mode;
manager_class->set_output_ctm = meta_monitor_manager_xrandr_set_output_ctm;
quark_meta_monitor_xrandr_data =
g_quark_from_static_string ("-meta-monitor-xrandr-data");

View File

@ -14,6 +14,7 @@
* Copyright (C) 2003 Rob Adams
* Copyright (C) 2004-2006 Elijah Newren
* Copyright (C) 2013-2017 Red Hat Inc.
* Copyright (C) 2020 NVIDIA CORPORATION
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@ -197,6 +198,21 @@ meta_output_xrandr_change_backlight (MetaOutputXrandr *output_xrandr,
meta_output_set_backlight (output, normalize_backlight (output, hw_value));
}
void
meta_output_xrandr_set_ctm (MetaOutputXrandr *output_xrandr,
const MetaOutputCtm *ctm)
{
MetaOutput *output = META_OUTPUT (output_xrandr);
Display *xdisplay = xdisplay_from_output (output);
Atom atom = XInternAtom (xdisplay, "CTM", False);
xcb_randr_change_output_property (XGetXCBConnection (xdisplay),
(XID) meta_output_get_id (output),
atom, XCB_ATOM_INTEGER, 32,
XCB_PROP_MODE_REPLACE,
18, &ctm->matrix);
}
static gboolean
output_get_integer_property (Display *xdisplay,
RROutput output_id,
@ -351,6 +367,32 @@ output_get_supports_underscanning_xrandr (Display *xdisplay,
return supports_underscanning;
}
static gboolean
output_get_supports_color_transform_xrandr (Display *xdisplay,
RROutput output_id)
{
Atom atom, actual_type;
int actual_format;
unsigned long nitems, bytes_after;
g_autofree unsigned char *buffer = NULL;
atom = XInternAtom (xdisplay, "CTM", False);
XRRGetOutputProperty (xdisplay,
(XID) output_id,
atom,
0, G_MAXLONG, False, False, XA_INTEGER,
&actual_type, &actual_format,
&nitems, &bytes_after, &buffer);
/*
* X's CTM property is 9 64-bit integers represented as an array of 18 32-bit
* integers.
*/
return (actual_type == XA_INTEGER &&
actual_format == 32 &&
nitems == 18);
}
static int
output_get_backlight_xrandr (MetaOutput *output)
{
@ -868,6 +910,8 @@ meta_output_xrandr_new (MetaGpuXrandr *gpu_xrandr,
output_info->supports_underscanning =
output_get_supports_underscanning_xrandr (xdisplay, output_id);
output_info->supports_color_transform =
output_get_supports_color_transform_xrandr (xdisplay, output_id);
output_info_init_backlight_limits_xrandr (output_info, xdisplay, output_id);
output = g_object_new (META_TYPE_OUTPUT_XRANDR,

View File

@ -2,6 +2,7 @@
/*
* Copyright (C) 2017 Red Hat
* Copyright (C) 2020 NVIDIA CORPORATION
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@ -38,6 +39,9 @@ void meta_output_xrandr_apply_mode (MetaOutputXrandr *output_xrandr);
void meta_output_xrandr_change_backlight (MetaOutputXrandr *output_xrandr,
int value);
void meta_output_xrandr_set_ctm (MetaOutputXrandr *output_xrandr,
const MetaOutputCtm *ctm);
GBytes * meta_output_xrandr_read_edid (MetaOutput *output_xrandr);
MetaOutputXrandr * meta_output_xrandr_new (MetaGpuXrandr *gpu_xrandr,