diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-04-03 11:16:39 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-10-16 14:50:39 +0100 |
commit | 1718cf5f8a39b922eba3ad1b3c9a9570188362b1 (patch) | |
tree | 4f6bf81cb4f382ca04856b98492289825133c5ae /apps/gui | |
parent | b16bae6fe624d30631bf83290e204197ab136c12 (diff) | |
download | rockbox-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')
-rw-r--r-- | apps/gui/icon.c | 8 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_backdrops.c | 14 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_parser.c | 16 |
3 files changed, 11 insertions, 27 deletions
diff --git a/apps/gui/icon.c b/apps/gui/icon.c index 9fe7090f4a..e78aa6841c 100644 --- a/apps/gui/icon.c +++ b/apps/gui/icon.c | |||
@@ -63,7 +63,6 @@ static struct iconset { | |||
63 | struct bitmap bmp; | 63 | struct bitmap bmp; |
64 | bool loaded; | 64 | bool loaded; |
65 | int handle; | 65 | int handle; |
66 | int handle_locked; | ||
67 | } iconsets[Iconset_Count][NB_SCREENS]; | 66 | } iconsets[Iconset_Count][NB_SCREENS]; |
68 | 67 | ||
69 | #define ICON_HEIGHT(screen) (!iconsets[Iconset_user][screen].loaded ? \ | 68 | #define ICON_HEIGHT(screen) (!iconsets[Iconset_user][screen].loaded ? \ |
@@ -160,8 +159,6 @@ static int buflib_move_callback(int handle, void* current, void* new) | |||
160 | struct iconset *set = &iconsets[i][j]; | 159 | struct iconset *set = &iconsets[i][j]; |
161 | if (set->bmp.data == current) | 160 | if (set->bmp.data == current) |
162 | { | 161 | { |
163 | if (set->handle_locked > 0) | ||
164 | return BUFLIB_CB_CANNOT_MOVE; | ||
165 | set->bmp.data = new; | 162 | set->bmp.data = new; |
166 | return BUFLIB_CB_OK; | 163 | return BUFLIB_CB_OK; |
167 | } | 164 | } |
@@ -201,11 +198,10 @@ static void load_icons(const char* filename, enum Iconset iconset, | |||
201 | goto finished; | 198 | goto finished; |
202 | } | 199 | } |
203 | lseek(fd, 0, SEEK_SET); | 200 | lseek(fd, 0, SEEK_SET); |
201 | core_pin(ic->handle); | ||
204 | ic->bmp.data = core_get_data(ic->handle); | 202 | ic->bmp.data = core_get_data(ic->handle); |
205 | |||
206 | ic->handle_locked = 1; | ||
207 | size_read = read_bmp_fd(fd, &ic->bmp, buf_size, bmpformat, NULL); | 203 | size_read = read_bmp_fd(fd, &ic->bmp, buf_size, bmpformat, NULL); |
208 | ic->handle_locked = 0; | 204 | core_unpin(ic->handle); |
209 | 205 | ||
210 | if (size_read < 0) | 206 | if (size_read < 0) |
211 | { | 207 | { |
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 |
44 | static int handle_being_loaded; | ||
45 | static int current_lcd_backdrop[NB_SCREENS]; | 44 | static int current_lcd_backdrop[NB_SCREENS]; |
46 | 45 | ||
47 | bool skin_backdrop_get_debug(int index, char **path, int *ref_count, size_t *size) | 46 | 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 | |||
65 | 64 | ||
66 | static int buflib_move_callback(int handle, void* current, void* new) | 65 | static 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__ |
1873 | static int currently_loading_handle = -1; | ||
1874 | static int buflib_move_callback(int handle, void* current, void* new) | 1873 | static 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 | } |
1892 | static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL, NULL}; | 1890 | static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL, NULL}; |
1893 | static void lock_handle(int handle) | ||
1894 | { | ||
1895 | currently_loading_handle = handle; | ||
1896 | } | ||
1897 | static void unlock_handle(void) | ||
1898 | { | ||
1899 | currently_loading_handle = -1; | ||
1900 | } | ||
1901 | #endif | 1891 | #endif |
1902 | 1892 | ||
1903 | static int load_skin_bmp(struct wps_data *wps_data, struct bitmap *bitmap, char* bmpdir) | 1893 | 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* | |||
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 | { |