diff options
author | Martin Robinson <mrobinson@igalia.com> | 2024-10-10 16:09:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-10 23:09:51 +0000 |
commit | 0553789d4839c4bf750f386f3f07a71b4a21f38e (patch) | |
tree | e137a22e77d784b11c3fe9c739719c57d73c4758 /components/canvas/raqote_backend.rs | |
parent | 4564ce2fcc970d213dc8c109ab8f02a959254046 (diff) | |
download | servo-0553789d4839c4bf750f386f3f07a71b4a21f38e.tar.gz servo-0553789d4839c4bf750f386f3f07a71b4a21f38e.zip |
fonts: Instantiate system fonts using system font loaders (#33747)
System fonts used to be instantiated using the system font loader and
this change restores that behavior. In addition, on macOS and FreeType
platforms font data for system fonts is loaded using memory mapping. The
benefit is that system font loaders typically are able to cache fonts in
system memory (using memory mapping, for instance) and we'd like to load
them in a the way most compatible with other applications.
On my Linux system, this manages to get the overhead of loading a very
large font down from 10ms to approximately 1ms. Subsequent runs show
even less overhead. We've measured similar gains on macOS systems.
Currently, system font data must be loaded into memory manually for
canvas and this is unlikely to change even with a switch to `vello`. The
use of explicit memmory mapping should help in this case -- though it
probably won't be possible to use this properly on macOS and Windows if
we ever want to load fonts from TTCs properly.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Diffstat (limited to 'components/canvas/raqote_backend.rs')
-rw-r--r-- | components/canvas/raqote_backend.rs | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/components/canvas/raqote_backend.rs b/components/canvas/raqote_backend.rs index cccf2bf70d1..e7e3d116b5f 100644 --- a/components/canvas/raqote_backend.rs +++ b/components/canvas/raqote_backend.rs @@ -555,9 +555,8 @@ impl GenericDrawTarget for raqote::DrawTarget { SHARED_FONT_CACHE.with(|font_cache| { let identifier = template.identifier(); if !font_cache.borrow().contains_key(&identifier) { - let Ok(font) = - Font::from_bytes(run.font.data.as_arc().clone(), identifier.index()) - else { + let data = std::sync::Arc::new(run.font.data().as_ref().to_vec()); + let Ok(font) = Font::from_bytes(data, identifier.index()) else { return; }; font_cache.borrow_mut().insert(identifier.clone(), font); |