mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-09 13:12:37 -05:00
Convert a number of allocations to use buflib pinning
Several places in the codebase implemented an ad-hoc form of pinning; they can be converted to use buflib pinning instead. Change-Id: I4450be007e80f6c9cc9f56c2929fa4b9b85ebff3
This commit is contained in:
parent
b16bae6fe6
commit
1718cf5f8a
10 changed files with 94 additions and 158 deletions
|
|
@ -63,7 +63,6 @@ static struct iconset {
|
|||
struct bitmap bmp;
|
||||
bool loaded;
|
||||
int handle;
|
||||
int handle_locked;
|
||||
} iconsets[Iconset_Count][NB_SCREENS];
|
||||
|
||||
#define ICON_HEIGHT(screen) (!iconsets[Iconset_user][screen].loaded ? \
|
||||
|
|
@ -160,8 +159,6 @@ static int buflib_move_callback(int handle, void* current, void* new)
|
|||
struct iconset *set = &iconsets[i][j];
|
||||
if (set->bmp.data == current)
|
||||
{
|
||||
if (set->handle_locked > 0)
|
||||
return BUFLIB_CB_CANNOT_MOVE;
|
||||
set->bmp.data = new;
|
||||
return BUFLIB_CB_OK;
|
||||
}
|
||||
|
|
@ -201,11 +198,10 @@ static void load_icons(const char* filename, enum Iconset iconset,
|
|||
goto finished;
|
||||
}
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
core_pin(ic->handle);
|
||||
ic->bmp.data = core_get_data(ic->handle);
|
||||
|
||||
ic->handle_locked = 1;
|
||||
size_read = read_bmp_fd(fd, &ic->bmp, buf_size, bmpformat, NULL);
|
||||
ic->handle_locked = 0;
|
||||
core_unpin(ic->handle);
|
||||
|
||||
if (size_read < 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ static struct skin_backdrop {
|
|||
} backdrops[NB_BDROPS];
|
||||
|
||||
#define NB_BDROPS SKINNABLE_SCREENS_COUNT*NB_SCREENS
|
||||
static int handle_being_loaded;
|
||||
static int current_lcd_backdrop[NB_SCREENS];
|
||||
|
||||
bool skin_backdrop_get_debug(int index, char **path, int *ref_count, size_t *size)
|
||||
|
|
@ -65,8 +64,8 @@ bool skin_backdrop_get_debug(int index, char **path, int *ref_count, size_t *siz
|
|||
|
||||
static int buflib_move_callback(int handle, void* current, void* new)
|
||||
{
|
||||
if (handle == handle_being_loaded)
|
||||
return BUFLIB_CB_CANNOT_MOVE;
|
||||
(void)handle;
|
||||
|
||||
for (int i=0; i<NB_BDROPS; i++)
|
||||
{
|
||||
if (backdrops[i].buffer == current)
|
||||
|
|
@ -96,7 +95,6 @@ bool skin_backdrop_init(void)
|
|||
}
|
||||
FOR_NB_SCREENS(i)
|
||||
current_lcd_backdrop[i] = -1;
|
||||
handle_being_loaded = -1;
|
||||
first_go = false;
|
||||
}
|
||||
return go_status;
|
||||
|
|
@ -182,16 +180,16 @@ bool skin_backdrops_preload(void)
|
|||
backdrops[i].buffer = core_get_data(backdrops[i].buflib_handle);
|
||||
if (strcmp(filename, BACKDROP_BUFFERNAME))
|
||||
{
|
||||
handle_being_loaded = backdrops[i].buflib_handle;
|
||||
core_pin(backdrops[i].buflib_handle);
|
||||
backdrops[i].loaded =
|
||||
screens[screen].backdrop_load(filename, backdrops[i].buffer);
|
||||
core_unpin(backdrops[i].buflib_handle);
|
||||
if (!backdrops[i].loaded)
|
||||
{
|
||||
core_free(backdrops[i].buflib_handle);
|
||||
backdrops[i].buflib_handle = -1;
|
||||
retval = false;
|
||||
}
|
||||
handle_being_loaded = -1;
|
||||
}
|
||||
else
|
||||
backdrops[i].loaded = true;
|
||||
|
|
@ -295,12 +293,12 @@ void skin_backdrop_load_setting(void)
|
|||
return;
|
||||
}
|
||||
bool loaded;
|
||||
core_pin(backdrops[i].buflib_handle);
|
||||
backdrops[i].buffer = core_get_data(backdrops[i].buflib_handle);
|
||||
handle_being_loaded = backdrops[i].buflib_handle;
|
||||
loaded = screens[SCREEN_MAIN].backdrop_load(
|
||||
global_settings.backdrop_file,
|
||||
backdrops[i].buffer);
|
||||
handle_being_loaded = -1;
|
||||
core_unpin(backdrops[i].buflib_handle);
|
||||
backdrops[i].name[2] = loaded ? '.' : '\0';
|
||||
backdrops[i].loaded = loaded;
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1870,13 +1870,11 @@ static void skin_data_reset(struct wps_data *wps_data)
|
|||
}
|
||||
|
||||
#ifndef __PCTOOL__
|
||||
static int currently_loading_handle = -1;
|
||||
static int buflib_move_callback(int handle, void* current, void* new)
|
||||
{
|
||||
(void)handle;
|
||||
(void)current;
|
||||
(void)new;
|
||||
if (handle == currently_loading_handle)
|
||||
return BUFLIB_CB_CANNOT_MOVE;
|
||||
/* Any active skins may be scrolling - which means using viewports which
|
||||
* will be moved after this callback returns. This is a hammer to make that
|
||||
* safe. TODO: use a screwdriver instead.
|
||||
|
|
@ -1890,14 +1888,6 @@ static int buflib_move_callback(int handle, void* current, void* new)
|
|||
return BUFLIB_CB_OK;
|
||||
}
|
||||
static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL, NULL};
|
||||
static void lock_handle(int handle)
|
||||
{
|
||||
currently_loading_handle = handle;
|
||||
}
|
||||
static void unlock_handle(void)
|
||||
{
|
||||
currently_loading_handle = -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int load_skin_bmp(struct wps_data *wps_data, struct bitmap *bitmap, char* bmpdir)
|
||||
|
|
@ -1944,12 +1934,12 @@ static int load_skin_bmp(struct wps_data *wps_data, struct bitmap *bitmap, char*
|
|||
_stats->buflib_handles++;
|
||||
_stats->images_size += buf_size;
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
lock_handle(handle);
|
||||
core_pin(handle);
|
||||
bitmap->data = core_get_data(handle);
|
||||
int ret = read_bmp_fd(fd, bitmap, buf_size, format, NULL);
|
||||
bitmap->data = NULL; /* do this to force a crash later if the
|
||||
caller doesnt call core_get_data() */
|
||||
unlock_handle();
|
||||
core_unpin(handle);
|
||||
close(fd);
|
||||
if (ret > 0)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue