diff mbox series

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

Message ID 20220110005638.21599-3-andre.przywara@arm.com
State Deferred
Delegated to: Tom Rini
Headers show
Series video: improve UEFI experience on DM_VIDEO | expand

Commit Message

Andre Przywara Jan. 10, 2022, 12:56 a.m. UTC
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@arm.com>
---
 drivers/video/console_normal.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

Comments

Simon Glass Jan. 12, 2022, 8:04 p.m. UTC | #1
On Sun, 9 Jan 2022 at 17:57, Andre Przywara <andre.przywara@arm.com> wrote:
>
> 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@arm.com>
> ---
>  drivers/video/console_normal.c | 25 ++++++++++++++++++++-----
>  1 file changed, 20 insertions(+), 5 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

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;