Page 1 of 1

efficiency of freetype?

Posted: Sat Jun 04, 2016 11:07 am
by mariuszp
Do any of your GUIs use FreeType for text rendering? If so, how efficient is it?

I have seen some advice on the Internet claiming that FreeType can be extremely inefficient, and they recommended using it to pre-render the characters you want to use, and then reuse the cached bitmaps.

My window manager re-renders all windows (including their captions) whenever the screen is changed (e.g. the mouse moves). (Note however, that the contents of each window are not re-drawn; they are stored in a buffer until an application updates it, and the manager just blits them to the screen during the update). Currently, if I move the mouse, and I'm using FreeType to render the captions, it takes a few seconds for the screen to respond. But since this problem does not occur when I type, I;m assuming it's most probably to do with bad contention issues as spinlocks (instead of mutexes, which I have not yet implemented in userspace, but I'm on it), are used to lock the window list, the cursor positon etc.

Either way, I just wanted to ask who uses FreeType in their GUIs for rendering text, and if there are any recommendations on how to use it efficiently. Currently my system works as follows: an application that wants to draw text creates a Pen object; this initialises FreeType and stores the FT_Library handle in the Pen object, then it loads the default font (as an FT_Face), and the application can make calls to write text using the pen, chaning the font etc inbetween segments if necessary, and the graphics library lays out the text. Every time the screen freezes, I can see the HDD read LED (the virtual one, in VirtualBox) is on, so I think it might also be that re-reading the font on each redraw is not the best idea.

Re: efficiency of freetype?

Posted: Sat Jun 04, 2016 2:19 pm
by BrightLight
I think rendering all the characters you need and caching them seems like a good idea. And whenever the user changes the font, you re-render them all and store them in memory.

Re: efficiency of freetype?

Posted: Sat Jun 04, 2016 5:26 pm
by mariuszp
omarrx024 wrote:I think rendering all the characters you need and caching them seems like a good idea. And whenever the user changes the font, you re-render them all and store them in memory.
I can't predict which characters the application will need. I thought maybe a better idea would be to have a Font object which stores the face plus cached bitmaps of all characters that were already rendered, and the application may choose the delete or keep certain Font objects.

Re: efficiency of freetype?

Posted: Sat Jun 04, 2016 5:40 pm
by BrightLight
mariuszp wrote:I can't predict which characters the application will need. I thought maybe a better idea would be to have a Font object which stores the face plus cached bitmaps of all characters that were already rendered, and the application may choose the delete or keep certain Font objects.
+1.
Or maybe just render every character supported by the font and increase your boot time by less than 1 second, and then store everything in a buffer?

Re: efficiency of freetype?

Posted: Sun Jun 05, 2016 3:23 am
by Brendan
Hi,
mariuszp wrote:
omarrx024 wrote:I think rendering all the characters you need and caching them seems like a good idea. And whenever the user changes the font, you re-render them all and store them in memory.
I can't predict which characters the application will need. I thought maybe a better idea would be to have a Font object which stores the face plus cached bitmaps of all characters that were already rendered, and the application may choose the delete or keep certain Font objects.
You can't cache individual characters - it ruins kerning, and breaks ligatures (especially in cursive scripts and/or scripts like Arabic).

Instead; cache larger things (e.g. paragraphs) as a "1 alpha value per pixel" bitmap.


Cheers,

Brendan

Re: efficiency of freetype?

Posted: Sun Jun 05, 2016 5:16 am
by mariuszp
Brendan wrote:Hi,
mariuszp wrote:
omarrx024 wrote:I think rendering all the characters you need and caching them seems like a good idea. And whenever the user changes the font, you re-render them all and store them in memory.
I can't predict which characters the application will need. I thought maybe a better idea would be to have a Font object which stores the face plus cached bitmaps of all characters that were already rendered, and the application may choose the delete or keep certain Font objects.
You can't cache individual characters - it ruins kerning, and breaks ligatures (especially in cursive scripts and/or scripts like Arabic).

Instead; cache larger things (e.g. paragraphs) as a "1 alpha value per pixel" bitmap.


Cheers,

Brendan
So for example I could store the window captions pre-rendered in a bitmap until they're changed?

Furthermore; can FreeType actually be used, on its own, to support Arabic text? Would I then just get negative "advance" values for X? How does that work?