Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fstanis opened this issue Jul 3, 2024 · 0 comments
Open

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

fstanis opened this issue Jul 3, 2024 · 0 comments

Comments

@fstanis
Copy link

fstanis commented Jul 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant