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

feat(core): support 32 bit colors in emulator

[no changelog]
This commit is contained in:
tychovrahe 2024-10-22 15:53:16 +02:00 committed by TychoVrahe
parent 80fcaa369f
commit 9f52918d27
2 changed files with 56 additions and 17 deletions

View File

@ -294,15 +294,15 @@ void gfx_draw_qrcode(int x, int y, uint8_t scale, const char* data) {
void display_clear(void) { gfx_clear(); } void display_clear(void) { gfx_clear(); }
void display_bar(int x, int y, int w, int h, uint16_t c) { void display_bar(int x, int y, int w, int h, uint16_t c) {
gfx_draw_bar(gfx_rect_wh(x, y, w, h), c); gfx_draw_bar(gfx_rect_wh(x, y, w, h), gfx_color16_to_color(c));
} }
void display_text(int x, int y, const char* text, int textlen, int font, void display_text(int x, int y, const char* text, int textlen, int font,
uint16_t fg_color, uint16_t bg_color) { uint16_t fg_color, uint16_t bg_color) {
gfx_text_attr_t attr = { gfx_text_attr_t attr = {
.font = font, .font = font,
.fg_color = fg_color, .fg_color = gfx_color16_to_color(fg_color),
.bg_color = bg_color, .bg_color = gfx_color16_to_color(bg_color),
}; };
size_t maxlen = textlen < 0 ? UINT32_MAX : textlen; size_t maxlen = textlen < 0 ? UINT32_MAX : textlen;
@ -313,8 +313,8 @@ void display_text_center(int x, int y, const char* text, int textlen, int font,
uint16_t fg_color, uint16_t bg_color) { uint16_t fg_color, uint16_t bg_color) {
gfx_text_attr_t attr = { gfx_text_attr_t attr = {
.font = font, .font = font,
.fg_color = fg_color, .fg_color = gfx_color16_to_color(fg_color),
.bg_color = bg_color, .bg_color = gfx_color16_to_color(bg_color),
}; };
size_t maxlen = textlen < 0 ? UINT32_MAX : textlen; size_t maxlen = textlen < 0 ? UINT32_MAX : textlen;

View File

@ -31,6 +31,28 @@
#define EMULATOR_BORDER 16 #define EMULATOR_BORDER 16
#ifdef UI_COLOR_32BIT
#define PIXEL_FORMAT SDL_PIXELFORMAT_ARGB8888
#define COLOR_DEPTH 32
#define COLOR_MASK_A 0xFF000000
#define COLOR_MASK_R 0x00FF0000
#define COLOR_MASK_G 0x0000FF00
#define COLOR_MASK_B 0x000000FF
#define PIXEL_SIZE 4
#else
#define PIXEL_FORMAT SDL_PIXELFORMAT_RGB565
#define COLOR_DEPTH 16
#define COLOR_MASK_R 0xF800
#define COLOR_MASK_G 0x07E0
#define COLOR_MASK_B 0x001F
#define COLOR_MASK_A 0x0000
#define PIXEL_SIZE 2
#endif
typedef struct { typedef struct {
// Set if the driver is initialized // Set if the driver is initialized
bool initialized; bool initialized;
@ -111,9 +133,10 @@ void display_init(display_content_mode_t mode) {
SDL_SetRenderDrawColor(drv->renderer, 0, 0, 0, 255); SDL_SetRenderDrawColor(drv->renderer, 0, 0, 0, 255);
SDL_RenderClear(drv->renderer); SDL_RenderClear(drv->renderer);
drv->buffer = SDL_CreateRGBSurface(0, DISPLAY_RESX, DISPLAY_RESY, 16, 0xF800, drv->buffer = SDL_CreateRGBSurface(0, DISPLAY_RESX, DISPLAY_RESY, COLOR_DEPTH,
0x07E0, 0x001F, 0x0000); COLOR_MASK_R, COLOR_MASK_G, COLOR_MASK_B,
drv->texture = SDL_CreateTexture(drv->renderer, SDL_PIXELFORMAT_RGB565, COLOR_MASK_A);
drv->texture = SDL_CreateTexture(drv->renderer, PIXEL_FORMAT,
SDL_TEXTUREACCESS_STREAMING, DISPLAY_RESX, SDL_TEXTUREACCESS_STREAMING, DISPLAY_RESX,
DISPLAY_RESY); DISPLAY_RESY);
SDL_SetTextureBlendMode(drv->texture, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(drv->texture, SDL_BLENDMODE_BLEND);
@ -252,16 +275,16 @@ bool display_get_frame_buffer(display_fb_info_t *fb) {
fb->ptr = NULL; fb->ptr = NULL;
fb->stride = 0; fb->stride = 0;
return false; return false;
} else { }
#ifdef DISPLAY_MONO #ifdef DISPLAY_MONO
fb->ptr = drv->mono_framebuf; fb->ptr = drv->mono_framebuf;
fb->stride = DISPLAY_RESX; fb->stride = DISPLAY_RESX;
#else #else
fb->ptr = drv->buffer->pixels; fb->ptr = drv->buffer->pixels;
fb->stride = DISPLAY_RESX * sizeof(uint16_t); fb->stride = DISPLAY_RESX * PIXEL_SIZE;
#endif #endif
return true; return true;
}
} }
#else // XFRAMEBUFFER #else // XFRAMEBUFFER
@ -338,7 +361,11 @@ void display_fill(const gfx_bitblt_t *bb) {
(uint8_t *)drv->buffer->pixels + (drv->buffer->pitch * bb_new.dst_y); (uint8_t *)drv->buffer->pixels + (drv->buffer->pitch * bb_new.dst_y);
bb_new.dst_stride = drv->buffer->pitch; bb_new.dst_stride = drv->buffer->pitch;
#ifdef UI_COLOR_32BIT
gfx_rgba8888_fill(&bb_new);
#else
gfx_rgb565_fill(&bb_new); gfx_rgb565_fill(&bb_new);
#endif
} }
void display_copy_rgb565(const gfx_bitblt_t *bb) { void display_copy_rgb565(const gfx_bitblt_t *bb) {
@ -353,7 +380,11 @@ void display_copy_rgb565(const gfx_bitblt_t *bb) {
(uint8_t *)drv->buffer->pixels + (drv->buffer->pitch * bb_new.dst_y); (uint8_t *)drv->buffer->pixels + (drv->buffer->pitch * bb_new.dst_y);
bb_new.dst_stride = drv->buffer->pitch; bb_new.dst_stride = drv->buffer->pitch;
#ifdef UI_COLOR_32BIT
gfx_rgba8888_copy_rgb565(&bb_new);
#else
gfx_rgb565_copy_rgb565(&bb_new); gfx_rgb565_copy_rgb565(&bb_new);
#endif
} }
void display_copy_mono1p(const gfx_bitblt_t *bb) { void display_copy_mono1p(const gfx_bitblt_t *bb) {
@ -368,7 +399,11 @@ void display_copy_mono1p(const gfx_bitblt_t *bb) {
(uint8_t *)drv->buffer->pixels + (drv->buffer->pitch * bb_new.dst_y); (uint8_t *)drv->buffer->pixels + (drv->buffer->pitch * bb_new.dst_y);
bb_new.dst_stride = drv->buffer->pitch; bb_new.dst_stride = drv->buffer->pitch;
#ifdef UI_COLOR_32BIT
gfx_rgba8888_copy_mono1p(&bb_new);
#else
gfx_rgb565_copy_mono1p(&bb_new); gfx_rgb565_copy_mono1p(&bb_new);
#endif
} }
void display_copy_mono4(const gfx_bitblt_t *bb) { void display_copy_mono4(const gfx_bitblt_t *bb) {
@ -383,7 +418,11 @@ void display_copy_mono4(const gfx_bitblt_t *bb) {
(uint8_t *)drv->buffer->pixels + (drv->buffer->pitch * bb_new.dst_y); (uint8_t *)drv->buffer->pixels + (drv->buffer->pitch * bb_new.dst_y);
bb_new.dst_stride = drv->buffer->pitch; bb_new.dst_stride = drv->buffer->pitch;
#ifdef UI_COLOR_32BIT
gfx_rgba8888_copy_mono4(&bb_new);
#else
gfx_rgb565_copy_mono4(&bb_new); gfx_rgb565_copy_mono4(&bb_new);
#endif
} }
#else // DISPLAY_MONO #else // DISPLAY_MONO