forked from len0rd/rockbox
RaaA: Use the host's malloc() for the skin engine.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28480 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
72964f2571
commit
97857324c3
4 changed files with 97 additions and 5 deletions
|
|
@ -38,11 +38,23 @@
|
|||
#include "skin_buffer.h"
|
||||
#include "statusbar-skinned.h"
|
||||
|
||||
static bool skins_initialising = true;
|
||||
|
||||
/* Hosted platforms use the host malloc to manage the buffer */
|
||||
#if ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
|
||||
static char *skin_buffer = NULL;
|
||||
void theme_init_buffer(void)
|
||||
{
|
||||
skin_buffer = buffer_alloc(SKIN_BUFFER_SIZE);
|
||||
skins_initialising = false;
|
||||
}
|
||||
#else
|
||||
#define skin_buffer NULL
|
||||
void theme_init_buffer(void)
|
||||
{
|
||||
skins_initialising = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
void settings_apply_skins(void)
|
||||
{
|
||||
|
|
@ -149,7 +161,7 @@ struct gui_wps *skin_get_gwps(enum skinnable_screens skin, enum screen_type scre
|
|||
{
|
||||
case CUSTOM_STATUSBAR:
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
if (skin_buffer == NULL)
|
||||
if (skins_initialising)
|
||||
{
|
||||
/* still loading, buffers not initialised yet,
|
||||
* viewport manager calls into the sbs code, not really
|
||||
|
|
|
|||
|
|
@ -1613,11 +1613,15 @@ bool skin_data_load(enum screen_type screen, struct wps_data *wps_data,
|
|||
wps_data->backdrop_id = -1;
|
||||
#endif
|
||||
/* parse the skin source */
|
||||
#if ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
|
||||
skin_buffer_save_position();
|
||||
#endif
|
||||
wps_data->tree = skin_parse(wps_buffer, skin_element_callback, wps_data);
|
||||
if (!wps_data->tree) {
|
||||
skin_data_reset(wps_data);
|
||||
#if ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
|
||||
skin_buffer_restore_position();
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -1639,7 +1643,9 @@ bool skin_data_load(enum screen_type screen, struct wps_data *wps_data,
|
|||
!skin_load_fonts(wps_data))
|
||||
{
|
||||
skin_data_reset(wps_data);
|
||||
#if ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
|
||||
skin_buffer_restore_position();
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -147,7 +147,9 @@ enum infoscreenorder
|
|||
INFO_DISK1, /* capacity or internal capacity/free on hotswap */
|
||||
INFO_DISK2, /* free space or external capacity/free on hotswap */
|
||||
INFO_BUFFER,
|
||||
#if ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
|
||||
INFO_SKIN_USAGE, /* ram usage of the skins */
|
||||
#endif
|
||||
INFO_VERSION,
|
||||
INFO_COUNT
|
||||
};
|
||||
|
|
@ -157,7 +159,9 @@ static const char* info_getname(int selected_item, void *data,
|
|||
{
|
||||
struct info_data *info = (struct info_data*)data;
|
||||
char s1[32];
|
||||
#if defined(HAVE_MULTIVOLUME) || ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
|
||||
char s2[32];
|
||||
#endif
|
||||
if (info->new_data)
|
||||
{
|
||||
fat_size(IF_MV2(0,) &info->size, &info->free);
|
||||
|
|
@ -242,12 +246,14 @@ static const char* info_getname(int selected_item, void *data,
|
|||
snprintf(buffer, buffer_len, SIZE_FMT, str(LANG_DISK_SIZE_INFO), s1);
|
||||
#endif
|
||||
break;
|
||||
#if ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
|
||||
case INFO_SKIN_USAGE:
|
||||
output_dyn_value(s1, sizeof s1, skin_buffer_usage(), byte_units, true);
|
||||
output_dyn_value(s2, sizeof s2, skin_buffer_usage()
|
||||
+skin_buffer_freespace(), byte_units, true);
|
||||
snprintf(buffer, buffer_len, "%s %s / %s", str(LANG_SKIN_RAM_USAGE), s1, s2);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
|
@ -328,10 +334,12 @@ static int info_speak_item(int selected_item, void * data)
|
|||
output_dyn_value(NULL, 0, info->size, kbyte_units, true);
|
||||
#endif
|
||||
break;
|
||||
#if ((CONFIG_PLATFORM&PLATFORM_HOSTED) == 0)
|
||||
case INFO_SKIN_USAGE:
|
||||
talk_id(LANG_SKIN_RAM_USAGE, false);
|
||||
output_dyn_value(NULL, 0, skin_buffer_usage(), byte_units, true);
|
||||
break;
|
||||
#endif
|
||||
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
* $Id: skin_buffer.c 25962 2010-05-12 09:31:40Z jdgordon $
|
||||
*
|
||||
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
||||
* Copyright (C) 2009 Jonathan Gordon
|
||||
* Copyright (C) 2010 Jonathan Gordon
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
@ -26,17 +26,72 @@
|
|||
|
||||
#include "skin_buffer.h"
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* This code handles buffer allocation for the entire skin system.
|
||||
* This needs to work in 3 different situations:
|
||||
* 1) as a stand alone library. ROCKBOX isnt defined, alloc using malloc()
|
||||
* and free the skin elements only (no callbacks doing more allocation)
|
||||
* 2) ROCKBOX builds for normal targets, alloc from a single big buffer
|
||||
* which origionally came from the audio buffer, likely to run out of
|
||||
* room with large themes. No need to free anything, just restore to
|
||||
* the start of our buffer
|
||||
* 3) ROCKBOX "application/hosted" builds, alloc using the hosts malloc().
|
||||
* We need to keep track of all allocations so they can be free()'d easily
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifdef ROCKBOX
|
||||
#include "config.h"
|
||||
|
||||
# if (CONFIG_PLATFORM&PLATFORM_HOSTED)
|
||||
# define USE_HOST_MALLOC
|
||||
# else
|
||||
# define USE_ROCKBOX_ALLOC
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_ROCKBOX_ALLOC
|
||||
static size_t buf_size;
|
||||
static unsigned char *buffer_start = NULL;
|
||||
static unsigned char *buffer_front = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef USE_HOST_MALLOC
|
||||
|
||||
struct malloc_object {
|
||||
void* object;
|
||||
struct malloc_object *next;
|
||||
};
|
||||
struct malloc_object *first = NULL, *last = NULL;
|
||||
|
||||
void skin_free_malloced(void)
|
||||
{
|
||||
struct malloc_object *obj = first, *this;
|
||||
while (obj)
|
||||
{
|
||||
this = obj;
|
||||
obj = this->next;
|
||||
free(this->object);
|
||||
free(this);
|
||||
}
|
||||
first = NULL;
|
||||
last = NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void skin_buffer_init(char* buffer, size_t size)
|
||||
{
|
||||
#if defined(ROCKBOX)
|
||||
#ifdef USE_ROCKBOX_ALLOC
|
||||
buffer_start = buffer_front = buffer;
|
||||
buf_size = size;
|
||||
#elif defined(USE_HOST_MALLOC)
|
||||
(void)buffer; (void)size;
|
||||
skin_free_malloced();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -44,13 +99,24 @@ void skin_buffer_init(char* buffer, size_t size)
|
|||
void* skin_buffer_alloc(size_t size)
|
||||
{
|
||||
void *retval = NULL;
|
||||
#ifdef ROCKBOX
|
||||
#ifdef USE_ROCKBOX_ALLOC
|
||||
/* 32-bit aligned */
|
||||
size = (size + 3) & ~3;
|
||||
if (size > skin_buffer_freespace())
|
||||
return NULL;
|
||||
retval = buffer_front;
|
||||
buffer_front += size;
|
||||
#elif defined(USE_HOST_MALLOC)
|
||||
struct malloc_object *obj = malloc(sizeof (struct malloc_object));
|
||||
if (!obj)
|
||||
return NULL;
|
||||
obj->object = malloc(size);
|
||||
obj->next = NULL;
|
||||
if (last == NULL)
|
||||
first = last = obj;
|
||||
else
|
||||
last->next = obj;
|
||||
retval = obj->object;
|
||||
#else
|
||||
retval = malloc(size);
|
||||
#endif
|
||||
|
|
@ -58,7 +124,7 @@ void* skin_buffer_alloc(size_t size)
|
|||
}
|
||||
|
||||
|
||||
#ifdef ROCKBOX
|
||||
#ifdef USE_ROCKBOX_ALLOC
|
||||
/* get the number of bytes currently being used */
|
||||
size_t skin_buffer_usage(void)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue