From f0ce906b73419000c1d61c2b88e6d5f4f36d2041 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Mon, 1 Apr 2024 22:47:18 +0200 Subject: [PATCH] wlr_gamma_control: Store gamma size when creating control When a wlr_gamma_control client calls set_gamma, we allocate a LUT based on the value returned from wlr_output_get_gamma_size at the time of the call. If the output is off and has no CRTC, such as if gamma changes in the background while a display is disabled for idle reasons, wlr_output_get_gamma_size returns 0. This leads to a zero-sized table, which the drm backend interprets as a request to reset gamma tables to their default. Store the gamma size when the gamma control was created. Even if the size changes, this is the size the client was sent and uses to create the LUTs it sends. --- types/wlr_gamma_control_v1.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/types/wlr_gamma_control_v1.c b/types/wlr_gamma_control_v1.c index fbf117f8..732439de 100644 --- a/types/wlr_gamma_control_v1.c +++ b/types/wlr_gamma_control_v1.c @@ -66,8 +66,7 @@ static void gamma_control_handle_set_gamma(struct wl_client *client, goto error_fd; } - uint32_t ramp_size = wlr_output_get_gamma_size(gamma_control->output); - size_t table_size = ramp_size * 3 * sizeof(uint16_t); + size_t table_size = gamma_control->ramp_size * 3 * sizeof(uint16_t); // Refuse to block when reading int fd_flags = fcntl(fd, F_GETFL, 0); @@ -104,7 +103,6 @@ static void gamma_control_handle_set_gamma(struct wl_client *client, free(gamma_control->table); gamma_control->table = table; - gamma_control->ramp_size = ramp_size; struct wlr_gamma_control_manager_v1_set_gamma_event event = { .output = gamma_control->output, @@ -176,6 +174,7 @@ static void gamma_control_manager_get_gamma_control(struct wl_client *client, gamma_control->output = output; gamma_control->manager = manager; gamma_control->resource = resource; + gamma_control->ramp_size = gamma_size; wl_resource_set_user_data(resource, gamma_control); wl_signal_add(&output->events.destroy,