From 2beb68007e707e52711200d9607f7d392bec21cd Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 3 Oct 2018 10:36:33 +0200 Subject: output: make gamma size a size_t and gamma table const --- include/backend/drm/iface.h | 8 ++++---- include/wlr/interfaces/wlr_output.h | 6 +++--- include/wlr/types/wlr_output.h | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/backend/drm/iface.h b/include/backend/drm/iface.h index ef0e7bf8..5308b136 100644 --- a/include/backend/drm/iface.h +++ b/include/backend/drm/iface.h @@ -28,11 +28,11 @@ struct wlr_drm_interface { struct wlr_drm_crtc *crtc, int x, int y); // Set the gamma lut on crtc bool (*crtc_set_gamma)(struct wlr_drm_backend *drm, - struct wlr_drm_crtc *crtc, uint16_t *r, uint16_t *g, uint16_t *b, - uint32_t size); + struct wlr_drm_crtc *crtc, size_t size, + uint16_t *r, uint16_t *g, uint16_t *b); // Get the gamma lut size of a crtc - uint32_t (*crtc_get_gamma_size)(struct wlr_drm_backend *drm, - struct wlr_drm_crtc *crtc); + size_t (*crtc_get_gamma_size)(struct wlr_drm_backend *drm, + struct wlr_drm_crtc *crtc); }; extern const struct wlr_drm_interface atomic_iface; diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index 4cbf0d67..bfb3bc9d 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -28,9 +28,9 @@ 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); - 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 (*set_gamma)(struct wlr_output *output, size_t size, + const uint16_t *r, const uint16_t *g, const uint16_t *b); + size_t (*get_gamma_size)(struct wlr_output *output); bool (*export_dmabuf)(struct wlr_output *output, struct wlr_dmabuf_attributes *attribs); }; diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index ecd4f759..9ede7ab7 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -182,7 +182,7 @@ 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); +size_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 @@ -190,8 +190,8 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output); * * 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); +bool wlr_output_set_gamma(struct wlr_output *output, size_t size, + const uint16_t *r, const uint16_t *g, const uint16_t *b); 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 e88db9a3fb4208776b2a3ef35fdbd5fa344c0905 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 3 Oct 2018 10:53:35 +0200 Subject: backend/drm: reset gamma table on VT switch --- backend/drm/backend.c | 10 ++++++++++ backend/drm/drm.c | 14 +++++++++++--- include/backend/drm/drm.h | 5 +++++ 3 files changed, 26 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/backend/drm/backend.c b/backend/drm/backend.c index bba79bda..76918e7d 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -101,6 +101,16 @@ static void session_signal(struct wl_listener *listener, void *data) { (plane && plane->cursor_enabled) ? plane->cursor_bo : NULL); drm->iface->crtc_move_cursor(drm, conn->crtc, conn->cursor_x, conn->cursor_y); + + if (conn->crtc->gamma_table != NULL) { + size_t size = conn->crtc->gamma_table_size; + uint16_t *r = conn->crtc->gamma_table; + uint16_t *g = conn->crtc->gamma_table + size; + uint16_t *b = conn->crtc->gamma_table + 2 * size; + drm->iface->crtc_set_gamma(drm, conn->crtc, size, r, g, b); + } else { + set_drm_connector_gamma(&conn->output, 0, NULL, NULL, NULL); + } } } else { wlr_log(WLR_INFO, "DRM fd paused"); diff --git a/backend/drm/drm.c b/backend/drm/drm.c index ac7fca02..fa9a95ae 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -193,6 +193,7 @@ void finish_drm_resources(struct wlr_drm_backend *drm) { if (crtc->gamma_lut) { drmModeDestroyPropertyBlob(drm->fd, crtc->gamma_lut); } + free(crtc->gamma_table); } for (size_t i = 0; i < drm->num_planes; ++i) { struct wlr_drm_plane *plane = &drm->planes[i]; @@ -270,7 +271,7 @@ static size_t drm_connector_get_gamma_size(struct wlr_output *output) { return 0; } -static bool drm_connector_set_gamma(struct wlr_output *output, size_t size, +bool set_drm_connector_gamma(struct wlr_output *output, size_t size, const uint16_t *r, const uint16_t *g, const uint16_t *b) { struct wlr_drm_connector *conn = get_drm_connector_from_output(output); struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend); @@ -308,8 +309,13 @@ static bool drm_connector_set_gamma(struct wlr_output *output, size_t size, bool ok = drm->iface->crtc_set_gamma(drm, conn->crtc, size, _r, _g, _b); if (ok) { wlr_output_update_needs_swap(output); + + free(conn->crtc->gamma_table); + conn->crtc->gamma_table = gamma_table; + conn->crtc->gamma_table_size = size; + } else { + free(gamma_table); } - free(gamma_table); return ok; } @@ -736,7 +742,7 @@ static const struct wlr_output_impl output_impl = { .destroy = drm_connector_destroy, .make_current = drm_connector_make_current, .swap_buffers = drm_connector_swap_buffers, - .set_gamma = drm_connector_set_gamma, + .set_gamma = set_drm_connector_gamma, .get_gamma_size = drm_connector_get_gamma_size, .export_dmabuf = drm_connector_export_dmabuf, }; @@ -771,6 +777,8 @@ static void dealloc_crtc(struct wlr_drm_connector *conn) { wlr_log(WLR_DEBUG, "De-allocating CRTC %zu for output '%s'", conn->crtc - drm->crtcs, conn->output.name); + set_drm_connector_gamma(&conn->output, 0, NULL, NULL, NULL); + for (size_t type = 0; type < 3; ++type) { struct wlr_drm_plane *plane = conn->crtc->planes[type]; if (plane == NULL) { diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index 3b01b64f..3c728808 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -57,6 +57,9 @@ struct wlr_drm_crtc { union wlr_drm_crtc_props props; struct wl_list connectors; + + uint16_t *gamma_table; + size_t gamma_table_size; }; struct wlr_drm_backend { @@ -151,5 +154,7 @@ void restore_drm_outputs(struct wlr_drm_backend *drm); void scan_drm_connectors(struct wlr_drm_backend *state); int handle_drm_event(int fd, uint32_t mask, void *data); bool enable_drm_connector(struct wlr_output *output, bool enable); +bool set_drm_connector_gamma(struct wlr_output *output, size_t size, + const uint16_t *r, const uint16_t *g, const uint16_t *b); #endif -- cgit v1.2.3