summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/context_x11egl.c
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2022-04-06 22:36:30 -0500
committerDudemanguy <random342@airmail.cc>2022-04-11 18:14:22 +0000
commit6158bb5be22e83270f79a771e11a65b274e51182 (patch)
treebd9535816e8b26bb6a6a523bcc125be65bb40ed4 /video/out/opengl/context_x11egl.c
parentfe6d9b6962dededc14d161e522e5f44c1ca2cd60 (diff)
downloadmpv-6158bb5be22e83270f79a771e11a65b274e51182.tar.bz2
mpv-6158bb5be22e83270f79a771e11a65b274e51182.tar.xz
x11: avoid wasteful rendering when possible
Because wayland is a special snowflake, mpv wound up incorporating a lot of logic into its render loop where visibilty checks are performed before rendering anything (in the name of efficiency of course). Only wayland actually uses this, but there's no reason why other backends (x11 in this commit) can't be smarter. It's far easier on xorg since we can just query _NET_WM_STATE_HIDDEN directly and not have to do silly callback dances. The function, vo_x11_check_net_wm_state_change, already tracks net wm changes, including _NET_WM_STATE_HIDDEN. There is an already existing window_hidden variable but that is actually just for checking if the window was mapped and has nothing to do with this particular atom. mpv also currently assumes that a _NET_WM_STATE_HIDDEN is exactly the same as being minimized but according to the spec, that's not neccesarily true (in practice, it's likely that these are the same though). Anyways, just keep track of this state in a new variable (hidden) and use that for determing if mpv should render or not. There is one catch though: this cannot work if a display sync mode is used. This is why the previous commit is needed. The display sync modes in mpv require a blocking vsync implementation since its render loop is directly driven by vsync. In xorg, if nothing is actually rendered, then there's nothing for eglSwapBuffers (or FIFO for vulkan) to block on so it returns immediately. This, of course, results in completely broken video. We just need to check to make sure that we aren't in a display sync mode before trying to be smart about rendering. Display sync is power inefficient anyways, so no one is really being hurt here. As an aside, this happens to work in wayland because there's basically a custom (and ugly) vsync blocking function + timeout but that's off topic.
Diffstat (limited to 'video/out/opengl/context_x11egl.c')
-rw-r--r--video/out/opengl/context_x11egl.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/video/out/opengl/context_x11egl.c b/video/out/opengl/context_x11egl.c
index f1596bcee4..4e0b277da7 100644
--- a/video/out/opengl/context_x11egl.c
+++ b/video/out/opengl/context_x11egl.c
@@ -75,6 +75,11 @@ static int pick_xrgba_config(void *user_data, EGLConfig *configs, int num_config
return 0;
}
+static bool mpegl_check_visible(struct ra_ctx *ctx)
+{
+ return vo_x11_check_visible(ctx->vo);
+}
+
static void mpegl_swap_buffers(struct ra_ctx *ctx)
{
struct priv *p = ctx->priv;
@@ -169,6 +174,7 @@ static bool mpegl_init(struct ra_ctx *ctx)
mpegl_load_functions(&p->gl, ctx->log);
struct ra_gl_ctx_params params = {
+ .check_visible = mpegl_check_visible,
.swap_buffers = mpegl_swap_buffers,
.get_vsync = mpegl_get_vsync,
};