menu_display_get_dpi - don't use video_driver_get_size inside function

This commit is contained in:
twinaphex 2019-08-13 17:12:55 +02:00
parent aaac54783d
commit 36ed0ca34f
3 changed files with 30 additions and 26 deletions

View File

@ -413,7 +413,8 @@ static void materialui_draw_tab_begin(
unsigned width, unsigned height, unsigned width, unsigned height,
float *tabs_bg_color, float *tabs_separator_color) float *tabs_bg_color, float *tabs_separator_color)
{ {
float scale_factor = menu_display_get_dpi(); float scale_factor = menu_display_get_dpi(video_info->width,
video_info->height);
mui->tabs_height = scale_factor / 3; mui->tabs_height = scale_factor / 3;
@ -593,14 +594,15 @@ static unsigned materialui_count_lines(const char *str)
} }
/* Compute the line height for each menu entry. */ /* Compute the line height for each menu entry. */
static void materialui_compute_entries_box(materialui_handle_t* mui, int width) static void materialui_compute_entries_box(materialui_handle_t* mui, int width,
int height)
{ {
unsigned i; unsigned i;
size_t usable_width = width - (mui->margin * 2); size_t usable_width = width - (mui->margin * 2);
file_list_t *list = menu_entries_get_selection_buf_ptr(0); file_list_t *list = menu_entries_get_selection_buf_ptr(0);
float sum = 0; float sum = 0;
size_t entries_end = menu_entries_get_size(); size_t entries_end = menu_entries_get_size();
float scale_factor = menu_display_get_dpi(); float scale_factor = menu_display_get_dpi(width, height);
for (i = 0; i < entries_end; i++) for (i = 0; i < entries_end; i++)
{ {
@ -662,7 +664,7 @@ static void materialui_render(void *data,
if (mui->need_compute) if (mui->need_compute)
{ {
if (mui->font) if (mui->font)
materialui_compute_entries_box(mui, width); materialui_compute_entries_box(mui, width, height);
mui->need_compute = false; mui->need_compute = false;
} }
@ -756,7 +758,8 @@ static void materialui_render_label_value(
size_t usable_width = width - (mui->margin * 2); size_t usable_width = width - (mui->margin * 2);
int icon_margin = 0; int icon_margin = 0;
enum msg_file_type hash_type = msg_hash_to_file_type(msg_hash_calculate(value)); enum msg_file_type hash_type = msg_hash_to_file_type(msg_hash_calculate(value));
float scale_factor = menu_display_get_dpi(); float scale_factor = menu_display_get_dpi(video_info->width,
video_info->height);
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
/* Initial ticker configuration */ /* Initial ticker configuration */
@ -1632,7 +1635,7 @@ static void materialui_layout(materialui_handle_t *mui, bool video_is_threaded)
* *
* On desktops, we just care about readability, with every widget * On desktops, we just care about readability, with every widget
* size proportional to the display width. */ * size proportional to the display width. */
scale_factor = menu_display_get_dpi(); scale_factor = menu_display_get_dpi(width, height);
new_header_height = scale_factor / 3; new_header_height = scale_factor / 3;
new_font_size = scale_factor / 9; new_font_size = scale_factor / 9;
@ -1682,13 +1685,17 @@ static void materialui_layout(materialui_handle_t *mui, bool video_is_threaded)
static void *materialui_init(void **userdata, bool video_is_threaded) static void *materialui_init(void **userdata, bool video_is_threaded)
{ {
float scale_factor = menu_display_get_dpi(); unsigned width, height;
float scale_factor = 0.0f;
materialui_handle_t *mui = NULL; materialui_handle_t *mui = NULL;
menu_handle_t *menu = (menu_handle_t*) menu_handle_t *menu = (menu_handle_t*)
calloc(1, sizeof(*menu)); calloc(1, sizeof(*menu));
if (!menu) if (!menu)
goto error; return NULL;
video_driver_get_size(&width, &height);
scale_factor = menu_display_get_dpi(width, height);
if (!menu_display_init_first_driver(video_is_threaded)) if (!menu_display_init_first_driver(video_is_threaded))
goto error; goto error;
@ -2338,6 +2345,7 @@ static void materialui_list_insert(void *userdata,
unsigned type) unsigned type)
{ {
float scale_factor; float scale_factor;
unsigned width, height;
int i = (int)list_size; int i = (int)list_size;
materialui_node_t *node = NULL; materialui_node_t *node = NULL;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
@ -2358,7 +2366,8 @@ static void materialui_list_insert(void *userdata,
return; return;
} }
scale_factor = menu_display_get_dpi(); video_driver_get_size(&width, &height);
scale_factor = menu_display_get_dpi(width, height);
node->line_height = scale_factor / 3; node->line_height = scale_factor / 3;
node->y = 0; node->y = 0;

View File

@ -685,28 +685,23 @@ void menu_display_unset_framebuffer_dirty_flag(void)
/* Get the preferred DPI at which to render the menu. /* Get the preferred DPI at which to render the menu.
* NOTE: Only MaterialUI menu driver so far uses this, neither * NOTE: Only MaterialUI menu driver so far uses this, neither
* RGUI or XMB use this. */ * RGUI or XMB use this. */
float menu_display_get_dpi(void) float menu_display_get_dpi(unsigned width, unsigned height)
{ {
unsigned width, height;
settings_t *settings = config_get_ptr();
float dpi = 0.0f;
float diagonal = 6.5f;
video_driver_get_size(&width, &height);
if (!settings)
return true;
#ifdef RARCH_MOBILE #ifdef RARCH_MOBILE
diagonal = 5.0f; float diagonal = 5.0f;
#else
float diagonal = 6.5f;
#endif #endif
/* Generic dpi calculation formula, /* Generic dpi calculation formula,
* the divider is the screen diagonal in inches */ * the divider is the screen diagonal in inches */
dpi = sqrt((width * width) + (height * height)) / diagonal; float dpi = sqrt(
(width * width) + (height * height)) / diagonal;
if (settings->bools.menu_dpi_override_enable) {
return settings->uints.menu_dpi_override_value; settings_t *settings = config_get_ptr();
if (settings && settings->bools.menu_dpi_override_enable)
return settings->uints.menu_dpi_override_value;
}
return dpi; return dpi;
} }

View File

@ -578,7 +578,7 @@ void menu_display_unset_viewport(unsigned width, unsigned height);
bool menu_display_get_framebuffer_dirty_flag(void); bool menu_display_get_framebuffer_dirty_flag(void);
void menu_display_set_framebuffer_dirty_flag(void); void menu_display_set_framebuffer_dirty_flag(void);
void menu_display_unset_framebuffer_dirty_flag(void); void menu_display_unset_framebuffer_dirty_flag(void);
float menu_display_get_dpi(void); float menu_display_get_dpi(unsigned width, unsigned height);
bool menu_display_init_first_driver(bool video_is_threaded); bool menu_display_init_first_driver(bool video_is_threaded);
bool menu_display_restore_clear_color(void); bool menu_display_restore_clear_color(void);
void menu_display_clear_color(menu_display_ctx_clearcolor_t *color, void menu_display_clear_color(menu_display_ctx_clearcolor_t *color,