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.
efficiency of freetype?
- BrightLight
- Member
- Posts: 901
- Joined: Sat Dec 27, 2014 9:11 am
- Location: Maadi, Cairo, Egypt
- Contact:
Re: efficiency of freetype?
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.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
Re: efficiency of freetype?
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.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.
- BrightLight
- Member
- Posts: 901
- Joined: Sat Dec 27, 2014 9:11 am
- Location: Maadi, Cairo, Egypt
- Contact:
Re: efficiency of freetype?
+1.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.
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?
You know your OS is advanced when you stop using the Intel programming guide as a reference.
Re: efficiency of freetype?
Hi,
Instead; cache larger things (e.g. paragraphs) as a "1 alpha value per pixel" bitmap.
Cheers,
Brendan
You can't cache individual characters - it ruins kerning, and breaks ligatures (especially in cursive scripts and/or scripts like Arabic).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.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.
Instead; cache larger things (e.g. paragraphs) as a "1 alpha value per pixel" bitmap.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: efficiency of freetype?
So for example I could store the window captions pre-rendered in a bitmap until they're changed?Brendan wrote:Hi,
You can't cache individual characters - it ruins kerning, and breaks ligatures (especially in cursive scripts and/or scripts like Arabic).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.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.
Instead; cache larger things (e.g. paragraphs) as a "1 alpha value per pixel" bitmap.
Cheers,
Brendan
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?