Open nox opened 4 years ago
I don't think FreeType is thread-safe in the same way though. (It's thread-safe in that the library can be used from multiple threads, but I don't think FT_Face
methods take locks.) So if we're going to make fonts Sync we need to audit the methods to make sure non-thread-safe functions take &mut self
.
I don't know about DirectWrite.
There seems be a thread safe implementation for DirectWrite:
Currently, we are using:
https://github.com/vvuk/dwrote-rs/blob/a75100ca9884880692d2523128a4eb5f279ec9b9/src/font.rs#L15
The cairo docs specifically say that
You must be careful when using this function in a library or in a threaded application, because freetype's design makes it unsafe to call freetype functions simultaneously from multiple threads, (even if using distinct FT_Face objects).
So freetype is not threadsafe and you need to do your own locking (and know exactly what you have to lock: you might need a global freetype lock, I can't tell from that quote).
See https://github.com/servo/core-foundation-rs/pull/347.