fix animated gif playback
A casualty of b8dcfba9a4 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.
This commit is contained in:
1 parent
09081d2189
commit
04b7cedd02
2 files changed
+17
-7
No files matched your search
@@ -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>,
|
||||
@@ -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>>,
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user