From 04b7cedd02eb533fa9eb3c3278764e982044ff96 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 14 Mar 2021 10:29:02 -0700 Subject: [PATCH] fix animated gif playback A casualty of b8dcfba9a4cc3477daca0b81be34625c07b4a86b was that the decoded gif would get reset each time the texture filled up. Take care to move that cached into the newly minted glyphcache. --- wezterm-gui/src/glyphcache.rs | 8 ++++---- wezterm-gui/src/renderstate.rs | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/wezterm-gui/src/glyphcache.rs b/wezterm-gui/src/glyphcache.rs index e2b7b3de9..17317f044 100644 --- a/wezterm-gui/src/glyphcache.rs +++ b/wezterm-gui/src/glyphcache.rs @@ -218,19 +218,19 @@ impl BlockKey { } #[derive(Debug)] -struct ImageFrame { +pub struct ImageFrame { duration: Duration, image: ::window::bitmaps::Image, } #[derive(Debug)] -enum CachedImage { +pub enum CachedImage { Animation(DecodedImage), SingleFrame, } #[derive(Debug)] -struct DecodedImage { +pub struct DecodedImage { frame_start: Instant, current_frame: usize, frames: Vec, @@ -318,7 +318,7 @@ pub struct GlyphCache { glyph_cache: HashMap>>, pub atlas: Atlas, fonts: Rc, - image_cache: LruCache, + pub image_cache: LruCache, frame_cache: HashMap<(usize, usize), Sprite>, line_glyphs: HashMap>, block_glyphs: HashMap>, diff --git a/wezterm-gui/src/renderstate.rs b/wezterm-gui/src/renderstate.rs index ee0c955b7..97caf6dee 100644 --- a/wezterm-gui/src/renderstate.rs +++ b/wezterm-gui/src/renderstate.rs @@ -348,9 +348,19 @@ impl RenderState { size: Option, ) -> anyhow::Result<()> { let size = size.unwrap_or_else(|| self.glyph_cache.borrow().atlas.size()); - let mut glyph_cache = GlyphCache::new_gl(&self.context, fonts, size, metrics)?; - self.util_sprites = UtilSprites::new(&mut glyph_cache, metrics)?; - *self.glyph_cache.borrow_mut() = glyph_cache; + let mut new_glyph_cache = GlyphCache::new_gl(&self.context, fonts, size, metrics)?; + self.util_sprites = UtilSprites::new(&mut new_glyph_cache, metrics)?; + + let mut glyph_cache = self.glyph_cache.borrow_mut(); + + // Steal the decoded image cache; without this, any animating gifs + // would reset back to frame 0 each time we filled the texture + std::mem::swap( + &mut glyph_cache.image_cache, + &mut new_glyph_cache.image_cache, + ); + + *glyph_cache = new_glyph_cache; Ok(()) } }