[PATCH 2/8] video: vidconsole: Support wider bitmap fonts

Andre Przywara andre.przywara at arm.com
Mon Jan 10 01:56:32 CET 2022


Currently the DM_VIDEO console only supports bitmap fonts with up to
8 pixels wide glyphs. Add support for fonts with glyphs up to 32 pixels
wide, as those might prove useful on high resolution screens.

This is done by expanding the glyph bits buffer to 32bits, and aligning
the font data to the high bits, counting down from there. The compiler
should optimise away any unneeded accesses for narrower fonts.

Signed-off-by: Andre Przywara <andre.przywara at arm.com>
---
 drivers/video/console_normal.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index bfd3aab8d24..9f552d02b30 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -13,6 +13,9 @@
 #include <video_console.h>
 #include <video_font.h>		/* Get font data, width and height */
 
+#define VIDEO_FONT_STRIDE	((VIDEO_FONT_WIDTH + 7) / 8)
+#define VIDEO_FONT_GLYPH_BYTES	(VIDEO_FONT_STRIDE * VIDEO_FONT_HEIGHT)
+
 static int console_normal_set_row(struct udevice *dev, uint row, int clr)
 {
 	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
@@ -98,8 +101,20 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
 		return -EAGAIN;
 
 	for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
-		unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
-		uchar bits = video_fontdata[idx];
+		uint32_t bits = video_fontdata[(u8)ch * VIDEO_FONT_GLYPH_BYTES +
+					       row * VIDEO_FONT_STRIDE] << 24;
+
+		if (VIDEO_FONT_WIDTH > 8)
+			bits |= video_fontdata[ch * VIDEO_FONT_GLYPH_BYTES +
+					     row * VIDEO_FONT_STRIDE + 1] << 16;
+
+		if (VIDEO_FONT_WIDTH > 16)
+			bits |= video_fontdata[ch * VIDEO_FONT_GLYPH_BYTES +
+					     row * VIDEO_FONT_STRIDE + 2] << 8;
+
+		if (VIDEO_FONT_WIDTH > 24)
+			bits |= video_fontdata[ch * VIDEO_FONT_GLYPH_BYTES +
+					     row * VIDEO_FONT_STRIDE + 3];
 
 		switch (vid_priv->bpix) {
 		case VIDEO_BPP8:
@@ -107,7 +122,7 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
 				uint8_t *dst = line;
 
 				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-					*dst++ = (bits & 0x80) ?
+					*dst++ = (bits & BIT(31)) ?
 						vid_priv->colour_fg :
 						vid_priv->colour_bg;
 					bits <<= 1;
@@ -119,7 +134,7 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
 				uint16_t *dst = line;
 
 				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-					*dst++ = (bits & 0x80) ?
+					*dst++ = (bits & BIT(31)) ?
 						vid_priv->colour_fg :
 						vid_priv->colour_bg;
 					bits <<= 1;
@@ -131,7 +146,7 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
 				uint32_t *dst = line;
 
 				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-					*dst++ = (bits & 0x80) ?
+					*dst++ = (bits & BIT(31)) ?
 						vid_priv->colour_fg :
 						vid_priv->colour_bg;
 					bits <<= 1;
-- 
2.17.6



More information about the U-Boot mailing list