mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Merge pull request #3298 from glennw/fix-font-cache
Reduce number of font instances and shaper structures created.
This commit is contained in:
commit
883fc2e404
1 changed files with 9 additions and 11 deletions
|
@ -14,7 +14,7 @@ use font::FontHandleMethods;
|
||||||
use platform::font::FontHandle;
|
use platform::font::FontHandle;
|
||||||
use servo_util::cache::HashCache;
|
use servo_util::cache::HashCache;
|
||||||
|
|
||||||
use std::rc::{Rc, Weak};
|
use std::rc::Rc;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use sync::Arc;
|
use sync::Arc;
|
||||||
|
|
||||||
|
@ -54,8 +54,8 @@ pub struct FontContext {
|
||||||
platform_handle: FontContextHandle,
|
platform_handle: FontContextHandle,
|
||||||
font_cache_task: FontCacheTask,
|
font_cache_task: FontCacheTask,
|
||||||
|
|
||||||
/// Weak reference as the layout FontContext is persistent.
|
/// TODO: See bug https://github.com/servo/servo/issues/3300.
|
||||||
layout_font_cache: Vec<Weak<RefCell<Font>>>,
|
layout_font_cache: Vec<Rc<RefCell<Font>>>,
|
||||||
|
|
||||||
/// Strong reference as the render FontContext is (for now) recycled
|
/// Strong reference as the render FontContext is (for now) recycled
|
||||||
/// per frame. TODO: Make this weak when incremental redraw is done.
|
/// per frame. TODO: Make this weak when incremental redraw is done.
|
||||||
|
@ -95,10 +95,8 @@ impl FontContext {
|
||||||
/// a cached font if this font instance has already been used by
|
/// a cached font if this font instance has already been used by
|
||||||
/// this context.
|
/// this context.
|
||||||
pub fn get_layout_font_group_for_style(&mut self, style: &SpecifiedFontStyle) -> FontGroup {
|
pub fn get_layout_font_group_for_style(&mut self, style: &SpecifiedFontStyle) -> FontGroup {
|
||||||
// Remove all weak pointers that have been dropped.
|
// TODO: The font context holds a strong ref to the cached fonts
|
||||||
self.layout_font_cache.retain(|maybe_font| {
|
// so they will never be released. Find out a good time to drop them.
|
||||||
maybe_font.upgrade().is_some()
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut fonts: Vec<Rc<RefCell<Font>>> = vec!();
|
let mut fonts: Vec<Rc<RefCell<Font>>> = vec!();
|
||||||
|
|
||||||
|
@ -107,9 +105,9 @@ impl FontContext {
|
||||||
|
|
||||||
// GWTODO: Check on real pages if this is faster as Vec() or HashMap().
|
// GWTODO: Check on real pages if this is faster as Vec() or HashMap().
|
||||||
let mut cache_hit = false;
|
let mut cache_hit = false;
|
||||||
for maybe_cached_font in self.layout_font_cache.iter() {
|
for cached_font in self.layout_font_cache.iter() {
|
||||||
let cached_font = maybe_cached_font.upgrade().unwrap();
|
if cached_font.borrow().descriptor == desc &&
|
||||||
if cached_font.borrow().descriptor == desc {
|
cached_font.borrow().pt_size == style.pt_size {
|
||||||
fonts.push(cached_font.clone());
|
fonts.push(cached_font.clone());
|
||||||
cache_hit = true;
|
cache_hit = true;
|
||||||
break;
|
break;
|
||||||
|
@ -119,7 +117,7 @@ impl FontContext {
|
||||||
if !cache_hit {
|
if !cache_hit {
|
||||||
let font_template = self.font_cache_task.get_font_template(family.clone(), desc.clone());
|
let font_template = self.font_cache_task.get_font_template(family.clone(), desc.clone());
|
||||||
let layout_font = Rc::new(RefCell::new(self.create_layout_font(font_template, desc.clone(), style.pt_size)));
|
let layout_font = Rc::new(RefCell::new(self.create_layout_font(font_template, desc.clone(), style.pt_size)));
|
||||||
self.layout_font_cache.push(layout_font.downgrade());
|
self.layout_font_cache.push(layout_font.clone());
|
||||||
fonts.push(layout_font);
|
fonts.push(layout_font);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue