Davejkane / riv

Riv - The Rust Image Viewer
MIT License
99 stars 10 forks source link

Make improvements to indicating the image doesn't need to be refreshed #42

Closed gurgalex closed 5 years ago

gurgalex commented 5 years ago

Leaving this here for thinking there may be a better way to prevent rerendering an image that doesn't need to be rerendered. An example would be toggling the infobar.

Currently, every caller that wants to update the rendered image needs to set the screen as dirty to true and then call set_image_texture. A new image texture replaces the stale texture. To render the image, call render_image.

Part of set_image_texture fn

    fn set_image_texture(&mut self) -> Result<(), String> {
        if self.paths.index == self.screen.last_index
            && self.screen.last_texture.is_some()
            && !self.screen.dirty
        {
            return Ok(());
        }
/// ~snip ~ ///

Data structures below for reference.

Screen struct

pub struct Screen<'a>
    /// - snip ~ ///
    /// last_index is the index of the last texture rendered
    pub last_index: usize,
    /// last_texture is the last image texture rendered
    pub last_texture: Option<sdl2::render::Texture<'a>>,
    /// dirty, if true indicates that last texture must be discarded
    pub dirty: bool,

Paths struct

pub struct Paths {
    /// ~snip~ ///
    /// index is the index of the images vector of the current image to be displayed.
    pub index: usize,
}
Davejkane commented 5 years ago

@gurgalex are you happy that @NickHackman 's PR takes care of this? Can we close this ticket?

gurgalex commented 5 years ago

Haven't come across a better way yet to say that parts of the screen need to be redrawn, but others do not. Though webrender's method seems promising, but complicated to do in SDL2 perhaps.

So, I guess it can be closed.

Davejkane commented 5 years ago

OK, if we feel it's a problem later we can always bring it back up