Skip to content

Commit 9b47613

Browse files
committed
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.
1 parent efe7d49 commit 9b47613

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

backend/fbdev.c

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,27 @@ static bool twin_fbdev_work(void *closure)
8888
return true;
8989
}
9090

91+
static inline bool twin_fbdev_is_rgb565(twin_fbdev_t *tx)
92+
{
93+
return tx->fb_var.red.offset == 11 && tx->fb_var.red.length == 5 &&
94+
tx->fb_var.green.offset == 5 && tx->fb_var.green.length == 6 &&
95+
tx->fb_var.blue.offset == 0 && tx->fb_var.blue.length == 5;
96+
}
97+
98+
static inline bool twin_fbdev_is_rgb888(twin_fbdev_t *tx)
99+
{
100+
return tx->fb_var.red.offset == 16 && tx->fb_var.red.length == 8 &&
101+
tx->fb_var.green.offset == 8 && tx->fb_var.green.length == 8 &&
102+
tx->fb_var.blue.offset == 0 && tx->fb_var.blue.length == 8;
103+
}
104+
105+
static inline bool twin_fbdev_is_argb32(twin_fbdev_t *tx)
106+
{
107+
return tx->fb_var.red.offset == 16 && tx->fb_var.red.length == 8 &&
108+
tx->fb_var.green.offset == 8 && tx->fb_var.green.length == 8 &&
109+
tx->fb_var.blue.offset == 0 && tx->fb_var.blue.length == 8;
110+
}
111+
91112
static bool twin_fbdev_apply_config(twin_fbdev_t *tx)
92113
{
93114
/* Read changable information of the framebuffer */
@@ -111,10 +132,29 @@ static bool twin_fbdev_apply_config(twin_fbdev_t *tx)
111132
return false;
112133
}
113134

114-
/* Check bits per pixel */
115-
if (tx->fb_var.bits_per_pixel != 32) {
116-
log_error("Failed to set framebuffer bpp to 32");
117-
return false;
135+
/* Examine the framebuffer format */
136+
switch (tx->fb_var.bits_per_pixel) {
137+
case 16: /* RGB565 */
138+
if (!twin_fbdev_is_rgb565(tx)) {
139+
log_error("Invalid framebuffer format for 16 bpp");
140+
return false;
141+
}
142+
break;
143+
case 24: /* RGB888 */
144+
if (!twin_fbdev_is_rgb888(tx)) {
145+
log_error("Invalid framebuffer format for 24 bpp");
146+
return false;
147+
}
148+
break;
149+
case 32: /* ARGB32 */
150+
if (!twin_fbdev_is_argb32(tx)) {
151+
log_error("Invalid framebuffer format for 32 bpp");
152+
return false;
153+
}
154+
break;
155+
default:
156+
log_error("Unsupported bits per pixel: %d", tx->fb_var.bits_per_pixel);
157+
break;
118158
}
119159

120160
/* Read unchangable information of the framebuffer */

0 commit comments

Comments
 (0)