From 1b588e7c1f869883a5abe7f3a52edc0d60afd496 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 6 Sep 2017 14:48:27 +0200 Subject: Add gamma_control skeleton --- include/wlr/types/wlr_gamma_control.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 include/wlr/types/wlr_gamma_control.h (limited to 'include') diff --git a/include/wlr/types/wlr_gamma_control.h b/include/wlr/types/wlr_gamma_control.h new file mode 100644 index 00000000..259c6474 --- /dev/null +++ b/include/wlr/types/wlr_gamma_control.h @@ -0,0 +1,21 @@ +#ifndef _WLR_GAMMA_CONTROL_H +#define _WLR_GAMMA_CONTROL_H +#include + +struct wlr_gamma_control_manager { + struct wl_global *wl_global; + + void *data; +}; + +struct wlr_gamma_control { + struct wl_resource *resource; + struct wl_resource *output; + + void* data; +}; + +struct wlr_gamma_control_manager *wlr_gamma_control_manager_create(struct wl_display *display); +void wlr_gamma_control_manager_destroy(struct wlr_gamma_control_manager *gamma_control_manager); + +#endif -- cgit v1.2.3 From cd125377fce057f7dbdd7afbbfa251311a91af5c Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 6 Sep 2017 17:34:09 +0200 Subject: Add wlr_output_{set_gamma,get_gamma_size} --- include/wlr/types/wlr_output.h | 3 +++ types/wlr_gamma_control.c | 16 ++++++++++++++-- types/wlr_output.c | 10 ++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 3371dcb5..b70bd19e 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -64,5 +64,8 @@ void wlr_output_effective_resolution(struct wlr_output *output, int *width, int *height); void wlr_output_make_current(struct wlr_output *output); void wlr_output_swap_buffers(struct wlr_output *output); +void wlr_output_set_gamma(struct wlr_output *output, + uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b); +uint16_t wlr_output_get_gamma_size(struct wlr_output *output); #endif diff --git a/types/wlr_gamma_control.c b/types/wlr_gamma_control.c index a6520802..d140259e 100644 --- a/types/wlr_gamma_control.c +++ b/types/wlr_gamma_control.c @@ -2,11 +2,11 @@ #include #include #include +#include #include #include "gamma-control-protocol.h" static void resource_destroy(struct wl_client *client, struct wl_resource *resource) { - // TODO: we probably need to do more than this wl_resource_destroy(resource); } @@ -18,7 +18,17 @@ static void gamma_control_destroy(struct wl_resource *resource) { static void gamma_control_set_gamma(struct wl_client *client, struct wl_resource *_gamma_control, struct wl_array *red, struct wl_array *green, struct wl_array *blue) { - // TODO + if (red->size != green->size || red->size != blue->size) { + wl_resource_post_error(_gamma_control, GAMMA_CONTROL_ERROR_INVALID_GAMMA, + "The gamma ramps don't have the same size"); + return; + } + uint16_t *r = (uint16_t *)red->data; + uint16_t *g = (uint16_t *)green->data; + uint16_t *b = (uint16_t *)blue->data; + struct wlr_gamma_control *gamma_control = wl_resource_get_user_data(_gamma_control); + struct wlr_output *output = wl_resource_get_user_data(gamma_control->output); + wlr_output_set_gamma(output, red->size / sizeof(uint16_t), r, g, b); } static void gamma_control_reset_gamma(struct wl_client *client, @@ -37,6 +47,7 @@ static void gamma_control_manager_get_gamma_control(struct wl_client *client, struct wl_resource *_output) { //struct wlr_gamma_control_manager *gamma_control_manager = // wl_resource_get_user_data(_gamma_control_manager); + struct wlr_output *output = wl_resource_get_user_data(_output); struct wlr_gamma_control *gamma_control; if (!(gamma_control = calloc(1, sizeof(struct wlr_gamma_control)))) { return; @@ -47,6 +58,7 @@ static void gamma_control_manager_get_gamma_control(struct wl_client *client, wlr_log(L_DEBUG, "new gamma_control %p (res %p)", gamma_control, gamma_control->resource); wl_resource_set_implementation(gamma_control->resource, &gamma_control_implementation, gamma_control, gamma_control_destroy); + gamma_control_send_gamma_size(_gamma_control_manager, wlr_output_get_gamma_size(output)); } static struct gamma_control_manager_interface gamma_control_manager_impl = { diff --git a/types/wlr_output.c b/types/wlr_output.c index ee050dc4..1d9fb8fc 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -223,3 +223,13 @@ void wlr_output_swap_buffers(struct wlr_output *output) { output->impl->swap_buffers(output); } + +void wlr_output_set_gamma(struct wlr_output *output, + uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b) { + // TODO +} + +uint16_t wlr_output_get_gamma_size(struct wlr_output *output) { + // TODO + return 0; +} -- cgit v1.2.3 From 6f98b5a33762f7d36bccf4902b52d8e70f71e9ca Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 6 Sep 2017 18:53:08 +0200 Subject: Add set_gamma and get_gamma_size to wlr_output_impl --- backend/drm/drm.c | 19 +++++++++++++++++++ include/wlr/interfaces/wlr_output.h | 3 +++ types/wlr_output.c | 10 +++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 5b24e05f..163321a3 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -301,6 +301,23 @@ static void wlr_drm_output_swap_buffers(struct wlr_output *_output) { output->pageflip_pending = true; } +static void wlr_drm_output_set_gamma(struct wlr_output *_output, + uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b) { + struct wlr_drm_output *output = (struct wlr_drm_output *)_output; + struct wlr_drm_backend *backend = + wl_container_of(output->renderer, backend, renderer); + drmModeCrtcSetGamma(backend->fd, output->crtc->id, size, r, g, b); +} + +static uint16_t wlr_drm_output_get_gamma_size(struct wlr_output *_output) { + struct wlr_drm_output *output = (struct wlr_drm_output *)_output; + drmModeCrtc *crtc = output->old_crtc; + if (!crtc) { + return 0; + } + return crtc->gamma_size; +} + void wlr_drm_output_start_renderer(struct wlr_drm_output *output) { if (output->state != WLR_DRM_OUTPUT_CONNECTED) { return; @@ -696,6 +713,8 @@ static struct wlr_output_impl output_impl = { .destroy = wlr_drm_output_destroy, .make_current = wlr_drm_output_make_current, .swap_buffers = wlr_drm_output_swap_buffers, + .set_gamma = wlr_drm_output_set_gamma, + .get_gamma_size = wlr_drm_output_get_gamma_size, }; static int find_id(const void *item, const void *cmp_to) { diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index efc8ef43..a95fe588 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -14,6 +14,9 @@ struct wlr_output_impl { void (*destroy)(struct wlr_output *output); void (*make_current)(struct wlr_output *output); void (*swap_buffers)(struct wlr_output *output); + void (*set_gamma)(struct wlr_output *output, + uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b); + uint16_t (*get_gamma_size)(struct wlr_output *output); }; void wlr_output_init(struct wlr_output *output, const struct wlr_output_impl *impl); diff --git a/types/wlr_output.c b/types/wlr_output.c index 1d9fb8fc..962685b8 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -226,10 +226,14 @@ void wlr_output_swap_buffers(struct wlr_output *output) { void wlr_output_set_gamma(struct wlr_output *output, uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b) { - // TODO + if (output->impl->set_gamma) { + output->impl->set_gamma(output, size, r, g, b); + } } uint16_t wlr_output_get_gamma_size(struct wlr_output *output) { - // TODO - return 0; + if (!output->impl->get_gamma_size) { + return 0; + } + return output->impl->get_gamma_size(output); } -- cgit v1.2.3