From 10a840c92d8fc34f95921e1057eb18fa4b03374e Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 4 Oct 2023 18:15:40 +0200 Subject: [PATCH] kms/impl-device: Handle NULL gamma updates We should not ever get one right now, but if we do, a NULL update means we bypass the gamma LUT. Part-of: --- .../native/meta-kms-impl-device-atomic.c | 59 +++++++++++-------- .../native/meta-kms-impl-device-simple.c | 37 ++++++++---- 2 files changed, 60 insertions(+), 36 deletions(-) diff --git a/src/backends/native/meta-kms-impl-device-atomic.c b/src/backends/native/meta-kms-impl-device-atomic.c index 2ca70326f..5d03cff44 100644 --- a/src/backends/native/meta-kms-impl-device-atomic.c +++ b/src/backends/native/meta-kms-impl-device-atomic.c @@ -675,34 +675,43 @@ process_crtc_color_updates (MetaKmsImplDevice *impl_device, if (color_update->gamma.has_update) { MetaGammaLut *gamma = color_update->gamma.state; - g_autofree struct drm_color_lut *drm_color_lut = NULL; - size_t color_lut_size; - int i; - uint32_t color_lut_blob_id; + uint32_t color_lut_blob_id = 0; - color_lut_size = sizeof (struct drm_color_lut) * gamma->size; - drm_color_lut = g_malloc (color_lut_size); - - for (i = 0; i < gamma->size; i++) + if (gamma && gamma->size > 0) { - drm_color_lut[i].red = gamma->red[i]; - drm_color_lut[i].green = gamma->green[i]; - drm_color_lut[i].blue = gamma->blue[i]; + g_autofree struct drm_color_lut *drm_color_lut = NULL; + size_t color_lut_size; + int i; + + color_lut_size = sizeof(struct drm_color_lut) * gamma->size; + drm_color_lut = g_malloc (color_lut_size); + + for (i = 0; i < gamma->size; i++) + { + drm_color_lut[i].red = gamma->red[i]; + drm_color_lut[i].green = gamma->green[i]; + drm_color_lut[i].blue = gamma->blue[i]; + } + + color_lut_blob_id = store_new_blob (impl_device, + blob_ids, + drm_color_lut, + color_lut_size, + error); + + meta_topic (META_DEBUG_KMS, + "[atomic] Setting CRTC (%u, %s) gamma, size: %zu", + meta_kms_crtc_get_id (crtc), + meta_kms_impl_device_get_path (impl_device), + gamma->size); + } + else + { + meta_topic (META_DEBUG_KMS, + "[atomic] Setting CRTC (%u, %s) gamma to bypass", + meta_kms_crtc_get_id (crtc), + meta_kms_impl_device_get_path (impl_device)); } - - color_lut_blob_id = store_new_blob (impl_device, - blob_ids, - drm_color_lut, - color_lut_size, - error); - if (!color_lut_blob_id) - return FALSE; - - meta_topic (META_DEBUG_KMS, - "[atomic] Setting CRTC (%u, %s) gamma, size: %zu", - meta_kms_crtc_get_id (crtc), - meta_kms_impl_device_get_path (impl_device), - gamma->size); if (!add_crtc_property (impl_device, crtc, req, diff --git a/src/backends/native/meta-kms-impl-device-simple.c b/src/backends/native/meta-kms-impl-device-simple.c index 2d68ba11f..926d3bf81 100644 --- a/src/backends/native/meta-kms-impl-device-simple.c +++ b/src/backends/native/meta-kms-impl-device-simple.c @@ -516,18 +516,33 @@ process_crtc_color_updates (MetaKmsImplDevice *impl_device, int fd; int ret; - meta_topic (META_DEBUG_KMS, - "[simple] Setting CRTC %u (%s) gamma, size: %zu", - meta_kms_crtc_get_id (crtc), - meta_kms_impl_device_get_path (impl_device), - gamma->size); - fd = meta_kms_impl_device_get_fd (impl_device); - ret = drmModeCrtcSetGamma (fd, meta_kms_crtc_get_id (crtc), - gamma->size, - gamma->red, - gamma->green, - gamma->blue); + + if (gamma) + { + meta_topic (META_DEBUG_KMS, + "[simple] Setting CRTC %u (%s) gamma, size: %zu", + meta_kms_crtc_get_id (crtc), + meta_kms_impl_device_get_path (impl_device), + gamma->size); + + ret = drmModeCrtcSetGamma (fd, meta_kms_crtc_get_id (crtc), + gamma->size, + gamma->red, + gamma->green, + gamma->blue); + } + else + { + meta_topic (META_DEBUG_KMS, + "[simple] Setting CRTC (%u, %s) gamma to bypass", + meta_kms_crtc_get_id (crtc), + meta_kms_impl_device_get_path (impl_device)); + + ret = drmModeCrtcSetGamma (fd, meta_kms_crtc_get_id (crtc), + 0, NULL, NULL, NULL); + } + if (ret != 0) { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),