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: <https://gitlab.gnome.org/Incubator/loupe/-/merge_requests/176>
This commit is contained in:
Sophie Herold 2023-04-13 01:19:53 +02:00
parent aca49427a1
commit 8669b870af
2 changed files with 21 additions and 0 deletions

View file

@ -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<FrameBuffer> {
});
}
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 {

View file

@ -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,