1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-27 00:28:10 +00:00

fix(core): port changes from drawlib to mercury

Again rebase on current drawlib
Move of canvas/Canvas to shape/Canvas.
Get rid of ui/shape/model.
A few other minor changes.

[no changelog]
This commit is contained in:
obrusvit 2024-03-29 00:14:15 +01:00 committed by Martin Milata
parent 9b98c8af11
commit 7ce980ca98
5 changed files with 8 additions and 88 deletions

View File

@ -6,7 +6,6 @@ use crate::{
micropython::buffer::StrBuffer,
translations::TR,
ui::{
canvas::algo::PI4,
component::{
base::Never, Bar, Child, Component, ComponentExt, Empty, Event, EventCtx, Label, Split,
},
@ -142,8 +141,8 @@ where
let start = (self.value as i32 - 100) % 1000;
let end = (self.value as i32 + 100) % 1000;
let start = ((start * 8 * PI4 as i32) / 1000) as i16;
let end = ((end * 8 * PI4 as i32) / 1000) as i16;
let start = ((start * 8 * shape::PI4 as i32) / 1000) as i16;
let end = ((end * 8 * shape::PI4 as i32) / 1000) as i16;
shape::Circle::new(center, LOADER_OUTER)
.with_bg(inactive_color)

View File

@ -559,7 +559,7 @@ impl Component for Lockscreen {
pub fn check_homescreen_format(buffer: &[u8]) -> bool {
#[cfg(not(feature = "new_rendering"))]
let result = is_image_jpeg(buffer) && jpeg_test(buffer);
let result = is_image_jpeg(buffer) && crate::ui::display::tjpgd::jpeg_test(buffer);
#[cfg(feature = "new_rendering")]
let result = is_image_jpeg(buffer); // !@# TODO: test like if `new_rendering` is off

View File

@ -4,7 +4,6 @@ use crate::{
error::Error,
strutil::StringType,
ui::{
canvas::algo::PI4,
component::{
base::ComponentExt,
paginated::Paginate,
@ -134,11 +133,11 @@ where
let (start, end) = if self.indeterminate {
let start = (self.value - 100) % 1000;
let end = (self.value + 100) % 1000;
let start = ((start as i32 * 8 * PI4 as i32) / 1000) as i16;
let end = ((end as i32 * 8 * PI4 as i32) / 1000) as i16;
let start = ((start as i32 * 8 * shape::PI4 as i32) / 1000) as i16;
let end = ((end as i32 * 8 * shape::PI4 as i32) / 1000) as i16;
(start, end)
} else {
let end = ((self.value as i32 * 8 * PI4 as i32) / 1000) as i16;
let end = ((self.value as i32 * 8 * shape::PI4 as i32) / 1000) as i16;
(0, end)
};

View File

@ -1,9 +1,9 @@
use crate::ui::{
canvas::Canvas,
display::Color,
geometry::{Alignment2D, Offset, Point, Rect},
shape::{DrawingCache, Renderer, Shape, ShapeClone},
shape::{Canvas, DrawingCache, Renderer, Shape, ShapeClone},
};
use without_alloc::alloc::LocalAllocLeakExt;
#[derive(Clone, Copy)]

View File

@ -1,78 +0,0 @@
use crate::ui::{
canvas::{BasicCanvas, Viewport},
display::Color,
geometry::{Offset, Rect},
shape::{DrawingCache, ProgressiveRenderer},
};
use crate::trezorhal::bitmap::{BitmapView, Dma2d};
use static_alloc::Bump;
pub fn render_on_display<'a, F>(clip: Option<Rect>, bg_color: Option<Color>, func: F)
where
F: FnOnce(&mut ProgressiveRenderer<'_, 'a, Bump<[u8; 40 * 1024]>, DisplayModelMercury>),
{
#[link_section = ".no_dma_buffers"]
static mut BUMP_A: Bump<[u8; 40 * 1024]> = Bump::uninit();
#[link_section = ".buf"]
static mut BUMP_B: Bump<[u8; 16 * 1024]> = Bump::uninit();
let bump_a = unsafe { &mut *core::ptr::addr_of_mut!(BUMP_A) };
let bump_b = unsafe { &mut *core::ptr::addr_of_mut!(BUMP_B) };
{
bump_a.reset();
bump_b.reset();
let cache = DrawingCache::new(bump_a, bump_b);
let mut canvas = DisplayModelMercury::acquire().unwrap();
if let Some(clip) = clip {
canvas.set_viewport(Viewport::new(clip));
}
let mut target = ProgressiveRenderer::new(&mut canvas, bg_color, &cache, bump_a, 45);
func(&mut target);
target.render(16);
}
}
pub struct DisplayModelMercury {
size: Offset,
viewport: Viewport,
}
impl DisplayModelMercury {
pub fn acquire() -> Option<Self> {
let size = Offset::new(240, 240); // TODO
let viewport = Viewport::from_size(size);
Some(Self { size, viewport })
}
}
impl BasicCanvas for DisplayModelMercury {
fn viewport(&self) -> Viewport {
self.viewport
}
fn set_viewport(&mut self, viewport: Viewport) {
self.viewport = viewport.absolute_clip(self.bounds());
}
fn size(&self) -> Offset {
self.size
}
fn fill_rect(&mut self, r: Rect, color: Color, _alpha: u8) {
let r = r.translate(self.viewport.origin);
Dma2d::wnd565_fill(r, self.viewport.clip, color);
}
fn draw_bitmap(&mut self, r: Rect, bitmap: BitmapView) {
let r = r.translate(self.viewport.origin);
Dma2d::wnd565_copy(r, self.viewport.clip, &bitmap);
}
}