1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-08-05 13:26:57 +00:00

fix(core): add boundaries check for icon rendering (framebuffer variant)

This commit is contained in:
tychovrahe 2023-09-22 16:49:12 +02:00
parent 34fdaff4aa
commit ccdb7d0560
3 changed files with 22 additions and 5 deletions

View File

@ -10,6 +10,7 @@ use crate::{
geometry::{Alignment2D, Offset, Point, Rect}, geometry::{Alignment2D, Offset, Point, Rect},
}, },
}; };
use core::cmp::max;
#[cfg(feature = "dma2d")] #[cfg(feature = "dma2d")]
use crate::{ use crate::{
@ -74,8 +75,9 @@ pub fn render_toif(toif: &Toif, center: Point, fg_color: Color, bg_color: Color)
pub fn render_toif(toif: &Toif, center: Point, fg_color: Color, bg_color: Color) { pub fn render_toif(toif: &Toif, center: Point, fg_color: Color, bg_color: Color) {
let r = Rect::from_center_and_size(center, toif.size()); let r = Rect::from_center_and_size(center, toif.size());
let area = r.translate(get_offset()); let area = r.translate(get_offset());
let clamped = area.clamp(constant::screen()).ensure_even_width();
set_window(area); set_window(clamped);
let mut b1 = BufferLine4bpp::get_cleared(); let mut b1 = BufferLine4bpp::get_cleared();
let mut b2 = BufferLine4bpp::get_cleared(); let mut b2 = BufferLine4bpp::get_cleared();
@ -85,13 +87,23 @@ pub fn render_toif(toif: &Toif, center: Point, fg_color: Color, bg_color: Color)
dma2d_setup_4bpp(fg_color.into(), bg_color.into()); dma2d_setup_4bpp(fg_color.into(), bg_color.into());
for y in area.y0..area.y1 { let x_shift = max(0, clamped.x0 - area.x0);
for y in area.y0..clamped.y1 {
let img_buffer_used = if y % 2 == 0 { &mut b1 } else { &mut b2 }; let img_buffer_used = if y % 2 == 0 { &mut b1 } else { &mut b2 };
unwrap!(ctx.uncompress(&mut (&mut img_buffer_used.buffer)[0..(area.width() / 2) as usize])); unwrap!(ctx.uncompress(&mut (&mut img_buffer_used.buffer)[..(area.width() / 2) as usize]));
dma2d_wait_for_transfer(); if y >= clamped.y0 {
unsafe { dma2d_start(&img_buffer_used.buffer, area.width()) }; dma2d_wait_for_transfer();
unsafe {
dma2d_start(
&img_buffer_used.buffer
[(x_shift / 2) as usize..((clamped.width() + x_shift) / 2) as usize],
clamped.width(),
)
};
}
} }
dma2d_wait_for_transfer(); dma2d_wait_for_transfer();

View File

@ -80,6 +80,7 @@ where
fadeout(); fadeout();
display::sync(); display::sync();
frame.paint(); frame.paint();
display::refresh();
fadein(); fadein();
loop { loop {
@ -264,6 +265,8 @@ fn screen_progress(
if initialize { if initialize {
fadein(); fadein();
} }
display::refresh();
} }
#[no_mangle] #[no_mangle]
@ -340,6 +343,7 @@ extern "C" fn screen_boot_empty(fading: bool) {
} else { } else {
display::set_backlight(BACKLIGHT_NORMAL); display::set_backlight(BACKLIGHT_NORMAL);
} }
display::refresh();
} }
#[no_mangle] #[no_mangle]

View File

@ -1594,6 +1594,7 @@ extern "C" fn draw_welcome_screen() -> Obj {
screen.place(constant::screen()); screen.place(constant::screen());
display::sync(); display::sync();
screen.paint(); screen.paint();
display::refresh();
display::set_backlight(theme::BACKLIGHT_NORMAL); display::set_backlight(theme::BACKLIGHT_NORMAL);
Obj::const_none() Obj::const_none()
} }