(Ozone) Horizontal list - put on stack - it's already on heap-allocated

struct as is
This commit is contained in:
twinaphex 2020-08-24 10:22:32 +02:00
parent 93fa9a0194
commit 7a6b9fd1b2
6 changed files with 49 additions and 72 deletions

View File

@ -72,6 +72,8 @@ void file_list_free(file_list_t *list);
bool file_list_deinitialize(file_list_t *list); bool file_list_deinitialize(file_list_t *list);
bool file_list_initialize(file_list_t *list);
/** /**
* @brief makes the list big enough to contain at least nitems * @brief makes the list big enough to contain at least nitems
* *

View File

@ -55,6 +55,18 @@ static bool file_list_deinitialize_internal(file_list_t *list)
return true; return true;
} }
bool file_list_initialize(file_list_t *list)
{
if (!list)
return false;
list->list = NULL;
list->capacity = 0;
list->size = 0;
return true;
}
bool file_list_reserve(file_list_t *list, size_t nitems) bool file_list_reserve(file_list_t *list, size_t nitems)
{ {
const size_t item_size = sizeof(struct item_file); const size_t item_size = sizeof(struct item_file);

View File

@ -280,8 +280,7 @@ static enum menu_action ozone_parse_menu_entry_action(
} }
} }
if (ozone->horizontal_list) horizontal_list_size = (unsigned)ozone->horizontal_list.size;
horizontal_list_size = (unsigned)ozone->horizontal_list->size;
ozone->messagebox_state = false || menu_input_dialog_get_display_kb(); ozone->messagebox_state = false || menu_input_dialog_get_display_kb();
selection_buf = menu_entries_get_selection_buf_ptr(0); selection_buf = menu_entries_get_selection_buf_ptr(0);
@ -669,14 +668,9 @@ static void *ozone_init(void **userdata, bool video_is_threaded)
gfx_display_allocate_white_texture(); gfx_display_allocate_white_texture();
ozone->horizontal_list = (file_list_t*)malloc(sizeof(file_list_t)); file_list_initialize(&ozone->horizontal_list);
ozone->horizontal_list->list = NULL; ozone_init_horizontal_list(ozone);
ozone->horizontal_list->capacity = 0;
ozone->horizontal_list->size = 0;
if (ozone->horizontal_list)
ozone_init_horizontal_list(ozone);
/* Theme */ /* Theme */
if (settings->bools.menu_use_preferred_system_color_theme) if (settings->bools.menu_use_preferred_system_color_theme)
@ -753,11 +747,8 @@ static void *ozone_init(void **userdata, bool video_is_threaded)
error: error:
if (ozone) if (ozone)
{ {
if (ozone->horizontal_list) ozone_free_list_nodes(&ozone->horizontal_list, false);
{ file_list_deinitialize(&ozone->horizontal_list);
ozone_free_list_nodes(ozone->horizontal_list, false);
file_list_free(ozone->horizontal_list);
}
if (ozone->selection_buf_old) if (ozone->selection_buf_old)
{ {
@ -766,7 +757,6 @@ error:
} }
ozone->selection_buf_old = NULL; ozone->selection_buf_old = NULL;
ozone->horizontal_list = NULL;
} }
if (menu) if (menu)
@ -797,13 +787,9 @@ static void ozone_free(void *data)
file_list_free(ozone->selection_buf_old); file_list_free(ozone->selection_buf_old);
} }
if (ozone->horizontal_list) ozone_free_list_nodes(&ozone->horizontal_list, false);
{ file_list_deinitialize(&ozone->horizontal_list);
ozone_free_list_nodes(ozone->horizontal_list, false);
file_list_free(ozone->horizontal_list);
}
ozone->horizontal_list = NULL;
ozone->selection_buf_old = NULL; ozone->selection_buf_old = NULL;
if (!string_is_empty(ozone->pending_message)) if (!string_is_empty(ozone->pending_message))
@ -1323,10 +1309,9 @@ static void *ozone_list_get_entry(void *data,
} }
break; break;
case MENU_LIST_HORIZONTAL: case MENU_LIST_HORIZONTAL:
if (ozone && ozone->horizontal_list) list_size = file_list_get_size(&ozone->horizontal_list);
list_size = file_list_get_size(ozone->horizontal_list);
if (i < list_size) if (i < list_size)
return (void*)&ozone->horizontal_list->list[i]; return (void*)&ozone->horizontal_list.list[i];
break; break;
default: default:
break; break;
@ -1689,8 +1674,7 @@ static void ozone_render(void *data,
bool first_entry_found = false; bool first_entry_found = false;
bool last_entry_found = false; bool last_entry_found = false;
unsigned horizontal_list_size = ozone->horizontal_list ? unsigned horizontal_list_size = (unsigned)ozone->horizontal_list.size;
(unsigned)ozone->horizontal_list->size : 0;
float category_height = ozone->dimensions.sidebar_entry_height + float category_height = ozone->dimensions.sidebar_entry_height +
ozone->dimensions.sidebar_entry_padding_vertical; ozone->dimensions.sidebar_entry_padding_vertical;
bool first_category_found = false; bool first_category_found = false;
@ -2880,12 +2864,10 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
static void ozone_set_header(ozone_handle_t *ozone) static void ozone_set_header(ozone_handle_t *ozone)
{ {
if (ozone->categories_selection_ptr <= ozone->system_tab_end) if (ozone->categories_selection_ptr <= ozone->system_tab_end)
{
menu_entries_get_title(ozone->title, sizeof(ozone->title)); menu_entries_get_title(ozone->title, sizeof(ozone->title));
} else
else if (ozone->horizontal_list)
{ {
ozone_node_t *node = (ozone_node_t*) file_list_get_userdata_at_offset(ozone->horizontal_list, ozone->categories_selection_ptr - ozone->system_tab_end-1); ozone_node_t *node = (ozone_node_t*)file_list_get_userdata_at_offset(&ozone->horizontal_list, ozone->categories_selection_ptr - ozone->system_tab_end-1);
if (node && node->console_name) if (node && node->console_name)
{ {
@ -3494,8 +3476,7 @@ static int ozone_pointer_up(void *userdata,
/* Otherwise, select current category */ /* Otherwise, select current category */
else if (ozone->pointer_categories_selection != ozone->categories_selection_ptr) else if (ozone->pointer_categories_selection != ozone->categories_selection_ptr)
{ {
unsigned horizontal_list_size = (ozone->horizontal_list) ? unsigned horizontal_list_size = (unsigned)ozone->horizontal_list.size;
(unsigned)ozone->horizontal_list->size : 0;
/* Ensure that current category is valid */ /* Ensure that current category is valid */
if (ozone->pointer_categories_selection <= ozone->system_tab_end + horizontal_list_size) if (ozone->pointer_categories_selection <= ozone->system_tab_end + horizontal_list_size)
@ -3568,9 +3549,7 @@ size_t ozone_list_get_size(void *data, enum menu_list_type type)
case MENU_LIST_PLAIN: case MENU_LIST_PLAIN:
return menu_entries_get_stack_size(0); return menu_entries_get_stack_size(0);
case MENU_LIST_HORIZONTAL: case MENU_LIST_HORIZONTAL:
if (ozone && ozone->horizontal_list) return file_list_get_size(&ozone->horizontal_list);
return file_list_get_size(ozone->horizontal_list);
break;
case MENU_LIST_TABS: case MENU_LIST_TABS:
return ozone->system_tab_end; return ozone->system_tab_end;
} }

View File

@ -220,7 +220,7 @@ struct ozone_handle
unsigned old_list_offset_y; unsigned old_list_offset_y;
file_list_t *horizontal_list; /* console tabs */ file_list_t horizontal_list; /* console tabs */ /* ptr alignment */
struct { struct {
int header_height; int header_height;

View File

@ -721,9 +721,9 @@ border_iterate:
uintptr_t texture = tex; uintptr_t texture = tex;
/* Console specific icons */ /* Console specific icons */
if (entry.type == FILE_TYPE_RPL_ENTRY && ozone->horizontal_list && ozone->categories_selection_ptr > ozone->system_tab_end) if (entry.type == FILE_TYPE_RPL_ENTRY && ozone->categories_selection_ptr > ozone->system_tab_end)
{ {
ozone_node_t *sidebar_node = (ozone_node_t*) file_list_get_userdata_at_offset(ozone->horizontal_list, ozone->categories_selection_ptr - ozone->system_tab_end-1); ozone_node_t *sidebar_node = (ozone_node_t*) file_list_get_userdata_at_offset(&ozone->horizontal_list, ozone->categories_selection_ptr - ozone->system_tab_end-1);
if (!sidebar_node || !sidebar_node->content_icon) if (!sidebar_node || !sidebar_node->content_icon)
texture = tex; texture = tex;
@ -736,13 +736,9 @@ border_iterate:
(entry.type >= MENU_SETTINGS_CHEEVOS_START) && (entry.type >= MENU_SETTINGS_CHEEVOS_START) &&
(entry.type < MENU_SETTINGS_NETPLAY_ROOMS_START) (entry.type < MENU_SETTINGS_NETPLAY_ROOMS_START)
)) ))
{
icon_color = ozone->theme_dynamic.entries_icon; icon_color = ozone->theme_dynamic.entries_icon;
}
else else
{
icon_color = ozone_pure_white; icon_color = ozone_pure_white;
}
gfx_display_set_alpha(icon_color, alpha); gfx_display_set_alpha(icon_color, alpha);

View File

@ -207,8 +207,7 @@ void ozone_draw_sidebar(
ticker.spacer = ticker_spacer; ticker.spacer = ticker_spacer;
} }
if (ozone->horizontal_list) horizontal_list_size = (unsigned)ozone->horizontal_list.size;
horizontal_list_size = (unsigned)ozone->horizontal_list->size;
gfx_display_scissor_begin(userdata, gfx_display_scissor_begin(userdata,
video_width, video_height, video_width, video_height,
@ -374,7 +373,7 @@ void ozone_draw_sidebar(
uint32_t text_color = COLOR_TEXT_ALPHA((selected ? ozone->theme->text_selected_rgba : ozone->theme->text_rgba), text_alpha); uint32_t text_color = COLOR_TEXT_ALPHA((selected ? ozone->theme->text_selected_rgba : ozone->theme->text_rgba), text_alpha);
ozone_node_t *node = (ozone_node_t*) file_list_get_userdata_at_offset(ozone->horizontal_list, i); ozone_node_t *node = (ozone_node_t*) file_list_get_userdata_at_offset(&ozone->horizontal_list, i);
if (!node) if (!node)
goto console_iterate; goto console_iterate;
@ -504,9 +503,9 @@ unsigned ozone_get_selected_sidebar_y_position(ozone_handle_t *ozone)
unsigned ozone_get_sidebar_height(ozone_handle_t *ozone) unsigned ozone_get_sidebar_height(ozone_handle_t *ozone)
{ {
int entries = (int)(ozone->system_tab_end + 1 + (ozone->horizontal_list ? ozone->horizontal_list->size : 0)); int entries = (int)(ozone->system_tab_end + 1 + (ozone->horizontal_list.size ));
return entries * ozone->dimensions.sidebar_entry_height + (entries - 1) * ozone->dimensions.sidebar_entry_padding_vertical + ozone->dimensions.sidebar_padding_vertical + return entries * ozone->dimensions.sidebar_entry_height + (entries - 1) * ozone->dimensions.sidebar_entry_padding_vertical + ozone->dimensions.sidebar_padding_vertical +
(ozone->horizontal_list && ozone->horizontal_list->size > 0 ? ozone->dimensions.sidebar_entry_padding_vertical + ozone->dimensions.spacer_1px : 0); (ozone->horizontal_list.size > 0 ? ozone->dimensions.sidebar_entry_padding_vertical + ozone->dimensions.spacer_1px : 0);
} }
void ozone_sidebar_update_collapse(ozone_handle_t *ozone, bool allow_animation) void ozone_sidebar_update_collapse(ozone_handle_t *ozone, bool allow_animation)
@ -746,7 +745,7 @@ void ozone_init_horizontal_list(ozone_handle_t *ozone)
menu_displaylist_info_init(&info); menu_displaylist_info_init(&info);
info.list = ozone->horizontal_list; info.list = &ozone->horizontal_list;
info.path = strdup(dir_playlist); info.path = strdup(dir_playlist);
info.label = strdup( info.label = strdup(
msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB)); msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB));
@ -774,12 +773,12 @@ void ozone_init_horizontal_list(ozone_handle_t *ozone)
playlist_file_noext[0] = '\0'; playlist_file_noext[0] = '\0';
/* Get playlist file name */ /* Get playlist file name */
file_list_get_at_offset(ozone->horizontal_list, i, file_list_get_at_offset(&ozone->horizontal_list, i,
&playlist_file, NULL, NULL, NULL); &playlist_file, NULL, NULL, NULL);
if (!playlist_file) if (!playlist_file)
{ {
file_list_set_alt_at_offset(ozone->horizontal_list, i, NULL); file_list_set_alt_at_offset(&ozone->horizontal_list, i, NULL);
continue; continue;
} }
@ -818,7 +817,7 @@ void ozone_init_horizontal_list(ozone_handle_t *ozone)
} }
/* Assign console name to list */ /* Assign console name to list */
file_list_set_alt_at_offset(ozone->horizontal_list, i, console_name); file_list_set_alt_at_offset(&ozone->horizontal_list, i, console_name);
} }
/* If playlist names were truncated and option is /* If playlist names were truncated and option is
@ -826,30 +825,19 @@ void ozone_init_horizontal_list(ozone_handle_t *ozone)
if (ozone_truncate_playlist_name && if (ozone_truncate_playlist_name &&
ozone_sort_after_truncate && ozone_sort_after_truncate &&
(list_size > 0)) (list_size > 0))
file_list_sort_on_alt(ozone->horizontal_list); file_list_sort_on_alt(&ozone->horizontal_list);
} }
void ozone_refresh_horizontal_list(ozone_handle_t *ozone) void ozone_refresh_horizontal_list(ozone_handle_t *ozone)
{ {
ozone_context_destroy_horizontal_list(ozone); ozone_context_destroy_horizontal_list(ozone);
if (ozone->horizontal_list) ozone_free_list_nodes(&ozone->horizontal_list, false);
{ file_list_deinitialize(&ozone->horizontal_list);
ozone_free_list_nodes(ozone->horizontal_list, false);
file_list_free(ozone->horizontal_list);
}
ozone->horizontal_list = NULL;
menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL); menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL);
ozone->horizontal_list = (file_list_t*) file_list_initialize(&ozone->horizontal_list);
malloc(sizeof(file_list_t)); ozone_init_horizontal_list(ozone);
ozone->horizontal_list->list = NULL;
ozone->horizontal_list->capacity = 0;
ozone->horizontal_list->size = 0;
if (ozone->horizontal_list)
ozone_init_horizontal_list(ozone);
ozone_context_reset_horizontal_list(ozone); ozone_context_reset_horizontal_list(ozone);
} }
@ -863,7 +851,7 @@ void ozone_context_reset_horizontal_list(ozone_handle_t *ozone)
{ {
const char *path = NULL; const char *path = NULL;
const char *console_name = NULL; const char *console_name = NULL;
ozone_node_t *node = (ozone_node_t*)file_list_get_userdata_at_offset(ozone->horizontal_list, i); ozone_node_t *node = (ozone_node_t*)file_list_get_userdata_at_offset(&ozone->horizontal_list, i);
if (!node) if (!node)
{ {
@ -872,7 +860,7 @@ void ozone_context_reset_horizontal_list(ozone_handle_t *ozone)
continue; continue;
} }
file_list_get_at_offset(ozone->horizontal_list, i, file_list_get_at_offset(&ozone->horizontal_list, i,
&path, NULL, NULL, NULL); &path, NULL, NULL, NULL);
if (!path) if (!path)
@ -950,7 +938,7 @@ void ozone_context_reset_horizontal_list(ozone_handle_t *ozone)
/* Console name */ /* Console name */
menu_entries_get_at_offset( menu_entries_get_at_offset(
ozone->horizontal_list, i, &ozone->horizontal_list, i,
NULL, NULL, NULL, NULL, &console_name); NULL, NULL, NULL, NULL, &console_name);
if (node->console_name) if (node->console_name)
@ -973,12 +961,12 @@ void ozone_context_destroy_horizontal_list(ozone_handle_t *ozone)
for (i = 0; i < list_size; i++) for (i = 0; i < list_size; i++)
{ {
const char *path = NULL; const char *path = NULL;
ozone_node_t *node = (ozone_node_t*)file_list_get_userdata_at_offset(ozone->horizontal_list, i); ozone_node_t *node = (ozone_node_t*)file_list_get_userdata_at_offset(&ozone->horizontal_list, i);
if (!node) if (!node)
continue; continue;
file_list_get_at_offset(ozone->horizontal_list, i, file_list_get_at_offset(&ozone->horizontal_list, i,
&path, NULL, NULL, NULL); &path, NULL, NULL, NULL);
if (!path || !string_ends_with_size(path, ".lpl", if (!path || !string_ends_with_size(path, ".lpl",