mirror of
https://github.com/servo/servo.git
synced 2025-07-22 06:43:40 +01:00
fonts: Make FontContext
thread-safe and share it per-Layout (#32205)
This allows sharing font templates, fonts, and platform fonts across layout threads. It's the first step toward storing web fonts in the layout versus the shared `FontCacheThread`. Now fonts and font groups have some locking (especially on FreeType), which will probably affect performance. On the other hand, we measured memory usage and this saves roughly 40 megabytes of memory when loading servo.org based on data from the memory profiler. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This commit is contained in:
parent
8ec5344f70
commit
556bfb7dff
27 changed files with 437 additions and 500 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
use std::borrow::ToOwned;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
|
||||
use canvas_traits::canvas::*;
|
||||
|
@ -11,6 +12,7 @@ use canvas_traits::ConstellationCanvasMsg;
|
|||
use crossbeam_channel::{select, unbounded, Sender};
|
||||
use euclid::default::Size2D;
|
||||
use gfx::font_cache_thread::FontCacheThread;
|
||||
use gfx::font_context::FontContext;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use ipc_channel::router::ROUTER;
|
||||
use log::warn;
|
||||
|
@ -40,7 +42,7 @@ pub struct CanvasPaintThread<'a> {
|
|||
canvases: HashMap<CanvasId, CanvasData<'a>>,
|
||||
next_canvas_id: CanvasId,
|
||||
webrender_api: Box<dyn WebrenderApi>,
|
||||
font_cache_thread: FontCacheThread,
|
||||
font_context: Arc<FontContext<FontCacheThread>>,
|
||||
}
|
||||
|
||||
impl<'a> CanvasPaintThread<'a> {
|
||||
|
@ -52,7 +54,7 @@ impl<'a> CanvasPaintThread<'a> {
|
|||
canvases: HashMap::new(),
|
||||
next_canvas_id: CanvasId(0),
|
||||
webrender_api,
|
||||
font_cache_thread,
|
||||
font_context: Arc::new(FontContext::new(font_cache_thread)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,8 +131,6 @@ impl<'a> CanvasPaintThread<'a> {
|
|||
AntialiasMode::None
|
||||
};
|
||||
|
||||
let font_cache_thread = self.font_cache_thread.clone();
|
||||
|
||||
let canvas_id = self.next_canvas_id;
|
||||
self.next_canvas_id.0 += 1;
|
||||
|
||||
|
@ -138,7 +138,7 @@ impl<'a> CanvasPaintThread<'a> {
|
|||
size,
|
||||
self.webrender_api.clone(),
|
||||
antialias,
|
||||
font_cache_thread,
|
||||
self.font_context.clone(),
|
||||
);
|
||||
self.canvases.insert(canvas_id, canvas_data);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue