From 0aa00da1f3795186b12e35f206e52d9670d61445 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 9 Sep 2017 22:41:23 +1200 Subject: [PATCH 01/12] Check for disappearing DRM connectors DisplayPort MST connectors will disappear when they're disconnected, so we need to check for that. --- backend/drm/drm.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 163321a3..a4f987ee 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -748,6 +748,11 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { return; } + size_t seen_len = backend->outputs->length; + // +1 so it can never be 0 + bool seen[seen_len + 1]; + memset(seen, 0, sizeof(seen)); + for (int i = 0; i < res->count_connectors; ++i) { drmModeConnector *conn = drmModeGetConnector(backend->fd, res->connectors[i]); @@ -791,7 +796,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { size_t edid_len = 0; uint8_t *edid = wlr_drm_get_prop_blob(backend->fd, - output->connector, output->props.edid, &edid_len); + output->connector, output->props.edid, &edid_len); parse_edid(&output->output, edid_len, edid); free(edid); @@ -805,6 +810,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { wlr_log(L_INFO, "Found display '%s'", output->output.name); } else { output = backend->outputs->items[index]; + seen[index] = true; } if (output->state == WLR_DRM_OUTPUT_DISCONNECTED && @@ -815,7 +821,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { for (int i = 0; i < conn->count_modes; ++i) { struct wlr_drm_output_mode *mode = calloc(1, - sizeof(struct wlr_drm_output_mode)); + sizeof(struct wlr_drm_output_mode)); if (!mode) { wlr_log_errno(L_ERROR, "Allocation failed"); continue; @@ -850,6 +856,22 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { } drmModeFreeResources(res); + + for (size_t i = seen_len; i-- > 0;) { + if (seen[i]) { + continue; + } + + struct wlr_drm_output *output = backend->outputs->items[i]; + + wlr_log(L_INFO, "'%s' disappeared", output->output.name); + wlr_drm_output_cleanup(output, false); + + drmModeFreeCrtc(output->old_crtc); + free(output); + + list_del(backend->outputs, i); + } } static void page_flip_handler(int fd, unsigned seq, From 6717b78bd6dcb1e103556cf86813c715c4212106 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 9 Sep 2017 23:06:44 +1200 Subject: [PATCH 02/12] Retry atomic commit on failure So we don't lose any previously "good" properties that were set. --- backend/drm/drm-atomic.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/drm/drm-atomic.c b/backend/drm/drm-atomic.c index 64028812..adb5bb47 100644 --- a/backend/drm/drm-atomic.c +++ b/backend/drm/drm-atomic.c @@ -53,6 +53,13 @@ static bool atomic_commit(int drm_fd, struct atomic *atom, int ret = drmModeAtomicCommit(drm_fd, atom->req, flags, output); if (ret) { wlr_log_errno(L_ERROR, "Atomic commit failed"); + + // Try to commit without new changes + drmModeAtomicSetCursor(atom->req, atom->cursor); + ret = drmModeAtomicCommit(drm_fd, atom->req, flags, output); + if (ret) { + wlr_log_errno(L_ERROR, "Atomic commit failed"); + } } drmModeAtomicSetCursor(atom->req, 0); From 1682c0d983630d315dab0277381a5c3ffb69feaf Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sun, 10 Sep 2017 00:13:39 +1200 Subject: [PATCH 03/12] Remove non-blocking flag on modesetting commits This seems to make hotplugging DisplayPort MST connectors more reliable. --- backend/drm/drm-atomic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/drm/drm-atomic.c b/backend/drm/drm-atomic.c index adb5bb47..a6523331 100644 --- a/backend/drm/drm-atomic.c +++ b/backend/drm/drm-atomic.c @@ -48,7 +48,7 @@ static bool atomic_commit(int drm_fd, struct atomic *atom, return false; } - uint32_t flags = DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_NONBLOCK | flag; + uint32_t flags = DRM_MODE_PAGE_FLIP_EVENT | flag; int ret = drmModeAtomicCommit(drm_fd, atom->req, flags, output); if (ret) { @@ -117,7 +117,7 @@ static bool atomic_crtc_pageflip(struct wlr_drm_backend *backend, atomic_add(&atom, crtc->id, crtc->props.active, 1); set_plane_props(&atom, crtc->primary, crtc->id, fb_id, true); return atomic_commit(backend->fd, &atom, - output, mode ? DRM_MODE_ATOMIC_ALLOW_MODESET : 0); + output, mode ? DRM_MODE_ATOMIC_ALLOW_MODESET : DRM_MODE_ATOMIC_NONBLOCK); } static void atomic_conn_enable(struct wlr_drm_backend *backend, From 4a53aab4663a2d26fa10d913222986201c080fbd Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 23 Sep 2017 13:20:17 +1200 Subject: [PATCH 04/12] Allow forcing legacy DRM interface --- backend/drm/drm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index a4f987ee..5c0bad46 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -31,7 +31,10 @@ bool wlr_drm_check_features(struct wlr_drm_backend *backend) { return false; } - if (drmSetClientCap(backend->fd, DRM_CLIENT_CAP_ATOMIC, 1)) { + if (getenv("WLR_DRM_NO_ATOMIC")) { + wlr_log(L_DEBUG, "WLR_DRM_NO_ATOMIC set, forcing legacy DRM interface"); + backend->iface = &legacy_iface; + } else if (drmSetClientCap(backend->fd, DRM_CLIENT_CAP_ATOMIC, 1)) { wlr_log(L_DEBUG, "Atomic modesetting unsupported, using legacy DRM interface"); backend->iface = &legacy_iface; } else { From 8cbade355f197e919e7d392a06b9b2851bf847cc Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 23 Sep 2017 13:38:43 +1200 Subject: [PATCH 05/12] Print connector name on atomic commit failure --- backend/drm/drm-atomic.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/drm/drm-atomic.c b/backend/drm/drm-atomic.c index a6523331..5d34cd48 100644 --- a/backend/drm/drm-atomic.c +++ b/backend/drm/drm-atomic.c @@ -43,7 +43,7 @@ static bool atomic_end(int drm_fd, struct atomic *atom) { } static bool atomic_commit(int drm_fd, struct atomic *atom, - struct wlr_drm_output *output, uint32_t flag) { + struct wlr_drm_output *output, uint32_t flag, bool modeset) { if (atom->failed) { return false; } @@ -52,13 +52,15 @@ static bool atomic_commit(int drm_fd, struct atomic *atom, int ret = drmModeAtomicCommit(drm_fd, atom->req, flags, output); if (ret) { - wlr_log_errno(L_ERROR, "Atomic commit failed"); + wlr_log_errno(L_ERROR, "%s: Atomic commit failed (%s)", + output->output.name, modeset ? "modeset" : "pageflip"); // Try to commit without new changes drmModeAtomicSetCursor(atom->req, atom->cursor); ret = drmModeAtomicCommit(drm_fd, atom->req, flags, output); if (ret) { - wlr_log_errno(L_ERROR, "Atomic commit failed"); + wlr_log_errno(L_ERROR, "%s: Atomic commit failed (%s)", + output->output.name, modeset ? "modeset" : "pageflip"); } } @@ -116,8 +118,9 @@ static bool atomic_crtc_pageflip(struct wlr_drm_backend *backend, atomic_add(&atom, crtc->id, crtc->props.mode_id, crtc->mode_id); atomic_add(&atom, crtc->id, crtc->props.active, 1); set_plane_props(&atom, crtc->primary, crtc->id, fb_id, true); - return atomic_commit(backend->fd, &atom, - output, mode ? DRM_MODE_ATOMIC_ALLOW_MODESET : DRM_MODE_ATOMIC_NONBLOCK); + return atomic_commit(backend->fd, &atom, output, + mode ? DRM_MODE_ATOMIC_ALLOW_MODESET : DRM_MODE_ATOMIC_NONBLOCK, + mode); } static void atomic_conn_enable(struct wlr_drm_backend *backend, From 459d138fa2f8c0ad3665cbbb393c366b895a4cde Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 23 Sep 2017 16:32:25 +1200 Subject: [PATCH 06/12] Add timeout to DRM cleanup This prevents a potential infinite loop preventing us from closing properly. --- backend/drm/backend.c | 3 ++ backend/drm/drm.c | 65 ++++++++++++++++++++++++++----------------- include/backend/drm.h | 5 ++-- 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/backend/drm/backend.c b/backend/drm/backend.c index 68e73268..8d562007 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -26,6 +26,9 @@ static void wlr_drm_backend_destroy(struct wlr_backend *_backend) { return; } struct wlr_drm_backend *backend = (struct wlr_drm_backend *)_backend; + + wlr_drm_restore_outputs(backend); + for (size_t i = 0; backend->outputs && i < backend->outputs->length; ++i) { struct wlr_drm_output *output = backend->outputs->items[i]; wlr_output_destroy(&output->output); diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 5c0bad46..b34e86fd 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -556,7 +557,7 @@ error_enc: error_conn: drmModeFreeConnector(conn); error_output: - wlr_drm_output_cleanup(output, false); + wlr_drm_output_cleanup(output); return false; } @@ -703,7 +704,7 @@ static bool wlr_drm_output_move_cursor(struct wlr_output *_output, static void wlr_drm_output_destroy(struct wlr_output *_output) { struct wlr_drm_output *output = (struct wlr_drm_output *)_output; - wlr_drm_output_cleanup(output, true); + wlr_drm_output_cleanup(output); free(output); } @@ -852,7 +853,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { conn->connection != DRM_MODE_CONNECTED) { wlr_log(L_INFO, "'%s' disconnected", output->output.name); - wlr_drm_output_cleanup(output, false); + wlr_drm_output_cleanup(output); } drmModeFreeConnector(conn); @@ -868,7 +869,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { struct wlr_drm_output *output = backend->outputs->items[i]; wlr_log(L_INFO, "'%s' disappeared", output->output.name); - wlr_drm_output_cleanup(output, false); + wlr_drm_output_cleanup(output); drmModeFreeCrtc(output->old_crtc); free(output); @@ -909,23 +910,46 @@ int wlr_drm_event(int fd, uint32_t mask, void *data) { return 1; } -static void restore_output(struct wlr_drm_output *output, int fd) { - // Wait for any pending pageflips to finish - while (output->pageflip_pending) { - wlr_drm_event(fd, 0, NULL); +void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) { + uint64_t to_close = (1 << drm->outputs->length) - 1; + + for (size_t i = 0; i < drm->outputs->length; ++i) { + struct wlr_drm_output *output = drm->outputs->items[i]; + if (output->state == WLR_DRM_OUTPUT_CONNECTED) { + output->state = WLR_DRM_OUTPUT_CLEANUP; + } } - drmModeCrtc *crtc = output->old_crtc; - if (!crtc) { - return; + time_t timeout = time(NULL) + 5; + + 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_output *output = drm->outputs->items[i]; + if (!output->pageflip_pending) { + to_close &= ~(1 << i); + } + } } - drmModeSetCrtc(fd, crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y, - &output->connector, 1, &crtc->mode); - drmModeFreeCrtc(crtc); + if (to_close) { + wlr_log(L_ERROR, "Timed out stopping output renderers"); + } + + for (size_t i = 0; i < drm->outputs->length; ++i) { + struct wlr_drm_output *output = drm->outputs->items[i]; + drmModeCrtc *crtc = output->old_crtc; + if (!crtc) { + continue; + } + + drmModeSetCrtc(drm->fd, crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y, + &output->connector, 1, &crtc->mode); + drmModeFreeCrtc(crtc); + } } -void wlr_drm_output_cleanup(struct wlr_drm_output *output, bool restore) { +void wlr_drm_output_cleanup(struct wlr_drm_output *output) { if (!output) { return; } @@ -936,12 +960,7 @@ void wlr_drm_output_cleanup(struct wlr_drm_output *output, bool restore) { switch (output->state) { case WLR_DRM_OUTPUT_CONNECTED: - output->state = WLR_DRM_OUTPUT_DISCONNECTED; - if (restore) { - restore_output(output, renderer->fd); - restore = false; - } - + case WLR_DRM_OUTPUT_CLEANUP:; struct wlr_drm_crtc *crtc = output->crtc; for (int i = 0; i < 3; ++i) { wlr_drm_plane_renderer_free(renderer, crtc->planes[i]); @@ -955,10 +974,6 @@ void wlr_drm_output_cleanup(struct wlr_drm_output *output, bool restore) { output->possible_crtc = 0; /* Fallthrough */ case WLR_DRM_OUTPUT_NEEDS_MODESET: - output->state = WLR_DRM_OUTPUT_DISCONNECTED; - if (restore) { - restore_output(output, renderer->fd); - } wlr_log(L_INFO, "Emmiting destruction signal for '%s'", output->output.name); wl_signal_emit(&backend->backend.events.output_remove, &output->output); diff --git a/include/backend/drm.h b/include/backend/drm.h index 342a980c..cc3e621b 100644 --- a/include/backend/drm.h +++ b/include/backend/drm.h @@ -127,6 +127,7 @@ struct wlr_drm_backend { enum wlr_drm_output_state { WLR_DRM_OUTPUT_DISCONNECTED, WLR_DRM_OUTPUT_NEEDS_MODESET, + WLR_DRM_OUTPUT_CLEANUP, WLR_DRM_OUTPUT_CONNECTED, }; @@ -176,8 +177,8 @@ struct wlr_drm_interface { bool wlr_drm_check_features(struct wlr_drm_backend *drm); bool wlr_drm_resources_init(struct wlr_drm_backend *drm); void wlr_drm_resources_free(struct wlr_drm_backend *drm); -void wlr_drm_output_cleanup(struct wlr_drm_output *output, bool restore); - +void wlr_drm_restore_outputs(struct wlr_drm_backend *drm); +void wlr_drm_output_cleanup(struct wlr_drm_output *output); void wlr_drm_scan_connectors(struct wlr_drm_backend *state); int wlr_drm_event(int fd, uint32_t mask, void *data); From 025b3ee515aedf008b94eb8aa791ecd7eaf817c9 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 23 Sep 2017 18:27:14 +1200 Subject: [PATCH 07/12] Add error recovery for failed page flips --- backend/drm/drm.c | 51 ++++++++++++++++++++++++++++++++++++++----- include/backend/drm.h | 1 + 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index b34e86fd..53d08291 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -301,8 +301,14 @@ static void wlr_drm_output_swap_buffers(struct wlr_output *_output) { wlr_drm_plane_swap_buffers(renderer, plane); - backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(plane->back), NULL); - output->pageflip_pending = true; + uint32_t fb_id = get_fb_for_bo(plane->back); + + if (backend->iface->crtc_pageflip(backend, output, crtc, fb_id, NULL)) { + output->pageflip_pending = true; + } else { + wl_event_source_timer_update(output->retry_pageflip, + output->output.current_mode->refresh); + } } static void wlr_drm_output_set_gamma(struct wlr_output *_output, @@ -348,8 +354,12 @@ void wlr_drm_output_start_renderer(struct wlr_drm_output *output) { struct wlr_drm_output_mode *_mode = (struct wlr_drm_output_mode *)output->output.current_mode; drmModeModeInfo *mode = &_mode->mode; - backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(bo), mode); - output->pageflip_pending = true; + if (backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(bo), mode)) { + output->pageflip_pending = true; + } else { + wl_event_source_timer_update(output->retry_pageflip, + output->output.current_mode->refresh); + } } static void wlr_drm_output_enable(struct wlr_output *_output, bool enable) { @@ -705,6 +715,7 @@ static bool wlr_drm_output_move_cursor(struct wlr_output *_output, static void wlr_drm_output_destroy(struct wlr_output *_output) { struct wlr_drm_output *output = (struct wlr_drm_output *)_output; wlr_drm_output_cleanup(output); + wl_event_source_remove(output->retry_pageflip); free(output); } @@ -721,6 +732,29 @@ static struct wlr_output_impl output_impl = { .get_gamma_size = wlr_drm_output_get_gamma_size, }; +static int retry_pageflip(void *data) { + struct wlr_drm_output *output = data; + struct wlr_drm_backend *backend = + wl_container_of(output->renderer, backend, renderer); + + struct wlr_drm_crtc *crtc = output->crtc; + struct wlr_drm_plane *plane = crtc->primary; + struct gbm_bo *bo = plane->front ? plane->front : plane->back; + + struct wlr_drm_output_mode *wlr_mode = + (struct wlr_drm_output_mode *)output->output.current_mode; + drmModeModeInfo *mode = &wlr_mode->mode; + + if (backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(bo), mode)) { + output->pageflip_pending = true; + } else { + wl_event_source_timer_update(output->retry_pageflip, + output->output.current_mode->refresh); + } + + return 1; +} + static int find_id(const void *item, const void *cmp_to) { const struct wlr_drm_output *output = item; const uint32_t *id = cmp_to; @@ -777,6 +811,11 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { } wlr_output_init(&output->output, &output_impl); + struct wl_event_loop *ev = wl_display_get_event_loop(backend->display); + output->retry_pageflip = wl_event_loop_add_timer(ev, retry_pageflip, + output); + + output->renderer = &backend->renderer; output->state = WLR_DRM_OUTPUT_DISCONNECTED; output->connector = conn->connector_id; @@ -807,6 +846,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { if (list_add(backend->outputs, output) == -1) { wlr_log_errno(L_ERROR, "Allocation failed"); drmModeFreeConnector(conn); + wl_event_source_remove(output->retry_pageflip); free(output); continue; } @@ -872,6 +912,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { wlr_drm_output_cleanup(output); drmModeFreeCrtc(output->old_crtc); + wl_event_source_remove(output->retry_pageflip); free(output); list_del(backend->outputs, i); @@ -926,7 +967,7 @@ void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) { wlr_drm_event(drm->fd, 0, NULL); for (size_t i = 0; i < drm->outputs->length; ++i) { struct wlr_drm_output *output = drm->outputs->items[i]; - if (!output->pageflip_pending) { + if (output->state != WLR_DRM_OUTPUT_CLEANUP || !output->pageflip_pending) { to_close &= ~(1 << i); } } diff --git a/include/backend/drm.h b/include/backend/drm.h index cc3e621b..27ddad6f 100644 --- a/include/backend/drm.h +++ b/include/backend/drm.h @@ -155,6 +155,7 @@ struct wlr_drm_output { struct wlr_drm_renderer *renderer; bool pageflip_pending; + struct wl_event_source *retry_pageflip; }; // Used to provide atomic or legacy DRM functions From db5e9385d4e1492630611265afcffd9b86867489 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 23 Sep 2017 18:44:39 +1200 Subject: [PATCH 08/12] Simplify retry_pageflip --- backend/drm/drm.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 53d08291..712a06b6 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -734,25 +734,9 @@ static struct wlr_output_impl output_impl = { static int retry_pageflip(void *data) { struct wlr_drm_output *output = data; - struct wlr_drm_backend *backend = - wl_container_of(output->renderer, backend, renderer); - - struct wlr_drm_crtc *crtc = output->crtc; - struct wlr_drm_plane *plane = crtc->primary; - struct gbm_bo *bo = plane->front ? plane->front : plane->back; - - struct wlr_drm_output_mode *wlr_mode = - (struct wlr_drm_output_mode *)output->output.current_mode; - drmModeModeInfo *mode = &wlr_mode->mode; - - if (backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(bo), mode)) { - output->pageflip_pending = true; - } else { - wl_event_source_timer_update(output->retry_pageflip, - output->output.current_mode->refresh); - } - - return 1; + wlr_log(L_INFO, "%s: Retrying pageflip", output->output.name); + wlr_drm_output_start_renderer(output); + return 0; } static int find_id(const void *item, const void *cmp_to) { From a466c86fba69e491ffbec1cacc440bee30ae9e63 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sun, 24 Sep 2017 12:06:00 +1300 Subject: [PATCH 09/12] Set state properly --- backend/drm/drm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 712a06b6..8e70e528 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -307,7 +307,7 @@ static void wlr_drm_output_swap_buffers(struct wlr_output *_output) { output->pageflip_pending = true; } else { wl_event_source_timer_update(output->retry_pageflip, - output->output.current_mode->refresh); + 1000.0f / output->output.current_mode->refresh); } } @@ -358,7 +358,7 @@ void wlr_drm_output_start_renderer(struct wlr_drm_output *output) { output->pageflip_pending = true; } else { wl_event_source_timer_update(output->retry_pageflip, - output->output.current_mode->refresh); + 1000.0f / output->output.current_mode->refresh); } } @@ -1006,4 +1006,6 @@ void wlr_drm_output_cleanup(struct wlr_drm_output *output) { case WLR_DRM_OUTPUT_DISCONNECTED: break; } + + output->state = WLR_DRM_OUTPUT_DISCONNECTED; } From 419400ae00b8c223eaa4ded9ba93c2f6e9a02dd8 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sun, 24 Sep 2017 12:09:17 +1300 Subject: [PATCH 10/12] Send failure code on partial atomic commit --- backend/drm/drm-atomic.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/drm/drm-atomic.c b/backend/drm/drm-atomic.c index 5d34cd48..16c9c5c3 100644 --- a/backend/drm/drm-atomic.c +++ b/backend/drm/drm-atomic.c @@ -57,8 +57,7 @@ static bool atomic_commit(int drm_fd, struct atomic *atom, // Try to commit without new changes drmModeAtomicSetCursor(atom->req, atom->cursor); - ret = drmModeAtomicCommit(drm_fd, atom->req, flags, output); - if (ret) { + if (drmModeAtomicCommit(drm_fd, atom->req, flags, output)) { wlr_log_errno(L_ERROR, "%s: Atomic commit failed (%s)", output->output.name, modeset ? "modeset" : "pageflip"); } From c8c5aedaa21e7b8c0a47761a987ab5770b674f0b Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sun, 24 Sep 2017 12:19:49 +1300 Subject: [PATCH 11/12] Add error checking to DRM legacy --- backend/drm/drm-legacy.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/backend/drm/drm-legacy.c b/backend/drm/drm-legacy.c index 5077fcab..9b7cd301 100644 --- a/backend/drm/drm-legacy.c +++ b/backend/drm/drm-legacy.c @@ -9,11 +9,17 @@ static bool legacy_crtc_pageflip(struct wlr_drm_backend *backend, struct wlr_drm_output *output, struct wlr_drm_crtc *crtc, uint32_t fb_id, drmModeModeInfo *mode) { if (mode) { - drmModeSetCrtc(backend->fd, crtc->id, fb_id, 0, 0, - &output->connector, 1, mode); + if (drmModeSetCrtc(backend->fd, crtc->id, fb_id, 0, 0, + &output->connector, 1, mode)) { + wlr_log_errno(L_ERROR, "%s: Failed to set CRTC", output->output.name); + return false; + } } - drmModePageFlip(backend->fd, crtc->id, fb_id, DRM_MODE_PAGE_FLIP_EVENT, output); + if (drmModePageFlip(backend->fd, crtc->id, fb_id, DRM_MODE_PAGE_FLIP_EVENT, output)) { + wlr_log_errno(L_ERROR, "%s: Failed to page flip", output->output.name); + return false; + } return true; } From 00f1686ce5b20fc2000ff577329f804f2a7b596a Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 25 Sep 2017 19:25:59 -0400 Subject: [PATCH 12/12] unset egl current before terminating display fixes segfault when closing the compositor with an egl window. --- render/egl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/render/egl.c b/render/egl.c index 2db8d4c0..048626ba 100644 --- a/render/egl.c +++ b/render/egl.c @@ -175,13 +175,14 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, return true; error: + eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglTerminate(egl->display); eglReleaseThread(); - eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); return false; } void wlr_egl_free(struct wlr_egl *egl) { + eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (egl->wl_display && egl->eglUnbindWaylandDisplayWL) { egl->eglUnbindWaylandDisplayWL(egl->display, egl->wl_display); } @@ -189,7 +190,6 @@ void wlr_egl_free(struct wlr_egl *egl) { eglDestroyContext(egl->display, egl->context); eglTerminate(egl->display); eglReleaseThread(); - eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } bool wlr_egl_bind_display(struct wlr_egl *egl, struct wl_display *local_display) {