summaryrefslogtreecommitdiff
path: root/apps/gui/skin_engine
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-04-03 11:16:39 +0100
committerAidan MacDonald <amachronic@protonmail.com>2022-10-16 14:50:39 +0100
commit1718cf5f8a39b922eba3ad1b3c9a9570188362b1 (patch)
tree4f6bf81cb4f382ca04856b98492289825133c5ae /apps/gui/skin_engine
parentb16bae6fe624d30631bf83290e204197ab136c12 (diff)
downloadrockbox-1718cf5f8a39b922eba3ad1b3c9a9570188362b1.tar.gz
rockbox-1718cf5f8a39b922eba3ad1b3c9a9570188362b1.zip
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
Diffstat (limited to 'apps/gui/skin_engine')
-rw-r--r--apps/gui/skin_engine/skin_backdrops.c14
-rw-r--r--apps/gui/skin_engine/skin_parser.c16
2 files changed, 9 insertions, 21 deletions
diff --git a/apps/gui/skin_engine/skin_backdrops.c b/apps/gui/skin_engine/skin_backdrops.c
index 1def0812da..215667d585 100644
--- a/apps/gui/skin_engine/skin_backdrops.c
+++ b/apps/gui/skin_engine/skin_backdrops.c
@@ -41,7 +41,6 @@ static struct skin_backdrop {
41} backdrops[NB_BDROPS]; 41} backdrops[NB_BDROPS];
42 42
43#define NB_BDROPS SKINNABLE_SCREENS_COUNT*NB_SCREENS 43#define NB_BDROPS SKINNABLE_SCREENS_COUNT*NB_SCREENS
44static int handle_being_loaded;
45static int current_lcd_backdrop[NB_SCREENS]; 44static int current_lcd_backdrop[NB_SCREENS];
46 45
47bool skin_backdrop_get_debug(int index, char **path, int *ref_count, size_t *size) 46bool 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
65 64
66static int buflib_move_callback(int handle, void* current, void* new) 65static int buflib_move_callback(int handle, void* current, void* new)
67{ 66{
68 if (handle == handle_being_loaded) 67 (void)handle;
69 return BUFLIB_CB_CANNOT_MOVE; 68
70 for (int i=0; i<NB_BDROPS; i++) 69 for (int i=0; i<NB_BDROPS; i++)
71 { 70 {
72 if (backdrops[i].buffer == current) 71 if (backdrops[i].buffer == current)
@@ -96,7 +95,6 @@ bool skin_backdrop_init(void)
96 } 95 }
97 FOR_NB_SCREENS(i) 96 FOR_NB_SCREENS(i)
98 current_lcd_backdrop[i] = -1; 97 current_lcd_backdrop[i] = -1;
99 handle_being_loaded = -1;
100 first_go = false; 98 first_go = false;
101 } 99 }
102 return go_status; 100 return go_status;
@@ -182,16 +180,16 @@ bool skin_backdrops_preload(void)
182 backdrops[i].buffer = core_get_data(backdrops[i].buflib_handle); 180 backdrops[i].buffer = core_get_data(backdrops[i].buflib_handle);
183 if (strcmp(filename, BACKDROP_BUFFERNAME)) 181 if (strcmp(filename, BACKDROP_BUFFERNAME))
184 { 182 {
185 handle_being_loaded = backdrops[i].buflib_handle; 183 core_pin(backdrops[i].buflib_handle);
186 backdrops[i].loaded = 184 backdrops[i].loaded =
187 screens[screen].backdrop_load(filename, backdrops[i].buffer); 185 screens[screen].backdrop_load(filename, backdrops[i].buffer);
186 core_unpin(backdrops[i].buflib_handle);
188 if (!backdrops[i].loaded) 187 if (!backdrops[i].loaded)
189 { 188 {
190 core_free(backdrops[i].buflib_handle); 189 core_free(backdrops[i].buflib_handle);
191 backdrops[i].buflib_handle = -1; 190 backdrops[i].buflib_handle = -1;
192 retval = false; 191 retval = false;
193 } 192 }
194 handle_being_loaded = -1;
195 } 193 }
196 else 194 else
197 backdrops[i].loaded = true; 195 backdrops[i].loaded = true;
@@ -295,12 +293,12 @@ void skin_backdrop_load_setting(void)
295 return; 293 return;
296 } 294 }
297 bool loaded; 295 bool loaded;
296 core_pin(backdrops[i].buflib_handle);
298 backdrops[i].buffer = core_get_data(backdrops[i].buflib_handle); 297 backdrops[i].buffer = core_get_data(backdrops[i].buflib_handle);
299 handle_being_loaded = backdrops[i].buflib_handle;
300 loaded = screens[SCREEN_MAIN].backdrop_load( 298 loaded = screens[SCREEN_MAIN].backdrop_load(
301 global_settings.backdrop_file, 299 global_settings.backdrop_file,
302 backdrops[i].buffer); 300 backdrops[i].buffer);
303 handle_being_loaded = -1; 301 core_unpin(backdrops[i].buflib_handle);
304 backdrops[i].name[2] = loaded ? '.' : '\0'; 302 backdrops[i].name[2] = loaded ? '.' : '\0';
305 backdrops[i].loaded = loaded; 303 backdrops[i].loaded = loaded;
306 return; 304 return;
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
index 047c4735a0..2eef2af7c0 100644
--- a/apps/gui/skin_engine/skin_parser.c
+++ b/apps/gui/skin_engine/skin_parser.c
@@ -1870,13 +1870,11 @@ static void skin_data_reset(struct wps_data *wps_data)
1870} 1870}
1871 1871
1872#ifndef __PCTOOL__ 1872#ifndef __PCTOOL__
1873static int currently_loading_handle = -1;
1874static int buflib_move_callback(int handle, void* current, void* new) 1873static int buflib_move_callback(int handle, void* current, void* new)
1875{ 1874{
1875 (void)handle;
1876 (void)current; 1876 (void)current;
1877 (void)new; 1877 (void)new;
1878 if (handle == currently_loading_handle)
1879 return BUFLIB_CB_CANNOT_MOVE;
1880 /* Any active skins may be scrolling - which means using viewports which 1878 /* Any active skins may be scrolling - which means using viewports which
1881 * will be moved after this callback returns. This is a hammer to make that 1879 * will be moved after this callback returns. This is a hammer to make that
1882 * safe. TODO: use a screwdriver instead. 1880 * safe. TODO: use a screwdriver instead.
@@ -1890,14 +1888,6 @@ static int buflib_move_callback(int handle, void* current, void* new)
1890 return BUFLIB_CB_OK; 1888 return BUFLIB_CB_OK;
1891} 1889}
1892static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL, NULL}; 1890static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL, NULL};
1893static void lock_handle(int handle)
1894{
1895 currently_loading_handle = handle;
1896}
1897static void unlock_handle(void)
1898{
1899 currently_loading_handle = -1;
1900}
1901#endif 1891#endif
1902 1892
1903static int load_skin_bmp(struct wps_data *wps_data, struct bitmap *bitmap, char* bmpdir) 1893static 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*
1944 _stats->buflib_handles++; 1934 _stats->buflib_handles++;
1945 _stats->images_size += buf_size; 1935 _stats->images_size += buf_size;
1946 lseek(fd, 0, SEEK_SET); 1936 lseek(fd, 0, SEEK_SET);
1947 lock_handle(handle); 1937 core_pin(handle);
1948 bitmap->data = core_get_data(handle); 1938 bitmap->data = core_get_data(handle);
1949 int ret = read_bmp_fd(fd, bitmap, buf_size, format, NULL); 1939 int ret = read_bmp_fd(fd, bitmap, buf_size, format, NULL);
1950 bitmap->data = NULL; /* do this to force a crash later if the 1940 bitmap->data = NULL; /* do this to force a crash later if the
1951 caller doesnt call core_get_data() */ 1941 caller doesnt call core_get_data() */
1952 unlock_handle(); 1942 core_unpin(handle);
1953 close(fd); 1943 close(fd);
1954 if (ret > 0) 1944 if (ret > 0)
1955 { 1945 {