Skip to content

Make refresh on viewport no-op if there's nothing to do #280

@fstanis

Description

@fstanis

Looking at the code for refresh in viewport, it seems it will call self._device.display even when there's nothing to do:

def refresh(self):
should_wait = False
for hotspot, xy in self._hotspots:
if hotspot.should_redraw() and self.is_overlapping_viewport(hotspot, xy):
pool.add_task(hotspot.paste_into, self._backing_image, xy)
should_wait = True
if should_wait:
pool.wait_completion()
im = self._backing_image.crop(box=self._crop_box())
if self._dither:
im = im.convert(self._device.mode)
self._device.display(im)

Since this function is usually called often (i.e. once per frame), would it make sense to skip this step if the image hasn't changed (i.e. should_wait == false)? I understand refresh is also called from display and set_position in which case it wouldn't be desirable to skip this step, but this could be mitigated by adding a flat to it, i.e. refresh(force = False) and calling it as refresh(True) from those two spots.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions