From 8669b870af71d3a1b30cdc4076d3c1b0f65d741f Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Thu, 13 Apr 2023 01:19:53 +0200 Subject: [PATCH] image: Fix textures and bg color not reloading The reload procedure for changed image files is triggered but the old data has to be deleted to be re-generated. Part-of: --- src/decoder/tiling.rs | 17 +++++++++++++++++ src/widgets/image.rs | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/src/decoder/tiling.rs b/src/decoder/tiling.rs index 62ebd01..3e9b09d 100644 --- a/src/decoder/tiling.rs +++ b/src/decoder/tiling.rs @@ -143,6 +143,14 @@ impl FrameBuffer { self.current().cleanup(zoom, viewport); } + /// Delete all stored information + /// + /// Used when reloading image + pub fn reset(&mut self) { + self.update_sender = None; + self.images.clear(); + } + pub fn contains(&self, zoom: f64, coordinates: Coordinates) -> bool { self.images .front() @@ -410,6 +418,7 @@ impl RectExt for graphene::Rect { pub trait FrameBufferExt { fn push(&self, tile: Tile); fn push_frame(&self, tile: Tile, dimensions: Coordinates, delay: Duration); + fn reset(&self); /// Return true if the next frame should be shown and removes the outdated frame fn frame_timeout(&self, elapsed: Duration) -> bool; /// Returns the number of currently buffered frames @@ -448,6 +457,14 @@ impl FrameBufferExt for ArcSwap { }); } + fn reset(&self) { + self.rcu(|tiling_store| { + let mut new_store = (**tiling_store).clone(); + new_store.reset(); + Arc::new(new_store) + }); + } + fn frame_timeout(&self, elapsed: Duration) -> bool { if let Some(next_frame) = self.load().images.get(1) { if elapsed >= next_frame.delay { diff --git a/src/widgets/image.rs b/src/widgets/image.rs index f15af62..869f52d 100644 --- a/src/widgets/image.rs +++ b/src/widgets/image.rs @@ -742,6 +742,10 @@ impl LpImage { self.set_file(file); let tiles = &self.imp().frame_buffer; + // Delete all stored textures for reloads + tiles.reset(); + // Reset background color for reloads + self.set_background_color(None); let (decoder, mut decoder_update) = match Decoder::new(file.clone(), tiles.clone()).await { Ok(x) => x,