From efa0d457574f02dfbe2403f501a4626acdcb64db Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Fri, 12 Apr 2024 12:39:32 +0200 Subject: 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. --- components/gfx/tests/font_template.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'components/gfx/tests/font_template.rs') diff --git a/components/gfx/tests/font_template.rs b/components/gfx/tests/font_template.rs index 1c8420bc45c..d35c3607497 100644 --- a/components/gfx/tests/font_template.rs +++ b/components/gfx/tests/font_template.rs @@ -11,7 +11,6 @@ fn test_font_template_descriptor() { use std::path::PathBuf; use gfx::font_cache_thread::FontIdentifier; - use gfx::font_context::FontContextHandle; use gfx::font_template::{FontTemplate, FontTemplateDescriptor}; use servo_url::ServoUrl; use style::values::computed::font::{FontStretch, FontStyle, FontWeight}; @@ -35,9 +34,7 @@ fn test_font_template_descriptor() { ) .unwrap(); - let context = FontContextHandle::default(); - - template.descriptor(&context).unwrap() + template.descriptor().unwrap() } assert_eq!( -- cgit v1.2.3