From c2b3ba907c2b0263c9d9cdf1216c8ead0a7e950c Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Mon, 16 Aug 2021 10:41:19 +0100 Subject: [PATCH 1/4] Revert "video_driver_init_internal - refactor" This reverts commit bba924e8d28a3bf2738a91da942b75a54d664e05. --- retroarch.c | 225 ++++++++++++++++++++++++---------------------------- 1 file changed, 103 insertions(+), 122 deletions(-) diff --git a/retroarch.c b/retroarch.c index f568e3ce8f..4299257a00 100644 --- a/retroarch.c +++ b/retroarch.c @@ -30046,102 +30046,6 @@ static void video_driver_set_viewport_square_pixel(struct retro_game_geometry *g aspectratio_lut[ASPECT_RATIO_SQUARE].value = (float)aspect_x / aspect_y; } -static void video_driver_init_internal_set_aspect( - struct retro_game_geometry *geom, - settings_t *settings -) -{ - unsigned new_aspect_idx = settings->uints.video_aspect_ratio_idx; - - /* Update core-dependent aspect ratio values. */ - video_driver_set_viewport_square_pixel(geom); - video_driver_set_viewport_core(); - video_driver_set_viewport_config(geom, - settings->floats.video_aspect_ratio, - settings->bools.video_aspect_ratio_auto); - - /* Update CUSTOM viewport. */ - - if (settings->uints.video_aspect_ratio_idx == ASPECT_RATIO_CUSTOM) - { - video_viewport_t *custom_vp = &settings->video_viewport_custom; - float default_aspect = aspectratio_lut[ASPECT_RATIO_CORE].value; - aspectratio_lut[ASPECT_RATIO_CUSTOM].value = - (custom_vp->width && custom_vp->height) ? - (float)custom_vp->width / custom_vp->height : default_aspect; - } - - /* Guard against aspect ratio index possibly being out of bounds */ - if (new_aspect_idx > ASPECT_RATIO_END) - new_aspect_idx = settings->uints.video_aspect_ratio_idx = 0; - - video_driver_set_aspect_ratio_value( - aspectratio_lut[new_aspect_idx].value); -} - -static unsigned video_driver_init_internal_set_scaling( - struct rarch_state *p_rarch, - struct retro_game_geometry *core_geom, - struct retro_game_geometry *geom -) -{ - unsigned max_dim, scale; -#ifdef HAVE_VIDEO_FILTER - if (p_rarch->video_driver_state_filter) - return p_rarch->video_driver_state_scale; -#endif - max_dim = MAX(geom->max_width, geom->max_height); - scale = next_pow2(max_dim) / RARCH_SCALE_BASE; - return MAX(scale, 1); -} - -static void video_driver_init_internal_apply_scaling( - struct rarch_state *p_rarch, - settings_t *settings, - struct retro_game_geometry *geom, - unsigned *width, - unsigned *height) -{ - if (settings->bools.video_fullscreen || p_rarch->rarch_force_fullscreen) - { - *width = settings->uints.video_fullscreen_x; - *height = settings->uints.video_fullscreen_y; - } - else - { - /* TODO: remove when the new window resizing core is hooked */ - if (settings->bools.video_window_save_positions && - (settings->uints.window_position_width || - settings->uints.window_position_height)) - { - *width = settings->uints.window_position_width; - *height = settings->uints.window_position_height; - } - else - { - float video_scale = settings->floats.video_scale; - 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); - } - } - -#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 -} - static bool video_driver_init_internal( struct rarch_state *p_rarch, settings_t *settings, @@ -30151,32 +30055,113 @@ static bool video_driver_init_internal( { video_info_t video; struct retro_game_geometry geom; - unsigned scale, width, height; + unsigned max_dim, scale, width, height; video_viewport_t *custom_vp = NULL; input_driver_t *tmp = NULL; static uint16_t dummy_pixels[32] = {0}; struct retro_game_geometry *core_geom = &p_rarch->video_driver_av_info.geometry; const enum retro_pixel_format - video_driver_pix_fmt = - p_rarch->video_driver_pix_fmt; + video_driver_pix_fmt = p_rarch->video_driver_pix_fmt; #ifdef HAVE_VIDEO_FILTER - const char *path_softfilter_plugin = - settings->paths.path_softfilter_plugin; + const char *path_softfilter_plugin = settings->paths.path_softfilter_plugin; + if (!string_is_empty(path_softfilter_plugin)) video_driver_init_filter(video_driver_pix_fmt, settings); #endif - geom.base_width = core_geom->base_width; - geom.base_height = core_geom->base_height; - geom.max_width = core_geom->max_width; - geom.max_height = core_geom->max_height; - geom.aspect_ratio = core_geom->aspect_ratio; - scale = video_driver_init_internal_set_scaling(p_rarch, - &geom, core_geom); - video_driver_init_internal_set_aspect(&geom, settings); - video_driver_init_internal_apply_scaling(p_rarch, settings, &geom, - &width, &height); - RARCH_LOG("[Video]: Video @ %ux%u using AV information (w=%d,h=%d,maxw=%d,maxh=%d,AR=%.2f)\n", width, height, geom.base_width, geom.base_height, geom.max_width, geom.max_height, geom.aspect_ratio); + geom.base_width = core_geom->base_width; + geom.base_height = core_geom->base_height; + geom.max_width = core_geom->max_width; + geom.max_height = core_geom->max_height; + geom.aspect_ratio = core_geom->aspect_ratio; + + RARCH_LOG("[Video]: AV geometry base width: %d, base_height: %d\n", geom.base_width, geom.base_height); + RARCH_LOG("[Video]: AV geometry max_width: %d, max_height: %d, aspect: %.2f\n", geom.max_width, geom.max_height, geom.aspect_ratio); + max_dim = MAX(geom.max_width, geom.max_height); + scale = next_pow2(max_dim) / RARCH_SCALE_BASE; + scale = MAX(scale, 1); + +#ifdef HAVE_VIDEO_FILTER + if (p_rarch->video_driver_state_filter) + scale = p_rarch->video_driver_state_scale; +#endif + + RARCH_LOG("[Video]: Video max dimensions: %d, windowed scale: %d\n", + max_dim, scale); + + /* Update core-dependent aspect ratio values. */ + video_driver_set_viewport_square_pixel(&geom); + video_driver_set_viewport_core(); + video_driver_set_viewport_config(&geom, + settings->floats.video_aspect_ratio, + settings->bools.video_aspect_ratio_auto); + + /* Update CUSTOM viewport. */ + custom_vp = &settings->video_viewport_custom; + + if (settings->uints.video_aspect_ratio_idx == ASPECT_RATIO_CUSTOM) + { + float default_aspect = aspectratio_lut[ASPECT_RATIO_CORE].value; + aspectratio_lut[ASPECT_RATIO_CUSTOM].value = + (custom_vp->width && custom_vp->height) ? + (float)custom_vp->width / custom_vp->height : default_aspect; + } + + { + /* Guard against aspect ratio index possibly being out of bounds */ + unsigned new_aspect_idx = settings->uints.video_aspect_ratio_idx; + if (new_aspect_idx > ASPECT_RATIO_END) + new_aspect_idx = settings->uints.video_aspect_ratio_idx = 0; + + video_driver_set_aspect_ratio_value( + aspectratio_lut[new_aspect_idx].value); + } + + if (settings->bools.video_fullscreen || p_rarch->rarch_force_fullscreen) + { + width = settings->uints.video_fullscreen_x; + height = settings->uints.video_fullscreen_y; + RARCH_LOG("[Video]: Set width and height to fullscreen values [%dx%d]\n", width, height); + } + else + { + /* TODO: remove when the new window resizing core is hooked */ + if (settings->bools.video_window_save_positions && + (settings->uints.window_position_width || + settings->uints.window_position_height)) + { + width = settings->uints.window_position_width; + height = settings->uints.window_position_height; + RARCH_LOG("[Video]: Set width and height based on window position width [%dx%d]\n", width, height); + } + else + { + float video_scale = settings->floats.video_scale; + 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); + RARCH_LOG("[Video]: Force video aspect\n"); + } + else + width = roundf(geom.base_width * video_scale); + height = roundf(geom.base_height * video_scale); + RARCH_LOG("[Video]: Set width and height based on window position width [%dx%d]\n", width, height); + } + } + +#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; + RARCH_LOG("[Video]: Force resolution [%dx%d]\n", width, height); + } +#endif + + RARCH_LOG("[Video]: Video @ %ux%u\n", width, height); p_rarch->video_driver_display_type = RARCH_DISPLAY_NONE; p_rarch->video_driver_display = 0; @@ -30268,19 +30253,15 @@ static bool video_driver_init_internal( p_rarch->current_video->poke_interface( p_rarch->video_driver_data, &p_rarch->video_driver_poke); - { - struct video_viewport *custom_vp = &settings->video_viewport_custom; - - if (p_rarch->current_video->viewport_info && + if (p_rarch->current_video->viewport_info && (!custom_vp->width || !custom_vp->height)) - { - /* Force custom viewport to have sane parameters. */ - custom_vp->width = width; - custom_vp->height = height; + { + /* Force custom viewport to have sane parameters. */ + custom_vp->width = width; + custom_vp->height = height; - video_driver_get_viewport_info(custom_vp); - } + video_driver_get_viewport_info(custom_vp); } video_driver_set_rotation(retroarch_get_rotation() % 4); From 6e7e8a76805267efd44230a5780d229348659b1c Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Mon, 16 Aug 2021 10:41:44 +0100 Subject: [PATCH 2/4] Revert "video_driver_init_internal - add more logs" This reverts commit d0a08ce959eb944d71ef6d169e40b9dd0a5bd61c. --- retroarch.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/retroarch.c b/retroarch.c index 4299257a00..cee3f72db7 100644 --- a/retroarch.c +++ b/retroarch.c @@ -30054,12 +30054,11 @@ static bool video_driver_init_internal( ) { video_info_t video; - struct retro_game_geometry geom; unsigned max_dim, scale, width, height; video_viewport_t *custom_vp = NULL; input_driver_t *tmp = NULL; static uint16_t dummy_pixels[32] = {0}; - struct retro_game_geometry *core_geom = &p_rarch->video_driver_av_info.geometry; + struct retro_game_geometry *geom = &p_rarch->video_driver_av_info.geometry; const enum retro_pixel_format video_driver_pix_fmt = p_rarch->video_driver_pix_fmt; #ifdef HAVE_VIDEO_FILTER @@ -30069,15 +30068,7 @@ static bool video_driver_init_internal( video_driver_init_filter(video_driver_pix_fmt, settings); #endif - geom.base_width = core_geom->base_width; - geom.base_height = core_geom->base_height; - geom.max_width = core_geom->max_width; - geom.max_height = core_geom->max_height; - geom.aspect_ratio = core_geom->aspect_ratio; - - RARCH_LOG("[Video]: AV geometry base width: %d, base_height: %d\n", geom.base_width, geom.base_height); - RARCH_LOG("[Video]: AV geometry max_width: %d, max_height: %d, aspect: %.2f\n", geom.max_width, geom.max_height, geom.aspect_ratio); - max_dim = MAX(geom.max_width, geom.max_height); + max_dim = MAX(geom->max_width, geom->max_height); scale = next_pow2(max_dim) / RARCH_SCALE_BASE; scale = MAX(scale, 1); @@ -30090,9 +30081,9 @@ static bool video_driver_init_internal( max_dim, scale); /* Update core-dependent aspect ratio values. */ - video_driver_set_viewport_square_pixel(&geom); + video_driver_set_viewport_square_pixel(geom); video_driver_set_viewport_core(); - video_driver_set_viewport_config(&geom, + video_driver_set_viewport_config(geom, settings->floats.video_aspect_ratio, settings->bools.video_aspect_ratio_auto); @@ -30141,13 +30132,13 @@ static bool video_driver_init_internal( { /* Do rounding here to simplify integer scale correctness. */ unsigned base_width = - roundf(geom.base_height * p_rarch->video_driver_aspect_ratio); + roundf(geom->base_height * p_rarch->video_driver_aspect_ratio); width = roundf(base_width * video_scale); RARCH_LOG("[Video]: Force video aspect\n"); } else - width = roundf(geom.base_width * video_scale); - height = roundf(geom.base_height * video_scale); + width = roundf(geom->base_width * video_scale); + height = roundf(geom->base_height * video_scale); RARCH_LOG("[Video]: Set width and height based on window position width [%dx%d]\n", width, height); } } From 0f142d531a548ad4710f8d030e2c4ee0ea8f16c3 Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Mon, 16 Aug 2021 10:42:16 +0100 Subject: [PATCH 3/4] Revert "Add extra video logs so we can see what goes on" This reverts commit 6780f5844428fc4e27c0619300229891ad2af219. --- retroarch.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/retroarch.c b/retroarch.c index cee3f72db7..d31658379f 100644 --- a/retroarch.c +++ b/retroarch.c @@ -30077,9 +30077,6 @@ static bool video_driver_init_internal( scale = p_rarch->video_driver_state_scale; #endif - RARCH_LOG("[Video]: Video max dimensions: %d, windowed scale: %d\n", - max_dim, scale); - /* Update core-dependent aspect ratio values. */ video_driver_set_viewport_square_pixel(geom); video_driver_set_viewport_core(); @@ -30108,11 +30105,10 @@ static bool video_driver_init_internal( aspectratio_lut[new_aspect_idx].value); } - if (settings->bools.video_fullscreen || p_rarch->rarch_force_fullscreen) + if (settings->bools.video_fullscreen|| p_rarch->rarch_force_fullscreen) { width = settings->uints.video_fullscreen_x; height = settings->uints.video_fullscreen_y; - RARCH_LOG("[Video]: Set width and height to fullscreen values [%dx%d]\n", width, height); } else { @@ -30123,7 +30119,6 @@ static bool video_driver_init_internal( { width = settings->uints.window_position_width; height = settings->uints.window_position_height; - RARCH_LOG("[Video]: Set width and height based on window position width [%dx%d]\n", width, height); } else { @@ -30134,12 +30129,10 @@ static bool video_driver_init_internal( unsigned base_width = roundf(geom->base_height * p_rarch->video_driver_aspect_ratio); width = roundf(base_width * video_scale); - RARCH_LOG("[Video]: Force video aspect\n"); } else width = roundf(geom->base_width * video_scale); height = roundf(geom->base_height * video_scale); - RARCH_LOG("[Video]: Set width and height based on window position width [%dx%d]\n", width, height); } } @@ -30148,11 +30141,13 @@ static bool video_driver_init_internal( { 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; - RARCH_LOG("[Video]: Force resolution [%dx%d]\n", width, height); } #endif - RARCH_LOG("[Video]: Video @ %ux%u\n", width, height); + if (width && height) + RARCH_LOG("[Video]: Video @ %ux%u\n", width, height); + else + RARCH_LOG("[Video]: Video @ fullscreen\n"); p_rarch->video_driver_display_type = RARCH_DISPLAY_NONE; p_rarch->video_driver_display = 0; From fa7dd0f6d942e63865657e2378184ef828164c72 Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Mon, 16 Aug 2021 17:48:09 +0100 Subject: [PATCH 4/4] Add facility to cap maximum window size in windowed mode --- config.def.h | 61 ++++++++++++++++---------- configuration.c | 7 ++- configuration.h | 3 ++ intl/msg_hash_lbl.h | 12 +++++ intl/msg_hash_us.h | 28 +++++++++++- menu/cbs/menu_cbs_sublabel.c | 12 +++++ menu/menu_displaylist.c | 79 +++++++++++++++++++++++---------- menu/menu_setting.c | 61 +++++++++++++++++++++++++- msg_hash.h | 3 ++ retroarch.c | 85 +++++++++++++++++++++++++++++++----- 10 files changed, 289 insertions(+), 62 deletions(-) diff --git a/config.def.h b/config.def.h index 06b969aac9..f28167729a 100644 --- a/config.def.h +++ b/config.def.h @@ -222,16 +222,51 @@ #define DEFAULT_MONITOR_INDEX 0 /* Window */ -/* Window size. A value of 0 uses window scale - * multiplied by the core framebuffer size. */ + +/* DEFAULT_WINDOW_DECORATIONS: + Whether to show the usual window decorations like border, titlebar etc. */ +#ifdef WEBOS +#define DEFAULT_WINDOW_DECORATIONS false +#else +#define DEFAULT_WINDOW_DECORATIONS true +#endif + +/* Amount of transparency to use for the main window. + * 1 is the most transparent while 100 is opaque. */ +#define DEFAULT_WINDOW_OPACITY 100 + +/* DEFAULT_WINDOW_SAVE_POSITIONS: + * Whether to remember window positions + * NOTE: Only enabled for desktop Windows + * at present. */ +#define DEFAULT_WINDOW_SAVE_POSITIONS false + +/* Whether to use custom (fixed size) + * window dimensions in windowed mode. */ +#ifdef WEBOS +#define DEFAULT_WINDOW_CUSTOM_SIZE_ENABLE true +#else +#define DEFAULT_WINDOW_CUSTOM_SIZE_ENABLE false +#endif + +/* Window dimensions when using a fixed size + * window. A value of 0 disables fixed size + * windows, using nominal dimensions of + * window scale multiplied by the core + * framebuffer size. */ #if defined(WEBOS) -#define DEFAULT_WINDOW_WIDTH 1920 +#define DEFAULT_WINDOW_WIDTH 1920 #define DEFAULT_WINDOW_HEIGHT 1080 #else -#define DEFAULT_WINDOW_WIDTH 1280 +#define DEFAULT_WINDOW_WIDTH 1280 #define DEFAULT_WINDOW_HEIGHT 720 #endif +/* Maximum auto-set window dimensions + * when not using a fixed size window */ +#define DEFAULT_WINDOW_AUTO_WIDTH_MAX 1920 +#define DEFAULT_WINDOW_AUTO_HEIGHT_MAX 1080 + /* Fullscreen resolution. A value of 0 uses the desktop * resolution. */ #if defined(DINGUX) @@ -251,24 +286,6 @@ /* Number of threads to use for video recording */ #define DEFAULT_VIDEO_RECORD_THREADS 2 -/* Amount of transparency to use for the main window. - * 1 is the most transparent while 100 is opaque. - */ -#define DEFAULT_WINDOW_OPACITY 100 - -/* DEFAULT_WINDOW_DECORATIONS: - Whether to show the usual window decorations like border, titlebar etc. */ -/* DEFAULT_WINDOW_SAVE_POSITIONS: - Whether to remember window positions - */ -#ifdef WEBOS -#define DEFAULT_WINDOW_DECORATIONS false -#define DEFAULT_WINDOW_SAVE_POSITIONS true -#else -#define DEFAULT_WINDOW_DECORATIONS true -#define DEFAULT_WINDOW_SAVE_POSITIONS false -#endif - #if defined(RARCH_CONSOLE) || defined(__APPLE__) #define DEFAULT_LOAD_DUMMY_ON_CORE_SHUTDOWN false #else diff --git a/configuration.c b/configuration.c index 43ecf76636..a055a92413 100644 --- a/configuration.c +++ b/configuration.c @@ -1851,6 +1851,7 @@ static struct config_bool_setting *populate_settings_bool( SETTING_BOOL("video_msg_bgcolor_enable", &settings->bools.video_msg_bgcolor_enable, true, message_bgcolor_enable, false); SETTING_BOOL("video_window_show_decorations", &settings->bools.video_window_show_decorations, true, DEFAULT_WINDOW_DECORATIONS, false); SETTING_BOOL("video_window_save_positions", &settings->bools.video_window_save_positions, true, DEFAULT_WINDOW_SAVE_POSITIONS, false); + SETTING_BOOL("video_window_custom_size_enable", &settings->bools.video_window_custom_size_enable, true, DEFAULT_WINDOW_CUSTOM_SIZE_ENABLE, false); SETTING_BOOL("sustained_performance_mode", &settings->bools.sustained_performance_mode, true, sustained_performance_mode, false); @@ -2135,8 +2136,10 @@ static struct config_uint_setting *populate_settings_uint( SETTING_UINT("video_stream_scale_factor", &settings->uints.video_stream_scale_factor, true, 1, false); SETTING_UINT("video_windowed_position_x", &settings->uints.window_position_x, true, 0, false); SETTING_UINT("video_windowed_position_y", &settings->uints.window_position_y, true, 0, false); - SETTING_UINT("video_windowed_position_width", &settings->uints.window_position_width, true, DEFAULT_WINDOW_WIDTH, false); - SETTING_UINT("video_windowed_position_height", &settings->uints.window_position_height, true, DEFAULT_WINDOW_HEIGHT, false); + SETTING_UINT("video_windowed_position_width", &settings->uints.window_position_width, true, DEFAULT_WINDOW_WIDTH, false); + SETTING_UINT("video_windowed_position_height", &settings->uints.window_position_height, true, DEFAULT_WINDOW_HEIGHT, false); + SETTING_UINT("video_window_auto_width_max", &settings->uints.window_auto_width_max, true, DEFAULT_WINDOW_AUTO_WIDTH_MAX, false); + SETTING_UINT("video_window_auto_height_max", &settings->uints.window_auto_height_max, true, DEFAULT_WINDOW_AUTO_HEIGHT_MAX, false); SETTING_UINT("ai_service_mode", &settings->uints.ai_service_mode, true, DEFAULT_AI_SERVICE_MODE, false); SETTING_UINT("ai_service_target_lang", &settings->uints.ai_service_target_lang, true, 0, false); SETTING_UINT("ai_service_source_lang", &settings->uints.ai_service_source_lang, true, 0, false); diff --git a/configuration.h b/configuration.h index d2fd45ee6e..1de7b5bd17 100644 --- a/configuration.h +++ b/configuration.h @@ -282,6 +282,8 @@ typedef struct settings unsigned window_position_y; unsigned window_position_width; unsigned window_position_height; + unsigned window_auto_width_max; + unsigned window_auto_height_max; unsigned video_record_threads; @@ -826,6 +828,7 @@ typedef struct settings bool video_window_show_decorations; bool video_window_save_positions; + bool video_window_custom_size_enable; bool sustained_performance_mode; bool playlist_use_old_format; diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index ccebb03cb3..66df80f03d 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -3528,6 +3528,14 @@ MSG_HASH( MENU_ENUM_LABEL_VIDEO_WINDOW_HEIGHT, "video_window_height" ) +MSG_HASH( + MENU_ENUM_LABEL_VIDEO_WINDOW_AUTO_WIDTH_MAX, + "video_window_auto_width_max" + ) +MSG_HASH( + MENU_ENUM_LABEL_VIDEO_WINDOW_AUTO_HEIGHT_MAX, + "video_window_auto_height_max" + ) MSG_HASH( MENU_ENUM_LABEL_VIDEO_FULLSCREEN_X, "video_fullscreen_x" @@ -4174,6 +4182,10 @@ MSG_HASH( MENU_ENUM_LABEL_VIDEO_WINDOW_SAVE_POSITION, "video_window_save_position" ) +MSG_HASH( + MENU_ENUM_LABEL_VIDEO_WINDOW_CUSTOM_SIZE_ENABLE, + "video_window_custom_size_enable" + ) MSG_HASH( MENU_ENUM_LABEL_MENU_RGUI_BORDER_FILLER_ENABLE, "menu_rgui_border_filler_enable" diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 1a4780fb43..89395451b6 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -1604,7 +1604,7 @@ MSG_HASH( ) MSG_HASH( MENU_ENUM_SUBLABEL_VIDEO_WINDOW_SCALE, - "Set the window size relative to the core viewport size. Alternatively, a window width and height can be set below for a fixed window size." + "Set the window size to the specified multiple of the core viewport size." ) MSG_HASH( MENU_ENUM_LABEL_VALUE_VIDEO_WINDOW_OPACITY, @@ -1620,7 +1620,15 @@ MSG_HASH( ) MSG_HASH( MENU_ENUM_SUBLABEL_VIDEO_WINDOW_SAVE_POSITION, - "Remember window size and position, enabling this has precedence over Windowed Scale." + "Show all content in a fixed size window of dimensions specified by 'Window Width' and 'Window Height', and save current window size and position upon closing RetroArch. When disabled, window size will be set dynamically based on 'Windowed Scale'." + ) +MSG_HASH( + MENU_ENUM_LABEL_VALUE_VIDEO_WINDOW_CUSTOM_SIZE_ENABLE, + "Use Custom Window Size" + ) +MSG_HASH( + MENU_ENUM_SUBLABEL_VIDEO_WINDOW_CUSTOM_SIZE_ENABLE, + "Show all content in a fixed size window of dimensions specified by 'Window Width' and 'Window Height'. When disabled, window size will be set dynamically based on 'Windowed Scale'." ) MSG_HASH( MENU_ENUM_LABEL_VALUE_VIDEO_WINDOW_WIDTH, @@ -1638,6 +1646,22 @@ MSG_HASH( MENU_ENUM_SUBLABEL_VIDEO_WINDOW_HEIGHT, "Set the custom height for the display window." ) +MSG_HASH( + MENU_ENUM_LABEL_VALUE_VIDEO_WINDOW_AUTO_WIDTH_MAX, + "Maximum Window Width" + ) +MSG_HASH( + MENU_ENUM_SUBLABEL_VIDEO_WINDOW_AUTO_WIDTH_MAX, + "Set the maximum width of the display window when automatically resizing based on 'Windowed Scale'." + ) +MSG_HASH( + MENU_ENUM_LABEL_VALUE_VIDEO_WINDOW_AUTO_HEIGHT_MAX, + "Maximum Window Height" + ) +MSG_HASH( + MENU_ENUM_SUBLABEL_VIDEO_WINDOW_AUTO_HEIGHT_MAX, + "Set the maximum height of the display window when automatically resizing based on 'Windowed Scale'." + ) /* Settings > Video > Scaling */ diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index 82ba188398..e3aae650db 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -435,10 +435,13 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_notification_show_screenshot_flash, DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_notification_show_refresh_rate, MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_REFRESH_RATE) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_window_width, MENU_ENUM_SUBLABEL_VIDEO_WINDOW_WIDTH) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_window_height, MENU_ENUM_SUBLABEL_VIDEO_WINDOW_HEIGHT) +DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_window_auto_width_max, MENU_ENUM_SUBLABEL_VIDEO_WINDOW_AUTO_WIDTH_MAX) +DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_window_auto_height_max, MENU_ENUM_SUBLABEL_VIDEO_WINDOW_AUTO_HEIGHT_MAX) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_fullscreen_x, MENU_ENUM_SUBLABEL_VIDEO_FULLSCREEN_X) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_fullscreen_y, MENU_ENUM_SUBLABEL_VIDEO_FULLSCREEN_Y) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_force_resolution, MENU_ENUM_SUBLABEL_VIDEO_FORCE_RESOLUTION) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_save_window_position, MENU_ENUM_SUBLABEL_VIDEO_WINDOW_SAVE_POSITION) +DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_window_custom_size_enable, MENU_ENUM_SUBLABEL_VIDEO_WINDOW_CUSTOM_SIZE_ENABLE) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_message_pos_x, MENU_ENUM_SUBLABEL_VIDEO_MESSAGE_POS_X) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_message_pos_y, MENU_ENUM_SUBLABEL_VIDEO_MESSAGE_POS_Y) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_font_size, MENU_ENUM_SUBLABEL_VIDEO_FONT_SIZE) @@ -3374,6 +3377,12 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_VIDEO_WINDOW_HEIGHT: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_video_window_height); break; + case MENU_ENUM_LABEL_VIDEO_WINDOW_AUTO_WIDTH_MAX: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_video_window_auto_width_max); + break; + case MENU_ENUM_LABEL_VIDEO_WINDOW_AUTO_HEIGHT_MAX: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_video_window_auto_height_max); + break; case MENU_ENUM_LABEL_VIDEO_FULLSCREEN_X: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_video_fullscreen_x); break; @@ -3386,6 +3395,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_VIDEO_WINDOW_SAVE_POSITION: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_video_save_window_position); break; + case MENU_ENUM_LABEL_VIDEO_WINDOW_CUSTOM_SIZE_ENABLE: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_video_window_custom_size_enable); + break; case MENU_ENUM_LABEL_QUIT_RETROARCH: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_quit_retroarch); break; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 4a2eb34c02..235e32f87a 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -7682,30 +7682,61 @@ unsigned menu_displaylist_build_list( } break; case DISPLAYLIST_VIDEO_WINDOWED_MODE_SETTINGS_LIST: - if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list, - MENU_ENUM_LABEL_VIDEO_SCALE, - PARSE_ONLY_FLOAT, false) == 0) - count++; - if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list, - MENU_ENUM_LABEL_VIDEO_WINDOW_OPACITY, - PARSE_ONLY_UINT, false) == 0) - count++; - if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list, - MENU_ENUM_LABEL_VIDEO_WINDOW_SHOW_DECORATIONS, - PARSE_ONLY_BOOL, false) == 0) - count++; - if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list, - MENU_ENUM_LABEL_VIDEO_WINDOW_SAVE_POSITION, - PARSE_ONLY_BOOL, false) == 0) - count++; - if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list, - MENU_ENUM_LABEL_VIDEO_WINDOW_WIDTH, - PARSE_ONLY_UINT, false) == 0) - count++; - if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list, - MENU_ENUM_LABEL_VIDEO_WINDOW_HEIGHT, - PARSE_ONLY_UINT, false) == 0) - count++; + { +#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 + menu_displaylist_build_info_selective_t build_list[] = { +#if defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__) + {MENU_ENUM_LABEL_VIDEO_WINDOW_SAVE_POSITION, PARSE_ONLY_BOOL, true }, +#else + {MENU_ENUM_LABEL_VIDEO_WINDOW_CUSTOM_SIZE_ENABLE, PARSE_ONLY_BOOL, true }, +#endif + {MENU_ENUM_LABEL_VIDEO_SCALE, PARSE_ONLY_FLOAT, false}, + {MENU_ENUM_LABEL_VIDEO_WINDOW_WIDTH, PARSE_ONLY_UINT, false}, + {MENU_ENUM_LABEL_VIDEO_WINDOW_HEIGHT, PARSE_ONLY_UINT, false}, + {MENU_ENUM_LABEL_VIDEO_WINDOW_AUTO_WIDTH_MAX, PARSE_ONLY_UINT, false}, + {MENU_ENUM_LABEL_VIDEO_WINDOW_AUTO_HEIGHT_MAX, PARSE_ONLY_UINT, false}, + {MENU_ENUM_LABEL_VIDEO_WINDOW_OPACITY, PARSE_ONLY_UINT, true }, + {MENU_ENUM_LABEL_VIDEO_WINDOW_SHOW_DECORATIONS, PARSE_ONLY_BOOL, true }, + }; + + for (i = 0; i < ARRAY_SIZE(build_list); i++) + { + switch (build_list[i].enum_idx) + { + case MENU_ENUM_LABEL_VIDEO_SCALE: + if (!window_custom_size_enable) + build_list[i].checked = true; + break; + case MENU_ENUM_LABEL_VIDEO_WINDOW_WIDTH: + case MENU_ENUM_LABEL_VIDEO_WINDOW_HEIGHT: + if (window_custom_size_enable) + build_list[i].checked = true; + break; + case MENU_ENUM_LABEL_VIDEO_WINDOW_AUTO_WIDTH_MAX: + case MENU_ENUM_LABEL_VIDEO_WINDOW_AUTO_HEIGHT_MAX: + if (!window_custom_size_enable) + build_list[i].checked = true; + break; + default: + break; + } + } + + for (i = 0; i < ARRAY_SIZE(build_list); i++) + { + if (!build_list[i].checked && !include_everything) + continue; + + if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list, + build_list[i].enum_idx, build_list[i].parse_type, + false) == 0) + count++; + } + } break; case DISPLAYLIST_VIDEO_FULLSCREEN_MODE_SETTINGS_LIST: if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list, diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 8b7f40ad9a..1c60afb5ca 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -11355,6 +11355,7 @@ static bool setting_append_list( (*list)[list_info->index - 1].action_ok = &setting_action_ok_uint; menu_settings_list_current_add_range(list, list_info, 1.0, 10.0, 1.0, true, true); SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(list, list_info, SD_FLAG_LAKKA_ADVANCED); + CONFIG_UINT( list, list_info, &settings->uints.window_position_width, @@ -11369,6 +11370,7 @@ static bool setting_append_list( (*list)[list_info->index - 1].action_ok = &setting_action_ok_uint_special; menu_settings_list_current_add_range(list, list_info, 0, 7680, 8, true, true); SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(list, list_info, SD_FLAG_LAKKA_ADVANCED); + CONFIG_UINT( list, list_info, &settings->uints.window_position_height, @@ -11383,6 +11385,37 @@ static bool setting_append_list( (*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); SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(list, list_info, SD_FLAG_LAKKA_ADVANCED); + + CONFIG_UINT( + list, list_info, + &settings->uints.window_auto_width_max, + MENU_ENUM_LABEL_VIDEO_WINDOW_AUTO_WIDTH_MAX, + MENU_ENUM_LABEL_VALUE_VIDEO_WINDOW_AUTO_WIDTH_MAX, + DEFAULT_WINDOW_AUTO_WIDTH_MAX, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + 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, 7680, 8, true, true); + SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(list, list_info, SD_FLAG_LAKKA_ADVANCED); + + CONFIG_UINT( + list, list_info, + &settings->uints.window_auto_height_max, + MENU_ENUM_LABEL_VIDEO_WINDOW_AUTO_HEIGHT_MAX, + MENU_ENUM_LABEL_VALUE_VIDEO_WINDOW_AUTO_HEIGHT_MAX, + DEFAULT_WINDOW_AUTO_HEIGHT_MAX, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + 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); + SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(list, list_info, SD_FLAG_LAKKA_ADVANCED); + CONFIG_UINT( list, list_info, &settings->uints.video_window_opacity, @@ -11416,12 +11449,13 @@ static bool setting_append_list( SD_FLAG_NONE); MENU_SETTINGS_LIST_CURRENT_ADD_CMD(list, list_info, CMD_EVENT_REINIT); +#if defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__) CONFIG_BOOL( list, list_info, &settings->bools.video_window_save_positions, MENU_ENUM_LABEL_VIDEO_WINDOW_SAVE_POSITION, MENU_ENUM_LABEL_VALUE_VIDEO_WINDOW_SAVE_POSITION, - false, + DEFAULT_WINDOW_SAVE_POSITIONS, MENU_ENUM_LABEL_VALUE_OFF, MENU_ENUM_LABEL_VALUE_ON, &group_info, @@ -11430,7 +11464,30 @@ static bool setting_append_list( general_write_handler, general_read_handler, SD_FLAG_NONE); - + (*list)[list_info->index - 1].action_ok = setting_bool_action_left_with_refresh; + (*list)[list_info->index - 1].action_left = setting_bool_action_left_with_refresh; + (*list)[list_info->index - 1].action_right = setting_bool_action_right_with_refresh; + MENU_SETTINGS_LIST_CURRENT_ADD_CMD(list, list_info, CMD_EVENT_REINIT); +#else + CONFIG_BOOL( + list, list_info, + &settings->bools.video_window_custom_size_enable, + MENU_ENUM_LABEL_VIDEO_WINDOW_CUSTOM_SIZE_ENABLE, + MENU_ENUM_LABEL_VALUE_VIDEO_WINDOW_CUSTOM_SIZE_ENABLE, + DEFAULT_WINDOW_CUSTOM_SIZE_ENABLE, + MENU_ENUM_LABEL_VALUE_OFF, + MENU_ENUM_LABEL_VALUE_ON, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler, + SD_FLAG_NONE); + (*list)[list_info->index - 1].action_ok = setting_bool_action_left_with_refresh; + (*list)[list_info->index - 1].action_left = setting_bool_action_left_with_refresh; + (*list)[list_info->index - 1].action_right = setting_bool_action_right_with_refresh; + MENU_SETTINGS_LIST_CURRENT_ADD_CMD(list, list_info, CMD_EVENT_REINIT); +#endif CONFIG_BOOL( list, list_info, &settings->bools.video_scale_integer, diff --git a/msg_hash.h b/msg_hash.h index f7741c91a9..d3fdb81c26 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -1054,6 +1054,8 @@ enum msg_hash_enums MENU_LABEL(VIDEO_WINDOWED_FULLSCREEN), MENU_LABEL(VIDEO_WINDOW_WIDTH), MENU_LABEL(VIDEO_WINDOW_HEIGHT), + MENU_LABEL(VIDEO_WINDOW_AUTO_WIDTH_MAX), + MENU_LABEL(VIDEO_WINDOW_AUTO_HEIGHT_MAX), MENU_LABEL(VIDEO_WINDOW_OPACITY), MENU_LABEL(VIDEO_FULLSCREEN_X), MENU_LABEL(VIDEO_FULLSCREEN_Y), @@ -2837,6 +2839,7 @@ enum msg_hash_enums MENU_LABEL(NETPLAY_MITM_SERVER), MENU_LABEL(VIDEO_WINDOW_SHOW_DECORATIONS), MENU_LABEL(VIDEO_WINDOW_SAVE_POSITION), + MENU_LABEL(VIDEO_WINDOW_CUSTOM_SIZE_ENABLE), MENU_ENUM_LABEL_VALUE_QT_INFO, MENU_ENUM_LABEL_VALUE_QT_MENU_FILE, diff --git a/retroarch.c b/retroarch.c index d31658379f..053a7a8894 100644 --- a/retroarch.c +++ b/retroarch.c @@ -30105,17 +30105,23 @@ static bool video_driver_init_internal( aspectratio_lut[new_aspect_idx].value); } - if (settings->bools.video_fullscreen|| p_rarch->rarch_force_fullscreen) + if (settings->bools.video_fullscreen || p_rarch->rarch_force_fullscreen) { width = settings->uints.video_fullscreen_x; height = settings->uints.video_fullscreen_y; } 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 (settings->bools.video_window_save_positions && - (settings->uints.window_position_width || - settings->uints.window_position_height)) + if (window_custom_size_enable && + settings->uints.window_position_width && + settings->uints.window_position_height) { width = settings->uints.window_position_width; height = settings->uints.window_position_height; @@ -30123,16 +30129,75 @@ static bool video_driver_init_internal( else { 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)) + { + /* > 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); + /* 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); + 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; + + 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; + } + } } }