diff options
author | Dudemanguy <random342@airmail.cc> | 2022-06-10 11:49:38 -0500 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2022-06-19 18:13:55 +0000 |
commit | 3d459832a88a9bd2835b339cf6ca98f84aad0115 (patch) | |
tree | aa1700e19dfd03239d08d2e4ac22d9a00565606e /video/out/opengl/context_x11egl.c | |
parent | ceade3493045898a30f0da1bbb639552447ffcdf (diff) | |
download | mpv-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/opengl/context_x11egl.c')
-rw-r--r-- | video/out/opengl/context_x11egl.c | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/video/out/opengl/context_x11egl.c b/video/out/opengl/context_x11egl.c index 4e0b277da7..549498b435 100644 --- a/video/out/opengl/context_x11egl.c +++ b/video/out/opengl/context_x11egl.c @@ -18,14 +18,15 @@ #include <assert.h> #include <X11/Xlib.h> +#include <X11/extensions/Xpresent.h> #include <EGL/egl.h> #include <EGL/eglext.h> #include "common/common.h" +#include "video/out/present_sync.h" #include "video/out/x11_common.h" #include "context.h" #include "egl_helpers.h" -#include "oml_sync.h" #include "utils.h" #define EGL_PLATFORM_X11_EXT 0x31D5 @@ -35,10 +36,6 @@ struct priv { EGLDisplay egl_display; EGLContext egl_context; EGLSurface egl_surface; - - EGLBoolean (*GetSyncValues)(EGLDisplay, EGLSurface, - int64_t*, int64_t*, int64_t*); - struct oml_sync sync; }; static void mpegl_uninit(struct ra_ctx *ctx) @@ -83,20 +80,16 @@ static bool mpegl_check_visible(struct ra_ctx *ctx) static void mpegl_swap_buffers(struct ra_ctx *ctx) { struct priv *p = ctx->priv; - eglSwapBuffers(p->egl_display, p->egl_surface); - - int64_t ust, msc, sbc; - if (!p->GetSyncValues || !p->GetSyncValues(p->egl_display, p->egl_surface, - &ust, &msc, &sbc)) - ust = msc = sbc = -1; - oml_sync_swap(&p->sync, ust, msc, sbc); + eglSwapBuffers(p->egl_display, p->egl_surface); + vo_x11_present(ctx->vo); + present_sync_swap(ctx->vo->x11->present); } static void mpegl_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info) { - struct priv *p = ctx->priv; - oml_sync_get_info(&p->sync, info); + struct vo_x11_state *x11 = ctx->vo->x11; + present_sync_get_info(x11->present, info); } static bool mpegl_init(struct ra_ctx *ctx) @@ -182,10 +175,6 @@ static bool mpegl_init(struct ra_ctx *ctx) if (!ra_gl_ctx_init(ctx, &p->gl, params)) goto uninit; - const char *exts = eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS); - if (gl_check_extension(exts, "EGL_CHROMIUM_sync_control")) - p->GetSyncValues = (void *)eglGetProcAddress("eglGetSyncValuesCHROMIUM"); - ra_add_native_resource(ctx->ra, "x11", vo->x11->display); return true; |