From a149c2370afa995968fde78721c36bb59e8e4b59 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 22 Jul 2018 13:23:32 +0100 Subject: Implement wlr-gamma-control-unstable-v1 --- include/wlr/interfaces/wlr_output.h | 2 +- include/wlr/types/wlr_gamma_control_v1.h | 31 +++++++++++++++++++++++++++++++ include/wlr/types/wlr_output.h | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 include/wlr/types/wlr_gamma_control_v1.h (limited to 'include/wlr') diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index 2224932f..4860a5b6 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -28,7 +28,7 @@ struct wlr_output_impl { void (*destroy)(struct wlr_output *output); bool (*make_current)(struct wlr_output *output, int *buffer_age); bool (*swap_buffers)(struct wlr_output *output, pixman_region32_t *damage); - void (*set_gamma)(struct wlr_output *output, + bool (*set_gamma)(struct wlr_output *output, uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); uint32_t (*get_gamma_size)(struct wlr_output *output); bool (*export_dmabuf)(struct wlr_output *output, diff --git a/include/wlr/types/wlr_gamma_control_v1.h b/include/wlr/types/wlr_gamma_control_v1.h new file mode 100644 index 00000000..5a173323 --- /dev/null +++ b/include/wlr/types/wlr_gamma_control_v1.h @@ -0,0 +1,31 @@ +#ifndef WLR_TYPES_WLR_GAMMA_CONTROL_V1_H +#define WLR_TYPES_WLR_GAMMA_CONTROL_V1_H + +#include + +struct wlr_gamma_control_manager_v1 { + struct wl_global *global; + struct wl_list resources; + struct wl_list controls; // wlr_gamma_control_v1::link + + struct wl_listener display_destroy; + + void *data; +}; + +struct wlr_gamma_control_v1 { + struct wl_resource *resource; + struct wlr_output *output; + struct wl_list link; + + struct wl_listener output_destroy_listener; + + void *data; +}; + +struct wlr_gamma_control_manager_v1 *wlr_gamma_control_manager_v1_create( + struct wl_display *display); +void wlr_gamma_control_manager_v1_destroy( + struct wlr_gamma_control_manager_v1 *manager); + +#endif diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index f8452d12..0cf3e9f6 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -174,7 +174,7 @@ bool wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when, * it is a no-op. */ void wlr_output_schedule_frame(struct wlr_output *output); -void wlr_output_set_gamma(struct wlr_output *output, +bool wlr_output_set_gamma(struct wlr_output *output, uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); uint32_t wlr_output_get_gamma_size(struct wlr_output *output); bool wlr_output_export_dmabuf(struct wlr_output *output, -- cgit v1.2.3 From e21563ec76b5f1f500b530cd2a5787123b26d627 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 22 Jul 2018 17:23:34 +0100 Subject: output: document gamma functions --- include/wlr/types/wlr_output.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 0cf3e9f6..e9f3ae3b 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -174,9 +174,17 @@ bool wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when, * it is a no-op. */ void wlr_output_schedule_frame(struct wlr_output *output); +/** + * Returns the maximum length of each gamma ramp, or 0 if unsupported. + */ +uint32_t wlr_output_get_gamma_size(struct wlr_output *output); +/** + * Sets the gamma table for this output. `r`, `g` and `b` are gamma ramps for + * red, green and blue. `size` is the length of the ramps and must not exceed + * the value returned by `wlr_output_get_gamma_size`. + */ bool wlr_output_set_gamma(struct wlr_output *output, uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); -uint32_t wlr_output_get_gamma_size(struct wlr_output *output); bool wlr_output_export_dmabuf(struct wlr_output *output, struct wlr_dmabuf_attributes *attribs); void wlr_output_set_fullscreen_surface(struct wlr_output *output, -- cgit v1.2.3 From 2ebecb6727b55dbdfe067d27bdb1679014e66879 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 22 Jul 2018 17:37:01 +0100 Subject: backend/drm: allow to pass empty gamma ramp to reset it --- backend/drm/drm.c | 48 +++++++++++++++++++++++++++++++----------- include/wlr/types/wlr_output.h | 2 ++ 2 files changed, 38 insertions(+), 12 deletions(-) (limited to 'include/wlr') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 3e6659f1..ce5a1640 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -228,19 +228,12 @@ static bool drm_connector_swap_buffers(struct wlr_output *output, return true; } -static bool drm_connector_set_gamma(struct wlr_output *output, - uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) { - struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; - - bool ok = false; - if (conn->crtc) { - ok = drm->iface->crtc_set_gamma(drm, conn->crtc, r, g, b, size); - if (ok) { - wlr_output_update_needs_swap(output); - } +static void fill_empty_gamma_table(uint32_t size, + uint16_t *r, uint16_t *g, uint16_t *b) { + for (uint32_t i = 0; i < size; ++i) { + uint16_t val = (uint32_t)0xffff * (uint32_t)i / (uint32_t)(size - 1); + r[i] = g[i] = b[i] = val; } - return ok; } static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) { @@ -254,6 +247,37 @@ static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) { return 0; } +static bool drm_connector_set_gamma(struct wlr_output *output, + uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) { + struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; + struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; + + if (!conn->crtc) { + return false; + } + + uint16_t *reset_table = NULL; + if (size == 0) { + size = drm_connector_get_gamma_size(output); + reset_table = malloc(3 * size * sizeof(uint16_t)); + if (reset_table == NULL) { + wlr_log(WLR_ERROR, "Failed to allocate gamma table"); + return false; + } + r = reset_table; + g = reset_table + size; + b = reset_table + 2 * size; + fill_empty_gamma_table(size, r, g, b); + } + + bool ok = drm->iface->crtc_set_gamma(drm, conn->crtc, r, g, b, size); + if (ok) { + wlr_output_update_needs_swap(output); + } + free(reset_table); + return ok; +} + static bool drm_connector_export_dmabuf(struct wlr_output *output, struct wlr_dmabuf_attributes *attribs) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index e9f3ae3b..3a9f3c41 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -182,6 +182,8 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output); * Sets the gamma table for this output. `r`, `g` and `b` are gamma ramps for * red, green and blue. `size` is the length of the ramps and must not exceed * the value returned by `wlr_output_get_gamma_size`. + * + * Providing zero-sized ramps resets the gamma table. */ bool wlr_output_set_gamma(struct wlr_output *output, uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); -- cgit v1.2.3