From 411b5be1d825706ee07447a2737b3a5644e7d99f Mon Sep 17 00:00:00 2001 From: Huaxin Date: Thu, 7 Nov 2024 22:35:47 +0800 Subject: [PATCH] Support 16/32 bit color depth Mado currently supports 32-bit color depth for desktop and laptop display devices. To enhance its compatibility across diverse Linux framebuffer environments, I have made the following changes to support both 16-bit and 32-bit color depths: - Distinguish the color format and perform color format conversion. - Examine the correctness of the framebuffer format based on the color format. These updates improve Mado's compatibility, enabling it to be used on devices with low memory overhead, such as the Raspberry Pi, in addition to desktop display devices. --- backend/fbdev.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/backend/fbdev.c b/backend/fbdev.c index d7fb08e..65b3637 100644 --- a/backend/fbdev.c +++ b/backend/fbdev.c @@ -88,6 +88,30 @@ static bool twin_fbdev_work(void *closure) return true; } +<<<<<<< HEAD +======= +static inline bool twin_fbdev_is_rgb565(twin_fbdev_t *tx) +{ + return tx->fb_var.red.offset == 11 && tx->fb_var.red.length == 5 && + tx->fb_var.green.offset == 5 && tx->fb_var.green.length == 6 && + tx->fb_var.blue.offset == 0 && tx->fb_var.blue.length == 5; +} + +static inline bool twin_fbdev_is_rgb888(twin_fbdev_t *tx) +{ + return tx->fb_var.red.offset == 16 && tx->fb_var.red.length == 8 && + tx->fb_var.green.offset == 8 && tx->fb_var.green.length == 8 && + tx->fb_var.blue.offset == 0 && tx->fb_var.blue.length == 8; +} + +static inline bool twin_fbdev_is_argb32(twin_fbdev_t *tx) +{ + return tx->fb_var.red.offset == 16 && tx->fb_var.red.length == 8 && + tx->fb_var.green.offset == 8 && tx->fb_var.green.length == 8 && + tx->fb_var.blue.offset == 0 && tx->fb_var.blue.length == 8; +} + +>>>>>>> b70c59c (Support 16/32 bit color depth) static bool twin_fbdev_apply_config(twin_fbdev_t *tx) { /* Read changable information of the framebuffer */ @@ -111,10 +135,36 @@ static bool twin_fbdev_apply_config(twin_fbdev_t *tx) return false; } +<<<<<<< HEAD /* Check bits per pixel */ if (tx->fb_var.bits_per_pixel != 32) { log_error("Failed to set framebuffer bpp to 32"); return false; +======= + /* Examine the framebuffer format */ + switch (tx->fb_var.bits_per_pixel) { + case 16: /* RGB565 */ + if (!twin_fbdev_is_rgb565(tx)) { + log_error("Invalid framebuffer format for 16 bpp"); + return false; + } + break; + case 24: /* RGB888 */ + if (!twin_fbdev_is_rgb888(tx)) { + log_error("Invalid framebuffer format for 24 bpp"); + return false; + } + break; + case 32: /* ARGB32 */ + if (!twin_fbdev_is_argb32(tx)) { + log_error("Invalid framebuffer format for 32 bpp"); + return false; + } + break; + default: + log_error("Unsupported bits per pixel: %d", tx->fb_var.bits_per_pixel); + break; +>>>>>>> b70c59c (Support 16/32 bit color depth) } /* Read unchangable information of the framebuffer */