diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2021-08-09 22:04:29 +0300 |
---|---|---|
committer | avih <avih@users.noreply.github.com> | 2021-08-18 02:21:33 +0300 |
commit | 19e24bbe86d5cb241c5a23a9fec423aef0a4063d (patch) | |
tree | 878743c4754c18c5c4b834b7633c489738bcb69d /video/out/w32_common.c | |
parent | 3abb23d70f064803e0399f44714791687b455b2f (diff) | |
download | mpv-19e24bbe86d5cb241c5a23a9fec423aef0a4063d.tar.bz2 mpv-19e24bbe86d5cb241c5a23a9fec423aef0a4063d.tar.xz |
win32: ensure initial dpi-scale value
vo_calc_window_geometry2(...) is called to initialize the window
size with the dpi_scale value as one of the arguments.
dpi_scale is 0 initially, and set to a valid value at update_dpi(),
which is called from [force_]update_display_info().
However, no measures were taken to ensure that dpi_scale is set
correctly before vo_calc_window_geometry2() is called, which could
result in incorrect window size if it's not initialized.
It did happen to get initialized on time, by luck, because
VOCTRL_GET_DISPLAY_FPS is used early, which happens to call
update_display_info to read the fps value (other update_display_info()
calls are after the first vo_calc_window_geometry2() call).
This commit ensures that dpi_scale is initialized on time if needed.
Also, update_dpi() now ensures that dpi_scale is never 0.
Diffstat (limited to 'video/out/w32_common.c')
-rw-r--r-- | video/out/w32_common.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/video/out/w32_common.c b/video/out/w32_common.c index 86334688be..d5ec8ee04b 100644 --- a/video/out/w32_common.c +++ b/video/out/w32_common.c @@ -537,24 +537,26 @@ done: static void update_dpi(struct vo_w32_state *w32) { UINT dpiX, dpiY; + HDC hdc = NULL; + int dpi = 0; + if (w32->api.pGetDpiForMonitor && w32->api.pGetDpiForMonitor(w32->monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY) == S_OK) { - w32->dpi = (int)dpiX; - w32->dpi_scale = w32->opts->hidpi_window_scale ? w32->dpi / 96.0 : 1.0; - MP_VERBOSE(w32, "DPI detected from the new API: %d\n", w32->dpi); - return; - } - HDC hdc = GetDC(NULL); - if (hdc) { - w32->dpi = GetDeviceCaps(hdc, LOGPIXELSX); - w32->dpi_scale = w32->opts->hidpi_window_scale ? w32->dpi / 96.0 : 1.0; + dpi = (int)dpiX; + MP_VERBOSE(w32, "DPI detected from the new API: %d\n", dpi); + } else if ((hdc = GetDC(NULL))) { + dpi = GetDeviceCaps(hdc, LOGPIXELSX); ReleaseDC(NULL, hdc); - MP_VERBOSE(w32, "DPI detected from the old API: %d\n", w32->dpi); - } else { - w32->dpi = 96; - w32->dpi_scale = 1.0; - MP_VERBOSE(w32, "Couldn't determine DPI, falling back to %d\n", w32->dpi); + MP_VERBOSE(w32, "DPI detected from the old API: %d\n", dpi); } + + if (dpi <= 0) { + dpi = 96; + MP_VERBOSE(w32, "Couldn't determine DPI, falling back to %d\n", dpi); + } + + w32->dpi = dpi; + w32->dpi_scale = w32->opts->hidpi_window_scale ? w32->dpi / 96.0 : 1.0; } static void update_display_info(struct vo_w32_state *w32) @@ -1420,6 +1422,9 @@ static void gui_thread_reconfig(void *ptr) struct mp_rect screen = { r.left, r.top, r.right, r.bottom }; struct vo_win_geometry geo; + if (w32->dpi_scale == 0) + force_update_display_info(w32); + vo_calc_window_geometry2(vo, &screen, w32->dpi_scale, &geo); vo_apply_window_geometry(vo, &geo); |