From 348f52b5fc9be71bc22a6c0e00682667fb62374a Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 2 Mar 2020 13:26:53 +0100 Subject: output: remove wlr_output_impl.schedule_frame This function allowed backends to provide a custom function for frame scheduling. Before resuming the rendering loop, the DRM and Wayland backends would wait for vsync. There isn't a clear benefit of doing this. The only upside is that we get more stable timings: the delay between two repaints doesn't change too much and is close to a mutliple of the refresh rate. However this introduces latency, especially when a client misses a frame. For instance a fullscreen game missing vblank will need to wait more than a whole frame before being able to display new content. This worst case scenario happens as follows: - Client is still rendering its frame and cannot submit it in time - Deadline is reached - Compositor decides to stop the rendering loop since nothing changed on screen - Client finally manages to render its frame, submits it - Compositor calls wlr_output_schedule_frame - DRM backend waits for next vblank - The wlr_output frame event is fired, compositor draws new content on screen - On the second next vblank, the new content reaches the screen With this patch, the wlr_output frame event is fired immediately when the client submits its late frame. This change also makes it easier to support variable refresh rate, since VRR is all about being able to present too-late frames earlier. References: https://github.com/swaywm/wlroots/issues/1925 --- backend/drm/drm.c | 42 ------------------------------------------ backend/wayland/output.c | 15 --------------- 2 files changed, 57 deletions(-) (limited to 'backend') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index a97915ec..ebea340e 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -960,47 +960,6 @@ static bool drm_connector_move_cursor(struct wlr_output *output, return ok; } -static bool drm_connector_schedule_frame(struct wlr_output *output) { - struct wlr_drm_connector *conn = get_drm_connector_from_output(output); - struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend); - if (!drm->session->active) { - return false; - } - - // We need to figure out where we are in the vblank cycle - // TODO: try using drmWaitVBlank and fallback to pageflipping - - struct wlr_drm_crtc *crtc = conn->crtc; - if (!crtc) { - return false; - } - struct wlr_drm_plane *plane = crtc->primary; - struct gbm_bo *bo = plane->surf.back; - if (!bo) { - // We haven't swapped buffers yet -- can't do a pageflip - wlr_output_send_frame(output); - return true; - } - if (drm->parent) { - bo = copy_drm_surface_mgpu(&plane->mgpu_surf, bo); - } - - if (conn->pageflip_pending) { - wlr_log(WLR_ERROR, "Skipping pageflip on output '%s'", - conn->output.name); - return true; - } - - uint32_t fb_id = get_fb_for_bo(bo, plane->drm_format, drm->addfb2_modifiers); - if (!drm->iface->crtc_pageflip(drm, conn, crtc, fb_id, NULL)) { - return false; - } - - conn->pageflip_pending = true; - wlr_output_update_enabled(output, true); - return true; -} - static uint32_t strip_alpha_channel(uint32_t format) { switch (format) { case DRM_FORMAT_ARGB8888: @@ -1070,7 +1029,6 @@ static const struct wlr_output_impl output_impl = { .set_gamma = set_drm_connector_gamma, .get_gamma_size = drm_connector_get_gamma_size, .export_dmabuf = drm_connector_export_dmabuf, - .schedule_frame = drm_connector_schedule_frame, .attach_buffer = drm_connector_attach_buffer, }; diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 7a3a08d0..2c80c77f 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -415,20 +415,6 @@ static bool output_move_cursor(struct wlr_output *_output, int x, int y) { return true; } -static bool output_schedule_frame(struct wlr_output *wlr_output) { - struct wlr_wl_output *output = get_wl_output_from_output(wlr_output); - - if (output->frame_callback != NULL) { - wlr_log(WLR_ERROR, "Skipping frame scheduling"); - return true; - } - - output->frame_callback = wl_surface_frame(output->surface); - wl_callback_add_listener(output->frame_callback, &frame_listener, output); - wl_surface_commit(output->surface); - return true; -} - static const struct wlr_output_impl output_impl = { .destroy = output_destroy, .attach_render = output_attach_render, @@ -436,7 +422,6 @@ static const struct wlr_output_impl output_impl = { .commit = output_commit, .set_cursor = output_set_cursor, .move_cursor = output_move_cursor, - .schedule_frame = output_schedule_frame, }; bool wlr_output_is_wl(struct wlr_output *wlr_output) { -- cgit v1.2.3