mirror of
https://github.com/mpv-player/mpv
synced 2025-01-15 19:42:53 +00:00
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.
This commit is contained in:
parent
3abb23d70f
commit
19e24bbe86
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user