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.
This commit is contained in:
Kenny Levinsen 2024-04-01 22:47:18 +02:00
parent 3fc66d4525
commit f0ce906b73
1 changed files with 2 additions and 3 deletions

View File

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