summaryrefslogtreecommitdiffstats
path: root/video/out/x11_common.h
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2022-06-10 11:49:38 -0500
committerDudemanguy <random342@airmail.cc>2022-06-19 18:13:55 +0000
commit3d459832a88a9bd2835b339cf6ca98f84aad0115 (patch)
treeaa1700e19dfd03239d08d2e4ac22d9a00565606e /video/out/x11_common.h
parentceade3493045898a30f0da1bbb639552447ffcdf (diff)
downloadmpv-3d459832a88a9bd2835b339cf6ca98f84aad0115.tar.bz2
mpv-3d459832a88a9bd2835b339cf6ca98f84aad0115.tar.xz
x11: support xorg present extension
This builds off of present_sync which was introduced in a previous commit to support xorg's present extension in all of the X11 backends (sans vdpau) in mpv. It turns out there is an Xpresent library that integrates the xorg present extention with Xlib (which barely anyone seems to use), so this can be added without too much trouble. The workflow is to first setup the event by telling Xorg we would like to receive PresentCompleteNotify (there are others in the extension but this is the only one we really care about). After that, just call XPresentNotifyMSC after every buffer swap with a target_msc of 0. Xorg then returns the last presentation through its usual event loop and we go ahead and use that information to update mpv's values for vsync timing purposes. One theoretical weakness of this approach is that the present event is put on the same queue as the rest of the XEvents. It would be nicer for it be placed somewhere else so we could just wait on that queue without having to deal with other possible events in there. In theory, xcb could do that with special events, but it doesn't really matter in practice. Unsurprisingly, this doesn't work on NVIDIA. Well NVIDIA does actually receive presentation events, but for whatever the calculations used make timings worse which defeats the purpose. This works perfectly fine on Mesa however. Utilizing the previous commit that detects Xrandr providers, we can enable this mechanism for users that have both Mesa and not NVIDIA (to avoid messing up anyone that has a switchable graphics system or such). Patches welcome if anyone figures out how to fix this on NVIDIA. Unlike the EGL/GLX sync extensions, the present extension works with any graphics API (good for vulkan since its timing extension has been in development hell). NVIDIA also happens to have zero support for the EGL/GLX sync extensions, so we can just remove it with no loss. Only Xorg ever used it and other backends already have their own present methods. vo_vdpau VO is a special case that has its own fancying timing code in its flip_page. This presumably works well, and I have no way of testing it so just leave it as it is.
Diffstat (limited to 'video/out/x11_common.h')
-rw-r--r--video/out/x11_common.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/video/out/x11_common.h b/video/out/x11_common.h
index e9abf51585..e08beca7b0 100644
--- a/video/out/x11_common.h
+++ b/video/out/x11_common.h
@@ -75,6 +75,10 @@ struct vo_x11_state {
bool dpms_touched;
double screensaver_time_last;
+ struct mp_present *present;
+ bool have_present;
+ int present_code;
+
XIM xim;
XIC xic;
bool no_autorepeat;
@@ -147,6 +151,8 @@ bool vo_x11_create_vo_window(struct vo *vo, XVisualInfo *vis,
void vo_x11_config_vo_window(struct vo *vo);
bool vo_x11_check_visible(struct vo *vo);
int vo_x11_control(struct vo *vo, int *events, int request, void *arg);
+void vo_x11_present(struct vo *vo);
+void vo_x11_sync_swap(struct vo *vo);
void vo_x11_wakeup(struct vo *vo);
void vo_x11_wait_events(struct vo *vo, int64_t until_time_us);