diff options
author | Martin Robinson <mrobinson@igalia.com> | 2024-05-02 12:34:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-02 10:34:10 +0000 |
commit | 556bfb7dff48f64e9e02872dba29fbdabc8c6ad0 (patch) | |
tree | 0c9e1e80582fee2a64aa5904df3230e8a3d2befd /components/gfx/platform/macos/font.rs | |
parent | 8ec5344f70dd1d556cacd72d778924048b0b1154 (diff) | |
download | servo-556bfb7dff48f64e9e02872dba29fbdabc8c6ad0.tar.gz servo-556bfb7dff48f64e9e02872dba29fbdabc8c6ad0.zip |
fonts: Make `FontContext` thread-safe and share it per-Layout (#32205)
This allows sharing font templates, fonts, and platform fonts across
layout threads. It's the first step toward storing web fonts in the
layout versus the shared `FontCacheThread`. Now fonts and font groups
have some locking (especially on FreeType), which will probably affect
performance. On the other hand, we measured memory usage and this saves
roughly 40 megabytes of memory when loading servo.org based on data from
the memory profiler.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Diffstat (limited to 'components/gfx/platform/macos/font.rs')
-rw-r--r-- | components/gfx/platform/macos/font.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs index c6e009ffae8..7ab00b51cd0 100644 --- a/components/gfx/platform/macos/font.rs +++ b/components/gfx/platform/macos/font.rs @@ -63,6 +63,17 @@ pub struct PlatformFont { can_do_fast_shaping: bool, } +// From https://developer.apple.com/documentation/coretext: +// > All individual functions in Core Text are thread-safe. Font objects (CTFont, +// > CTFontDescriptor, and associated objects) can be used simultaneously by multiple +// > operations, work queues, or threads. However, the layout objects (CTTypesetter, +// > CTFramesetter, CTRun, CTLine, CTFrame, and associated objects) should be used in a +// > single operation, work queue, or thread. +// +// The other element is a read-only CachedKernTable which is stored in a CFData. +unsafe impl Sync for PlatformFont {} +unsafe impl Send for PlatformFont {} + impl PlatformFont { /// Cache all the data needed for basic horizontal kerning. This is used only as a fallback or /// fast path (when the GPOS table is missing or unnecessary) so it needn't handle every case. |