diff --git a/gfx/common/win32_common.c b/gfx/common/win32_common.c index 4e180fb1fa..f935870429 100644 --- a/gfx/common/win32_common.c +++ b/gfx/common/win32_common.c @@ -1666,31 +1666,45 @@ bool win32_get_metrics(void *data, enum display_metric_types type, float *value) { #if !defined(_XBOX) - HDC monitor = GetDC(NULL); - int pixels_x = GetDeviceCaps(monitor, HORZRES); - int pixels_y = GetDeviceCaps(monitor, VERTRES); - int physical_width = GetDeviceCaps(monitor, HORZSIZE); - int physical_height = GetDeviceCaps(monitor, VERTSIZE); - - ReleaseDC(NULL, monitor); - switch (type) { case DISPLAY_METRIC_PIXEL_WIDTH: - *value = pixels_x; + { + HDC monitor = GetDC(NULL); + *value = GetDeviceCaps(monitor, HORZRES); + ReleaseDC(NULL, monitor); + } return true; case DISPLAY_METRIC_PIXEL_HEIGHT: - *value = pixels_y; + { + HDC monitor = GetDC(NULL); + *value = GetDeviceCaps(monitor, VERTRES); + ReleaseDC(NULL, monitor); + } return true; case DISPLAY_METRIC_MM_WIDTH: - *value = physical_width; + { + HDC monitor = GetDC(NULL); + *value = GetDeviceCaps(monitor, HORZSIZE); + ReleaseDC(NULL, monitor); + } return true; case DISPLAY_METRIC_MM_HEIGHT: - *value = physical_height; + { + HDC monitor = GetDC(NULL); + *value = GetDeviceCaps(monitor, VERTSIZE); + ReleaseDC(NULL, monitor); + } return true; case DISPLAY_METRIC_DPI: /* 25.4 mm in an inch. */ - *value = 254 * pixels_x / physical_width / 10; + { + HDC monitor = GetDC(NULL); + int pixels_x = GetDeviceCaps(monitor, HORZRES); + int physical_width = GetDeviceCaps(monitor, HORZSIZE); + *value = 254 * pixels_x / physical_width / 10; + ReleaseDC(NULL, monitor); + } return true; case DISPLAY_METRIC_NONE: default: diff --git a/uwp/uwp_main.cpp b/uwp/uwp_main.cpp index 0f717a25fc..f8e13f511d 100644 --- a/uwp/uwp_main.cpp +++ b/uwp/uwp_main.cpp @@ -639,36 +639,39 @@ extern "C" { bool win32_get_metrics(void* data, enum display_metric_types type, float* value) { - int pixels_x = DisplayInformation::GetForCurrentView()->ScreenWidthInRawPixels; - int pixels_y = DisplayInformation::GetForCurrentView()->ScreenHeightInRawPixels; - int raw_dpi_x = DisplayInformation::GetForCurrentView()->RawDpiX; - int raw_dpi_y = DisplayInformation::GetForCurrentView()->RawDpiY; - int physical_width = pixels_x / raw_dpi_x; - int physical_height = pixels_y / raw_dpi_y; - switch (type) { - case DISPLAY_METRIC_PIXEL_WIDTH: - *value = pixels_x; - return true; + case DISPLAY_METRIC_PIXEL_WIDTH: + *value = DisplayInformation::GetForCurrentView()->ScreenWidthInRawPixels; + return true; case DISPLAY_METRIC_PIXEL_HEIGHT: - *value = pixels_y; - return true; + *value = DisplayInformation::GetForCurrentView()->ScreenHeightInRawPixels; + return true; case DISPLAY_METRIC_MM_WIDTH: - /* 25.4 mm in an inch. */ - *value = 254 * physical_width / 10; - return true; + /* 25.4 mm in an inch. */ + { + int pixels_x = DisplayInformation::GetForCurrentView()->ScreenWidthInRawPixels; + int raw_dpi_x = DisplayInformation::GetForCurrentView()->RawDpiX; + int physical_width = pixels_x / raw_dpi_x; + *value = 254 * physical_width / 10; + } + return true; case DISPLAY_METRIC_MM_HEIGHT: - /* 25.4 mm in an inch. */ - *value = 254 * physical_height / 10; - return true; + /* 25.4 mm in an inch. */ + { + int pixels_y = DisplayInformation::GetForCurrentView()->ScreenHeightInRawPixels; + int raw_dpi_y = DisplayInformation::GetForCurrentView()->RawDpiY; + int physical_height = pixels_y / raw_dpi_y; + *value = 254 * physical_height / 10; + } + return true; case DISPLAY_METRIC_DPI: - *value = raw_dpi_x; - return true; + *value = DisplayInformation::GetForCurrentView()->RawDpiX; + return true; case DISPLAY_METRIC_NONE: default: - *value = 0; - break; + *value = 0; + break; } return false; }