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
This commit is contained in:
parent
613f9c6f8d
commit
348f52b5fc
|
@ -960,47 +960,6 @@ static bool drm_connector_move_cursor(struct wlr_output *output,
|
||||||
return ok;
|
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) {
|
static uint32_t strip_alpha_channel(uint32_t format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case DRM_FORMAT_ARGB8888:
|
case DRM_FORMAT_ARGB8888:
|
||||||
|
@ -1070,7 +1029,6 @@ static const struct wlr_output_impl output_impl = {
|
||||||
.set_gamma = set_drm_connector_gamma,
|
.set_gamma = set_drm_connector_gamma,
|
||||||
.get_gamma_size = drm_connector_get_gamma_size,
|
.get_gamma_size = drm_connector_get_gamma_size,
|
||||||
.export_dmabuf = drm_connector_export_dmabuf,
|
.export_dmabuf = drm_connector_export_dmabuf,
|
||||||
.schedule_frame = drm_connector_schedule_frame,
|
|
||||||
.attach_buffer = drm_connector_attach_buffer,
|
.attach_buffer = drm_connector_attach_buffer,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -415,20 +415,6 @@ static bool output_move_cursor(struct wlr_output *_output, int x, int y) {
|
||||||
return true;
|
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 = {
|
static const struct wlr_output_impl output_impl = {
|
||||||
.destroy = output_destroy,
|
.destroy = output_destroy,
|
||||||
.attach_render = output_attach_render,
|
.attach_render = output_attach_render,
|
||||||
|
@ -436,7 +422,6 @@ static const struct wlr_output_impl output_impl = {
|
||||||
.commit = output_commit,
|
.commit = output_commit,
|
||||||
.set_cursor = output_set_cursor,
|
.set_cursor = output_set_cursor,
|
||||||
.move_cursor = output_move_cursor,
|
.move_cursor = output_move_cursor,
|
||||||
.schedule_frame = output_schedule_frame,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool wlr_output_is_wl(struct wlr_output *wlr_output) {
|
bool wlr_output_is_wl(struct wlr_output *wlr_output) {
|
||||||
|
|
|
@ -27,7 +27,6 @@ struct wlr_output_impl {
|
||||||
size_t (*get_gamma_size)(struct wlr_output *output);
|
size_t (*get_gamma_size)(struct wlr_output *output);
|
||||||
bool (*export_dmabuf)(struct wlr_output *output,
|
bool (*export_dmabuf)(struct wlr_output *output,
|
||||||
struct wlr_dmabuf_attributes *attribs);
|
struct wlr_dmabuf_attributes *attribs);
|
||||||
bool (*schedule_frame)(struct wlr_output *output);
|
|
||||||
bool (*attach_buffer)(struct wlr_output *output, struct wlr_buffer *buffer);
|
bool (*attach_buffer)(struct wlr_output *output, struct wlr_buffer *buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -599,11 +599,8 @@ void wlr_output_send_frame(struct wlr_output *output) {
|
||||||
static void schedule_frame_handle_idle_timer(void *data) {
|
static void schedule_frame_handle_idle_timer(void *data) {
|
||||||
struct wlr_output *output = data;
|
struct wlr_output *output = data;
|
||||||
output->idle_frame = NULL;
|
output->idle_frame = NULL;
|
||||||
if (!output->frame_pending && output->impl->schedule_frame) {
|
if (!output->frame_pending) {
|
||||||
// Ask the backend to send a frame event when appropriate
|
wlr_output_send_frame(output);
|
||||||
if (output->impl->schedule_frame(output)) {
|
|
||||||
output->frame_pending = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue