aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx/font_context.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2024-04-12 12:39:32 +0200
committerGitHub <noreply@github.com>2024-04-12 10:39:32 +0000
commitefa0d457574f02dfbe2403f501a4626acdcb64db (patch)
treef114f9a1233a111863170b6eea10f02d11d57b37 /components/gfx/font_context.rs
parente9591ce62f210d374463bdf1a6d956e19cca81f0 (diff)
downloadservo-efa0d457574f02dfbe2403f501a4626acdcb64db.tar.gz
servo-efa0d457574f02dfbe2403f501a4626acdcb64db.zip
Remove `FontContextHandle` (#32038)
The `FontContextHandle` was really only used on FreeType platforms to store the `FT_Library` handle to use for creating faces. Each `FontContext` and `FontCacheThread` would create its own `FontContextHandle`. This change removes this data structure in favor of a mutex-protected shared `FontContextHandle` for an entire Servo process. The handle is initialized using a `OnceLock` to ensure that it only happens once and also that it stays alive for the entire process lifetime. In addition to greatly simplifying the code, this will make it possible for different threads to share platform-specific `FontHandle`s, avoiding multiple allocations for a single font. The only downside to all of this is that memory usage of FreeType fonts isn't measured (though the mechanism is still there). This is because the `FontCacheThread` currently doesn't do any memory measurement. Eventually this *will* happen though, during the font system redesign. In exchange, this should reduce the memory usage since there is only a single FreeType library loaded into memory now. This is part of #32033.
Diffstat (limited to 'components/gfx/font_context.rs')
-rw-r--r--components/gfx/font_context.rs18
1 files changed, 1 insertions, 17 deletions
diff --git a/components/gfx/font_context.rs b/components/gfx/font_context.rs
index c7f2eaef530..d316ceb50c1 100644
--- a/components/gfx/font_context.rs
+++ b/components/gfx/font_context.rs
@@ -12,7 +12,6 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use app_units::Au;
use fnv::FnvHasher;
use log::debug;
-use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use servo_arc::Arc;
use style::computed_values::font_variant_caps::T as FontVariantCaps;
use style::properties::style_structs::Font as FontStyleStruct;
@@ -24,7 +23,6 @@ use crate::font::{
use crate::font_cache_thread::FontTemplateInfo;
use crate::font_template::FontTemplateDescriptor;
use crate::platform::font::FontHandle;
-pub use crate::platform::font_context::FontContextHandle;
static SMALL_CAPS_SCALE_FACTOR: f32 = 0.8; // Matches FireFox (see gfxFont.h)
@@ -48,7 +46,6 @@ pub trait FontSource {
/// required.
#[derive(Debug)]
pub struct FontContext<S: FontSource> {
- platform_handle: FontContextHandle,
font_source: S,
// TODO: The font context holds a strong ref to the cached fonts
@@ -66,9 +63,7 @@ pub struct FontContext<S: FontSource> {
impl<S: FontSource> FontContext<S> {
pub fn new(font_source: S) -> FontContext<S> {
#[allow(clippy::default_constructed_unit_structs)]
- let handle = FontContextHandle::default();
FontContext {
- platform_handle: handle,
font_source,
font_cache: HashMap::new(),
font_template_cache: HashMap::new(),
@@ -217,11 +212,7 @@ impl<S: FontSource> FontContext<S> {
descriptor: FontDescriptor,
synthesized_small_caps: Option<FontRef>,
) -> Result<Font, &'static str> {
- let handle = FontHandle::new_from_template(
- &self.platform_handle,
- info.font_template,
- Some(descriptor.pt_size),
- )?;
+ let handle = FontHandle::new_from_template(info.font_template, Some(descriptor.pt_size))?;
let font_instance_key = self
.font_source
@@ -235,13 +226,6 @@ impl<S: FontSource> FontContext<S> {
}
}
-impl<S: FontSource> MallocSizeOf for FontContext<S> {
- fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
- // FIXME(njn): Measure other fields eventually.
- self.platform_handle.size_of(ops)
- }
-}
-
#[derive(Debug, Eq, Hash, PartialEq)]
struct FontCacheKey {
font_descriptor: FontDescriptor,