From 6c7a354822a0c16a75bb1f43ffc5ac5ca3d60bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Sun, 3 Sep 2017 14:51:14 -0300 Subject: [PATCH 1/3] (xmb) Remove xmb->menu_stack_old --- menu/drivers/xmb.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 088ab6c558..b284cf4d83 100755 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -174,7 +174,6 @@ enum typedef struct xmb_handle { - file_list_t *menu_stack_old; file_list_t *selection_buf_old; file_list_t *horizontal_list; size_t selection_ptr_old; @@ -2297,7 +2296,7 @@ static void xmb_draw_items( video_frame_info_t *video_info, menu_display_frame_info_t menu_disp_info, xmb_handle_t *xmb, - file_list_t *list, file_list_t *stack, + file_list_t *list, size_t current, size_t cat_selection_ptr, float *color, unsigned width, unsigned height) { @@ -2809,7 +2808,6 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) unsigned height = video_info->height; bool render_background = false; file_list_t *selection_buf = NULL; - file_list_t *menu_stack = NULL; xmb_handle_t *xmb = (xmb_handle_t*)data; if (!xmb) @@ -3086,7 +3084,6 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) menu_disp_info, xmb, xmb->selection_buf_old, - xmb->menu_stack_old, xmb->selection_ptr_old, (xmb_list_get_size(xmb, MENU_LIST_PLAIN) > 1) ? xmb->categories.selection_ptr : xmb->categories.selection_ptr_old, @@ -3095,14 +3092,12 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) height); selection_buf = menu_entries_get_selection_buf_ptr(0); - menu_stack = menu_entries_get_menu_stack_ptr(0); xmb_draw_items( video_info, menu_disp_info, xmb, selection_buf, - menu_stack, selection, xmb->categories.selection_ptr, &item_color[0], @@ -3431,11 +3426,6 @@ static void *xmb_init(void **userdata, bool video_is_threaded) *userdata = xmb; - xmb->menu_stack_old = (file_list_t*)calloc(1, sizeof(file_list_t)); - - if (!xmb->menu_stack_old) - goto error; - xmb->selection_buf_old = (file_list_t*)calloc(1, sizeof(file_list_t)); if (!xmb->selection_buf_old) @@ -3503,9 +3493,6 @@ error: if (xmb) { - if (xmb->menu_stack_old) - free(xmb->menu_stack_old); - xmb->menu_stack_old = NULL; if (xmb->selection_buf_old) free(xmb->selection_buf_old); xmb->selection_buf_old = NULL; @@ -3525,12 +3512,6 @@ static void xmb_free(void *data) if (xmb) { - if (xmb->menu_stack_old) - { - xmb_free_list_nodes(xmb->menu_stack_old, false); - file_list_free(xmb->menu_stack_old); - } - if (xmb->selection_buf_old) { xmb_free_list_nodes(xmb->selection_buf_old, false); @@ -3543,7 +3524,6 @@ static void xmb_free(void *data) file_list_free(xmb->horizontal_list); } - xmb->menu_stack_old = NULL; xmb->selection_buf_old = NULL; xmb->horizontal_list = NULL; @@ -3976,10 +3956,7 @@ static void xmb_list_cache(void *data, enum menu_list_type type, unsigned action /* Check whether to enable the horizontal animation. */ if (settings->bools.menu_horizontal_animation) - { xmb_list_deep_copy(selection_buf, xmb->selection_buf_old); - xmb_list_deep_copy(menu_stack, xmb->menu_stack_old); - } /* FIXME: this shouldn't be happening at all */ if (selection >= xmb->selection_buf_old->size) From d40deb737d3bd7448854e9f965865db6d7f858b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Sun, 3 Sep 2017 14:58:01 -0300 Subject: [PATCH 2/3] (file_list.c) Add file_list_reserve() --- libretro-common/include/lists/file_list.h | 12 +++++++ libretro-common/lists/file_list.c | 43 +++++++++-------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/libretro-common/include/lists/file_list.h b/libretro-common/include/lists/file_list.h index 67d3875fc9..85ea8dbc3a 100644 --- a/libretro-common/include/lists/file_list.h +++ b/libretro-common/include/lists/file_list.h @@ -71,6 +71,18 @@ void *file_list_get_actiondata_at_offset(const file_list_t *list, */ void file_list_free(file_list_t *list); +/** + * @brief makes the list big enough to contain at least nitems + * + * This function will not change the capacity if nitems is smaller + * than the current capacity. + * + * @param list + * @param nitems + * @return whether or not the operation succeeded + */ +bool file_list_reserve(file_list_t *list, size_t nitems); + bool file_list_append(file_list_t *userdata, const char *path, const char *label, unsigned type, size_t current_directory_ptr, size_t entry_index); diff --git a/libretro-common/lists/file_list.c b/libretro-common/lists/file_list.c index 9ad11a8805..87e23c6d74 100644 --- a/libretro-common/lists/file_list.c +++ b/libretro-common/lists/file_list.c @@ -29,28 +29,25 @@ #include #include -/** - * file_list_capacity: - * @list : pointer to file list - * @cap : new capacity for file list. - * - * Change maximum capacity of file list's size. - * - * Returns: true (1) if successful, otherwise false (0). - **/ -static struct item_file *realloc_file_list_capacity(file_list_t *list, size_t cap) +bool file_list_reserve(file_list_t *list, size_t nitems) { - struct item_file *new_data = (struct item_file*)realloc(list->list, - cap * sizeof(struct item_file)); + const size_t item_size = sizeof(struct item_file); + struct item_file *new_data; - if (!new_data) - return NULL; + if (nitems < list->capacity || nitems > (size_t)-1/item_size) + return false; - if (cap > list->capacity) - memset(&new_data[list->capacity], 0, - sizeof(*new_data) * (cap - list->capacity)); + new_data = (struct item_file*)realloc(list->list, nitems * item_size); - return new_data; + if (new_data) + { + memset(&new_data[list->capacity], 0, item_size * (nitems - list->capacity)); + + list->list = new_data; + list->capacity = nitems; + } + + return new_data != NULL; } static void file_list_add(file_list_t *list, unsigned idx, @@ -78,16 +75,8 @@ static void file_list_add(file_list_t *list, unsigned idx, static bool file_list_expand_if_needed(file_list_t *list) { if (list->size >= list->capacity) - { - size_t new_capacity = list->capacity * 2 + 1; - struct item_file *items = realloc_file_list_capacity( - list, new_capacity); + return file_list_reserve(list, list->capacity * 2 + 1); - if (!items) - return false; - list->list = items; - list->capacity = new_capacity; - } return true; } From eac68b9d41735d46b4a6019ec8feea39c4e3469c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Sun, 3 Sep 2017 16:04:06 -0300 Subject: [PATCH 3/3] (xmb) Limit selection_buf_old to visible items --- menu/drivers/xmb.c | 54 ++++++++++++++++++++++++++++++----------- menu/menu_displaylist.c | 3 +++ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index b284cf4d83..5e1cd99fae 100755 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -3911,35 +3911,47 @@ static void xmb_list_free(file_list_t *list, size_t a, size_t b) xmb_list_clear(list); } -static void xmb_list_deep_copy(const file_list_t *src, file_list_t *dst) +static void xmb_list_deep_copy(const file_list_t *src, file_list_t *dst, + size_t first, size_t last) { - size_t i; + size_t i, j = 0; menu_animation_ctx_tag tag = (uintptr_t)dst; - size_t size = dst->size; menu_animation_ctl(MENU_ANIMATION_CTL_KILL_BY_TAG, &tag); /* use true here because file_list_copy() doesn't free actiondata */ xmb_free_list_nodes(dst, true); - file_list_copy(src, dst); - size = dst->size; + file_list_clear(dst); + file_list_reserve(dst, (last + 1) - first); - for (i = 0; i < size; ++i) + for (i = first; i <= last; ++i) { - void *src_udata = menu_entries_get_userdata_at_offset(src, i); - void *src_adata = (void*)menu_entries_get_actiondata_at_offset(src, i); + struct item_file *d = &dst->list[j]; + struct item_file *s = &src->list[i]; + + void *src_udata = s->userdata; + void *src_adata = s->actiondata; + + *d = *s; + d->alt = string_is_empty(d->alt) ? NULL : strdup(d->alt); + d->path = string_is_empty(d->path) ? NULL : strdup(d->path); + d->label = string_is_empty(d->label) ? NULL : strdup(d->label); if (src_udata) - file_list_set_userdata(dst, i, (xmb_node_t*)xmb_copy_node(src_udata)); + file_list_set_userdata(dst, j, (xmb_node_t*)xmb_copy_node(src_udata)); if (src_adata) { void *data = malloc(sizeof(menu_file_list_cbs_t)); memcpy(data, src_adata, sizeof(menu_file_list_cbs_t)); - file_list_set_actiondata(dst, i, data); + file_list_set_actiondata(dst, j, data); } + + ++j; } + + dst->size = j; } static void xmb_list_cache(void *data, enum menu_list_type type, unsigned action) @@ -3954,16 +3966,30 @@ static void xmb_list_cache(void *data, enum menu_list_type type, unsigned action if (!xmb) return; - /* Check whether to enable the horizontal animation. */ - if (settings->bools.menu_horizontal_animation) - xmb_list_deep_copy(selection_buf, xmb->selection_buf_old); - /* FIXME: this shouldn't be happening at all */ if (selection >= xmb->selection_buf_old->size) selection = xmb->selection_buf_old->size ? xmb->selection_buf_old->size - 1 : 0; xmb->selection_ptr_old = selection; + /* Check whether to enable the horizontal animation. */ + if (settings->bools.menu_horizontal_animation) + { + unsigned first = 0, last = 0; + unsigned height = 0; + video_driver_get_size(NULL, &height); + + xmb_calculate_visible_range(xmb, height, selection_buf->size, + xmb->selection_ptr_old, &first, &last); + + xmb_list_deep_copy(selection_buf, xmb->selection_buf_old, first, last); + + xmb->selection_ptr_old -= first; + last -= first; + first = 0; + } + + list_size = xmb_list_get_size(xmb, MENU_LIST_HORIZONTAL) + xmb->system_tab_end; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index fcd2a38541..d745f9028c 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -1550,6 +1550,9 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info, menu_driver_set_thumbnail_system(lpl_basename, sizeof(lpl_basename)); } + /* prealocate the file list */ + file_list_reserve(info->list, list_size); + for (i = 0; i < list_size; i++) { char fill_buf[PATH_MAX_LENGTH];