Rockbox

  • Status Closed
  • Percent Complete
    100%
  • Task Type Patches
  • Category User Interface → Font/charset
  • Assigned To No-one
  • Operating System All players
  • Severity Low
  • Priority Very Low
  • Reported Version Release 3.9
  • Due in Version Undecided
  • Due Date Undecided
  • Votes
  • Private
Attached to Project: Rockbox
Opened by freddyb - 2011-09-25
Last edited by freddyb - 2011-11-19

FS#12293 - Global default glyph size setting for gui/skins

We should allocate font memory according to the number of glyphs needed because the font coverage can vary quite a bit between a small mono font and a large anti-aliased font for a given buffer size. It’s easy to do this now that font memory is reserved via buflib. This patch adds a global setting for the default number of glyphs for fonts rather than a fixed buffer size for each font. The setting is under Theme Settings>Glyphs to cache, which sets global_settings.glyphs (default 250).

Adds the function font_load_glyphs( char *path, int glyphs );
Adds a #define font_load_whole( char *path ); that tries to load the entire font into memory.
font_load_glyphs now checks if the specified number of glyphs would make the font_cache structure larger than the font file and if so, just loads the whole font file in memory instead.

Closed by  freddyb
2011-11-19 23:40
Reason for closing:  Accepted
Additional comments about closing:   Warning: Undefined array key "typography" in /home/rockbox/flyspray/plugins/dokuwiki/inc/parserutils.php on line 371 Warning: Undefined array key "camelcase" in /home/rockbox/flyspray/plugins/dokuwiki/inc/parserutils.php on line 407

In r31031.

No, this is very much overkill, most times we load a font we want to be able to cache as much of it as possible, but we have to make sure not to waste too much ram doing so. So if you want to add a setting to speficy the maximum actual buffer size that would be fine (and not require an extra few disk accesses on load), but just adding a setting to say how many glpyhs to load is not a good idea.

I disagree. The only way to allocate font memory efficiently is in terms of glyphs. Anything else is just a number out of the air.

This is an example of why font memory should use a smarter allocation system. The following shows how the current behavior is completely inconsistent with needs. Glyph coverage varies by orders of magnitude. The default theme CabbieV2 allocates 1250 glyphs, the iLike theme allocates 8818, while BigInfoAA only allocates 82 for its big font. The argument against reading the font header before loading the font doesn’t make sense to me because the extra read should very inexpensive. I simply do not understand the logic that this is overkill after all the work done to create buflib and move fonts over to it. If the glyphcache file bug gets fixed this would also reduce the chances of someone who uses many glyphs wiping out most of their glyphcache info by loading a large point font.

15-Adobe-Helvetica.fnt loaded (cache). file size 231946 - 60000 bytes - 1250 glyphs
20-Ubuntu-R.fnt loaded (cache). file size 431297 - 60000 bytes - 280 glyphs
38-Ubuntu-R.fnt loaded (cache). file size 656925 - 60000 bytes - 82 glyphs
15-Adobe-Helvetica.fnt loaded (cache). file size 231946 - 60000 bytes - 1250 glyphs
24 iLike.fnt loaded (mem). file_size 48510 - 8818 glyphs
18 iLike.fnt loaded (mem). file_size 48510 - 8818 glyphs
18 iLike.fnt loaded (mem). file_size 48510 - 8818 glyphs
TimesNewRomanPSMT-16.fnt loaded (cache). file size 401709 - 60000 bytes - 256 glyphs
Georgia-19.fnt loaded (cache). file size 253293 - 60000 bytes - 272 glyphs
Army-23.fnt loaded (cache). file size 225679 - 60000 bytes - 180 glyphs
Army-15.fnt loaded (mem). file_size 6305 - 95 glyphs
Army-18.fnt loaded (cache). file size 212355 - 60000 bytes - 300 glyphs
15-Adobe-Helvetica.fnt loaded (cache). file size 231946 - 60000 bytes - 1250 glyphs
DejaVuSans_10.fnt loaded (mem). file_size 57759 - 11351 glyphs
DejaVuSans_15.fnt loaded (cache). file size 79401 - 60000 bytes - 410 glyphs
DejaVuSans_20.fnt loaded (cache). file size 130751 - 60000 bytes - 250 glyphs
FreeSerif-10.fnt loaded (cache). file size 464502 - 60000 bytes - 517 glyphs
FreeSerif-20.fnt loaded (cache). file size 851638 - 60000 bytes - 142 glyphs
FreeSerif-30.fnt loaded (cache). file size 1489538 - 60000 bytes - 64 glyphs

This change adds a #define LIMIT_GLYPH_LOADS for targets with less than 4MB which limits font buffers to MAX_FONT_SIZE even if more glyphs are requested. Hopefully, this addresses the objections.

I’m reopening this to try again. This version includes some refactoring of font loading. The functional changes are the following:

-Creates a theme menu entry for the default number of glyphs to load
-Font_load_ex() is now font_load_ex( name, buffer size, glyphs ).
-Buffer size and glyphs may be zero for defaults.
-Default font_load() allocates the lesser of 256 glyphs or MAX_FONT_SIZE, which can be a significant memory savings (~46000 bytes for 15-Adobe-Helvetica)
-Font buffer will be limited to MAX_FONT_SIZE for targets with less than 4MB, overriding the glyph parameter
-Font buffer can exceed MAX_FONT_SIZE if glyphs are specified and buffer size is not and target mem >= 4MB.
-Font buffer will be limited to buffer size if both parameters are given.
-(The original patch limited the size of the font buffer to the size of the font file but that change was committed to SVN separately.)
-Skin fonts will use the global glyph parameter if not specified in the skin.

Updated version.

Loading...

Available keyboard shortcuts

Tasklist

Task Details

Task Editing