summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/gui/skin_engine/skin_engine.c14
-rw-r--r--apps/gui/skin_engine/skin_parser.c6
-rw-r--r--apps/menus/main_menu.c8
-rw-r--r--lib/skin_parser/skin_buffer.c74
4 files changed, 97 insertions, 5 deletions
diff --git a/apps/gui/skin_engine/skin_engine.c b/apps/gui/skin_engine/skin_engine.c
index 8bf165812a..960bbdb313 100644
--- a/apps/gui/skin_engine/skin_engine.c
+++ b/apps/gui/skin_engine/skin_engine.c
@@ -38,11 +38,23 @@
38#include "skin_buffer.h" 38#include "skin_buffer.h"
39#include "statusbar-skinned.h" 39#include "statusbar-skinned.h"
40 40
41static bool skins_initialising = true;
42
43/* Hosted platforms use the host malloc to manage the buffer */
44#if ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
41static char *skin_buffer = NULL; 45static char *skin_buffer = NULL;
42void theme_init_buffer(void) 46void theme_init_buffer(void)
43{ 47{
44 skin_buffer = buffer_alloc(SKIN_BUFFER_SIZE); 48 skin_buffer = buffer_alloc(SKIN_BUFFER_SIZE);
49 skins_initialising = false;
45} 50}
51#else
52#define skin_buffer NULL
53void theme_init_buffer(void)
54{
55 skins_initialising = false;
56}
57#endif
46 58
47void settings_apply_skins(void) 59void settings_apply_skins(void)
48{ 60{
@@ -149,7 +161,7 @@ struct gui_wps *skin_get_gwps(enum skinnable_screens skin, enum screen_type scre
149 { 161 {
150 case CUSTOM_STATUSBAR: 162 case CUSTOM_STATUSBAR:
151#ifdef HAVE_LCD_BITMAP 163#ifdef HAVE_LCD_BITMAP
152 if (skin_buffer == NULL) 164 if (skins_initialising)
153 { 165 {
154 /* still loading, buffers not initialised yet, 166 /* still loading, buffers not initialised yet,
155 * viewport manager calls into the sbs code, not really 167 * viewport manager calls into the sbs code, not really
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
index 43c2ffa304..c0ea3e3ca9 100644
--- a/apps/gui/skin_engine/skin_parser.c
+++ b/apps/gui/skin_engine/skin_parser.c
@@ -1613,11 +1613,15 @@ bool skin_data_load(enum screen_type screen, struct wps_data *wps_data,
1613 wps_data->backdrop_id = -1; 1613 wps_data->backdrop_id = -1;
1614#endif 1614#endif
1615 /* parse the skin source */ 1615 /* parse the skin source */
1616#if ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
1616 skin_buffer_save_position(); 1617 skin_buffer_save_position();
1618#endif
1617 wps_data->tree = skin_parse(wps_buffer, skin_element_callback, wps_data); 1619 wps_data->tree = skin_parse(wps_buffer, skin_element_callback, wps_data);
1618 if (!wps_data->tree) { 1620 if (!wps_data->tree) {
1619 skin_data_reset(wps_data); 1621 skin_data_reset(wps_data);
1622#if ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
1620 skin_buffer_restore_position(); 1623 skin_buffer_restore_position();
1624#endif
1621 return false; 1625 return false;
1622 } 1626 }
1623 1627
@@ -1639,7 +1643,9 @@ bool skin_data_load(enum screen_type screen, struct wps_data *wps_data,
1639 !skin_load_fonts(wps_data)) 1643 !skin_load_fonts(wps_data))
1640 { 1644 {
1641 skin_data_reset(wps_data); 1645 skin_data_reset(wps_data);
1646#if ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
1642 skin_buffer_restore_position(); 1647 skin_buffer_restore_position();
1648#endif
1643 return false; 1649 return false;
1644 } 1650 }
1645#endif 1651#endif
diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c
index 1d22dba7ea..98f664eda6 100644
--- a/apps/menus/main_menu.c
+++ b/apps/menus/main_menu.c
@@ -147,7 +147,9 @@ enum infoscreenorder
147 INFO_DISK1, /* capacity or internal capacity/free on hotswap */ 147 INFO_DISK1, /* capacity or internal capacity/free on hotswap */
148 INFO_DISK2, /* free space or external capacity/free on hotswap */ 148 INFO_DISK2, /* free space or external capacity/free on hotswap */
149 INFO_BUFFER, 149 INFO_BUFFER,
150#if ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
150 INFO_SKIN_USAGE, /* ram usage of the skins */ 151 INFO_SKIN_USAGE, /* ram usage of the skins */
152#endif
151 INFO_VERSION, 153 INFO_VERSION,
152 INFO_COUNT 154 INFO_COUNT
153}; 155};
@@ -157,7 +159,9 @@ static const char* info_getname(int selected_item, void *data,
157{ 159{
158 struct info_data *info = (struct info_data*)data; 160 struct info_data *info = (struct info_data*)data;
159 char s1[32]; 161 char s1[32];
162#if defined(HAVE_MULTIVOLUME) || ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
160 char s2[32]; 163 char s2[32];
164#endif
161 if (info->new_data) 165 if (info->new_data)
162 { 166 {
163 fat_size(IF_MV2(0,) &info->size, &info->free); 167 fat_size(IF_MV2(0,) &info->size, &info->free);
@@ -242,12 +246,14 @@ static const char* info_getname(int selected_item, void *data,
242 snprintf(buffer, buffer_len, SIZE_FMT, str(LANG_DISK_SIZE_INFO), s1); 246 snprintf(buffer, buffer_len, SIZE_FMT, str(LANG_DISK_SIZE_INFO), s1);
243#endif 247#endif
244 break; 248 break;
249#if ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
245 case INFO_SKIN_USAGE: 250 case INFO_SKIN_USAGE:
246 output_dyn_value(s1, sizeof s1, skin_buffer_usage(), byte_units, true); 251 output_dyn_value(s1, sizeof s1, skin_buffer_usage(), byte_units, true);
247 output_dyn_value(s2, sizeof s2, skin_buffer_usage() 252 output_dyn_value(s2, sizeof s2, skin_buffer_usage()
248 +skin_buffer_freespace(), byte_units, true); 253 +skin_buffer_freespace(), byte_units, true);
249 snprintf(buffer, buffer_len, "%s %s / %s", str(LANG_SKIN_RAM_USAGE), s1, s2); 254 snprintf(buffer, buffer_len, "%s %s / %s", str(LANG_SKIN_RAM_USAGE), s1, s2);
250 break; 255 break;
256#endif
251 } 257 }
252 return buffer; 258 return buffer;
253} 259}
@@ -328,10 +334,12 @@ static int info_speak_item(int selected_item, void * data)
328 output_dyn_value(NULL, 0, info->size, kbyte_units, true); 334 output_dyn_value(NULL, 0, info->size, kbyte_units, true);
329#endif 335#endif
330 break; 336 break;
337#if ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
331 case INFO_SKIN_USAGE: 338 case INFO_SKIN_USAGE:
332 talk_id(LANG_SKIN_RAM_USAGE, false); 339 talk_id(LANG_SKIN_RAM_USAGE, false);
333 output_dyn_value(NULL, 0, skin_buffer_usage(), byte_units, true); 340 output_dyn_value(NULL, 0, skin_buffer_usage(), byte_units, true);
334 break; 341 break;
342#endif
335 343
336 } 344 }
337 return 0; 345 return 0;
diff --git a/lib/skin_parser/skin_buffer.c b/lib/skin_parser/skin_buffer.c
index ecfe04b167..608b03434d 100644
--- a/lib/skin_parser/skin_buffer.c
+++ b/lib/skin_parser/skin_buffer.c
@@ -8,7 +8,7 @@
8 * $Id: skin_buffer.c 25962 2010-05-12 09:31:40Z jdgordon $ 8 * $Id: skin_buffer.c 25962 2010-05-12 09:31:40Z jdgordon $
9 * 9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing 10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 * Copyright (C) 2009 Jonathan Gordon 11 * Copyright (C) 2010 Jonathan Gordon
12 * 12 *
13 * This program is free software; you can redistribute it and/or 13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License 14 * modify it under the terms of the GNU General Public License
@@ -26,17 +26,72 @@
26 26
27#include "skin_buffer.h" 27#include "skin_buffer.h"
28 28
29/****************************************************************************
30 *
31 * This code handles buffer allocation for the entire skin system.
32 * This needs to work in 3 different situations:
33 * 1) as a stand alone library. ROCKBOX isnt defined, alloc using malloc()
34 * and free the skin elements only (no callbacks doing more allocation)
35 * 2) ROCKBOX builds for normal targets, alloc from a single big buffer
36 * which origionally came from the audio buffer, likely to run out of
37 * room with large themes. No need to free anything, just restore to
38 * the start of our buffer
39 * 3) ROCKBOX "application/hosted" builds, alloc using the hosts malloc().
40 * We need to keep track of all allocations so they can be free()'d easily
41 *
42 *
43 ****************************************************************************/
44
45
29#ifdef ROCKBOX 46#ifdef ROCKBOX
47#include "config.h"
48
49# if (CONFIG_PLATFORM&PLATFORM_HOSTED)
50# define USE_HOST_MALLOC
51# else
52# define USE_ROCKBOX_ALLOC
53# endif
54
55#endif
56
57#ifdef USE_ROCKBOX_ALLOC
30static size_t buf_size; 58static size_t buf_size;
31static unsigned char *buffer_start = NULL; 59static unsigned char *buffer_start = NULL;
32static unsigned char *buffer_front = NULL; 60static unsigned char *buffer_front = NULL;
33#endif 61#endif
34 62
63#ifdef USE_HOST_MALLOC
64
65struct malloc_object {
66 void* object;
67 struct malloc_object *next;
68};
69struct malloc_object *first = NULL, *last = NULL;
70
71void skin_free_malloced(void)
72{
73 struct malloc_object *obj = first, *this;
74 while (obj)
75 {
76 this = obj;
77 obj = this->next;
78 free(this->object);
79 free(this);
80 }
81 first = NULL;
82 last = NULL;
83}
84
85#endif
86
35void skin_buffer_init(char* buffer, size_t size) 87void skin_buffer_init(char* buffer, size_t size)
36{ 88{
37#if defined(ROCKBOX) 89#ifdef USE_ROCKBOX_ALLOC
38 buffer_start = buffer_front = buffer; 90 buffer_start = buffer_front = buffer;
39 buf_size = size; 91 buf_size = size;
92#elif defined(USE_HOST_MALLOC)
93 (void)buffer; (void)size;
94 skin_free_malloced();
40#endif 95#endif
41} 96}
42 97
@@ -44,13 +99,24 @@ void skin_buffer_init(char* buffer, size_t size)
44void* skin_buffer_alloc(size_t size) 99void* skin_buffer_alloc(size_t size)
45{ 100{
46 void *retval = NULL; 101 void *retval = NULL;
47#ifdef ROCKBOX 102#ifdef USE_ROCKBOX_ALLOC
48 /* 32-bit aligned */ 103 /* 32-bit aligned */
49 size = (size + 3) & ~3; 104 size = (size + 3) & ~3;
50 if (size > skin_buffer_freespace()) 105 if (size > skin_buffer_freespace())
51 return NULL; 106 return NULL;
52 retval = buffer_front; 107 retval = buffer_front;
53 buffer_front += size; 108 buffer_front += size;
109#elif defined(USE_HOST_MALLOC)
110 struct malloc_object *obj = malloc(sizeof (struct malloc_object));
111 if (!obj)
112 return NULL;
113 obj->object = malloc(size);
114 obj->next = NULL;
115 if (last == NULL)
116 first = last = obj;
117 else
118 last->next = obj;
119 retval = obj->object;
54#else 120#else
55 retval = malloc(size); 121 retval = malloc(size);
56#endif 122#endif
@@ -58,7 +124,7 @@ void* skin_buffer_alloc(size_t size)
58} 124}
59 125
60 126
61#ifdef ROCKBOX 127#ifdef USE_ROCKBOX_ALLOC
62/* get the number of bytes currently being used */ 128/* get the number of bytes currently being used */
63size_t skin_buffer_usage(void) 129size_t skin_buffer_usage(void)
64{ 130{