alexfru wrote:How about you make it portable and profile in your regular OS with regular tools?
I'd actually suggest that most of code should be tested and debugged this way until your own OS can do it too.
A big plus on this! SSFN was made portable (relies on a pixel buffer and libc only) and there are several tests for this very reason. I ran those tests through valgrind, strace etc. on a Linux box, I suggest you to do the same with your code.
mrjbom wrote:I noticed that when trying to draw a few lines of text, it is drawn very slowly. And this is present on all emulators, as well as on a real computer.
I also noticed that memory functions are called more than 7000 times, is this normal for the library?
I can't quite figure out if I need to look for problems in the memory manager or somewhere else.
Thanks.
Yes. I have tried to minimize (re)allocation of memory, but there are many arrays to be kept track of when rasterising vector images. Outlines, even-odd pairs, one array per raster line, coloumns for counting pixels to detect hinting grid etc. For this reason you should cache the returned glyph and reuse whenever you can.
If you're using the same style and size for the font, you only need to render each glyph once. You should clear the glyph cache when you call ssfn_select to change the typeface, otherwise reuse them as much as possible. The API is designed in a way to make this easy: the returned glyph is a single byte array without pointers, contains only bitmap or alpha channel (without the actual foreground color), and kerning is implemented in a separate function, independently to the rasterizer etc.
For example, you could have an array of pointers to the glyphs, indexed by the UNICODE code point.
Code: Select all
if (glyphcache[idx] == NULL) {
glyph = glyphcache[idx] = ssfn_render(&ctx, idx);
} else {
glyph = glyphcache[idx];
}
Of course this is the simplest method. With 16 bit code points on 32 bit arch, this would require 256k additional memory. If that's too much, or if you want to handle all the more than one million code points, then you can implement a b-tree or a hash bucket list, etc. to look up the cached glyphs.
Another solution would be to use a font with bitmap glyphs and render that with ssfn_putc. That simple renderer was designed to be called many many times repeatedly, and it does not allocate any extra memory at all. The price for speed is that it cannot scale glyphs.
Cheers,
bzt