efficiency of freetype?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

efficiency of freetype?

Post 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.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: efficiency of freetype?

Post 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.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: efficiency of freetype?

Post 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.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: efficiency of freetype?

Post 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?
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: efficiency of freetype?

Post 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
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.
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: efficiency of freetype?

Post 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?
Post Reply