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

rust: Concrete renderers #4137

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

rust: Concrete renderers #4137

wants to merge 11 commits into from

Conversation

matejcik
Copy link
Contributor

This PR reworks the way we invoke display renderers, replacing closure-based run_with_bumps with a guard-based locking mechanism, and replacing render_on_display with a macro.

This significantly reduces the amount of trickery needed to get Rust to accept the various lifetime bounds (not to zero, unfortunately :( ), and -- perhaps more importantly -- it allows us to create a Display trait that is a parameter of UIFeaturesCommon, cleanly binding each model to a particular Display implementation and providing an obvious location to change it without relying on exclusive features.

(ideally this would also let us remove the display_xxxx features, because we can now build all the impls at the same time, and select the one to be used via UIFeatures. @cepetr do you think this is viable?)

the drawback is that you can no longer freely build, say, model_mercury UI for the Trezor T hardware just by switching some feature flags, because ModelTTFeatures specify the NoFb implementation. But if this is desired, we can move the feature-flag selection into ModelTTFeatures (which is frankly a better place for it because model TT only works on color displays anyway)

Importantly, Display does not have lifetime parameters, which makes it very useful downstream -- e.g., it would be possible to keep LayoutObj object-safe even if parametrized by Display. (which is the endgame here -- get rid of all "selectors" that import different modules based on which model is selected, and so be able to e.g. run all rust tests for all models from a single binary)


additionally, f2baf82 fixes unsound API of trezorhal::display::get_frame_buffer

code for given models wouldn't build without these
get_frame_buffer would indiscriminately hand out a &'static mut
reference to the same memory. In practice these references are
short-lived, but the function as written is not safe.
This also makes Mono8 display use the separate bumps instead of a single
larger one, because the merge is introducing an unnecessary difference
@matejcik
Copy link
Contributor Author

note: switch on "hide whitespace" to review bootloader/mod.rs

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

Successfully merging this pull request may close these issues.

1 participant