From 5f30194a348315169bc09500cc052c9d3242db65 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Thu, 23 May 2024 13:21:24 +0200 Subject: [PATCH] fix(core): prevent unnecessary display refreshing [no changelog] --- core/src/trezor/ui/layouts/mercury/__init__.py | 3 ++- core/src/trezor/ui/layouts/mercury/fido.py | 4 ++-- core/src/trezor/ui/layouts/mercury/homescreen.py | 8 ++++---- core/src/trezor/ui/layouts/progress.py | 8 ++++---- core/src/trezor/ui/layouts/tr/__init__.py | 3 ++- core/src/trezor/ui/layouts/tr/homescreen.py | 8 ++++---- core/src/trezor/ui/layouts/tt/__init__.py | 3 ++- core/src/trezor/ui/layouts/tt/fido.py | 4 ++-- core/src/trezor/ui/layouts/tt/homescreen.py | 8 ++++---- 9 files changed, 26 insertions(+), 23 deletions(-) diff --git a/core/src/trezor/ui/layouts/mercury/__init__.py b/core/src/trezor/ui/layouts/mercury/__init__.py index 51fdb01c00..4a3197875c 100644 --- a/core/src/trezor/ui/layouts/mercury/__init__.py +++ b/core/src/trezor/ui/layouts/mercury/__init__.py @@ -52,7 +52,8 @@ class RustLayout(ui.Layout): painted = self.layout.paint() - ui.refresh() + if painted: + ui.refresh() if storage_cache.homescreen_shown is not None and painted: storage_cache.homescreen_shown = None diff --git a/core/src/trezor/ui/layouts/mercury/fido.py b/core/src/trezor/ui/layouts/mercury/fido.py index f4f628e469..390fb4b7e0 100644 --- a/core/src/trezor/ui/layouts/mercury/fido.py +++ b/core/src/trezor/ui/layouts/mercury/fido.py @@ -36,8 +36,8 @@ if __debug__: (io.TOUCH_END, 220, 220), ): msg = self.layout.touch_event(event, x, y) - self.layout.paint() - ui.refresh() + if self.layout.paint(): + ui.refresh() if msg is not None: raise Result(msg) diff --git a/core/src/trezor/ui/layouts/mercury/homescreen.py b/core/src/trezor/ui/layouts/mercury/homescreen.py index bd608aefe0..da8021b2d8 100644 --- a/core/src/trezor/ui/layouts/mercury/homescreen.py +++ b/core/src/trezor/ui/layouts/mercury/homescreen.py @@ -19,8 +19,8 @@ class HomescreenBase(RustLayout): super().__init__(layout=layout) def _paint(self) -> None: - self.layout.paint() - ui.refresh() + if self.layout.paint(): + ui.refresh() def _first_paint(self) -> None: if storage_cache.homescreen_shown is not self.RENDER_INDICATOR: @@ -76,8 +76,8 @@ class Homescreen(HomescreenBase): while True: is_connected = await usbcheck self.layout.usb_event(is_connected) - self.layout.paint() - ui.refresh() + if self.layout.paint(): + ui.refresh() def create_tasks(self) -> Tuple[loop.AwaitableTask, ...]: return super().create_tasks() + (self.usb_checker_task(),) diff --git a/core/src/trezor/ui/layouts/progress.py b/core/src/trezor/ui/layouts/progress.py index 53b960a83d..8fe3f6a108 100644 --- a/core/src/trezor/ui/layouts/progress.py +++ b/core/src/trezor/ui/layouts/progress.py @@ -36,8 +36,8 @@ class RustProgress: self.layout = layout ui.backlight_fade(ui.BacklightLevels.DIM) self.layout.attach_timer_fn(self.set_timer) - self.layout.paint() - ui.refresh() + if self.layout.paint(): + ui.refresh() ui.backlight_fade(ui.BacklightLevels.NORMAL) def set_timer(self, token: int, deadline: int) -> None: @@ -46,8 +46,8 @@ class RustProgress: def report(self, value: int, description: str | None = None): msg = self.layout.progress_event(value, description or "") assert msg is None - self.layout.paint() - ui.refresh() + if self.layout.paint(): + ui.refresh() def progress( diff --git a/core/src/trezor/ui/layouts/tr/__init__.py b/core/src/trezor/ui/layouts/tr/__init__.py index 58288a78f6..aaaa198230 100644 --- a/core/src/trezor/ui/layouts/tr/__init__.py +++ b/core/src/trezor/ui/layouts/tr/__init__.py @@ -56,7 +56,8 @@ class RustLayout(LayoutParentType[T]): painted = self.layout.paint() - ui.refresh() + if painted: + ui.refresh() if storage_cache.homescreen_shown is not None and painted: storage_cache.homescreen_shown = None diff --git a/core/src/trezor/ui/layouts/tr/homescreen.py b/core/src/trezor/ui/layouts/tr/homescreen.py index ae82749c62..9bbd74738a 100644 --- a/core/src/trezor/ui/layouts/tr/homescreen.py +++ b/core/src/trezor/ui/layouts/tr/homescreen.py @@ -19,8 +19,8 @@ class HomescreenBase(RustLayout): super().__init__(layout=layout) def _paint(self) -> None: - self.layout.paint() - ui.refresh() + if self.layout.paint(): + ui.refresh() def _first_paint(self) -> None: if storage_cache.homescreen_shown is not self.RENDER_INDICATOR: @@ -65,8 +65,8 @@ class Homescreen(HomescreenBase): while True: is_connected = await usbcheck self.layout.usb_event(is_connected) - self.layout.paint() - ui.refresh() + if self.layout.paint(): + ui.refresh() def create_tasks(self) -> Tuple[loop.AwaitableTask, ...]: return super().create_tasks() + (self.usb_checker_task(),) diff --git a/core/src/trezor/ui/layouts/tt/__init__.py b/core/src/trezor/ui/layouts/tt/__init__.py index 089926ac72..25aefe2c55 100644 --- a/core/src/trezor/ui/layouts/tt/__init__.py +++ b/core/src/trezor/ui/layouts/tt/__init__.py @@ -58,7 +58,8 @@ class RustLayout(LayoutParentType[T]): painted = self.layout.paint() - ui.refresh() + if painted: + ui.refresh() if storage_cache.homescreen_shown is not None and painted: storage_cache.homescreen_shown = None diff --git a/core/src/trezor/ui/layouts/tt/fido.py b/core/src/trezor/ui/layouts/tt/fido.py index f4f628e469..390fb4b7e0 100644 --- a/core/src/trezor/ui/layouts/tt/fido.py +++ b/core/src/trezor/ui/layouts/tt/fido.py @@ -36,8 +36,8 @@ if __debug__: (io.TOUCH_END, 220, 220), ): msg = self.layout.touch_event(event, x, y) - self.layout.paint() - ui.refresh() + if self.layout.paint(): + ui.refresh() if msg is not None: raise Result(msg) diff --git a/core/src/trezor/ui/layouts/tt/homescreen.py b/core/src/trezor/ui/layouts/tt/homescreen.py index bd608aefe0..da8021b2d8 100644 --- a/core/src/trezor/ui/layouts/tt/homescreen.py +++ b/core/src/trezor/ui/layouts/tt/homescreen.py @@ -19,8 +19,8 @@ class HomescreenBase(RustLayout): super().__init__(layout=layout) def _paint(self) -> None: - self.layout.paint() - ui.refresh() + if self.layout.paint(): + ui.refresh() def _first_paint(self) -> None: if storage_cache.homescreen_shown is not self.RENDER_INDICATOR: @@ -76,8 +76,8 @@ class Homescreen(HomescreenBase): while True: is_connected = await usbcheck self.layout.usb_event(is_connected) - self.layout.paint() - ui.refresh() + if self.layout.paint(): + ui.refresh() def create_tasks(self) -> Tuple[loop.AwaitableTask, ...]: return super().create_tasks() + (self.usb_checker_task(),)