From a58585d5e063a97f33a67cc500015c1c30473bcc Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 8 Jan 2020 02:16:45 +0100 Subject: [PATCH] command: cache display-hidpi-scale property This is a gross hack for the shitty design of how VO properties are handled (which was fine with MPlayer, but became increasingly a shit tub with mpv's VO thread). The problem here is that console.lua reads display-hidpi-scale on every render, but which may take a long time for video timing and vsync blocking. It will also block the core, making osc.lua unable to react to window resizing quickly enough. This should be solved by not using the "classic" blocking VOCTRL mechanism, and instead side-stepping it with something that doesn't require any waiting (like for example the "fullscreen" property does). But this require more thinking and work my "brain" can handle at the moment. So for now add a shitty hack that will cause a lot of problems, and which will have to be replaced later. Most importantly, it'll break theoretic support for multiple screens with different DPI, or runtime DPI changes. Possibly could affect the Cocoa backend; the X11 isn't dynamic enough by nature, and other backends do not implement this. --- player/command.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/player/command.c b/player/command.c index 5d5fcbfe7d..e7a0ef6a4f 100644 --- a/player/command.c +++ b/player/command.c @@ -104,6 +104,8 @@ struct command_ctx { struct mp_cmd_ctx *cache_dump_cmd; // in progress cache dumping char **script_props; + + double cached_window_scale; }; static const struct m_option script_props_type = { @@ -2329,11 +2331,19 @@ static int mp_property_hidpi_scale(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; + struct command_ctx *cmd = mpctx->command_ctx; struct vo *vo = mpctx->video_out; - double scale = 0; - if (!vo || vo_control(vo, VOCTRL_GET_HIDPI_SCALE, &scale) < 1 || scale <= 0) + if (!vo) return M_PROPERTY_UNAVAILABLE; - return m_property_double_ro(action, arg, scale); + if (!cmd->cached_window_scale) { + double scale = 0; + if (vo_control(vo, VOCTRL_GET_HIDPI_SCALE, &scale) < 1 || !scale) + scale = -1; + cmd->cached_window_scale = scale; + } + if (cmd->cached_window_scale < 0) + return M_PROPERTY_UNAVAILABLE; + return m_property_double_ro(action, arg, cmd->cached_window_scale); } static int mp_property_display_names(void *ctx, struct m_property *prop, @@ -3514,7 +3524,7 @@ static const char *const *const mp_event_property_change[] = { "demuxer-cache-state"), E(MP_EVENT_WIN_RESIZE, "current-window-scale", "osd-width", "osd-height", "osd-par", "osd-dimensions"), - E(MP_EVENT_WIN_STATE, "display-names", "display-fps"), + E(MP_EVENT_WIN_STATE, "display-names", "display-fps", "display-hidpi-scale"), E(MP_EVENT_CHANGE_PLAYLIST, "playlist", "playlist-pos", "playlist-pos-1", "playlist-count", "playlist/count"), E(MP_EVENT_CORE_IDLE, "core-idle", "eof-reached"),