mirror of
https://github.com/servo/servo.git
synced 2025-08-02 12:10:29 +01:00
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.
55 lines
1.5 KiB
Rust
55 lines
1.5 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* 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/. */
|
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
|
pub use crate::platform::freetype::{font, font_list, font_template, library_handle};
|
|
#[cfg(target_os = "macos")]
|
|
pub use crate::platform::macos::{font, font_list, font_template};
|
|
#[cfg(target_os = "windows")]
|
|
pub use crate::platform::windows::{font, font_list, font_template};
|
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
|
mod freetype {
|
|
use std::ffi::CStr;
|
|
use std::str;
|
|
|
|
use libc::c_char;
|
|
|
|
/// Creates a String from the given null-terminated buffer.
|
|
/// Panics if the buffer does not contain UTF-8.
|
|
unsafe fn c_str_to_string(s: *const c_char) -> String {
|
|
str::from_utf8(CStr::from_ptr(s).to_bytes())
|
|
.unwrap()
|
|
.to_owned()
|
|
}
|
|
|
|
pub mod font;
|
|
|
|
#[cfg(target_os = "linux")]
|
|
pub mod font_list;
|
|
#[cfg(target_os = "android")]
|
|
mod android {
|
|
pub mod font_list;
|
|
mod xml;
|
|
}
|
|
#[cfg(target_os = "android")]
|
|
pub use self::android::font_list;
|
|
|
|
pub mod font_template;
|
|
pub mod library_handle;
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]
|
|
mod macos {
|
|
pub mod font;
|
|
pub mod font_list;
|
|
pub mod font_template;
|
|
}
|
|
|
|
#[cfg(target_os = "windows")]
|
|
mod windows {
|
|
pub mod font;
|
|
pub mod font_list;
|
|
pub mod font_template;
|
|
}
|