aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx/tests
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/tests
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/tests')
-rw-r--r--components/gfx/tests/font_context.rs8
-rw-r--r--components/gfx/tests/font_template.rs5
2 files changed, 3 insertions, 10 deletions
diff --git a/components/gfx/tests/font_context.rs b/components/gfx/tests/font_context.rs
index 3447493399d..24965e272f1 100644
--- a/components/gfx/tests/font_context.rs
+++ b/components/gfx/tests/font_context.rs
@@ -14,7 +14,7 @@ use gfx::font::{
fallback_font_families, FontDescriptor, FontFamilyDescriptor, FontFamilyName, FontSearchScope,
};
use gfx::font_cache_thread::{FontIdentifier, FontTemplateInfo, FontTemplates};
-use gfx::font_context::{FontContext, FontContextHandle, FontSource};
+use gfx::font_context::{FontContext, FontSource};
use gfx::font_template::FontTemplateDescriptor;
use servo_arc::Arc;
use servo_atoms::Atom;
@@ -30,7 +30,6 @@ use style::values::generics::font::LineHeight;
use webrender_api::{FontInstanceKey, FontKey, IdNamespace};
struct TestFontSource {
- handle: FontContextHandle,
families: HashMap<String, FontTemplates>,
find_font_count: Rc<Cell<isize>>,
}
@@ -52,7 +51,6 @@ impl TestFontSource {
families.insert(fallback_font_families(None)[0].to_owned(), fallback);
TestFontSource {
- handle: FontContextHandle::default(),
families,
find_font_count: Rc::new(Cell::new(0)),
}
@@ -90,12 +88,10 @@ impl FontSource for TestFontSource {
template_descriptor: FontTemplateDescriptor,
family_descriptor: FontFamilyDescriptor,
) -> Option<FontTemplateInfo> {
- let handle = &self.handle;
-
self.find_font_count.set(self.find_font_count.get() + 1);
self.families
.get_mut(family_descriptor.name())
- .and_then(|family| family.find_font_for_style(&template_descriptor, handle))
+ .and_then(|family| family.find_font_for_style(&template_descriptor))
.map(|template| FontTemplateInfo {
font_template: template,
font_key: FontKey(IdNamespace(0), 0),
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!(