From c03e7746367194b859125624b059c1725eb7ae30 Mon Sep 17 00:00:00 2001 From: Heghedus Razvan Date: Thu, 19 Oct 2017 16:48:00 +0300 Subject: Replace list_t with wl_list in wlr_drm_backend Signed-off-by: Heghedus Razvan --- backend/drm/drm.c | 83 +++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 42 deletions(-) (limited to 'backend/drm/drm.c') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index ff4dc7f6..74a63f79 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -313,7 +313,7 @@ static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in) static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector *conn) { uint32_t crtc[drm->num_crtcs]; uint32_t crtc_res[drm->num_crtcs]; - uint32_t possible_crtc[drm->outputs->length]; + uint32_t possible_crtc[wl_list_length(&drm->outputs)]; for (size_t i = 0; i < drm->num_crtcs; ++i) { crtc[i] = UNMATCHED; @@ -321,9 +321,9 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector memset(possible_crtc, 0, sizeof(possible_crtc)); - ssize_t index = -1; - for (size_t i = 0; i < drm->outputs->length; ++i) { - struct wlr_drm_connector *c = drm->outputs->items[i]; + ssize_t index = -1, i = 0; + struct wlr_drm_connector *c; + wl_list_for_each(c, &drm->outputs, link) { if (c == conn) { index = i; } @@ -334,11 +334,12 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector possible_crtc[i] = c->possible_crtc; crtc[c->crtc - drm->crtcs] = i; + i++; } assert(index != -1); possible_crtc[index] = conn->possible_crtc; - match_obj(drm->outputs->length, possible_crtc, drm->num_crtcs, + match_obj(wl_list_length(&drm->outputs), possible_crtc, drm->num_crtcs, crtc, crtc_res); bool matched = false; @@ -363,7 +364,14 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector } if (crtc_res[i] != crtc[i]) { - struct wlr_drm_connector *c = drm->outputs->items[crtc_res[i]]; + struct wlr_drm_connector *c; + size_t pos = 0; + wl_list_for_each(c, &drm->outputs, link) { + if (pos == crtc_res[i]) { + break; + } + pos++; + } c->crtc = &drm->crtcs[i]; } } @@ -438,8 +446,7 @@ static bool wlr_drm_connector_set_mode(struct wlr_output *output, // Since realloc_crtcs can deallocate planes on OTHER outputs, // we actually need to reinitalise all of them - for (size_t i = 0; i < drm->outputs->length; ++i) { - struct wlr_drm_connector *conn = drm->outputs->items[i]; + wl_list_for_each(conn, &drm->outputs, link) { struct wlr_output_mode *mode = conn->output.current_mode; struct wlr_drm_crtc *crtc = conn->crtc; @@ -667,13 +674,6 @@ static int retry_pageflip(void *data) { return 0; } -static int find_id(const void *item, const void *cmp_to) { - const struct wlr_drm_connector *conn = item; - const uint32_t *id = cmp_to; - - return (int)conn->id - (int)*id; -} - static const int32_t subpixel_map[] = { [DRM_MODE_SUBPIXEL_UNKNOWN] = WL_OUTPUT_SUBPIXEL_UNKNOWN, [DRM_MODE_SUBPIXEL_HORIZONTAL_RGB] = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB, @@ -692,7 +692,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { return; } - size_t seen_len = drm->outputs->length; + size_t seen_len = wl_list_length(&drm->outputs); // +1 so it can never be 0 bool seen[seen_len + 1]; memset(seen, 0, sizeof(seen)); @@ -704,11 +704,16 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { wlr_log_errno(L_ERROR, "Failed to get DRM connector"); continue; } - - struct wlr_drm_connector *wlr_conn; - int index = list_seq_find(drm->outputs, find_id, &drm_conn->connector_id); - - if (index == -1) { + int index = 0; + struct wlr_drm_connector *c, *wlr_conn = NULL; + wl_list_for_each(c, &drm->outputs, link) { + index++; + if (c->id == drm_conn->connector_id) { + wlr_conn = c; + break; + } + } + if (!wlr_conn) { wlr_conn = calloc(1, sizeof(*wlr_conn)); if (!wlr_conn) { wlr_log_errno(L_ERROR, "Allocation failed"); @@ -749,17 +754,10 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { parse_edid(&wlr_conn->output, edid_len, edid); free(edid); - if (list_add(drm->outputs, wlr_conn) == -1) { - wlr_log_errno(L_ERROR, "Allocation failed"); - drmModeFreeConnector(drm_conn); - wl_event_source_remove(wlr_conn->retry_pageflip); - free(wlr_conn); - continue; - } + wl_list_insert(&drm->outputs, &wlr_conn->link); wlr_output_create_global(&wlr_conn->output, drm->display); wlr_log(L_INFO, "Found display '%s'", wlr_conn->output.name); } else { - wlr_conn = drm->outputs->items[index]; seen[index] = true; } @@ -807,12 +805,14 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { drmModeFreeResources(res); - for (size_t i = seen_len; i-- > 0;) { - if (seen[i]) { + struct wlr_drm_connector *conn, *tmp_conn; + size_t index = seen_len - 1; + wl_list_for_each_safe(conn, tmp_conn, &drm->outputs, link) { + if (seen[index]) { + index--; continue; } - - struct wlr_drm_connector *conn = drm->outputs->items[i]; + index--; wlr_log(L_INFO, "'%s' disappeared", conn->output.name); wlr_drm_connector_cleanup(conn); @@ -820,8 +820,6 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { drmModeFreeCrtc(conn->old_crtc); wl_event_source_remove(conn->retry_pageflip); free(conn); - - list_del(drm->outputs, i); } } @@ -856,10 +854,10 @@ int wlr_drm_event(int fd, uint32_t mask, void *data) { } void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) { - uint64_t to_close = (1 << drm->outputs->length) - 1; + uint64_t to_close = (1 << wl_list_length(&drm->outputs)) - 1; - for (size_t i = 0; i < drm->outputs->length; ++i) { - struct wlr_drm_connector *conn = drm->outputs->items[i]; + struct wlr_drm_connector *conn; + wl_list_for_each(conn, &drm->outputs, link) { if (conn->state == WLR_DRM_CONN_CONNECTED) { conn->state = WLR_DRM_CONN_CLEANUP; } @@ -869,11 +867,13 @@ void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) { while (to_close && time(NULL) < timeout) { wlr_drm_event(drm->fd, 0, NULL); - for (size_t i = 0; i < drm->outputs->length; ++i) { - struct wlr_drm_connector *conn = drm->outputs->items[i]; + size_t i = 0; + struct wlr_drm_connector *conn; + wl_list_for_each(conn, &drm->outputs, link) { if (conn->state != WLR_DRM_CONN_CLEANUP || !conn->pageflip_pending) { to_close &= ~(1 << i); } + i++; } } @@ -881,8 +881,7 @@ void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) { wlr_log(L_ERROR, "Timed out stopping output renderers"); } - for (size_t i = 0; i < drm->outputs->length; ++i) { - struct wlr_drm_connector *conn = drm->outputs->items[i]; + wl_list_for_each(conn, &drm->outputs, link) { drmModeCrtc *crtc = conn->old_crtc; if (!crtc) { continue; -- cgit v1.2.3 From 1d716241afbc721c3ae65d4a2bb0e25866fe081c Mon Sep 17 00:00:00 2001 From: Heghedus Razvan Date: Sun, 15 Oct 2017 13:32:37 +0300 Subject: Replace list_t with wl_list in wlr_output Signed-off-by: Heghedus Razvan --- backend/drm/drm.c | 6 +----- examples/shared.c | 6 ++++-- include/wlr/types/wlr_output.h | 4 ++-- rootston/output.c | 8 +++++--- types/wlr_output.c | 14 +++++++------- 5 files changed, 19 insertions(+), 19 deletions(-) (limited to 'backend/drm/drm.c') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 74a63f79..60ac8e3e 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -782,11 +782,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { mode->wlr_mode.width, mode->wlr_mode.height, mode->wlr_mode.refresh); - if (list_add(wlr_conn->output.modes, mode) == -1) { - wlr_log_errno(L_ERROR, "Allocation failed"); - free(mode); - continue; - } + wl_list_insert(&wlr_conn->output.modes, &mode->wlr_mode.link); } wlr_conn->state = WLR_DRM_CONN_NEEDS_MODESET; diff --git a/examples/shared.c b/examples/shared.c index bb1d2737..d9f9ae61 100644 --- a/examples/shared.c +++ b/examples/shared.c @@ -427,8 +427,10 @@ static void output_add_notify(struct wl_listener *listener, void *data) { wlr_log(L_DEBUG, "Output '%s' added", output->name); wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm", output->make, output->model, output->phys_width, output->phys_height); - if (output->modes->length > 0) { - wlr_output_set_mode(output, output->modes->items[0]); + if (wl_list_length(&output->modes) > 0) { + struct wlr_output_mode *mode = NULL; + wl_container_of((&output->modes)->prev, mode, link); + wlr_output_set_mode(output, mode); } struct output_state *ostate = calloc(1, sizeof(struct output_state)); clock_gettime(CLOCK_MONOTONIC, &ostate->last_frame); diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index dc637e26..15df4efd 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -2,13 +2,13 @@ #define WLR_TYPES_WLR_OUTPUT_H #include -#include #include struct wlr_output_mode { uint32_t flags; // enum wl_output_mode int32_t width, height; int32_t refresh; // mHz + struct wl_list link; }; struct wlr_output_impl; @@ -32,7 +32,7 @@ struct wlr_output { float transform_matrix[16]; /* Note: some backends may have zero modes */ - list_t *modes; + struct wl_list modes; struct wlr_output_mode *current_mode; struct { diff --git a/rootston/output.c b/rootston/output.c index 39a90fe3..95e052fb 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -166,9 +166,11 @@ void output_add_notify(struct wl_listener *listener, void *data) { wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm", wlr_output->make, wlr_output->model, wlr_output->phys_width, wlr_output->phys_height); - if (wlr_output->modes->length > 0) { - wlr_output_set_mode(wlr_output, wlr_output->modes->items[0]); - } + if (wl_list_length(&wlr_output->modes) > 0) { + struct wlr_output_mode *mode = NULL; + mode = wl_container_of((&wlr_output->modes)->prev, mode, link); + wlr_output_set_mode(wlr_output, mode); + } struct roots_output *output = calloc(1, sizeof(struct roots_output)); clock_gettime(CLOCK_MONOTONIC, &output->last_frame); diff --git a/types/wlr_output.c b/types/wlr_output.c index eb969b9a..82e04ebf 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -26,8 +26,8 @@ static void wl_output_send_to_resource(struct wl_resource *resource) { output->make, output->model, output->transform); } if (version >= WL_OUTPUT_MODE_SINCE_VERSION) { - for (size_t i = 0; i < output->modes->length; ++i) { - struct wlr_output_mode *mode = output->modes->items[i]; + struct wlr_output_mode *mode; + wl_list_for_each(mode, &output->modes, link) { // TODO: mode->flags should just be preferred uint32_t flags = mode->flags; if (output->current_mode == mode) { @@ -37,7 +37,7 @@ static void wl_output_send_to_resource(struct wl_resource *resource) { mode->width, mode->height, mode->refresh); } - if (output->modes->length == 0) { + if (wl_list_length(&output->modes) == 0) { // Output has no mode, send the current width/height wl_output_send_mode(resource, WL_OUTPUT_MODE_CURRENT, output->width, output->height, 0); @@ -296,7 +296,7 @@ bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) { void wlr_output_init(struct wlr_output *output, const struct wlr_output_impl *impl) { output->impl = impl; - output->modes = list_create(); + wl_list_init(&output->modes); output->transform = WL_OUTPUT_TRANSFORM_NORMAL; output->scale = 1; wl_signal_init(&output->events.frame); @@ -320,11 +320,11 @@ void wlr_output_destroy(struct wlr_output *output) { wlr_texture_destroy(output->cursor.texture); wlr_renderer_destroy(output->cursor.renderer); - for (size_t i = 0; output->modes && i < output->modes->length; ++i) { - struct wlr_output_mode *mode = output->modes->items[i]; + struct wlr_output_mode *mode, *tmp_mode; + wl_list_for_each_safe(mode, tmp_mode, &output->modes, link) { free(mode); } - list_free(output->modes); + wl_list_remove(&output->modes); if (output->impl && output->impl->destroy) { output->impl->destroy(output); } else { -- cgit v1.2.3 From 4ea84c5765b138153aa313f23288935192b75c42 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 21 Oct 2017 17:35:37 +1300 Subject: Remove unnecesary wlr_renderers --- backend/drm/drm.c | 12 ++---------- include/backend/drm/drm.h | 1 - 2 files changed, 2 insertions(+), 11 deletions(-) (limited to 'backend/drm/drm.c') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index ff4dc7f6..0e898d3f 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -177,9 +177,6 @@ void wlr_drm_resources_free(struct wlr_drm_backend *drm) { if (plane->wlr_tex) { wlr_texture_destroy(plane->wlr_tex); } - if (plane->wlr_rend) { - wlr_renderer_destroy(plane->wlr_rend); - } } free(drm->crtcs); @@ -525,12 +522,7 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, // TODO the image needs to be rotated depending on the output rotation - plane->wlr_rend = wlr_gles2_renderer_create(&drm->backend); - if (!plane->wlr_rend) { - return false; - } - - plane->wlr_tex = wlr_render_texture_create(plane->wlr_rend); + plane->wlr_tex = wlr_render_texture_create(plane->surf.renderer->wlr_rend); if (!plane->wlr_tex) { return false; } @@ -595,7 +587,7 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, float matrix[16]; wlr_texture_get_matrix(plane->wlr_tex, &matrix, &plane->matrix, 0, 0); - wlr_render_with_matrix(plane->wlr_rend, plane->wlr_tex, &matrix); + wlr_render_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex, &matrix); glFinish(); glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, bo_stride); diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index 7a0e43ea..2ef3cf92 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -30,7 +30,6 @@ struct wlr_drm_plane { // Only used by cursor float matrix[16]; - struct wlr_renderer *wlr_rend; struct wlr_texture *wlr_tex; struct gbm_bo *cursor_bo; -- cgit v1.2.3 From 822a9f65a4f965a7561de287013c2a5c159453ab Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 21 Oct 2017 17:37:25 +1300 Subject: Add pointer to backend inside wlr_output --- backend/drm/drm.c | 2 +- backend/wayland/output.c | 2 +- backend/x11/backend.c | 2 +- include/wlr/interfaces/wlr_output.h | 6 ++++-- include/wlr/types/wlr_output.h | 4 +++- types/wlr_output.c | 3 ++- 6 files changed, 12 insertions(+), 7 deletions(-) (limited to 'backend/drm/drm.c') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 0e898d3f..b3057166 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -707,7 +707,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { drmModeFreeConnector(drm_conn); continue; } - wlr_output_init(&wlr_conn->output, &output_impl); + wlr_output_init(&wlr_conn->output, &drm->backend, &output_impl); struct wl_event_loop *ev = wl_display_get_event_loop(drm->display); wlr_conn->retry_pageflip = wl_event_loop_add_timer(ev, retry_pageflip, diff --git a/backend/wayland/output.c b/backend/wayland/output.c index e1138ee1..0216823e 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -241,7 +241,7 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { wlr_log(L_ERROR, "Failed to allocate wlr_wl_backend_output"); return NULL; } - wlr_output_init(&output->wlr_output, &output_impl); + wlr_output_init(&output->wlr_output, &backend->backend, &output_impl); struct wlr_output *wlr_output = &output->wlr_output; wlr_output->width = 640; diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 4ecca325..d30ec376 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -264,7 +264,7 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { output->x11 = x11; - wlr_output_init(&output->wlr_output, &output_impl); + wlr_output_init(&output->wlr_output, &x11->backend, &output_impl); snprintf(output->wlr_output.name, sizeof(output->wlr_output.name), "X11-1"); output->win = xcb_generate_id(x11->xcb_conn); diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index b7927569..17dd5538 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -1,8 +1,9 @@ #ifndef WLR_INTERFACES_WLR_OUTPUT_H #define WLR_INTERFACES_WLR_OUTPUT_H -#include #include +#include +#include struct wlr_output_impl { void (*enable)(struct wlr_output *output, bool enable); @@ -21,7 +22,8 @@ struct wlr_output_impl { uint16_t (*get_gamma_size)(struct wlr_output *output); }; -void wlr_output_init(struct wlr_output *output, const struct wlr_output_impl *impl); +void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, + const struct wlr_output_impl *impl); void wlr_output_free(struct wlr_output *output); void wlr_output_update_matrix(struct wlr_output *output); struct wl_global *wlr_output_create_global( diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 312b51f8..a2d595ea 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -1,9 +1,10 @@ #ifndef WLR_TYPES_WLR_OUTPUT_H #define WLR_TYPES_WLR_OUTPUT_H +#include #include +#include #include -#include struct wlr_output_mode { uint32_t flags; // enum wl_output_mode @@ -15,6 +16,7 @@ struct wlr_output_impl; struct wlr_output { const struct wlr_output_impl *impl; + struct wlr_backend *backend; struct wl_global *wl_global; struct wl_list wl_resources; diff --git a/types/wlr_output.c b/types/wlr_output.c index 5e10509e..c89c5c45 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -307,8 +307,9 @@ bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) { return output->impl->move_cursor(output, x, y); } -void wlr_output_init(struct wlr_output *output, +void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, const struct wlr_output_impl *impl) { + output->backend = backend; output->impl = impl; output->modes = list_create(); output->transform = WL_OUTPUT_TRANSFORM_NORMAL; -- cgit v1.2.3 From bdeffad7e5cacd2d1e27ddc0d44b3d9e2c19587d Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 21 Oct 2017 17:44:49 +1300 Subject: Remove drm field from wlr_drm_connector --- backend/drm/drm.c | 20 ++++++++++---------- include/backend/drm/drm.h | 1 - 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'backend/drm/drm.c') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index b3057166..04d7ea77 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -190,7 +190,7 @@ static void wlr_drm_connector_make_current(struct wlr_output *output) { static void wlr_drm_connector_swap_buffers(struct wlr_output *output) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - struct wlr_drm_backend *drm = conn->drm; + struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_plane *plane = crtc->primary; @@ -213,7 +213,8 @@ static void wlr_drm_connector_swap_buffers(struct wlr_output *output) { static void wlr_drm_connector_set_gamma(struct wlr_output *output, uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - drmModeCrtcSetGamma(conn->drm->fd, conn->crtc->id, size, r, g, b); + struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; + drmModeCrtcSetGamma(drm->fd, conn->crtc->id, size, r, g, b); } static uint16_t wlr_drm_connector_get_gamma_size(struct wlr_output *output) { @@ -227,7 +228,7 @@ void wlr_drm_connector_start_renderer(struct wlr_drm_connector *conn) { return; } - struct wlr_drm_backend *drm = conn->drm; + struct wlr_drm_backend *drm = (struct wlr_drm_backend *)conn->output.backend; struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_plane *plane = crtc->primary; @@ -250,7 +251,7 @@ static void wlr_drm_connector_enable(struct wlr_output *output, bool enable) { return; } - struct wlr_drm_backend *drm = conn->drm; + struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; drm->iface->conn_enable(drm, conn, enable); if (enable) { @@ -403,7 +404,7 @@ error_conn: static bool wlr_drm_connector_set_mode(struct wlr_output *output, struct wlr_output_mode *mode) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - struct wlr_drm_backend *drm = conn->drm; + struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; wlr_log(L_INFO, "Modesetting '%s' with '%ux%u@%u mHz'", conn->output.name, mode->width, mode->height, mode->refresh); @@ -469,7 +470,7 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y, bool update_pixels) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - struct wlr_drm_backend *drm = conn->drm; + struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_renderer *renderer = &drm->renderer; struct wlr_drm_crtc *crtc = conn->crtc; @@ -604,7 +605,7 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, static bool wlr_drm_connector_move_cursor(struct wlr_output *output, int x, int y) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - struct wlr_drm_backend *drm = conn->drm; + struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; int width, height, tmp; wlr_output_effective_resolution(output, &width, &height); @@ -714,7 +715,6 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { wlr_conn); - wlr_conn->drm = drm; wlr_conn->state = WLR_DRM_CONN_DISCONNECTED; wlr_conn->id = drm_conn->connector_id; @@ -820,7 +820,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { static void page_flip_handler(int fd, unsigned seq, unsigned tv_sec, unsigned tv_usec, void *user) { struct wlr_drm_connector *conn = user; - struct wlr_drm_backend *drm = conn->drm; + struct wlr_drm_backend *drm = (struct wlr_drm_backend *)conn->output.backend; conn->pageflip_pending = false; if (conn->state != WLR_DRM_CONN_CONNECTED) { @@ -891,7 +891,7 @@ void wlr_drm_connector_cleanup(struct wlr_drm_connector *conn) { return; } - struct wlr_drm_backend *drm = conn->drm; + struct wlr_drm_backend *drm = (struct wlr_drm_backend *)conn->output.backend; switch (conn->state) { case WLR_DRM_CONN_CONNECTED: diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index 2ef3cf92..b0f5838e 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -112,7 +112,6 @@ struct wlr_drm_mode { struct wlr_drm_connector { struct wlr_output output; - struct wlr_drm_backend *drm; enum wlr_drm_connector_state state; uint32_t id; -- cgit v1.2.3 From 2ab080e79af7c529a61adc11a7edd7c13873893b Mon Sep 17 00:00:00 2001 From: Versus Void Date: Sun, 22 Oct 2017 10:45:23 +0000 Subject: Fix index computation in DRM output scan and CRTC match --- backend/drm/drm.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'backend/drm/drm.c') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 31255a7c..51a5f636 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -319,9 +319,10 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector memset(possible_crtc, 0, sizeof(possible_crtc)); - ssize_t index = -1, i = 0; + ssize_t index = -1, i = -1; struct wlr_drm_connector *c; wl_list_for_each(c, &drm->outputs, link) { + i++; if (c == conn) { index = i; } @@ -332,7 +333,6 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector possible_crtc[i] = c->possible_crtc; crtc[c->crtc - drm->crtcs] = i; - i++; } assert(index != -1); @@ -686,7 +686,8 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { } size_t seen_len = wl_list_length(&drm->outputs); - // +1 so it can never be 0 + // +1 so length can never be 0, which is undefined behaviour. + // Last element isn't used. bool seen[seen_len + 1]; memset(seen, 0, sizeof(seen)); @@ -697,7 +698,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { wlr_log_errno(L_ERROR, "Failed to get DRM connector"); continue; } - int index = 0; + int index = -1; struct wlr_drm_connector *c, *wlr_conn = NULL; wl_list_for_each(c, &drm->outputs, link) { index++; @@ -794,13 +795,12 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { drmModeFreeResources(res); struct wlr_drm_connector *conn, *tmp_conn; - size_t index = seen_len - 1; + size_t index = wl_list_length(&drm->outputs); wl_list_for_each_safe(conn, tmp_conn, &drm->outputs, link) { - if (seen[index]) { - index--; + index--; + if (index >= seen_len || seen[index]) { continue; } - index--; wlr_log(L_INFO, "'%s' disappeared", conn->output.name); wlr_drm_connector_cleanup(conn); -- cgit v1.2.3 From e1d213fccdae068ecc0f11f4321dfd6528163253 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 22 Oct 2017 22:21:23 +0200 Subject: Create globals only for enabled outputs in DRM backend --- backend/drm/drm.c | 7 ++++--- examples/screenshot.c | 4 ---- include/wlr/interfaces/wlr_output.h | 5 +++-- types/wlr_output.c | 31 ++++++++++++++++++++++++------- 4 files changed, 31 insertions(+), 16 deletions(-) (limited to 'backend/drm/drm.c') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 51a5f636..8f80e65c 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -748,7 +748,6 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { free(edid); wl_list_insert(&drm->outputs, &wlr_conn->link); - wlr_output_create_global(&wlr_conn->output, drm->display); wlr_log(L_INFO, "Found display '%s'", wlr_conn->output.name); } else { seen[index] = true; @@ -756,7 +755,6 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { if (wlr_conn->state == WLR_DRM_CONN_DISCONNECTED && drm_conn->connection == DRM_MODE_CONNECTED) { - wlr_log(L_INFO, "'%s' connected", wlr_conn->output.name); wlr_log(L_INFO, "Detected modes:"); @@ -778,14 +776,17 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { wl_list_insert(&wlr_conn->output.modes, &mode->wlr_mode.link); } + wlr_output_create_global(&wlr_conn->output, drm->display); + wlr_conn->state = WLR_DRM_CONN_NEEDS_MODESET; wlr_log(L_INFO, "Sending modesetting signal for '%s'", wlr_conn->output.name); wl_signal_emit(&drm->backend.events.output_add, &wlr_conn->output); } else if (wlr_conn->state == WLR_DRM_CONN_CONNECTED && drm_conn->connection != DRM_MODE_CONNECTED) { - wlr_log(L_INFO, "'%s' disconnected", wlr_conn->output.name); + + wlr_output_destroy_global(&wlr_conn->output); wlr_drm_connector_cleanup(wlr_conn); } diff --git a/examples/screenshot.c b/examples/screenshot.c index 95af49ca..2a3b74aa 100644 --- a/examples/screenshot.c +++ b/examples/screenshot.c @@ -267,10 +267,6 @@ int main(int argc, char *argv[]) { struct screenshooter_output *output; wl_list_for_each(output, &output_list, link) { - if (output->width == 0 || output->height == 0) { - continue; - } - output->buffer = create_shm_buffer(output->width, output->height, &output->data); if (output->buffer == NULL) { return -1; diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index 17dd5538..338d3375 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -26,7 +26,8 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, const struct wlr_output_impl *impl); void wlr_output_free(struct wlr_output *output); void wlr_output_update_matrix(struct wlr_output *output); -struct wl_global *wlr_output_create_global( - struct wlr_output *wlr_output, struct wl_display *display); +struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output, + struct wl_display *display); +void wlr_output_destroy_global(struct wlr_output *wlr_output); #endif diff --git a/types/wlr_output.c b/types/wlr_output.c index 611d4ad1..eb5bdd26 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -76,16 +76,20 @@ static void wl_output_bind(struct wl_client *wl_client, void *_wlr_output, struct wlr_output *wlr_output = _wlr_output; assert(wl_client && wlr_output); - struct wl_resource *wl_resource = wl_resource_create( - wl_client, &wl_output_interface, version, id); - wl_resource_set_implementation(wl_resource, &wl_output_impl, - wlr_output, wl_output_destroy); - wl_list_insert(&wlr_output->wl_resources, wl_resource_get_link(wl_resource)); + struct wl_resource *wl_resource = wl_resource_create(wl_client, + &wl_output_interface, version, id); + wl_resource_set_implementation(wl_resource, &wl_output_impl, wlr_output, + wl_output_destroy); + wl_list_insert(&wlr_output->wl_resources, + wl_resource_get_link(wl_resource)); wl_output_send_to_resource(wl_resource); } -struct wl_global *wlr_output_create_global( - struct wlr_output *wlr_output, struct wl_display *display) { +struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output, + struct wl_display *display) { + if (wlr_output->wl_global != NULL) { + return wlr_output->wl_global; + } struct wl_global *wl_global = wl_global_create(display, &wl_output_interface, 3, wlr_output, wl_output_bind); wlr_output->wl_global = wl_global; @@ -93,6 +97,19 @@ struct wl_global *wlr_output_create_global( return wl_global; } +void wlr_output_destroy_global(struct wlr_output *wlr_output) { + if (wlr_output->wl_global == NULL) { + return; + } + struct wl_resource *resource, *tmp; + wl_resource_for_each_safe(resource, tmp, &wlr_output->wl_resources) { + struct wl_list *link = wl_resource_get_link(resource); + wl_list_remove(link); + } + wl_global_destroy(wlr_output->wl_global); + wlr_output->wl_global = NULL; +} + void wlr_output_update_matrix(struct wlr_output *output) { wlr_matrix_texture(output->transform_matrix, output->width, output->height, output->transform); } -- cgit v1.2.3 From 1cc8f21d8e19df2d1cc43864ae5715fbb5fbbe21 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 22 Oct 2017 12:30:45 +0200 Subject: Cleanup wlr_gamma_control --- backend/drm/drm.c | 4 +- include/wlr/interfaces/wlr_output.h | 4 +- include/wlr/types/wlr_gamma_control.h | 16 ++++- include/wlr/types/wlr_output.h | 4 +- types/wlr_gamma_control.c | 121 +++++++++++++++++++++++++--------- types/wlr_output.c | 4 +- 6 files changed, 111 insertions(+), 42 deletions(-) (limited to 'backend/drm/drm.c') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 8f80e65c..d0bdfcd5 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -211,13 +211,13 @@ static void wlr_drm_connector_swap_buffers(struct wlr_output *output) { } static void wlr_drm_connector_set_gamma(struct wlr_output *output, - uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b) { + 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; drmModeCrtcSetGamma(drm->fd, conn->crtc->id, size, r, g, b); } -static uint16_t wlr_drm_connector_get_gamma_size(struct wlr_output *output) { +static uint32_t wlr_drm_connector_get_gamma_size(struct wlr_output *output) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; drmModeCrtc *crtc = conn->old_crtc; return crtc ? crtc->gamma_size : 0; diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index 338d3375..636cc06c 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -18,8 +18,8 @@ struct wlr_output_impl { 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); + uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); + uint32_t (*get_gamma_size)(struct wlr_output *output); }; void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, diff --git a/include/wlr/types/wlr_gamma_control.h b/include/wlr/types/wlr_gamma_control.h index 96c9f545..59f18494 100644 --- a/include/wlr/types/wlr_gamma_control.h +++ b/include/wlr/types/wlr_gamma_control.h @@ -5,18 +5,28 @@ struct wlr_gamma_control_manager { struct wl_global *wl_global; + struct wl_list controls; // list of wlr_gamma_control void *data; }; struct wlr_gamma_control { struct wl_resource *resource; - struct wl_resource *output; + struct wlr_output *output; + struct wl_list link; + + struct wl_listener output_destroy_listener; + + struct { + struct wl_signal destroy; + } events; 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); +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 diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index d8649bbb..74eb15ed 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -84,7 +84,7 @@ void wlr_output_effective_resolution(struct wlr_output *output, 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); + uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); +uint32_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 973fd613..9d74e749 100644 --- a/types/wlr_gamma_control.c +++ b/types/wlr_gamma_control.c @@ -6,96 +6,155 @@ #include #include "gamma-control-protocol.h" -static void resource_destroy(struct wl_client *client, struct wl_resource *resource) { +static void resource_destroy(struct wl_client *client, + struct wl_resource *resource) { wl_resource_destroy(resource); } -static void gamma_control_destroy(struct wl_resource *resource) { - struct wlr_gamma_control *gamma_control = wl_resource_get_user_data(resource); +static void gamma_control_destroy(struct wlr_gamma_control *gamma_control) { + wl_signal_emit(&gamma_control->events.destroy, gamma_control); + wl_list_remove(&gamma_control->output_destroy_listener.link); + wl_resource_set_user_data(gamma_control->resource, NULL); free(gamma_control); } +static void gamma_control_destroy_resource(struct wl_resource *resource) { + struct wlr_gamma_control *gamma_control = + wl_resource_get_user_data(resource); + gamma_control_destroy(gamma_control); +} + +static void gamma_control_handle_output_destroy(struct wl_listener *listener, + void *data) { + struct wlr_gamma_control *gamma_control = + wl_container_of(listener, gamma_control, output_destroy_listener); + gamma_control_destroy(gamma_control); +} + static void gamma_control_set_gamma(struct wl_client *client, - struct wl_resource *_gamma_control, struct wl_array *red, + struct wl_resource *gamma_control_resource, struct wl_array *red, struct wl_array *green, struct wl_array *blue) { + struct wlr_gamma_control *gamma_control = + wl_resource_get_user_data(gamma_control_resource); + if (red->size != green->size || red->size != blue->size) { - wl_resource_post_error(_gamma_control, GAMMA_CONTROL_ERROR_INVALID_GAMMA, + wl_resource_post_error(gamma_control_resource, + GAMMA_CONTROL_ERROR_INVALID_GAMMA, "The gamma ramps don't have the same size"); return; } + + uint32_t size = red->size / sizeof(uint16_t); 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); + + wlr_output_set_gamma(gamma_control->output, size, r, g, b); } static void gamma_control_reset_gamma(struct wl_client *client, - struct wl_resource *_gamma_control) { + struct wl_resource *gamma_control_resource) { // TODO } -static const struct gamma_control_interface gamma_control_implementation = { +static const struct gamma_control_interface gamma_control_impl = { .destroy = resource_destroy, .set_gamma = gamma_control_set_gamma, .reset_gamma = gamma_control_reset_gamma, }; static void gamma_control_manager_get_gamma_control(struct wl_client *client, - struct wl_resource *_gamma_control_manager, uint32_t id, - 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)))) { + struct wl_resource *gamma_control_manager_resource, uint32_t id, + struct wl_resource *output_resource) { + struct wlr_gamma_control_manager *gamma_control_manager = + wl_resource_get_user_data(gamma_control_manager_resource); + struct wlr_output *output = wl_resource_get_user_data(output_resource); + + struct wlr_gamma_control *gamma_control = + calloc(1, sizeof(struct wlr_gamma_control)); + if (gamma_control == NULL) { + wl_client_post_no_memory(client); return; } - gamma_control->output = _output; + gamma_control->output = output; + + int version = wl_resource_get_version(gamma_control_manager_resource); gamma_control->resource = wl_resource_create(client, - &gamma_control_interface, wl_resource_get_version(_gamma_control_manager), id); - wlr_log(L_DEBUG, "new gamma_control %p (res %p)", gamma_control, gamma_control->resource); + &gamma_control_interface, version, id); + if (gamma_control->resource == NULL) { + wl_client_post_no_memory(client); + free(gamma_control); + return; + } + 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->resource, wlr_output_get_gamma_size(output)); + &gamma_control_impl, gamma_control, gamma_control_destroy_resource); + + wl_signal_init(&gamma_control->events.destroy); + + wl_signal_add(&output->events.destroy, + &gamma_control->output_destroy_listener); + gamma_control->output_destroy_listener.notify = + gamma_control_handle_output_destroy; + + wl_list_insert(&gamma_control_manager->controls, &gamma_control->link); + + gamma_control_send_gamma_size(gamma_control->resource, + wlr_output_get_gamma_size(output)); } static struct gamma_control_manager_interface gamma_control_manager_impl = { .get_gamma_control = gamma_control_manager_get_gamma_control, }; -static void gamma_control_manager_bind(struct wl_client *wl_client, +static void gamma_control_manager_bind(struct wl_client *client, void *_gamma_control_manager, uint32_t version, uint32_t id) { - struct wlr_gamma_control_manager *gamma_control_manager = _gamma_control_manager; - assert(wl_client && gamma_control_manager); + struct wlr_gamma_control_manager *gamma_control_manager = + _gamma_control_manager; + assert(client && gamma_control_manager); - struct wl_resource *wl_resource = wl_resource_create( - wl_client, &gamma_control_manager_interface, version, id); - wl_resource_set_implementation(wl_resource, &gamma_control_manager_impl, + struct wl_resource *resource = wl_resource_create(client, + &gamma_control_manager_interface, version, id); + if (resource == NULL) { + wl_client_post_no_memory(client); + return; + } + wl_resource_set_implementation(resource, &gamma_control_manager_impl, gamma_control_manager, NULL); } -struct wlr_gamma_control_manager *wlr_gamma_control_manager_create(struct wl_display *display) { +struct wlr_gamma_control_manager *wlr_gamma_control_manager_create( + struct wl_display *display) { struct wlr_gamma_control_manager *gamma_control_manager = calloc(1, sizeof(struct wlr_gamma_control_manager)); if (!gamma_control_manager) { return NULL; } struct wl_global *wl_global = wl_global_create(display, - &gamma_control_manager_interface, 1, gamma_control_manager, gamma_control_manager_bind); + &gamma_control_manager_interface, 1, gamma_control_manager, + gamma_control_manager_bind); if (!wl_global) { free(gamma_control_manager); return NULL; } gamma_control_manager->wl_global = wl_global; + + wl_list_init(&gamma_control_manager->controls); + return gamma_control_manager; } -void wlr_gamma_control_manager_destroy(struct wlr_gamma_control_manager *gamma_control_manager) { +void wlr_gamma_control_manager_destroy( + struct wlr_gamma_control_manager *gamma_control_manager) { if (!gamma_control_manager) { return; } + struct wlr_gamma_control *gamma_control, *tmp; + wl_list_for_each_safe(gamma_control, tmp, &gamma_control_manager->controls, + link) { + gamma_control_destroy(gamma_control); + } // TODO: this segfault (wl_display->registry_resource_list is not init) // wl_global_destroy(gamma_control_manager->wl_global); free(gamma_control_manager); diff --git a/types/wlr_output.c b/types/wlr_output.c index eb5bdd26..a02798b2 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -404,13 +404,13 @@ 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) { + uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) { 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) { +uint32_t wlr_output_get_gamma_size(struct wlr_output *output) { if (!output->impl->get_gamma_size) { return 0; } -- cgit v1.2.3 From ecb2a2b0d3c5766f0147af2a54ec7d213c070f88 Mon Sep 17 00:00:00 2001 From: Versus Void Date: Sun, 22 Oct 2017 10:01:21 +0000 Subject: Emit output resolution event only when resolution changes --- backend/drm/drm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'backend/drm/drm.c') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 51a5f636..4c13d01a 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -437,10 +437,12 @@ static bool wlr_drm_connector_set_mode(struct wlr_output *output, crtc->cursor ? crtc->cursor - drm->cursor_planes : -1); conn->state = WLR_DRM_CONN_CONNECTED; - conn->output.width = mode->width; - conn->output.height = mode->height; conn->output.current_mode = mode; - wl_signal_emit(&conn->output.events.resolution, &conn->output); + if (conn->output.width != mode->width || conn->output.height != mode->height) { + conn->output.width = mode->width; + conn->output.height = mode->height; + wl_signal_emit(&conn->output.events.resolution, &conn->output); + } // Since realloc_crtcs can deallocate planes on OTHER outputs, // we actually need to reinitalise all of them -- cgit v1.2.3 From 3c31209a979faf9e25ec055ae32f17f9b64b70be Mon Sep 17 00:00:00 2001 From: Versus Void Date: Sun, 22 Oct 2017 10:15:02 +0000 Subject: Reinitialize only changed DRM outputs after setting mode on one --- backend/drm/drm.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'backend/drm/drm.c') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 4c13d01a..cd3208d3c 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -259,7 +259,8 @@ static void wlr_drm_connector_enable(struct wlr_output *output, bool enable) { } } -static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in) { +static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in, + bool *changed_outputs) { // overlay, primary, cursor for (int type = 0; type < 3; ++type) { if (drm->num_type_planes[type] == 0) { @@ -298,6 +299,7 @@ static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in) struct wlr_drm_plane *new = &drm->type_planes[type][crtc_res[i]]; if (*old != new) { + changed_outputs[crtc_res[i]] = true; if (*old) { wlr_drm_surface_finish(&(*old)->surf); } @@ -308,7 +310,8 @@ static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in) } } -static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector *conn) { +static void realloc_crtcs(struct wlr_drm_backend *drm, + struct wlr_drm_connector *conn, bool *changed_outputs) { uint32_t crtc[drm->num_crtcs]; uint32_t crtc_res[drm->num_crtcs]; uint32_t possible_crtc[wl_list_length(&drm->outputs)]; @@ -356,12 +359,15 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector return; } + changed_outputs[index] = true; + for (size_t i = 0; i < drm->num_crtcs; ++i) { if (crtc_res[i] == UNMATCHED) { continue; } if (crtc_res[i] != crtc[i]) { + changed_outputs[crtc_res[i]] = true; struct wlr_drm_connector *c; size_t pos = 0; wl_list_for_each(c, &drm->outputs, link) { @@ -374,7 +380,7 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector } } - realloc_planes(drm, crtc_res); + realloc_planes(drm, crtc_res, changed_outputs); } static uint32_t get_possible_crtcs(int fd, uint32_t conn_id) { @@ -413,6 +419,7 @@ static bool wlr_drm_connector_set_mode(struct wlr_output *output, struct wlr_output_mode *mode) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; + bool changed_outputs[wl_list_length(&drm->outputs)]; wlr_log(L_INFO, "Modesetting '%s' with '%ux%u@%u mHz'", conn->output.name, mode->width, mode->height, mode->refresh); @@ -422,7 +429,8 @@ static bool wlr_drm_connector_set_mode(struct wlr_output *output, goto error_conn; } - realloc_crtcs(drm, conn); + memset(changed_outputs, false, sizeof(changed_outputs)); + realloc_crtcs(drm, conn, changed_outputs); if (!conn->crtc) { wlr_log(L_ERROR, "Unable to match %s with a CRTC", conn->output.name); @@ -445,12 +453,15 @@ static bool wlr_drm_connector_set_mode(struct wlr_output *output, } // Since realloc_crtcs can deallocate planes on OTHER outputs, - // we actually need to reinitalise all of them + // we actually need to reinitalise any than has changed + ssize_t output_index = -1; wl_list_for_each(conn, &drm->outputs, link) { + output_index += 1; struct wlr_output_mode *mode = conn->output.current_mode; struct wlr_drm_crtc *crtc = conn->crtc; - if (conn->state != WLR_DRM_CONN_CONNECTED) { + if (conn->state != WLR_DRM_CONN_CONNECTED || + !changed_outputs[output_index]) { continue; } -- cgit v1.2.3 From 549777ca19b2040ff0824ac7764bbe1cb834e953 Mon Sep 17 00:00:00 2001 From: Versus Void Date: Sun, 22 Oct 2017 21:38:30 +0000 Subject: Set crtc field when scanning for DRM connectors and always use it when matching CRTCs with connectors. Fix deactivated monitors check. --- backend/drm/drm.c | 57 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 18 deletions(-) (limited to 'backend/drm/drm.c') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index cd3208d3c..94923d04 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -314,7 +314,8 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector *conn, bool *changed_outputs) { uint32_t crtc[drm->num_crtcs]; uint32_t crtc_res[drm->num_crtcs]; - uint32_t possible_crtc[wl_list_length(&drm->outputs)]; + ssize_t num_outputs = wl_list_length(&drm->outputs); + uint32_t possible_crtc[num_outputs]; for (size_t i = 0; i < drm->num_crtcs; ++i) { crtc[i] = UNMATCHED; @@ -330,35 +331,41 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, index = i; } - if (c->state != WLR_DRM_CONN_CONNECTED) { - continue; + if (c->crtc) { + crtc[c->crtc - drm->crtcs] = i; + } + + if (c->state == WLR_DRM_CONN_CONNECTED) { + possible_crtc[i] = c->possible_crtc; } - possible_crtc[i] = c->possible_crtc; - crtc[c->crtc - drm->crtcs] = i; } assert(index != -1); possible_crtc[index] = conn->possible_crtc; - match_obj(wl_list_length(&drm->outputs), possible_crtc, drm->num_crtcs, - crtc, crtc_res); + match_obj(wl_list_length(&drm->outputs), possible_crtc, + drm->num_crtcs, crtc, crtc_res); - bool matched = false; + bool matched[num_outputs]; + memset(matched, false, sizeof(matched)); for (size_t i = 0; i < drm->num_crtcs; ++i) { - // We don't want any of the current monitors to be deactivated. - if (crtc[i] != UNMATCHED && crtc_res[i] == UNMATCHED) { - return; - } - if (crtc_res[i] == index) { - matched = true; + if (crtc_res[i] != UNMATCHED) { + matched[crtc_res[i]] = true; } } // There is no point doing anything if this monitor doesn't get activated - if (!matched) { + if (!matched[index]) { return; } + for (size_t i = 0; i < drm->num_crtcs; ++i) { + // We don't want any of the current monitors to be deactivated. + if (crtc[i] != UNMATCHED && !matched[crtc[i]]) { + return; + } + } + changed_outputs[index] = true; for (size_t i = 0; i < drm->num_crtcs; ++i) { @@ -711,6 +718,9 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { wlr_log_errno(L_ERROR, "Failed to get DRM connector"); continue; } + drmModeEncoder *curr_enc = drmModeGetEncoder(drm->fd, + drm_conn->encoder_id); + int index = -1; struct wlr_drm_connector *c, *wlr_conn = NULL; wl_list_for_each(c, &drm->outputs, link) { @@ -720,10 +730,12 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { break; } } + if (!wlr_conn) { wlr_conn = calloc(1, sizeof(*wlr_conn)); if (!wlr_conn) { wlr_log_errno(L_ERROR, "Allocation failed"); + drmModeFreeEncoder(curr_enc); drmModeFreeConnector(drm_conn); continue; } @@ -737,11 +749,8 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { wlr_conn->state = WLR_DRM_CONN_DISCONNECTED; wlr_conn->id = drm_conn->connector_id; - drmModeEncoder *curr_enc = drmModeGetEncoder(drm->fd, - drm_conn->encoder_id); if (curr_enc) { wlr_conn->old_crtc = drmModeGetCrtc(drm->fd, curr_enc->crtc_id); - drmModeFreeEncoder(curr_enc); } wlr_conn->output.phys_width = drm_conn->mmWidth; @@ -767,6 +776,17 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { seen[index] = true; } + if (curr_enc) { + for (size_t i = 0; i < drm->num_crtcs; ++i) { + if (drm->crtcs[i].id == curr_enc->crtc_id) { + wlr_conn->crtc = &drm->crtcs[i]; + break; + } + } + } else { + wlr_conn->crtc = NULL; + } + if (wlr_conn->state == WLR_DRM_CONN_DISCONNECTED && drm_conn->connection == DRM_MODE_CONNECTED) { @@ -802,6 +822,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { wlr_drm_connector_cleanup(wlr_conn); } + drmModeFreeEncoder(curr_enc); drmModeFreeConnector(drm_conn); } -- cgit v1.2.3