aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx/font_template.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2024-05-02 12:34:10 +0200
committerGitHub <noreply@github.com>2024-05-02 10:34:10 +0000
commit556bfb7dff48f64e9e02872dba29fbdabc8c6ad0 (patch)
tree0c9e1e80582fee2a64aa5904df3230e8a3d2befd /components/gfx/font_template.rs
parent8ec5344f70dd1d556cacd72d778924048b0b1154 (diff)
downloadservo-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/font_template.rs')
-rw-r--r--components/gfx/font_template.rs5
1 files changed, 2 insertions, 3 deletions
diff --git a/components/gfx/font_template.rs b/components/gfx/font_template.rs
index 30a40608df5..0af8aa75443 100644
--- a/components/gfx/font_template.rs
+++ b/components/gfx/font_template.rs
@@ -2,12 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
-use std::cell::RefCell;
use std::fmt::{Debug, Error, Formatter};
use std::ops::RangeInclusive;
-use std::rc::Rc;
use std::sync::Arc;
+use atomic_refcell::AtomicRefCell;
use serde::{Deserialize, Serialize};
use servo_url::ServoUrl;
use style::computed_values::font_stretch::T as FontStretch;
@@ -22,7 +21,7 @@ use crate::platform::font::PlatformFont;
use crate::platform::font_list::LocalFontIdentifier;
/// A reference to a [`FontTemplate`] with shared ownership and mutability.
-pub type FontTemplateRef = Rc<RefCell<FontTemplate>>;
+pub type FontTemplateRef = Arc<AtomicRefCell<FontTemplate>>;
/// Describes how to select a font from a given family. This is very basic at the moment and needs
/// to be expanded or refactored when we support more of the font styling parameters.