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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3309>
This commit is contained in:
Sebastian Wick 2023-10-04 18:15:40 +02:00 committed by Marge Bot
parent e21f839776
commit 10a840c92d
2 changed files with 60 additions and 36 deletions

View File

@ -675,34 +675,43 @@ process_crtc_color_updates (MetaKmsImplDevice *impl_device,
if (color_update->gamma.has_update) if (color_update->gamma.has_update)
{ {
MetaGammaLut *gamma = color_update->gamma.state; MetaGammaLut *gamma = color_update->gamma.state;
g_autofree struct drm_color_lut *drm_color_lut = NULL; uint32_t color_lut_blob_id = 0;
size_t color_lut_size;
int i;
uint32_t color_lut_blob_id;
color_lut_size = sizeof (struct drm_color_lut) * gamma->size; if (gamma && gamma->size > 0)
drm_color_lut = g_malloc (color_lut_size);
for (i = 0; i < gamma->size; i++)
{ {
drm_color_lut[i].red = gamma->red[i]; g_autofree struct drm_color_lut *drm_color_lut = NULL;
drm_color_lut[i].green = gamma->green[i]; size_t color_lut_size;
drm_color_lut[i].blue = gamma->blue[i]; 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, if (!add_crtc_property (impl_device,
crtc, req, crtc, req,

View File

@ -516,18 +516,33 @@ process_crtc_color_updates (MetaKmsImplDevice *impl_device,
int fd; int fd;
int ret; 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); fd = meta_kms_impl_device_get_fd (impl_device);
ret = drmModeCrtcSetGamma (fd, meta_kms_crtc_get_id (crtc),
gamma->size, if (gamma)
gamma->red, {
gamma->green, meta_topic (META_DEBUG_KMS,
gamma->blue); "[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) if (ret != 0)
{ {
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret), g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),