From 771263380c3b3b4b412964b0fe53619aa7c580e2 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 4 Jan 2018 12:46:15 +0100 Subject: Add wlr_output::enabled --- backend/drm/drm.c | 9 ++++++--- backend/headless/backend.c | 2 +- backend/headless/output.c | 5 +++-- backend/wayland/output.c | 5 +++-- backend/x11/backend.c | 8 +++++--- 5 files changed, 18 insertions(+), 11 deletions(-) (limited to 'backend') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index dd5c97f5..32b2f88c 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -257,6 +257,8 @@ static void wlr_drm_connector_enable(struct wlr_output *output, bool enable) { if (enable) { wlr_drm_connector_start_renderer(conn); } + + wlr_output_update_enabled(&conn->output, enable); } static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in, @@ -722,7 +724,8 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { drmModeFreeConnector(drm_conn); continue; } - wlr_output_init(&wlr_conn->output, &drm->backend, &output_impl); + wlr_output_init(&wlr_conn->output, &drm->backend, &output_impl, + drm->display); struct wl_event_loop *ev = wl_display_get_event_loop(drm->display); wlr_conn->retry_pageflip = wl_event_loop_add_timer(ev, retry_pageflip, @@ -792,7 +795,7 @@ 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_output_update_enabled(&wlr_conn->output, true); wlr_conn->state = WLR_DRM_CONN_NEEDS_MODESET; wlr_log(L_INFO, "Sending modesetting signal for '%s'", @@ -802,7 +805,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { drm_conn->connection != DRM_MODE_CONNECTED) { wlr_log(L_INFO, "'%s' disconnected", wlr_conn->output.name); - wlr_output_destroy_global(&wlr_conn->output); + wlr_output_update_enabled(&wlr_conn->output, false); wlr_drm_connector_cleanup(wlr_conn); } diff --git a/backend/headless/backend.c b/backend/headless/backend.c index f95e3897..cef8eec4 100644 --- a/backend/headless/backend.c +++ b/backend/headless/backend.c @@ -15,7 +15,7 @@ static bool backend_start(struct wlr_backend *wlr_backend) { struct wlr_headless_output *output; wl_list_for_each(output, &backend->outputs, link) { wl_event_source_timer_update(output->frame_timer, output->frame_delay); - wlr_output_create_global(&output->wlr_output, backend->display); + wlr_output_update_enabled(&output->wlr_output, true); wl_signal_emit(&backend->backend.events.output_add, &output->wlr_output); } diff --git a/backend/headless/output.c b/backend/headless/output.c index 511c2c53..9fc92e88 100644 --- a/backend/headless/output.c +++ b/backend/headless/output.c @@ -105,7 +105,8 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend, return NULL; } output->backend = backend; - wlr_output_init(&output->wlr_output, &backend->backend, &output_impl); + wlr_output_init(&output->wlr_output, &backend->backend, &output_impl, + backend->display); struct wlr_output *wlr_output = &output->wlr_output; output->egl_surface = egl_create_surface(&backend->egl, width, height); @@ -138,7 +139,7 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend, if (backend->started) { wl_event_source_timer_update(output->frame_timer, output->frame_delay); - wlr_output_create_global(wlr_output, backend->display); + wlr_output_update_enabled(wlr_output, true); wl_signal_emit(&backend->backend.events.output_add, wlr_output); } diff --git a/backend/wayland/output.c b/backend/wayland/output.c index d76f6366..52791679 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -261,7 +261,8 @@ 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, &backend->backend, &output_impl); + wlr_output_init(&output->wlr_output, &backend->backend, &output_impl, + backend->local_display); struct wlr_output *wlr_output = &output->wlr_output; wlr_output_update_custom_mode(wlr_output, 1280, 720, 0); @@ -325,7 +326,7 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { } wl_list_insert(&backend->outputs, &output->link); - wlr_output_create_global(wlr_output, backend->local_display); + wlr_output_update_enabled(wlr_output, true); wl_signal_emit(&backend->backend.events.output_add, wlr_output); return wlr_output; diff --git a/backend/x11/backend.c b/backend/x11/backend.c index d2690342..e1622d06 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -181,7 +181,8 @@ static int signal_frame(void *data) { static void init_atom(struct wlr_x11_backend *x11, struct wlr_x11_atom *atom, uint8_t only_if_exists, const char *name) { - atom->cookie = xcb_intern_atom(x11->xcb_conn, only_if_exists, strlen(name), name); + atom->cookie = xcb_intern_atom(x11->xcb_conn, only_if_exists, strlen(name), + name); atom->reply = xcb_intern_atom_reply(x11->xcb_conn, atom->cookie, NULL); } @@ -201,7 +202,8 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { output->x11 = x11; - wlr_output_init(&output->wlr_output, &x11->backend, &output_impl); + wlr_output_init(&output->wlr_output, &x11->backend, &output_impl, + x11->wl_display); snprintf(output->wlr_output.name, sizeof(output->wlr_output.name), "X11-1"); output->win = xcb_generate_id(x11->xcb_conn); @@ -224,7 +226,7 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { xcb_map_window(x11->xcb_conn, output->win); xcb_flush(x11->xcb_conn); - wlr_output_create_global(&output->wlr_output, x11->wl_display); + wlr_output_update_enabled(&output->wlr_output, true); wl_signal_emit(&x11->backend.events.output_add, output); wl_signal_emit(&x11->backend.events.input_add, &x11->keyboard_dev); -- cgit v1.2.3 From 53ba9b4eec4345cb5ba6640e8677f3b2477d2693 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 7 Jan 2018 00:28:21 +0100 Subject: Fix output enable in DRM backend --- backend/drm/atomic.c | 14 +++++++++++--- backend/drm/drm.c | 5 ++++- backend/drm/legacy.c | 5 +++-- include/backend/drm/iface.h | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) (limited to 'backend') diff --git a/backend/drm/atomic.c b/backend/drm/atomic.c index e7374a00..8d98bac2 100644 --- a/backend/drm/atomic.c +++ b/backend/drm/atomic.c @@ -123,14 +123,22 @@ static bool atomic_crtc_pageflip(struct wlr_drm_backend *drm, mode); } -static void atomic_conn_enable(struct wlr_drm_backend *drm, +static bool atomic_conn_enable(struct wlr_drm_backend *drm, struct wlr_drm_connector *conn, bool enable) { struct wlr_drm_crtc *crtc = conn->crtc; - struct atomic atom; + struct atomic atom; atomic_begin(crtc, &atom); atomic_add(&atom, crtc->id, crtc->props.active, enable); - atomic_end(drm->fd, &atom); + if (enable) { + atomic_add(&atom, conn->id, conn->props.crtc_id, crtc->id); + atomic_add(&atom, crtc->id, crtc->props.mode_id, crtc->mode_id); + } else { + atomic_add(&atom, conn->id, conn->props.crtc_id, 0); + atomic_add(&atom, crtc->id, crtc->props.mode_id, 0); + } + return atomic_commit(drm->fd, &atom, conn, DRM_MODE_ATOMIC_ALLOW_MODESET, + true); } bool legacy_crtc_set_cursor(struct wlr_drm_backend *drm, diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 32b2f88c..0d32605a 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -252,7 +252,10 @@ static void wlr_drm_connector_enable(struct wlr_output *output, bool enable) { } struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; - drm->iface->conn_enable(drm, conn, enable); + bool ok = drm->iface->conn_enable(drm, conn, enable); + if (!ok) { + return; + } if (enable) { wlr_drm_connector_start_renderer(conn); diff --git a/backend/drm/legacy.c b/backend/drm/legacy.c index d75eb2cb..61140cec 100644 --- a/backend/drm/legacy.c +++ b/backend/drm/legacy.c @@ -25,10 +25,11 @@ static bool legacy_crtc_pageflip(struct wlr_drm_backend *drm, return true; } -static void legacy_conn_enable(struct wlr_drm_backend *drm, +static bool legacy_conn_enable(struct wlr_drm_backend *drm, struct wlr_drm_connector *conn, bool enable) { - drmModeConnectorSetProperty(drm->fd, conn->id, conn->props.dpms, + int ret = drmModeConnectorSetProperty(drm->fd, conn->id, conn->props.dpms, enable ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF); + return ret >= 0; } bool legacy_crtc_set_cursor(struct wlr_drm_backend *drm, diff --git a/include/backend/drm/iface.h b/include/backend/drm/iface.h index bc61eb51..4a5d2e9d 100644 --- a/include/backend/drm/iface.h +++ b/include/backend/drm/iface.h @@ -15,7 +15,7 @@ struct wlr_drm_crtc; // Used to provide atomic or legacy DRM functions struct wlr_drm_interface { // Enable or disable DPMS for connector - void (*conn_enable)(struct wlr_drm_backend *drm, + bool (*conn_enable)(struct wlr_drm_backend *drm, struct wlr_drm_connector *conn, bool enable); // Pageflip on crtc. If mode is non-NULL perform a full modeset using it. bool (*crtc_pageflip)(struct wlr_drm_backend *drm, -- cgit v1.2.3 From c00e9d1416e609543b41d15550841a10a9b38632 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Sat, 13 Jan 2018 21:20:15 +0100 Subject: adds remote argument to wayland backend create Add a remote display name argument to wlr_wl_backend_create. If NULL is passed to the wayland backend at all times, creating a wayland backend *after* the compositor was started up, would require changing the WAYLAND_DISPLAY environment variable. --- backend/backend.c | 2 +- backend/wayland/backend.c | 4 ++-- include/wlr/backend/wayland.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'backend') diff --git a/backend/backend.c b/backend/backend.c index 6b32bc6a..54e1cdca 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -53,7 +53,7 @@ struct wlr_egl *wlr_backend_get_egl(struct wlr_backend *backend) { } static struct wlr_backend *attempt_wl_backend(struct wl_display *display) { - struct wlr_backend *backend = wlr_wl_backend_create(display); + struct wlr_backend *backend = wlr_wl_backend_create(display, NULL); if (backend) { int outputs = 1; const char *_outputs = getenv("WLR_WL_OUTPUTS"); diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 36fbd8e0..32fdc2b6 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -158,7 +158,7 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) { wlr_wl_backend_destroy(&backend->backend); } -struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) { +struct wlr_backend *wlr_wl_backend_create(struct wl_display *display, const char *remote) { wlr_log(L_INFO, "Creating wayland backend"); struct wlr_wl_backend *backend = calloc(1, sizeof(struct wlr_wl_backend)); @@ -173,7 +173,7 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) { backend->local_display = display; - backend->remote_display = wl_display_connect(NULL); + backend->remote_display = wl_display_connect(remote); if (!backend->remote_display) { wlr_log_errno(L_ERROR, "Could not connect to remote display"); return false; diff --git a/include/wlr/backend/wayland.h b/include/wlr/backend/wayland.h index b10ffee3..02ee5b2d 100644 --- a/include/wlr/backend/wayland.h +++ b/include/wlr/backend/wayland.h @@ -12,7 +12,7 @@ * Creates a new wlr_wl_backend. This backend will be created with no outputs; * you must use wlr_wl_output_create to add them. */ -struct wlr_backend *wlr_wl_backend_create(struct wl_display *display); +struct wlr_backend *wlr_wl_backend_create(struct wl_display *display, const char *remote); /** * Adds a new output to this backend. You may remove outputs by destroying them. -- cgit v1.2.3 From 3101c300b1b60bf47e7dd8032aff4da88a7b9e36 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Mon, 15 Jan 2018 12:21:22 +0000 Subject: Don't crash if crtc->cursor is NULL Same as what atomic_crtc_set_cursor does Core was generated by `_build/rootston/rootston'. Program terminated with signal SIGSEGV, Segmentation fault. 0 0xb6f28a1c in atomic_crtc_move_cursor (drm=0x1ebc8e8, crtc=0x1ead498, x=0, y=0) at ../backend/drm/atomic.c:170 170 if (!crtc || !crtc->cursor) { (gdb) bt 0 0xb6f28a1c in atomic_crtc_move_cursor (drm=0x1ebc8e8, crtc=0x1ead498, x=0, y=0) at ../backend/drm/atomic.c:170 1 0xb6f2a856 in wlr_drm_connector_move_cursor (output=0x2242b28, x=0, y=0) at ../backend/drm/drm.c:634 2 0xb6f3cea0 in wlr_output_cursor_set_image (cursor=0x21a0338, pixels=0x22e1290 "", stride=24, width=24, height=24, hotspot_x=4, hotspot_y=4) at ../types/wlr_output.c:516 3 0xb6f39da2 in wlr_cursor_set_image (cur=0x22cfc90, pixels=0x22e1290 "", stride=24, width=24, height=24, hotspot_x=4, hotspot_y=4, scale=1) at ../types/wlr_cursor.c:310 4 0xb6f44d2a in wlr_xcursor_manager_set_cursor_image (manager=0x22cfd10, name=0x434420 "left_ptr", cursor=0x22cfc90) at ../types/wlr_xcursor_manager.c:80 5 0x00431c0a in roots_seat_configure_xcursor (seat=0x22cef08) at ../rootston/seat.c:515 6 0x0043137c in roots_seat_init_cursor (seat=0x22cef08) at ../rootston/seat.c:210 7 0x004315ec in roots_seat_create (input=0x218d220, name=0x434594 "seat0") at ../rootston/seat.c:289 8 0x0042ecba in input_get_seat (input=0x218d220, name=0x434594 "seat0") at ../rootston/input.c:39 9 0x0042ed04 in input_add_notify (listener=0x218d228, data=0x218d3b0) at ../rootston/input.c:54 10 0xb6f2f2e6 in wl_signal_emit (signal=0x1ea548c, data=0x218d3b0) at /usr/include/wayland-server-core.h:387 11 0xb6f2f572 in input_add_reemit (listener=0x1ea9990, data=0x218d3b0) at ../backend/multi/backend.c:101 12 0xb6f2db7e in wl_signal_emit (signal=0x1ea992c, data=0x218d3b0) at /usr/include/wayland-server-core.h:387 13 0xb6f2ddaa in handle_device_added (backend=0x1ea9920, libinput_dev=0x2292598) at ../backend/libinput/events.c:87 14 0xb6f2e164 in wlr_libinput_event (backend=0x1ea9920, event=0x2292b78) at ../backend/libinput/events.c:198 15 0xb6f2d678 in wlr_libinput_readable (fd=23, mask=1, _backend=0x1ea9920) at ../backend/libinput/backend.c:28 16 0xb6f2d7c0 in wlr_libinput_backend_start (_backend=0x1ea9920) at ../backend/libinput/backend.c:74 17 0xb6f27170 in wlr_backend_start (backend=0x1ea9920) at ../backend/backend.c:30 18 0xb6f2f320 in multi_backend_start (wlr_backend=0x1ea5480) at ../backend/multi/backend.c:22 19 0xb6f27170 in wlr_backend_start (backend=0x1ea5480) at ../backend/backend.c:30 20 0x0042fbc6 in main (argc=1, argv=0xbe89dd04) at ../rootston/main.c:60 --- backend/drm/atomic.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'backend') diff --git a/backend/drm/atomic.c b/backend/drm/atomic.c index e7374a00..64fae6e4 100644 --- a/backend/drm/atomic.c +++ b/backend/drm/atomic.c @@ -167,6 +167,10 @@ bool legacy_crtc_move_cursor(struct wlr_drm_backend *drm, static bool atomic_crtc_move_cursor(struct wlr_drm_backend *drm, struct wlr_drm_crtc *crtc, int x, int y) { + if (!crtc || !crtc->cursor) { + return true; + } + struct wlr_drm_plane *plane = crtc->cursor; // We can't use atomic operations on fake planes if (plane->id == 0) { -- cgit v1.2.3 From 0eebaf98d0550a9ea7adb743a5b85634f1d76b73 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 15 Jan 2018 21:49:37 +0100 Subject: drm: do not pageflip when enabling output --- backend/drm/atomic.c | 24 +++++++++++++----------- types/wlr_output.c | 4 ++++ 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'backend') diff --git a/backend/drm/atomic.c b/backend/drm/atomic.c index 8d98bac2..3e8866ad 100644 --- a/backend/drm/atomic.c +++ b/backend/drm/atomic.c @@ -33,7 +33,6 @@ static bool atomic_end(int drm_fd, struct atomic *atom) { } uint32_t flags = DRM_MODE_ATOMIC_TEST_ONLY | DRM_MODE_ATOMIC_NONBLOCK; - if (drmModeAtomicCommit(drm_fd, atom->req, flags, NULL)) { wlr_log_errno(L_ERROR, "Atomic test failed"); drmModeAtomicSetCursor(atom->req, atom->cursor); @@ -44,13 +43,11 @@ static bool atomic_end(int drm_fd, struct atomic *atom) { } static bool atomic_commit(int drm_fd, struct atomic *atom, - struct wlr_drm_connector *conn, uint32_t flag, bool modeset) { + struct wlr_drm_connector *conn, uint32_t flags, bool modeset) { if (atom->failed) { return false; } - uint32_t flags = DRM_MODE_PAGE_FLIP_EVENT | flag; - int ret = drmModeAtomicCommit(drm_fd, atom->req, flags, conn); if (ret) { wlr_log_errno(L_ERROR, "%s: Atomic commit failed (%s)", @@ -59,7 +56,8 @@ static bool atomic_commit(int drm_fd, struct atomic *atom, // Try to commit without new changes drmModeAtomicSetCursor(atom->req, atom->cursor); if (drmModeAtomicCommit(drm_fd, atom->req, flags, conn)) { - wlr_log_errno(L_ERROR, "%s: Atomic commit failed (%s)", + wlr_log_errno(L_ERROR, + "%s: Atomic commit without new changes failed (%s)", conn->output.name, modeset ? "modeset" : "pageflip"); } } @@ -100,8 +98,8 @@ static bool atomic_crtc_pageflip(struct wlr_drm_backend *drm, struct wlr_drm_connector *conn, struct wlr_drm_crtc *crtc, uint32_t fb_id, drmModeModeInfo *mode) { - if (mode) { - if (crtc->mode_id) { + if (mode != NULL) { + if (crtc->mode_id != 0) { drmModeDestroyPropertyBlob(drm->fd, crtc->mode_id); } @@ -111,16 +109,20 @@ static bool atomic_crtc_pageflip(struct wlr_drm_backend *drm, } } - struct atomic atom; + uint32_t flags = DRM_MODE_PAGE_FLIP_EVENT; + if (mode != NULL) { + flags |= DRM_MODE_ATOMIC_ALLOW_MODESET; + } else { + flags |= DRM_MODE_ATOMIC_NONBLOCK; + } + struct atomic atom; atomic_begin(crtc, &atom); atomic_add(&atom, conn->id, conn->props.crtc_id, crtc->id); 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(drm->fd, &atom, conn, - mode ? DRM_MODE_ATOMIC_ALLOW_MODESET : DRM_MODE_ATOMIC_NONBLOCK, - mode); + return atomic_commit(drm->fd, &atom, conn, flags, mode); } static bool atomic_conn_enable(struct wlr_drm_backend *drm, diff --git a/types/wlr_output.c b/types/wlr_output.c index 8194c17e..b47fb3a0 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -156,6 +156,10 @@ static void wlr_output_update_matrix(struct wlr_output *output) { } void wlr_output_enable(struct wlr_output *output, bool enable) { + if (output->enabled == enable) { + return; + } + if (output->impl->enable) { output->impl->enable(output, enable); } -- cgit v1.2.3