summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--video/out/opengl/context_wayland.c4
-rw-r--r--video/out/vo_vaapi_wayland.c4
-rw-r--r--video/out/vo_wlshm.c4
-rw-r--r--video/out/vulkan/context_wayland.c4
-rw-r--r--video/out/wayland_common.c17
-rw-r--r--video/out/wayland_common.h1
6 files changed, 21 insertions, 13 deletions
diff --git a/video/out/opengl/context_wayland.c b/video/out/opengl/context_wayland.c
index b374be64c9..2782d46509 100644
--- a/video/out/opengl/context_wayland.c
+++ b/video/out/opengl/context_wayland.c
@@ -101,14 +101,14 @@ static void wayland_egl_swap_buffers(struct ra_ctx *ctx)
if (!wl->opts->disable_vsync)
vo_wayland_wait_frame(wl);
- if (wl->presentation)
+ if (wl->use_present)
present_sync_swap(wl->present);
}
static void wayland_egl_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info)
{
struct vo_wayland_state *wl = ctx->vo->wl;
- if (wl->presentation)
+ if (wl->use_present)
present_sync_get_info(wl->present, info);
}
diff --git a/video/out/vo_vaapi_wayland.c b/video/out/vo_vaapi_wayland.c
index dd4851f633..ad88d50e55 100644
--- a/video/out/vo_vaapi_wayland.c
+++ b/video/out/vo_vaapi_wayland.c
@@ -361,7 +361,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
if (!wl->opts->disable_vsync)
vo_wayland_wait_frame(wl);
- if (wl->presentation)
+ if (wl->use_present)
present_sync_swap(wl->present);
}
static void flip_page(struct vo *vo)
@@ -372,7 +372,7 @@ static void flip_page(struct vo *vo)
static void get_vsync(struct vo *vo, struct vo_vsync_info *info)
{
struct vo_wayland_state *wl = vo->wl;
- if (wl->presentation)
+ if (wl->use_present)
present_sync_get_info(wl->present, info);
}
diff --git a/video/out/vo_wlshm.c b/video/out/vo_wlshm.c
index b8db2ebd4e..6064c2acc1 100644
--- a/video/out/vo_wlshm.c
+++ b/video/out/vo_wlshm.c
@@ -262,14 +262,14 @@ static void flip_page(struct vo *vo)
if (!wl->opts->disable_vsync)
vo_wayland_wait_frame(wl);
- if (wl->presentation)
+ if (wl->use_present)
present_sync_swap(wl->present);
}
static void get_vsync(struct vo *vo, struct vo_vsync_info *info)
{
struct vo_wayland_state *wl = vo->wl;
- if (wl->presentation)
+ if (wl->use_present)
present_sync_get_info(wl->present, info);
}
diff --git a/video/out/vulkan/context_wayland.c b/video/out/vulkan/context_wayland.c
index 7bc26ab1c6..fe20336a9e 100644
--- a/video/out/vulkan/context_wayland.c
+++ b/video/out/vulkan/context_wayland.c
@@ -39,14 +39,14 @@ static void wayland_vk_swap_buffers(struct ra_ctx *ctx)
if (!wl->opts->disable_vsync)
vo_wayland_wait_frame(wl);
- if (wl->presentation)
+ if (wl->use_present)
present_sync_swap(wl->present);
}
static void wayland_vk_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info)
{
struct vo_wayland_state *wl = ctx->vo->wl;
- if (wl->presentation)
+ if (wl->use_present)
present_sync_get_info(wl->present, info);
}
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) {
diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h
index 365ae42dab..77699a3dd6 100644
--- a/video/out/wayland_common.h
+++ b/video/out/wayland_common.h
@@ -92,6 +92,7 @@ struct vo_wayland_state {
struct wp_presentation_feedback *feedback;
struct mp_present *present;
int64_t refresh_interval;
+ bool use_present;
/* xdg-decoration */
struct zxdg_decoration_manager_v1 *xdg_decoration_manager;