summaryrefslogtreecommitdiffstats
path: root/video/out/x11_common.h
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/x11_common.h
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/x11_common.h')
-rw-r--r--video/out/x11_common.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/video/out/x11_common.h b/video/out/x11_common.h
index 45c8d04d21..acc08f2ee0 100644
--- a/video/out/x11_common.h
+++ b/video/out/x11_common.h
@@ -80,6 +80,7 @@ struct vo_x11_state {
Colormap colormap;
int wm_type;
+ bool hidden; // _NET_WM_STATE_HIDDEN
bool window_hidden; // the window was mapped at least once
bool pseudo_mapped; // not necessarily mapped, but known window size
int fs; // whether we assume the window is in fullscreen mode
@@ -142,6 +143,7 @@ bool vo_x11_screen_is_composited(struct vo *vo);
bool vo_x11_create_vo_window(struct vo *vo, XVisualInfo *vis,
const char *classname);
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_wakeup(struct vo *vo);
void vo_x11_wait_events(struct vo *vo, int64_t until_time_us);