From eb50d7dbb43cf4e5f7c92ecd7be951e22ff1e9e8 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 20 Aug 2021 23:16:01 +0200 Subject: [PATCH] (UWP) Push temporary fixes for issue that happens when resizing on UWP with latest Xbox Series dashboard; DXGIResizeBuffers passing 0, 0 as width/height is apparently problematic as it changes 0, 0 to 8,8 instead, breaking the program --- config.def.h | 3 - configuration.c | 3 - configuration.h | 1 - gfx/common/win32_common.h | 2 + menu/menu_setting.c | 17 ----- retroarch.c | 156 +++++++++++++++++++------------------- uwp/uwp_main.cpp | 19 +++-- 7 files changed, 93 insertions(+), 108 deletions(-) diff --git a/config.def.h b/config.def.h index 506c88ecc1..3fb02ace30 100644 --- a/config.def.h +++ b/config.def.h @@ -280,9 +280,6 @@ #define DEFAULT_FULLSCREEN_Y 0 #endif -/* Force 4k resolution */ -#define DEFAULT_FORCE_RESOLUTION false - /* Number of threads to use for video recording */ #define DEFAULT_VIDEO_RECORD_THREADS 2 diff --git a/configuration.c b/configuration.c index ac2276083d..1ef50d7368 100644 --- a/configuration.c +++ b/configuration.c @@ -1572,9 +1572,6 @@ static struct config_bool_setting *populate_settings_bool( SETTING_BOOL("auto_screenshot_filename", &settings->bools.auto_screenshot_filename, true, DEFAULT_AUTO_SCREENSHOT_FILENAME, false); SETTING_BOOL("video_force_srgb_disable", &settings->bools.video_force_srgb_disable, true, false, false); SETTING_BOOL("video_fullscreen", &settings->bools.video_fullscreen, true, DEFAULT_FULLSCREEN, false); -#ifdef __WINRT__ - SETTING_BOOL("video_force_resolution", &settings->bools.video_force_resolution, true, DEFAULT_FORCE_RESOLUTION, false); -#endif SETTING_BOOL("bundle_assets_extract_enable", &settings->bools.bundle_assets_extract_enable, true, DEFAULT_BUNDLE_ASSETS_EXTRACT_ENABLE, false); SETTING_BOOL("video_vsync", &settings->bools.video_vsync, true, DEFAULT_VSYNC, false); SETTING_BOOL("video_adaptive_vsync", &settings->bools.video_adaptive_vsync, true, DEFAULT_ADAPTIVE_VSYNC, false); diff --git a/configuration.h b/configuration.h index 1de7b5bd17..cfac5c81ac 100644 --- a/configuration.h +++ b/configuration.h @@ -524,7 +524,6 @@ typedef struct settings #ifdef HAVE_VIDEO_LAYOUT bool video_layout_enable; #endif - bool video_force_resolution; /* Accessibility */ bool accessibility_enable; diff --git a/gfx/common/win32_common.h b/gfx/common/win32_common.h index 006471e00c..4012b39046 100644 --- a/gfx/common/win32_common.h +++ b/gfx/common/win32_common.h @@ -97,6 +97,8 @@ void win32_show_cursor(void *data, bool state); HWND win32_get_window(void); +bool is_running_on_xbox(void); + bool win32_has_focus(void *data); void win32_clip_window(bool grab); diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 4e3d69bb9c..06489a78b9 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -11017,23 +11017,6 @@ static bool setting_append_list( general_read_handler); (*list)[list_info->index - 1].action_ok = &setting_action_ok_uint_special; menu_settings_list_current_add_range(list, list_info, 0, 4320, 8, true, true); - - CONFIG_BOOL( - list, list_info, - &settings->bools.video_force_resolution, - MENU_ENUM_LABEL_VIDEO_FORCE_RESOLUTION, - MENU_ENUM_LABEL_VALUE_VIDEO_FORCE_RESOLUTION, - DEFAULT_FORCE_RESOLUTION, - MENU_ENUM_LABEL_VALUE_OFF, - MENU_ENUM_LABEL_VALUE_ON, - &group_info, - &subgroup_info, - parent_group, - general_write_handler, - general_read_handler, - SD_FLAG_CMD_APPLY_AUTO); - MENU_SETTINGS_LIST_CURRENT_ADD_CMD(list, list_info, CMD_EVENT_REINIT_FROM_TOGGLE); - SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(list, list_info, SD_FLAG_LAKKA_ADVANCED); } #if defined(DINGUX) && defined(DINGUX_BETA) diff --git a/retroarch.c b/retroarch.c index d7a62adb97..98dd4056c8 100644 --- a/retroarch.c +++ b/retroarch.c @@ -30105,103 +30105,101 @@ static bool video_driver_init_internal( } else { -#if defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__) - bool window_custom_size_enable = settings->bools.video_window_save_positions; -#else - bool window_custom_size_enable = settings->bools.video_window_custom_size_enable; -#endif - - /* TODO: remove when the new window resizing core is hooked */ - if (window_custom_size_enable && - settings->uints.window_position_width && - settings->uints.window_position_height) +#ifdef __WINRT__ + if (is_running_on_xbox()) { - width = settings->uints.window_position_width; - height = settings->uints.window_position_height; + width = settings->uints.video_fullscreen_x != 0 ? settings->uints.video_fullscreen_x : 3840; + height = settings->uints.video_fullscreen_y != 0 ? settings->uints.video_fullscreen_y : 2160; } else +#endif { - float video_scale = settings->floats.video_scale; - unsigned max_win_width; - unsigned max_win_height; - - /* Determine maximum allowed window dimensions - * NOTE: We cannot read the actual display - * metrics here, because the context driver - * has not yet been initialised... */ - - /* > Try explicitly configured values */ - max_win_width = settings->uints.window_auto_width_max; - max_win_height = settings->uints.window_auto_height_max; - - /* > Handle invalid settings */ - if ((max_win_width == 0) || (max_win_height == 0)) +#if defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__) + bool window_custom_size_enable = settings->bools.video_window_save_positions; +#else + bool window_custom_size_enable = settings->bools.video_window_custom_size_enable; +#endif + /* TODO: remove when the new window resizing core is hooked */ + if (window_custom_size_enable && + settings->uints.window_position_width && + settings->uints.window_position_height) { - /* > Try configured fullscreen width/height */ - max_win_width = settings->uints.video_fullscreen_x; - max_win_height = settings->uints.video_fullscreen_y; - - if ((max_win_width == 0) || (max_win_height == 0)) - { - /* Maximum window width/size *must* be non-zero; - * if all else fails, used defined default - * maximum window size */ - max_win_width = DEFAULT_WINDOW_AUTO_WIDTH_MAX; - max_win_height = DEFAULT_WINDOW_AUTO_HEIGHT_MAX; - } - } - - /* Determine nominal window size based on - * core geometry */ - if (settings->bools.video_force_aspect) - { - /* Do rounding here to simplify integer - * scale correctness. */ - unsigned base_width = roundf(geom->base_height * - p_rarch->video_driver_aspect_ratio); - width = roundf(base_width * video_scale); + width = settings->uints.window_position_width; + height = settings->uints.window_position_height; } else - width = roundf(geom->base_width * video_scale); - - height = roundf(geom->base_height * video_scale); - - /* Cap window size to maximum allowed values */ - if ((width > max_win_width) || (height > max_win_height)) { - unsigned geom_width = (width > 0) ? width : 1; - unsigned geom_height = (height > 0) ? height : 1; - float geom_aspect = (float)geom_width / (float)geom_height; - float max_win_aspect = (float)max_win_width / (float)max_win_height; + float video_scale = settings->floats.video_scale; + /* Determine maximum allowed window dimensions + * NOTE: We cannot read the actual display + * metrics here, because the context driver + * has not yet been initialised... */ - if (geom_aspect > max_win_aspect) + /* > Try explicitly configured values */ + unsigned max_win_width = settings->uints.window_auto_width_max; + unsigned max_win_height = settings->uints.window_auto_height_max; + + /* > Handle invalid settings */ + if ((max_win_width == 0) || (max_win_height == 0)) { - width = max_win_width; - height = geom_height * max_win_width / geom_width; - /* Account for any possible rounding errors... */ - height = (height < 1) ? 1 : height; - height = (height > max_win_height) ? max_win_height : height; + /* > Try configured fullscreen width/height */ + max_win_width = settings->uints.video_fullscreen_x; + max_win_height = settings->uints.video_fullscreen_y; + + if ((max_win_width == 0) || (max_win_height == 0)) + { + /* Maximum window width/size *must* be non-zero; + * if all else fails, used defined default + * maximum window size */ + max_win_width = DEFAULT_WINDOW_AUTO_WIDTH_MAX; + max_win_height = DEFAULT_WINDOW_AUTO_HEIGHT_MAX; + } + } + + /* Determine nominal window size based on + * core geometry */ + if (settings->bools.video_force_aspect) + { + /* Do rounding here to simplify integer + * scale correctness. */ + unsigned base_width = roundf(geom->base_height * + p_rarch->video_driver_aspect_ratio); + width = roundf(base_width * video_scale); } else + width = roundf(geom->base_width * video_scale); + + height = roundf(geom->base_height * video_scale); + + /* Cap window size to maximum allowed values */ + if ((width > max_win_width) || (height > max_win_height)) { - height = max_win_height; - width = geom_width * max_win_height / geom_height; - /* Account for any possible rounding errors... */ - width = (width < 1) ? 1 : width; - width = (width > max_win_width) ? max_win_width : width; + unsigned geom_width = (width > 0) ? width : 1; + unsigned geom_height = (height > 0) ? height : 1; + float geom_aspect = (float)geom_width / (float)geom_height; + float max_win_aspect = (float)max_win_width / (float)max_win_height; + + if (geom_aspect > max_win_aspect) + { + width = max_win_width; + height = geom_height * max_win_width / geom_width; + /* Account for any possible rounding errors... */ + height = (height < 1) ? 1 : height; + height = (height > max_win_height) ? max_win_height : height; + } + else + { + height = max_win_height; + width = geom_width * max_win_height / geom_height; + /* Account for any possible rounding errors... */ + width = (width < 1) ? 1 : width; + width = (width > max_win_width) ? max_win_width : width; + } } } } } -#ifdef __WINRT__ - if (settings->bools.video_force_resolution) - { - width = settings->uints.video_fullscreen_x != 0 ? settings->uints.video_fullscreen_x : 3840; - height = settings->uints.video_fullscreen_y != 0 ? settings->uints.video_fullscreen_y : 2160; - } -#endif - if (width && height) RARCH_LOG("[Video]: Video @ %ux%u\n", width, height); else diff --git a/uwp/uwp_main.cpp b/uwp/uwp_main.cpp index d1e5a49a9c..0f717a25fc 100644 --- a/uwp/uwp_main.cpp +++ b/uwp/uwp_main.cpp @@ -558,6 +558,8 @@ void App::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) /* DisplayInformation event handlers. */ + + void App::OnDpiChanged(DisplayInformation^ sender, Object^ args) { m_windowResized = true; @@ -587,6 +589,12 @@ void App::OnPackageInstalling(PackageCatalog^ sender, PackageInstallingEventArgs /* Implement UWP equivalents of various win32_* functions */ extern "C" { + bool is_running_on_xbox(void) + { + Platform::String^ device_family = Windows::System::Profile::AnalyticsInfo::VersionInfo->DeviceFamily; + return (device_family == L"Windows.Xbox"); + } + bool win32_has_focus(void *data) { return App::GetInstance()->IsWindowFocused(); @@ -668,12 +676,13 @@ extern "C" { void win32_check_window(void *data, bool *quit, bool *resize, unsigned *width, unsigned *height) { - *quit = App::GetInstance()->IsWindowClosed(); - settings_t* settings = config_get_ptr(); - if (settings->bools.video_force_resolution) + static bool is_xbox = is_running_on_xbox(); + *quit = App::GetInstance()->IsWindowClosed(); + if (is_xbox) { - *width = settings->uints.video_fullscreen_x != 0 ? settings->uints.video_fullscreen_x : 3840; - *height = settings->uints.video_fullscreen_y != 0 ? settings->uints.video_fullscreen_y : 2160; + settings_t* settings = config_get_ptr(); + *width = settings->uints.video_fullscreen_x != 0 ? settings->uints.video_fullscreen_x : 3840; + *height = settings->uints.video_fullscreen_y != 0 ? settings->uints.video_fullscreen_y : 2160; return; }