diff options
author | Joe Wilm <joe@jwilm.com> | 2017-10-14 18:58:19 -0700 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2017-10-14 19:07:43 -0700 |
commit | e8f5ab89ee0b6810649f76c6dbd15ee1105554e8 (patch) | |
tree | f9ba9fa4e23f99b3b9ecfde84d32bce03730f7a4 /src/display.rs | |
parent | 8a0b1d9c3f5a9ddb98469a340bbcd06374d4a24e (diff) | |
download | alacritty-e8f5ab89ee0b6810649f76c6dbd15ee1105554e8.tar.gz alacritty-e8f5ab89ee0b6810649f76c6dbd15ee1105554e8.zip |
Fix memory leak from font resizing
The source of the leak was loading up multiple copies of the FT_face
even when not necessary. Fonts are now appropriately cached for
FreeType when going through the `Rasterize::load_font` API.
Additionally, textures in the glyph cache are now reused.
The result of this is that resizing to already loaded fonts is free
from a memory consumption perspective.
Diffstat (limited to 'src/display.rs')
-rw-r--r-- | src/display.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/display.rs b/src/display.rs index 25318f0e..eb562e8f 100644 --- a/src/display.rs +++ b/src/display.rs @@ -240,14 +240,15 @@ impl Display { return Ok((glyph_cache, cell_width as f32, cell_height as f32)); } - pub fn update_glyph_cache(&mut self, config: &Config, font_size_delta: i8) - { - let (glyph_cache, cell_width, cell_height) = - Self::new_glyph_cache(&self.window, - &mut self.renderer, config, font_size_delta).unwrap(); - self.glyph_cache = glyph_cache; - self.size_info.cell_width = cell_width; - self.size_info.cell_height = cell_height; + pub fn update_glyph_cache(&mut self, config: &Config, font_size_delta: i8) { + let cache = &mut self.glyph_cache; + self.renderer.with_loader(|mut api| { + let _ = cache.update_font_size(config.font(), font_size_delta, &mut api); + }); + + let metrics = cache.font_metrics(); + self.size_info.cell_width = (metrics.average_advance + config.font().offset().x as f64) as f32; + self.size_info.cell_height = (metrics.line_height + config.font().offset().y as f64) as f32; } #[inline] |