Update WR (font instance API).

WR now has a concept of font templates and font instances. This
makes the WR font interfaces closer to Cairo and Gecko, and also
makes some future performance optimizations possible.

A font template is the font family, and data backing the font.
A font instance is a reference to a font template and per-instance
options, such as font size, anti-aliasing settings etc.

To update Servo in a minimally invasive way, I added a new font
cache call, that creates a font instance. This means that when
a font is created, and doesn't exist in the cache there are now
two calls to the font cache thread. We could refactor the font
cache to make this work in one call, which we should do in the
future. However, refactoring the font cache is a large chunk of
work by itself. The extra call is only when a font doesn't already
exist in the font context cache, so it should have minimal
performance impact.
This commit is contained in:
Glenn Watson 2017-08-31 14:58:04 +10:00
parent 9a9866117a
commit b015e93dc5
9 changed files with 92 additions and 102 deletions

View file

@ -92,7 +92,9 @@ impl FontContext {
template,
Some(actual_pt_size))?;
Ok(Font::new(handle, variant, descriptor, pt_size, actual_pt_size, font_key))
let font_instance_key = self.font_cache_thread
.get_font_instance(font_key, actual_pt_size);
Ok(Font::new(handle, variant, descriptor, pt_size, actual_pt_size, font_instance_key))
}
fn expire_font_caches_if_necessary(&mut self) {
@ -166,8 +168,7 @@ impl FontContext {
desc.clone(),
style.font_size.0,
style.font_variant_caps,
template_info.font_key
.expect("No font key present!"));
template_info.font_key);
let font = match layout_font {
Ok(layout_font) => {
let layout_font = Rc::new(RefCell::new(layout_font));
@ -212,7 +213,7 @@ impl FontContext {
desc.clone(),
style.font_size.0,
style.font_variant_caps,
template_info.font_key.expect("No font key present!"));
template_info.font_key);
match layout_font {
Ok(layout_font) => {
let layout_font = Rc::new(RefCell::new(layout_font));