1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Jonathan Gordon 2010-08-25 14:11:38 +00:00
parent 05d16b1d4e
commit faaf431d32
7 changed files with 59 additions and 9 deletions

View file

@ -628,6 +628,35 @@ void glyph_cache_save(struct font* pf)
return;
}
int get_glyph_size(const char *path)
{
struct font f;
int overhead;
char buf[FONT_HEADER_SIZE];
f.buffer_start = buf;
f.buffer_size = sizeof(buf);
f.buffer_position = buf;
f.fd = open(path, O_RDONLY|O_BINARY);
if(f.fd < 0)
return 0;
read(f.fd, f.buffer_position, FONT_HEADER_SIZE);
f.buffer_end = f.buffer_position + FONT_HEADER_SIZE;
if( !font_load_header(&f) )
{
close(f.fd);
return 0;
}
close(f.fd);
overhead = LRU_SLOT_OVERHEAD + sizeof(struct font_cache_entry) +
sizeof( unsigned short);
return overhead + (f.maxwidth * ((f.height + 7) / 8));
}
static int ushortcmp(const void *a, const void *b)
{
return ((int)(*(unsigned short*)a - *(unsigned short*)b));