summaryrefslogtreecommitdiff
path: root/src/backends/x11
diff options
context:
space:
mode:
authorJonas Ådahl <jadahl@gmail.com>2021-12-03 17:34:34 +0100
committerJonas Ådahl <jadahl@gmail.com>2022-09-01 17:52:01 +0200
commitb59dc05b22461adfd415b980ea452b976ea17042 (patch)
treec7cb540585eac6aa924cd6e2eb89cfef91bd203a /src/backends/x11
parent9dda79b281cce6edc5640f02bd3b5d91124642ed (diff)
downloadmutter-b59dc05b22461adfd415b980ea452b976ea17042.tar.gz
crtc: Get/set gamma via helper struct
Instead of passing 4 arguments (red, green and blue arrays as well as a size), always pass them together in a new struct MetaGammaLut. Makes things slightly less tedious. The KMS layer still has its own variant, but lets leave it as that for now, to keep the KMS layer "below" the cross backend CRTC layer. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
Diffstat (limited to 'src/backends/x11')
-rw-r--r--src/backends/x11/meta-crtc-xrandr.c58
1 files changed, 36 insertions, 22 deletions
diff --git a/src/backends/x11/meta-crtc-xrandr.c b/src/backends/x11/meta-crtc-xrandr.c
index 4fc579bed..c9104002f 100644
--- a/src/backends/x11/meta-crtc-xrandr.c
+++ b/src/backends/x11/meta-crtc-xrandr.c
@@ -297,38 +297,51 @@ meta_crtc_xrandr_new (MetaGpuXrandr *gpu_xrandr,
return crtc_xrandr;
}
-static void
-meta_crtc_xrandr_get_gamma_lut (MetaCrtc *crtc,
- size_t *size,
- unsigned short **red,
- unsigned short **green,
- unsigned short **blue)
+static MetaGammaLut *
+meta_crtc_xrandr_get_gamma_lut (MetaCrtc *crtc)
+{
+ MetaGpu *gpu = meta_crtc_get_gpu (crtc);
+ MetaBackend *backend = meta_gpu_get_backend (gpu);
+ Display *xdisplay =
+ meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
+ XRRCrtcGamma *gamma;
+ MetaGammaLut *lut;
+
+ gamma = XRRGetCrtcGamma (xdisplay, (XID) meta_crtc_get_id (crtc));
+
+ lut = g_new0 (MetaGammaLut, 1);
+ lut->size = gamma->size;
+ lut->red = g_memdup2 (gamma->red, sizeof (unsigned short) * gamma->size);
+ lut->green = g_memdup2 (gamma->green, sizeof (unsigned short) * gamma->size);
+ lut->blue = g_memdup2 (gamma->blue, sizeof (unsigned short) * gamma->size);
+
+ XRRFreeGamma (gamma);
+
+ return lut;
+}
+
+static size_t
+meta_crtc_xrandr_get_gamma_lut_size (MetaCrtc *crtc)
{
MetaGpu *gpu = meta_crtc_get_gpu (crtc);
MetaBackend *backend = meta_gpu_get_backend (gpu);
Display *xdisplay =
meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
XRRCrtcGamma *gamma;
+ size_t size;
gamma = XRRGetCrtcGamma (xdisplay, (XID) meta_crtc_get_id (crtc));
- *size = gamma->size;
- if (red)
- *red = g_memdup2 (gamma->red, sizeof (unsigned short) * gamma->size);
- if (green)
- *green = g_memdup2 (gamma->green, sizeof (unsigned short) * gamma->size);
- if (blue)
- *blue = g_memdup2 (gamma->blue, sizeof (unsigned short) * gamma->size);
+ size = gamma->size;
XRRFreeGamma (gamma);
+
+ return size;
}
static void
-meta_crtc_xrandr_set_gamma_lut (MetaCrtc *crtc,
- size_t size,
- unsigned short *red,
- unsigned short *green,
- unsigned short *blue)
+meta_crtc_xrandr_set_gamma_lut (MetaCrtc *crtc,
+ const MetaGammaLut *lut)
{
MetaGpu *gpu = meta_crtc_get_gpu (crtc);
MetaBackend *backend = meta_gpu_get_backend (gpu);
@@ -336,10 +349,10 @@ meta_crtc_xrandr_set_gamma_lut (MetaCrtc *crtc,
meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
XRRCrtcGamma *gamma;
- gamma = XRRAllocGamma (size);
- memcpy (gamma->red, red, sizeof (unsigned short) * size);
- memcpy (gamma->green, green, sizeof (unsigned short) * size);
- memcpy (gamma->blue, blue, sizeof (unsigned short) * size);
+ gamma = XRRAllocGamma (lut->size);
+ memcpy (gamma->red, lut->red, sizeof (uint16_t) * lut->size);
+ memcpy (gamma->green, lut->green, sizeof (uint16_t) * lut->size);
+ memcpy (gamma->blue, lut->blue, sizeof (uint16_t) * lut->size);
XRRSetCrtcGamma (xdisplay, (XID) meta_crtc_get_id (crtc), gamma);
@@ -356,6 +369,7 @@ meta_crtc_xrandr_class_init (MetaCrtcXrandrClass *klass)
{
MetaCrtcClass *crtc_class = META_CRTC_CLASS (klass);
+ crtc_class->get_gamma_lut_size = meta_crtc_xrandr_get_gamma_lut_size;
crtc_class->get_gamma_lut = meta_crtc_xrandr_get_gamma_lut;
crtc_class->set_gamma_lut = meta_crtc_xrandr_set_gamma_lut;
}