diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2010-08-25 14:11:38 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2010-08-25 14:11:38 +0000 |
commit | faaf431d321f30881ac39342d4cdc2170b922cb6 (patch) | |
tree | 23689929fef19f4d572157e53eeef652057af8e8 /apps/gui | |
parent | 05d16b1d4e8947b23afc64a52ccfccbf2284d97b (diff) |
Accept FS#11567 by Fred Bauer - better memory management for the skin fonts
%Fl now takes an optional 3rd param which is the number of glyphs to cache (default to 256). the smaller the number, the less ram will be used (i.e using 15 for a font which only shown numbers is a good idea)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27882 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui')
-rw-r--r-- | apps/gui/skin_engine/skin_fonts.c | 14 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_fonts.h | 6 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_parser.c | 10 |
3 files changed, 24 insertions, 6 deletions
diff --git a/apps/gui/skin_engine/skin_fonts.c b/apps/gui/skin_engine/skin_fonts.c index 2510c8c68c..b00f1572b8 100644 --- a/apps/gui/skin_engine/skin_fonts.c +++ b/apps/gui/skin_engine/skin_fonts.c @@ -57,9 +57,10 @@ void skin_font_init(void) } /* load a font into the skin buffer. return the font id. */ -int skin_font_load(char* font_name) +int skin_font_load(char* font_name, int glyphs) { int i; + int skin_font_size; struct font *pf; struct skin_font_info *font = NULL; char filename[MAX_PATH]; @@ -92,7 +93,14 @@ int skin_font_load(char* font_name) pf = &font->font; if (!font->buffer) { - pf->buffer_start = (char*)skin_buffer_alloc(SKIN_FONT_SIZE); + if (!glyphs) + glyphs = GLYPHS_TO_CACHE; + skin_font_size = glyphs * get_glyph_size(filename); + if ( !skin_font_size ) + { + skin_font_size = SKIN_FONT_SIZE; + } + pf->buffer_start = (char*)skin_buffer_alloc(skin_font_size); if (!pf->buffer_start) return -1; font->buffer = pf->buffer_start; @@ -101,7 +109,7 @@ int skin_font_load(char* font_name) { pf->buffer_start = font->buffer; } - pf->buffer_size = SKIN_FONT_SIZE; + pf->buffer_size = skin_font_size; pf->fd = -1; font->font_id = font_load(pf, filename); diff --git a/apps/gui/skin_engine/skin_fonts.h b/apps/gui/skin_engine/skin_fonts.h index 2988b43415..698ed4fe7c 100644 --- a/apps/gui/skin_engine/skin_fonts.h +++ b/apps/gui/skin_engine/skin_fonts.h @@ -36,11 +36,13 @@ #else #define SKIN_FONT_SIZE (1024*3) #endif +#define GLYPHS_TO_CACHE 256 void skin_font_init(void); -/* load a font into the skin buffer. return the font id. */ -int skin_font_load(char* font_name); +/* load a font into the skin buffer. return the font id. + * reserve room for glyphs glyphs */ +int skin_font_load(char* font_name, int glyphs); /* unload a skin font. If a font has been loaded more than once it wont actually * be unloaded untill all references have been unloaded */ diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index 2c766162c3..a5ff64ac9d 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c @@ -343,6 +343,7 @@ static int parse_image_load(struct skin_element *element, struct skin_font { int id; /* the id from font_load */ char *name; /* filename without path and extension */ + int glyphs; /* how many glyphs to reserve room for */ }; static struct skin_font skinfonts[MAXUSERFONTS]; static int parse_font_load(struct skin_element *element, @@ -352,8 +353,13 @@ static int parse_font_load(struct skin_element *element, (void)wps_data; (void)token; int id = element->params[0].data.number; char *filename = element->params[1].data.text; + int glyphs; char *ptr; + if(element->params_count > 2) + glyphs = element->params[2].data.number; + else + glyphs = GLYPHS_TO_CACHE; #if defined(DEBUG) || defined(SIMULATOR) if (skinfonts[id-FONT_FIRSTUSERFONT].name != NULL) { @@ -367,6 +373,7 @@ static int parse_font_load(struct skin_element *element, return WPS_ERROR_INVALID_PARAM; skinfonts[id-FONT_FIRSTUSERFONT].id = -1; skinfonts[id-FONT_FIRSTUSERFONT].name = filename; + skinfonts[id-FONT_FIRSTUSERFONT].glyphs = glyphs; return 0; } @@ -1160,7 +1167,8 @@ static bool skin_load_fonts(struct wps_data *data) { char *dot = strchr(font->name, '.'); *dot = '\0'; - font->id = skin_font_load(font->name); + font->id = skin_font_load(font->name, + skinfonts[font_id-FONT_FIRSTUSERFONT].glyphs); } if (font->id < 0) |