mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
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.
This commit is contained in:
parent
e9591ce62f
commit
efa0d45757
16 changed files with 152 additions and 247 deletions
|
@ -26,7 +26,6 @@ use webrender_api::{FontInstanceKey, FontKey};
|
|||
use crate::font::{FontFamilyDescriptor, FontFamilyName, FontSearchScope};
|
||||
use crate::font_context::FontSource;
|
||||
use crate::font_template::{FontTemplate, FontTemplateDescriptor};
|
||||
use crate::platform::font_context::FontContextHandle;
|
||||
use crate::platform::font_list::{
|
||||
for_each_available_family, for_each_variation, system_default_family, LocalFontIdentifier,
|
||||
SANS_SERIF_FONT_FAMILY,
|
||||
|
@ -75,13 +74,12 @@ impl FontTemplates {
|
|||
pub fn find_font_for_style(
|
||||
&mut self,
|
||||
desc: &FontTemplateDescriptor,
|
||||
fctx: &FontContextHandle,
|
||||
) -> Option<Arc<FontTemplateData>> {
|
||||
// TODO(Issue #189): optimize lookup for
|
||||
// regular/bold/italic/bolditalic with fixed offsets and a
|
||||
// static decision table for fallback between these values.
|
||||
for template in &mut self.templates {
|
||||
let maybe_template = template.data_for_descriptor(fctx, desc);
|
||||
let maybe_template = template.data_for_descriptor(desc);
|
||||
if maybe_template.is_some() {
|
||||
return maybe_template;
|
||||
}
|
||||
|
@ -91,8 +89,7 @@ impl FontTemplates {
|
|||
// TODO(#190): Do a better job.
|
||||
let (mut best_template_data, mut best_distance) = (None, f32::MAX);
|
||||
for template in &mut self.templates {
|
||||
if let Some((template_data, distance)) =
|
||||
template.data_for_approximate_descriptor(fctx, desc)
|
||||
if let Some((template_data, distance)) = template.data_for_approximate_descriptor(desc)
|
||||
{
|
||||
if distance < best_distance {
|
||||
best_template_data = Some(template_data);
|
||||
|
@ -159,7 +156,6 @@ struct FontCache {
|
|||
generic_fonts: HashMap<FontFamilyName, LowercaseString>,
|
||||
local_families: HashMap<LowercaseString, FontTemplates>,
|
||||
web_families: HashMap<LowercaseString, FontTemplates>,
|
||||
font_context: FontContextHandle,
|
||||
core_resource_thread: CoreResourceThread,
|
||||
webrender_api: Box<dyn WebrenderApi>,
|
||||
webrender_fonts: HashMap<FontIdentifier, FontKey>,
|
||||
|
@ -404,7 +400,7 @@ impl FontCache {
|
|||
// TODO(Issue #192: handle generic font families, like 'serif' and 'sans-serif'.
|
||||
// if such family exists, try to match style to a font
|
||||
|
||||
s.find_font_for_style(template_descriptor, &self.font_context)
|
||||
s.find_font_for_style(template_descriptor)
|
||||
} else {
|
||||
debug!(
|
||||
"FontList: Couldn't find font family with name={}",
|
||||
|
@ -423,7 +419,7 @@ impl FontCache {
|
|||
|
||||
if self.web_families.contains_key(&family_name) {
|
||||
let templates = self.web_families.get_mut(&family_name).unwrap();
|
||||
templates.find_font_for_style(template_descriptor, &self.font_context)
|
||||
templates.find_font_for_style(template_descriptor)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -498,7 +494,6 @@ impl FontCacheThread {
|
|||
generic_fonts,
|
||||
local_families: HashMap::new(),
|
||||
web_families: HashMap::new(),
|
||||
font_context: FontContextHandle::default(),
|
||||
core_resource_thread,
|
||||
webrender_api,
|
||||
webrender_fonts: HashMap::new(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue