summaryrefslogtreecommitdiffstats
path: root/video/out/wayland_common.c
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2022-10-04 11:05:00 -0500
committerDudemanguy <random342@airmail.cc>2022-10-06 18:08:51 +0000
commitd2a0791fe83d8382e06232e72549cab4e4c66130 (patch)
treeae253cf7a653c5940f99649475cb5b4f10f9e59c /video/out/wayland_common.c
parent7f5541fc3c440a4aa5fdec2899c02d1caf7fb227 (diff)
downloadmpv-d2a0791fe83d8382e06232e72549cab4e4c66130.tar.bz2
mpv-d2a0791fe83d8382e06232e72549cab4e4c66130.tar.xz
wayland: correctly handle non-CLOCK_MONOTONIC clocks
The wayland presentation time code currently always assumes that only CLOCK_MONOTONIC can be used. There is a naive attempt to ignore clocks other than CLOCK_MONOTONIC, but the logic is actually totally wrong and the timestamps would be used anyway. Fix this by checking a use_present bool (similar to use_present in xorg) which is set to true if we receive a valid clock in the clockid event. Additionally, allow CLOCK_MONOTONIC_RAW as a valid clockid. In practice, it should be the same as CLOCK_MONOTONIC for us (ntp/adjustime difference wouldn't matter). Since this is a linux-specific clock, add a define for it if it is not found.
Diffstat (limited to 'video/out/wayland_common.c')
-rw-r--r--video/out/wayland_common.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
index ae1e1eb87d..e4a590704b 100644
--- a/video/out/wayland_common.c
+++ b/video/out/wayland_common.c
@@ -46,6 +46,10 @@
#define HAVE_WAYLAND_1_20
#endif
+#ifndef CLOCK_MONOTONIC_RAW
+#define CLOCK_MONOTONIC_RAW 4
+#endif
+
static const struct mp_keymap keymap[] = {
/* Special keys */
@@ -968,12 +972,12 @@ static const struct zxdg_toplevel_decoration_v1_listener decoration_listener = {
};
static void pres_set_clockid(void *data, struct wp_presentation *pres,
- uint32_t clockid)
+ uint32_t clockid)
{
struct vo_wayland_state *wl = data;
- if (clockid == CLOCK_MONOTONIC)
- wl->presentation = pres;
+ if (clockid == CLOCK_MONOTONIC || clockid == CLOCK_MONOTONIC_RAW)
+ wl->use_present = true;
}
static const struct wp_presentation_listener pres_listener = {
@@ -996,6 +1000,9 @@ static void feedback_presented(void *data, struct wp_presentation_feedback *fbac
if (fback)
wp_presentation_feedback_destroy(fback);
+ if (!wl->use_present)
+ return;
+
wl->refresh_interval = (int64_t)refresh_nsec / 1000;
// Very similar to oml_sync_control, in this case we assume that every
@@ -2099,7 +2106,7 @@ void vo_wayland_wait_frame(struct vo_wayland_state *wl)
* 3. refresh rate of the output reported by the compositor
* 4. make up crap if vblank_time is still <= 0 (better than nothing) */
- if (wl->presentation)
+ if (wl->use_present)
vblank_time = wl->present->vsync_duration;
if (vblank_time <= 0 && wl->refresh_interval > 0)
@@ -2126,7 +2133,7 @@ void vo_wayland_wait_frame(struct vo_wayland_state *wl)
/* If the compositor does not have presentation time, we cannot be sure
* that this wait is accurate. Do a hacky block with wl_display_roundtrip. */
- if (!wl->presentation && !wl_display_get_error(wl->display))
+ if (!wl->use_present && !wl_display_get_error(wl->display))
wl_display_roundtrip(wl->display);
if (wl->frame_wait) {