Get rid of duplicate code in gfx_widgets -

gfx_display_get_widget_dpi_scale made redundant
This commit is contained in:
twinaphex 2021-09-13 20:21:36 +02:00
parent 490233f3c5
commit 5e4ce74000
5 changed files with 61 additions and 86 deletions

View File

@ -362,7 +362,10 @@ float gfx_display_get_dpi_scale_internal(
float gfx_display_get_dpi_scale(
gfx_display_t *p_disp,
void *settings_data,
unsigned width, unsigned height)
unsigned width, unsigned height,
bool fullscreen,
bool is_widget
)
{
static unsigned last_width = 0;
static unsigned last_height = 0;
@ -373,7 +376,45 @@ float gfx_display_get_dpi_scale(
static enum menu_driver_id_type last_menu_driver_id = MENU_DRIVER_ID_UNKNOWN;
static float adjusted_scale = 1.0f;
settings_t *settings = (settings_t*)settings_data;
#ifdef HAVE_GFX_WIDGETS
bool gfx_widget_scale_auto = settings->bools.menu_widget_scale_auto;
#if (defined(RARCH_CONSOLE) || defined(RARCH_MOBILE))
float menu_widget_scale_factor = settings->floats.menu_widget_scale_factor;
#else
float menu_widget_scale_factor_fullscreen = settings->floats.menu_widget_scale_factor;
float menu_widget_scale_factor_windowed = settings->floats.menu_widget_scale_factor_windowed;
float menu_widget_scale_factor = fullscreen ?
menu_widget_scale_factor_fullscreen : menu_widget_scale_factor_windowed;
#endif
float menu_scale_factor = is_widget
? menu_widget_scale_factor
: settings->floats.menu_scale_factor;
#else
float menu_scale_factor = settings->floats.menu_scale_factor;
#endif
#ifdef HAVE_GFX_WIDGETS
if (is_widget)
{
if (gfx_widget_scale_auto)
{
#ifdef HAVE_RGUI
/* When using RGUI, _menu_scale_factor
* is ignored
* > If we are not using a widget scale factor override,
* just set menu_scale_factor to 1.0 */
if (p_disp->menu_driver_id == MENU_DRIVER_ID_RGUI)
menu_scale_factor = 1.0f;
else
#endif
{
float _menu_scale_factor =
settings->floats.menu_scale_factor;
menu_scale_factor = _menu_scale_factor;
}
}
}
#endif
/* Scale is based on display metrics - these are a fixed
* hardware property. To minimise performance overheads

View File

@ -342,7 +342,9 @@ float gfx_display_get_dpi_scale_internal(unsigned width, unsigned height);
float gfx_display_get_dpi_scale(
gfx_display_t *p_disp,
void *settings_data,
unsigned width, unsigned height);
unsigned width, unsigned height,
bool fullscreen,
bool is_widget);
void gfx_display_deinit_white_texture(void);

View File

@ -86,79 +86,6 @@ const static gfx_widget_t* const widgets[] = {
&gfx_widget_load_content_animation
};
static float gfx_display_get_widget_dpi_scale(
gfx_display_t *p_disp,
settings_t *settings,
unsigned width, unsigned height, bool fullscreen)
{
static unsigned last_width = 0;
static unsigned last_height = 0;
static float scale = 0.0f;
static bool scale_cached = false;
bool scale_updated = false;
static float last_menu_scale_factor = 0.0f;
static enum menu_driver_id_type last_menu_driver_id = MENU_DRIVER_ID_UNKNOWN;
static float adjusted_scale = 1.0f;
bool gfx_widget_scale_auto = settings->bools.menu_widget_scale_auto;
#if (defined(RARCH_CONSOLE) || defined(RARCH_MOBILE))
float menu_widget_scale_factor = settings->floats.menu_widget_scale_factor;
#else
float menu_widget_scale_factor_fullscreen = settings->floats.menu_widget_scale_factor;
float menu_widget_scale_factor_windowed = settings->floats.menu_widget_scale_factor_windowed;
float menu_widget_scale_factor = fullscreen ?
menu_widget_scale_factor_fullscreen : menu_widget_scale_factor_windowed;
#endif
float menu_scale_factor = menu_widget_scale_factor;
if (gfx_widget_scale_auto)
{
#ifdef HAVE_RGUI
/* When using RGUI, _menu_scale_factor
* is ignored
* > If we are not using a widget scale factor override,
* just set menu_scale_factor to 1.0 */
if (p_disp->menu_driver_id == MENU_DRIVER_ID_RGUI)
menu_scale_factor = 1.0f;
else
#endif
{
float _menu_scale_factor =
settings->floats.menu_scale_factor;
menu_scale_factor = _menu_scale_factor;
}
}
/* Scale is based on display metrics - these are a fixed
* hardware property. To minimise performance overheads
* we therefore only call video_context_driver_get_metrics()
* on first run, or when the current video resolution changes */
if (!scale_cached ||
(width != last_width) ||
(height != last_height))
{
scale = gfx_display_get_dpi_scale_internal(width, height);
scale_cached = true;
scale_updated = true;
last_width = width;
last_height = height;
}
/* Adjusted scale calculation may also be slow, so
* only update if something changes */
if (scale_updated ||
(menu_scale_factor != last_menu_scale_factor) ||
(p_disp->menu_driver_id != last_menu_driver_id))
{
adjusted_scale = gfx_display_get_adjusted_scale(
p_disp,
scale, menu_scale_factor, width);
last_menu_scale_factor = menu_scale_factor;
last_menu_driver_id = p_disp->menu_driver_id;
}
return adjusted_scale;
}
#if defined(HAVE_MENU) && defined(HAVE_XMB)
static float gfx_display_get_widget_pixel_scale(
gfx_display_t *p_disp,
@ -995,8 +922,9 @@ void gfx_widgets_iterate(
scale_factor = gfx_display_get_widget_pixel_scale(p_disp, settings, width, height, fullscreen);
else
#endif
scale_factor = gfx_display_get_widget_dpi_scale(p_disp,
settings, width, height, fullscreen);
scale_factor = gfx_display_get_dpi_scale(
p_disp,
settings, width, height, fullscreen, true);
/* Check whether screen dimensions or menu scale
* factor have changed */
@ -2079,11 +2007,11 @@ static void gfx_widgets_context_reset(
p_dispwidget->last_video_height, fullscreen);
else
#endif
p_dispwidget->last_scale_factor = gfx_display_get_widget_dpi_scale(
p_dispwidget->last_scale_factor = gfx_display_get_dpi_scale(
p_disp, settings,
p_dispwidget->last_video_width,
p_dispwidget->last_video_height,
fullscreen);
fullscreen, true);
gfx_widgets_layout(p_disp, p_dispwidget,
is_threaded, dir_assets, font_path);

View File

@ -3539,7 +3539,8 @@ static void materialui_render(void *data,
/* Check whether screen dimensions, menu scale
* factor or layout optimisation settings have changed */
scale_factor = gfx_display_get_dpi_scale(p_disp, settings, width, height);
scale_factor = gfx_display_get_dpi_scale(p_disp, settings,
width, height, false, false);
if ((scale_factor != mui->last_scale_factor) ||
(width != mui->last_width) ||
@ -7900,8 +7901,9 @@ static void materialui_menu_animation_update_time(
* a small correction factor to achieve a
* default scroll speed equal to that of the
* non-smooth ticker */
*(ticker_pixel_increment) *= gfx_display_get_dpi_scale(p_disp, settings,
video_width, video_height) * 0.8f;
*(ticker_pixel_increment) *= gfx_display_get_dpi_scale(
p_disp, settings,
video_width, video_height, false, false) * 0.8f;
}
static void *materialui_init(void **userdata, bool video_is_threaded)
@ -7944,7 +7946,8 @@ static void *materialui_init(void **userdata, bool video_is_threaded)
mui->last_width = width;
mui->last_height = height;
mui->last_scale_factor = gfx_display_get_dpi_scale(
p_disp, settings, width, height);
p_disp, settings, width, height,
false, false);
mui->dip_base_unit_size = mui->last_scale_factor
* MUI_DIP_BASE_UNIT_SIZE;

View File

@ -6792,7 +6792,7 @@ static void ozone_menu_animation_update_time(
* default scroll speed equal to that of the
* non-smooth ticker */
*(ticker_pixel_increment) *= gfx_display_get_dpi_scale(p_disp,
settings, video_width, video_height) * 0.5f;
settings, video_width, video_height, false, false) * 0.5f;
}
static void *ozone_init(void **userdata, bool video_is_threaded)
@ -6825,7 +6825,7 @@ static void *ozone_init(void **userdata, bool video_is_threaded)
ozone->last_width = width;
ozone->last_height = height;
ozone->last_scale_factor = gfx_display_get_dpi_scale(p_disp,
settings, width, height);
settings, width, height, false, false);
file_list_initialize(&ozone->selection_buf_old);
@ -7889,7 +7889,8 @@ static void ozone_render(void *data,
/* Check whether screen dimensions or menu scale
* factor have changed */
scale_factor = gfx_display_get_dpi_scale(p_disp, settings, width, height);
scale_factor = gfx_display_get_dpi_scale(p_disp, settings,
width, height, false, false);
if ((scale_factor != ozone->last_scale_factor) ||
(width != ozone->last_width) ||