Skip to content

Commit

Permalink
fix animated gif playback
Browse files Browse the repository at this point in the history
A casualty of b8dcfba 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.
  • Loading branch information
wez committed Mar 14, 2021
1 parent 09081d2 commit 04b7ced
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 4 additions & 4 deletions wezterm-gui/src/glyphcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageFrame>,
Expand Down Expand Up @@ -318,7 +318,7 @@ pub struct GlyphCache<T: Texture2d> {
glyph_cache: HashMap<GlyphKey, Rc<CachedGlyph<T>>>,
pub atlas: Atlas<T>,
fonts: Rc<FontConfiguration>,
image_cache: LruCache<usize, CachedImage>,
pub image_cache: LruCache<usize, CachedImage>,
frame_cache: HashMap<(usize, usize), Sprite<T>>,
line_glyphs: HashMap<LineKey, Sprite<T>>,
block_glyphs: HashMap<BlockKey, Sprite<T>>,
Expand Down
16 changes: 13 additions & 3 deletions wezterm-gui/src/renderstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,19 @@ impl RenderState {
size: Option<usize>,
) -> 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(())
}
}

0 comments on commit 04b7ced

Please sign in to comment.