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

@@ -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,