diff options
author | Simon Ser <contact@emersion.fr> | 2023-10-30 18:37:13 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-10-30 18:39:39 +0100 |
commit | 1c24b1182ba39cb8c508580713336dcf79e6a295 (patch) | |
tree | 5c2554accf8a5aabd2413648397836da050a1dde | |
parent | 5fac9b1beb2281fb13d3e5de7fdd10ff7ba0f30b (diff) |
backend: drop wlr_backend_get_presentation_clock()
We can just assume CLOCK_MONOTONIC everywhere.
Simplifies the backend API, and fixes clock mismatches when multiple
backends are used together with different clocks.
-rw-r--r-- | backend/backend.c | 7 | ||||
-rw-r--r-- | backend/drm/backend.c | 6 | ||||
-rw-r--r-- | backend/drm/drm.c | 10 | ||||
-rw-r--r-- | backend/multi/backend.c | 15 | ||||
-rw-r--r-- | backend/wayland/backend.c | 13 | ||||
-rw-r--r-- | include/backend/drm/drm.h | 2 | ||||
-rw-r--r-- | include/backend/wayland.h | 1 | ||||
-rw-r--r-- | include/wlr/backend.h | 4 | ||||
-rw-r--r-- | include/wlr/backend/interface.h | 2 | ||||
-rw-r--r-- | include/wlr/types/wlr_presentation_time.h | 1 | ||||
-rw-r--r-- | types/output/output.c | 4 | ||||
-rw-r--r-- | types/wlr_presentation_time.c | 4 |
12 files changed, 13 insertions, 56 deletions
diff --git a/backend/backend.c b/backend/backend.c index 125ed411..e5b8db14 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -116,13 +116,6 @@ static struct wlr_session *session_create_and_wait(struct wl_display *disp) { #endif } -clockid_t wlr_backend_get_presentation_clock(struct wlr_backend *backend) { - if (backend->impl->get_presentation_clock) { - return backend->impl->get_presentation_clock(backend); - } - return CLOCK_MONOTONIC; -} - int wlr_backend_get_drm_fd(struct wlr_backend *backend) { if (!backend->impl->get_drm_fd) { return -1; diff --git a/backend/drm/backend.c b/backend/drm/backend.c index df02c6b3..4ee79773 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -64,11 +64,6 @@ static void backend_destroy(struct wlr_backend *backend) { free(drm); } -static clockid_t backend_get_presentation_clock(struct wlr_backend *backend) { - struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend); - return drm->clock; -} - static int backend_get_drm_fd(struct wlr_backend *backend) { struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend); @@ -86,7 +81,6 @@ static uint32_t drm_backend_get_buffer_caps(struct wlr_backend *backend) { static const struct wlr_backend_impl backend_impl = { .start = backend_start, .destroy = backend_destroy, - .get_presentation_clock = backend_get_presentation_clock, .get_drm_fd = backend_get_drm_fd, .get_buffer_caps = drm_backend_get_buffer_caps, }; diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 3db27749..f7c33690 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -80,6 +80,11 @@ bool check_drm_features(struct wlr_drm_backend *drm) { return false; } + if (drmGetCap(drm->fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap) || !cap) { + wlr_log(WLR_ERROR, "DRM_CAP_TIMESTAMP_MONOTONIC unsupported"); + return false; + } + if (env_parse_bool("WLR_DRM_FORCE_LIBLIFTOFF")) { #if HAVE_LIBLIFTOFF wlr_log(WLR_INFO, @@ -110,13 +115,10 @@ bool check_drm_features(struct wlr_drm_backend *drm) { drm->supports_tearing_page_flips = drmGetCap(drm->fd, DRM_CAP_ASYNC_PAGE_FLIP, &cap) == 0 && cap == 1; } - int ret = drmGetCap(drm->fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap); - drm->clock = (ret == 0 && cap == 1) ? CLOCK_MONOTONIC : CLOCK_REALTIME; - if (env_parse_bool("WLR_DRM_NO_MODIFIERS")) { wlr_log(WLR_DEBUG, "WLR_DRM_NO_MODIFIERS set, disabling modifiers"); } else { - ret = drmGetCap(drm->fd, DRM_CAP_ADDFB2_MODIFIERS, &cap); + int ret = drmGetCap(drm->fd, DRM_CAP_ADDFB2_MODIFIERS, &cap); drm->addfb2_modifiers = ret == 0 && cap == 1; wlr_log(WLR_DEBUG, "ADDFB2 modifiers %s", drm->addfb2_modifiers ? "supported" : "unsupported"); diff --git a/backend/multi/backend.c b/backend/multi/backend.c index fccad5b4..8c36834e 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -63,20 +63,6 @@ static void multi_backend_destroy(struct wlr_backend *wlr_backend) { free(backend); } -static clockid_t multi_backend_get_presentation_clock( - struct wlr_backend *backend) { - struct wlr_multi_backend *multi = multi_backend_from_backend(backend); - - struct subbackend_state *sub; - wl_list_for_each(sub, &multi->backends, link) { - if (sub->backend->impl->get_presentation_clock) { - return wlr_backend_get_presentation_clock(sub->backend); - } - } - - return CLOCK_MONOTONIC; -} - static int multi_backend_get_drm_fd(struct wlr_backend *backend) { struct wlr_multi_backend *multi = multi_backend_from_backend(backend); @@ -115,7 +101,6 @@ static uint32_t multi_backend_get_buffer_caps(struct wlr_backend *backend) { static const struct wlr_backend_impl backend_impl = { .start = multi_backend_start, .destroy = multi_backend_destroy, - .get_presentation_clock = multi_backend_get_presentation_clock, .get_drm_fd = multi_backend_get_drm_fd, .get_buffer_caps = multi_backend_get_buffer_caps, }; diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index e8d06eba..9f78b6f1 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -95,7 +95,11 @@ static const struct xdg_wm_base_listener xdg_wm_base_listener = { static void presentation_handle_clock_id(void *data, struct wp_presentation *presentation, uint32_t clock) { struct wlr_wl_backend *wl = data; - wl->presentation_clock = clock; + + if (clock != CLOCK_MONOTONIC) { + wp_presentation_destroy(wl->presentation); + wl->presentation = NULL; + } } static const struct wp_presentation_listener presentation_listener = { @@ -535,11 +539,6 @@ static void backend_destroy(struct wlr_backend *backend) { free(wl); } -static clockid_t backend_get_presentation_clock(struct wlr_backend *backend) { - struct wlr_wl_backend *wl = get_wl_backend_from_backend(backend); - return wl->presentation_clock; -} - static int backend_get_drm_fd(struct wlr_backend *backend) { struct wlr_wl_backend *wl = get_wl_backend_from_backend(backend); return wl->drm_fd; @@ -554,7 +553,6 @@ static uint32_t get_buffer_caps(struct wlr_backend *backend) { static const struct wlr_backend_impl backend_impl = { .start = backend_start, .destroy = backend_destroy, - .get_presentation_clock = backend_get_presentation_clock, .get_drm_fd = backend_get_drm_fd, .get_buffer_caps = get_buffer_caps, }; @@ -585,7 +583,6 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display, wl_list_init(&wl->outputs); wl_list_init(&wl->seats); wl_list_init(&wl->buffers); - wl->presentation_clock = CLOCK_MONOTONIC; if (remote_display != NULL) { wl->remote_display = remote_display; diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index 69416925..c7dd70f8 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -4,7 +4,6 @@ #include <stdbool.h> #include <stddef.h> #include <stdint.h> -#include <time.h> #include <wayland-server-core.h> #include <wayland-util.h> #include <wlr/backend/drm.h> @@ -79,7 +78,6 @@ struct wlr_drm_backend { struct wlr_drm_backend *parent; const struct wlr_drm_interface *iface; - clockid_t clock; bool addfb2_modifiers; int fd; diff --git a/include/backend/wayland.h b/include/backend/wayland.h index a51595ec..d6796b44 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -43,7 +43,6 @@ struct wlr_wl_backend { struct zwp_relative_pointer_manager_v1 *zwp_relative_pointer_manager_v1; struct wl_list seats; // wlr_wl_seat.link struct zwp_tablet_manager_v2 *tablet_manager; - clockid_t presentation_clock; struct wlr_drm_format_set shm_formats; struct wlr_drm_format_set linux_dmabuf_v1_formats; struct wl_drm *legacy_drm; diff --git a/include/wlr/backend.h b/include/wlr/backend.h index fac49f06..9a8a2d87 100644 --- a/include/wlr/backend.h +++ b/include/wlr/backend.h @@ -52,10 +52,6 @@ bool wlr_backend_start(struct wlr_backend *backend); */ void wlr_backend_destroy(struct wlr_backend *backend); /** - * Returns the clock used by the backend for presentation feedback. - */ -clockid_t wlr_backend_get_presentation_clock(struct wlr_backend *backend); -/** * Returns the DRM node file descriptor used by the backend's underlying * platform. Can be used by consumers for additional rendering operations. * The consumer must not close the file descriptor since the backend continues diff --git a/include/wlr/backend/interface.h b/include/wlr/backend/interface.h index 8b922f1d..da57cae9 100644 --- a/include/wlr/backend/interface.h +++ b/include/wlr/backend/interface.h @@ -10,13 +10,11 @@ #define WLR_BACKEND_INTERFACE_H #include <stdbool.h> -#include <time.h> #include <wlr/backend.h> struct wlr_backend_impl { bool (*start)(struct wlr_backend *backend); void (*destroy)(struct wlr_backend *backend); - clockid_t (*get_presentation_clock)(struct wlr_backend *backend); int (*get_drm_fd)(struct wlr_backend *backend); uint32_t (*get_buffer_caps)(struct wlr_backend *backend); }; diff --git a/include/wlr/types/wlr_presentation_time.h b/include/wlr/types/wlr_presentation_time.h index a8df292d..9543cff6 100644 --- a/include/wlr/types/wlr_presentation_time.h +++ b/include/wlr/types/wlr_presentation_time.h @@ -21,7 +21,6 @@ struct wlr_output_event_present; struct wlr_presentation { struct wl_global *global; - clockid_t clock; struct { struct wl_signal destroy; diff --git a/types/output/output.c b/types/output/output.c index a04df4e4..08a71d83 100644 --- a/types/output/output.c +++ b/types/output/output.c @@ -913,9 +913,7 @@ void wlr_output_send_present(struct wlr_output *output, struct timespec now; if (event->presented && event->when == NULL) { - clockid_t clock = wlr_backend_get_presentation_clock(output->backend); - errno = 0; - if (clock_gettime(clock, &now) != 0) { + if (clock_gettime(CLOCK_MONOTONIC, &now) != 0) { wlr_log_errno(WLR_ERROR, "failed to send output present event: " "failed to read clock"); return; diff --git a/types/wlr_presentation_time.c b/types/wlr_presentation_time.c index 65c06ce3..fcfa0f74 100644 --- a/types/wlr_presentation_time.c +++ b/types/wlr_presentation_time.c @@ -168,7 +168,7 @@ static void presentation_bind(struct wl_client *client, void *data, wl_resource_set_implementation(resource, &presentation_impl, presentation, NULL); - wp_presentation_send_clock_id(resource, (uint32_t)presentation->clock); + wp_presentation_send_clock_id(resource, CLOCK_MONOTONIC); } static void handle_display_destroy(struct wl_listener *listener, void *data) { @@ -194,8 +194,6 @@ struct wlr_presentation *wlr_presentation_create(struct wl_display *display, return NULL; } - presentation->clock = wlr_backend_get_presentation_clock(backend); - wl_signal_init(&presentation->events.destroy); presentation->display_destroy.notify = handle_display_destroy; |