summaryrefslogtreecommitdiffstats
path: root/video/out/vo_xv.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/vo_xv.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/vo_xv.c')
-rw-r--r--video/out/vo_xv.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/video/out/vo_xv.c b/video/out/vo_xv.c
index 43fc046f9f..d93673493f 100644
--- a/video/out/vo_xv.c
+++ b/video/out/vo_xv.c
@@ -697,6 +697,9 @@ static void draw_image(struct vo *vo, mp_image_t *mpi)
struct xvctx *ctx = vo->priv;
wait_for_completion(vo, ctx->num_buffers - 1);
+ bool render = vo_x11_check_visible(vo);
+ if (!render)
+ return;
struct mp_image xv_buffer = get_xv_buffer(vo, ctx->current_buf);
if (mpi) {