Skip to contentSkip to conversation

vidconsole: refactoring and support for wider fonts

PATCH Superseded Dzmitry Sankouski 3 participants 18 messages Feb 13, 2023 – Feb 15, 2023 Framebuffer layer

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v2 cover vidconsole: refactoring and support for wider fonts

Modern mobile phones typically have high pixel density. Bootmenu is hardly readable on those with 8x16 font.

This patch series aims to add wider fonts for devices with high ppi.

Add 16x32, 12x22 fonts from linux, and allow font size configuration.

There was significant changes in version 3:
- fix video tests failures
- add runtime font size configuration
- add test for 12x22 font

Dzmitry Sankouski (8):
video console: unite normal and rotated files
video console: refactoring and optimization
video console: add support for fonts wider than 1 byte video console: add select font logic to vidconsole uclass driver video console: allow font size configuration at runtime video console: add 12x22 Sun font from linux
video console: add 16x32 Terminus font from linux video console: add 12x22 console simple font test

 cmd/Kconfig                       |    8 +
 cmd/Makefile                      |    2 +-
 cmd/font.c                        |    7 +-
 common/splash.c                   |    7 +-
 configs/qemu-x86_defconfig        |    1 +
 configs/sandbox_defconfig         |    3 +
 drivers/video/Kconfig             |   38 +-
 drivers/video/Makefile            |    3 +-
 drivers/video/console_normal.c    |  178 -
 drivers/video/console_rotate.c    |  497 ---
 drivers/video/console_simple.c    |  638 +++
 drivers/video/console_truetype.c  |    6 +-
 drivers/video/vidconsole-uclass.c |   22 +
 include/video.h                   |    1 +
 include/video_console.h           |   18 +-
 include/video_font.h              |   31 +-
 include/video_font_4x6.h          |   11 +-
 include/video_font_8x16.h         | 4624 ++++++++++++++++++++++
 include/video_font_data.h         | 4644 +---------------------
 include/video_font_sun12x22.h     | 6158 +++++++++++++++++++++++++++++
 include/video_font_ter16x32.h     | 2062 ++++++++++
 test/dm/video.c                   |   41 +
 22 files changed, 13681 insertions(+), 5319 deletions(-)
 delete mode 100644 drivers/video/console_normal.c
 delete mode 100644 drivers/video/console_rotate.c
 create mode 100644 drivers/video/console_simple.c
 create mode 100644 include/video_font_8x16.h
 create mode 100644 include/video_font_sun12x22.h
 create mode 100644 include/video_font_ter16x32.h
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/8 video console: unite normal and rotated files

Unite console_normal.c and console_rotate.c files. Those files have similar logic, and common logic may be extracted after putting code in single file.

---
Changes for v2:
- none

 drivers/video/Kconfig                         |   8 +-
 drivers/video/Makefile                        |   3 +-
 drivers/video/console_normal.c                | 178 ------------------
 .../{console_rotate.c => console_simple.c}    | 166 ++++++++++++++++
 4 files changed, 171 insertions(+), 184 deletions(-)
 delete mode 100644 drivers/video/console_normal.c
 rename drivers/video/{console_rotate.c => console_simple.c} (75%)
drivers/video/Kconfig +4 -4
index f539977d9b..1dfe11d182 100644
@@ -124,17 +124,17 @@ config VIDEO_MIPI_DSI
 	  The MIPI Display Serial Interface (MIPI DSI) defines a high-speed
 	  serial interface between a host processor and a display module.
 
-config CONSOLE_NORMAL
+config VIDEO_CONSOLE
 	bool "Support a simple text console"
 	default y
 	help
 	  Support drawing text on the frame buffer console so that it can be
-	  used as a console. Rotation is not supported by this driver (see
-	  CONFIG_CONSOLE_ROTATION for that). A built-in 8x16 font is used
-	  for the display.
+	  used as a console. See CONFIG_CONSOLE_ROTATION for rotation support.
+	  A built-in 8x16 font is used for the display.
 
 config CONSOLE_ROTATION
 	bool "Support rotated displays"
+	depends on VIDEO_CONSOLE
 	help
 	  Sometimes, for example if the display is mounted in portrait
 	  mode or even if it's mounted landscape but rotated by 180degree,
drivers/video/Makefile +1 -2
index 40a871d638..75decf707d 100644
@@ -7,8 +7,7 @@ ifdef CONFIG_DM
 obj-$(CONFIG_BACKLIGHT) += backlight-uclass.o
 obj-$(CONFIG_BACKLIGHT_GPIO) += backlight_gpio.o
 obj-$(CONFIG_BACKLIGHT_PWM) += pwm_backlight.o
-obj-$(CONFIG_CONSOLE_NORMAL) += console_normal.o
-obj-$(CONFIG_CONSOLE_ROTATION) += console_rotate.o
+obj-$(CONFIG_VIDEO_CONSOLE) += console_simple.o
 obj-$(CONFIG_CONSOLE_TRUETYPE) += console_truetype.o fonts/
 obj-$(CONFIG_DISPLAY) += display-uclass.o
 obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi-host-uclass.o
drivers/video/console_normal.c deleted +0 -178

178 lines not on this page · raw message

drivers/video/console_simple.c renamed from drivers/video/console_rotate.c +166 -0

175 lines not on this page · raw message

Signature · 1 line
2.30.2
#2 lore raw

PATCH v2 2/8 video console: refactoring and optimization

In reply to Dzmitry Sankouski

- get rid of code duplications in switch across bpp values
- extract common pixel fill logic in two functions one per horizontal and vertical filling
- rearrange statements in put_xy* methods in unified way
- replace types - uint*_t to u*

---
Changes for v2:
- move width and pixel data size macros to console_simple.c
- performance: move if statement out of pixel fill loops
- document new functions
- remove console_probe_2 function
- make fill_pixel_and_goto_next void
- fix video unit tests failures

 drivers/video/console_simple.c | 598 ++++++++++++++-------------------
 1 file changed, 258 insertions(+), 340 deletions(-)
drivers/video/console_simple.c +258 -340
index a4b3cfe3d8..1eb47be449 100644
@@ -3,6 +3,7 @@
  * Copyright (c) 2015 Google, Inc
  * (C) Copyright 2015
  * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
+ * (C) Copyright 2023 Dzmitry Sankouski <[email protected]>
  */
 
 #include <common.h>
@@ -11,46 +12,209 @@
 #include <video_console.h>
 #include <video_font.h>		/* Get font data, width and 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);
-	void *line, *end;
-	int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
-	int ret;
-	int i;
+#define VIDEO_FONT_BYTE_WIDTH	((VIDEO_FONT_WIDTH / 8) + (VIDEO_FONT_WIDTH % 8 > 0))
 
-	line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
-	switch (vid_priv->bpix) {
-	case VIDEO_BPP8:
-		if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
-			uint8_t *dst = line;
+#define FLIPPED_DIRECTION 1
+#define NORMAL_DIRECTION 0
 
-			for (i = 0; i < pixels; i++)
-				*dst++ = clr;
-			end = dst;
-			break;
-		}
+/**
+ * Checks if bits per pixel supported.
+ *
+ * @param bpix	framebuffer bits per pixel.
+ *
+ * @returns 0, if supported, or else -ENOSYS.
+ */
+static int check_bpix_support(int bpix)
+{
+	switch (bpix) {
+	case VIDEO_BPP8:
+		if (IS_ENABLED(CONFIG_VIDEO_BPP8))
+			return 0;
 	case VIDEO_BPP16:
-		if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
-			uint16_t *dst = line;
+		if (IS_ENABLED(CONFIG_VIDEO_BPP16))
+			return 0;
+	case VIDEO_BPP32:
+		if (IS_ENABLED(CONFIG_VIDEO_BPP32))
+			return 0;
+	default:
+		return -ENOSYS;
+	}
+}
+
+/**
+ * Fill 1 pixel in framebuffer, and go to next one.
+ *
+ * @param dstp		a pointer to pointer to framebuffer.
+ * @param value		value to write to framebuffer.
+ * @param pbytes	framebuffer bytes per pixel.
+ * @param step		framebuffer pointer increment. Usually is equal to pbytes,
+ *			and may be negative to control filling direction.
+ */
+static inline void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes, int step)
+{
+	u8 *dst_byte = *dstp;
+
+	if (pbytes == 4) {
+		u32 *dst = *dstp;
+		*dst = value;
+	}
+	if (pbytes == 2) {
+		u16 *dst = *dstp;
+		*dst = value;
+	}
+	if (pbytes == 1) {
+		u8 *dst = *dstp;
+		*dst = value;
+	}
+	*dstp = dst_byte + step;
+}
+
+#if (CONFIG_IS_ENABLED(CONSOLE_ROTATION))
+/**
+ * Fills 1 character in framebuffer horizontally.
+ * Horizontally means we're filling char font data columns across the lines.
+ *
+ * @param pfont		a pointer to character font data.
+ * @param line		a pointer to pointer to framebuffer. It's a point for upper left char corner
+ * @param vid_priv	driver private data.
+ * @param direction	controls character orientation. Can be normal or flipped.
+ * When normal:               When flipped:
+ *|-----------------------------------------------|
+ *|               *        |   line stepping      |
+ *|    ^  * * * * *        |   |                  |
+ *|    |    *     *        |   v   *     *        |
+ *|    |                   |       * * * * *      |
+ *|  line stepping         |       *              |
+ *|                        |                      |
+ *|  stepping ->           |        <- stepping   |
+ *|---!!we're starting from upper left char corner|
+ *|-----------------------------------------------|
+ *
+ * @returns 0, if success, or else error code.
+ */
+static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *vid_priv,
+				  bool direction)
+{
+	int step, line_step, pbytes, ret;
+	void *dst;
+	u8 mask = 0x80;
+
+	ret = check_bpix_support(vid_priv->bpix);
+	if (ret)
+		return ret;
+
+	pbytes = VNBYTES(vid_priv->bpix);
+	if (direction) {
+		step = -pbytes;
+		line_step = vid_priv->line_length;
+	} else {
+		step = pbytes;
+		line_step = -vid_priv->line_length;
+	}
+	for (int col = 0; col < VIDEO_FONT_WIDTH; col++) {
+		dst = *line;
+		for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+			u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH] & mask) ?
+						vid_priv->colour_fg :
+						vid_priv->colour_bg;
 
-			for (i = 0; i < pixels; i++)
-				*dst++ = clr;
-			end = dst;
-			break;
+			fill_pixel_and_goto_next(&dst,
+						 value,
+						 pbytes,
+						 step
+			);
 		}
-	case VIDEO_BPP32:
-		if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
-			uint32_t *dst = line;
+		*line += line_step;
+		mask >>= 1;
+	}
+	return ret;
+}
+#endif
 
-			for (i = 0; i < pixels; i++)
-				*dst++ = clr;
-			end = dst;
-			break;
+/**
+ * Fills 1 character in framebuffer vertically. Vertically means we're filling char font data rows
+ * across the lines.
+ *
+ * @param pfont		a pointer to character font data.
+ * @param line		a pointer to pointer to framebuffer. It's a point for upper left char corner
+ * @param vid_priv	driver private data.
+ * @param direction	controls character orientation. Can be normal or flipped.
+ * When normal:               When flipped:
+ *|-----------------------------------------------|
+ *| line stepping        |                        |
+ *|            |         |       stepping ->      |
+ *|     *      |         |       * * *            |
+ *|   * *      v         |         *              |
+ *|     *                |         *              |
+ *|     *                |         * *      ^     |
+ *|   * * *              |         *        |     |
+ *|                      |                  |     |
+ *| stepping ->          |         line stepping  |
+ *|---!!we're starting from upper left char corner|
+ *|-----------------------------------------------|
+ *
+ * @returns 0, if success, or else error code.
+ */
+static int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vid_priv,
+				bool direction)
+{
+	int step, line_step, pbytes, ret;
+	void *dst;
+
+	ret = check_bpix_support(vid_priv->bpix);
+	if (ret)
+		return ret;
+
+	pbytes = VNBYTES(vid_priv->bpix);
+	if (direction) {
+		step = -pbytes;
+		line_step = -vid_priv->line_length;
+	} else {
+		step = pbytes;
+		line_step = vid_priv->line_length;
+	}
+
+	for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+		dst = *line;
+		uchar bits = pfont[row];
+
+		for (int i = 0; i < VIDEO_FONT_WIDTH; i++) {
+			u32 value = (bits & 0x80) ?
+				vid_priv->colour_fg :
+				vid_priv->colour_bg;
+
+			fill_pixel_and_goto_next(&dst,
+						 value,
+						 pbytes,
+						 step
+			);
+			bits <<= 1;
 		}
-	default:
-		return -ENOSYS;
+		*line += line_step;
 	}
+	return ret;
+}
+
+static int console_set_row(struct udevice *dev, uint row, int clr)
+{
+	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+	void *line, *dst, *end;
+	int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
+	int ret;
+	int i;
+	int pbytes;
+
+	ret = check_bpix_support(vid_priv->bpix);
+	if (ret)
+		return ret;
+
+	line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
+	dst = line;
+	pbytes = VNBYTES(vid_priv->bpix);
+	for (i = 0; i < pixels; i++)
+		fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
+	end = dst;
+
 	ret = vidconsole_sync_copy(dev, line, end);
 	if (ret)
 		return ret;
@@ -58,8 +222,8 @@ static int console_normal_set_row(struct udevice *dev, uint row, int clr)
 	return 0;
 }
 
-static int console_normal_move_rows(struct udevice *dev, uint rowdst,
-				     uint rowsrc, uint count)
+static int console_move_rows(struct udevice *dev, uint rowdst,
+			     uint rowsrc, uint count)
 {
 	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
 	void *dst;
@@ -77,70 +241,30 @@ static int console_normal_move_rows(struct udevice *dev, uint rowdst,
 	return 0;
 }
 
-static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
-				  char ch)
+static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch)
 {
 	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
 	struct udevice *vid = dev->parent;
 	struct video_priv *vid_priv = dev_get_uclass_priv(vid);
-	int i, row;
-	void *start;
-	void *line;
-	int ret;
+	int pbytes = VNBYTES(vid_priv->bpix);
+	int x, linenum, ret;
+	void *start, *line;
+	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
 
-	start = vid_priv->fb + y * vid_priv->line_length +
-		VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
+	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
+		return -EAGAIN;
+	linenum = y;
+	x = VID_TO_PIXEL(x_frac);
+	start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes;
 	line = start;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
 
-	for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
-		unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
-		uchar bits = video_fontdata[idx];
-
-		switch (vid_priv->bpix) {
-		case VIDEO_BPP8:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
-				uint8_t *dst = line;
+	ret = fill_char_vertically(pfont, &line, vid_priv, NORMAL_DIRECTION);
+	if (ret)
+		return ret;
 
-				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-					*dst++ = (bits & 0x80) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-					bits <<= 1;
-				}
-				break;
-			}
-		case VIDEO_BPP16:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
-				uint16_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-					*dst++ = (bits & 0x80) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-					bits <<= 1;
-				}
-				break;
-			}
-		case VIDEO_BPP32:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
-				uint32_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-					*dst++ = (bits & 0x80) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-					bits <<= 1;
-				}
-				break;
-			}
-		default:
-			return -ENOSYS;
-		}
-		line += vid_priv->line_length;
-	}
 	ret = vidconsole_sync_copy(dev, start, line);
 	if (ret)
 		return ret;
@@ -148,7 +272,7 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
 	return VID_TO_POS(VIDEO_FONT_WIDTH);
 }
 
-static int console_normal_probe(struct udevice *dev)
+static int console_probe(struct udevice *dev)
 {
 	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
 	struct udevice *vid_dev = dev->parent;
@@ -162,25 +286,25 @@ static int console_normal_probe(struct udevice *dev)
 	return 0;
 }
 
-struct vidconsole_ops console_normal_ops = {
-	.putc_xy	= console_normal_putc_xy,
-	.move_rows	= console_normal_move_rows,
-	.set_row	= console_normal_set_row,
+struct vidconsole_ops console_ops = {
+	.putc_xy	= console_putc_xy,
+	.move_rows	= console_move_rows,
+	.set_row	= console_set_row,
 };
 
 U_BOOT_DRIVER(vidconsole_normal) = {
 	.name	= "vidconsole0",
 	.id	= UCLASS_VIDEO_CONSOLE,
-	.ops	= &console_normal_ops,
-	.probe	= console_normal_probe,
+	.ops	= &console_ops,
+	.probe	= console_probe,
 };
 
-#if defined(CONFIG_CONSOLE_ROTATION)
+#if (CONFIG_IS_ENABLED(CONSOLE_ROTATION))
 static int console_set_row_1(struct udevice *dev, uint row, int clr)
 {
 	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
 	int pbytes = VNBYTES(vid_priv->bpix);
-	void *start, *line;
+	void *start, *dst, *line;
 	int i, j;
 	int ret;
 
@@ -188,34 +312,9 @@ static int console_set_row_1(struct udevice *dev, uint row, int clr)
 		(row + 1) * VIDEO_FONT_HEIGHT * pbytes;
 	line = start;
 	for (j = 0; j < vid_priv->ysize; j++) {
-		switch (vid_priv->bpix) {
-		case VIDEO_BPP8:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
-				uint8_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
-					*dst++ = clr;
-				break;
-			}
-		case VIDEO_BPP16:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
-				uint16_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
-					*dst++ = clr;
-				break;
-			}
-		case VIDEO_BPP32:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
-				uint32_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
-					*dst++ = clr;
-				break;
-			}
-		default:
-			return -ENOSYS;
-		}
+		dst = line;
+		for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
+			fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
 		line += vid_priv->line_length;
 	}
 	ret = vidconsole_sync_copy(dev, start, line);
@@ -226,7 +325,7 @@ static int console_set_row_1(struct udevice *dev, uint row, int clr)
 }
 
 static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
-			       uint count)
+				   uint count)
 {
 	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
 	int pbytes = VNBYTES(vid_priv->bpix);
@@ -241,7 +340,7 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
 
 	for (j = 0; j < vid_priv->ysize; j++) {
 		ret = vidconsole_memmove(dev, dst, src,
-					 VIDEO_FONT_HEIGHT * pbytes * count);
+					VIDEO_FONT_HEIGHT * pbytes * count);
 		if (ret)
 			return ret;
 		src += vid_priv->line_length;
@@ -256,60 +355,22 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
 	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
 	struct udevice *vid = dev->parent;
 	struct video_priv *vid_priv = dev_get_uclass_priv(vid);
-	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
 	int pbytes = VNBYTES(vid_priv->bpix);
-	int i, col, x, linenum, ret;
-	int mask = 0x80;
+	int x, linenum, ret;
 	void *start, *line;
+	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
 
+	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
+		return -EAGAIN;
 	linenum = VID_TO_PIXEL(x_frac) + 1;
 	x = y + 1;
 	start = vid_priv->fb + linenum * vid_priv->line_length - x * pbytes;
 	line = start;
-	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
-		return -EAGAIN;
 
-	for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
-		switch (vid_priv->bpix) {
-		case VIDEO_BPP8:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
-				uint8_t *dst = line;
+	ret = fill_char_horizontally(pfont, &line, vid_priv, FLIPPED_DIRECTION);
+	if (ret)
+		return ret;
 
-				for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
-					*dst-- = (pfont[i] & mask) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-				}
-				break;
-			}
-		case VIDEO_BPP16:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
-				uint16_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
-					*dst-- = (pfont[i] & mask) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-				}
-				break;
-			}
-		case VIDEO_BPP32:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
-				uint32_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
-					*dst-- = (pfont[i] & mask) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-				}
-				break;
-			}
-		default:
-			return -ENOSYS;
-		}
-		line += vid_priv->line_length;
-		mask >>= 1;
-	}
 	/* We draw backwards from 'start, so account for the first line */
 	ret = vidconsole_sync_copy(dev, start - vid_priv->line_length, line);
 	if (ret)
@@ -322,44 +383,18 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
 static int console_set_row_2(struct udevice *dev, uint row, int clr)
 {
 	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
-	void *start, *line, *end;
+	void *start, *line, *dst, *end;
 	int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
 	int i, ret;
+	int pbytes = VNBYTES(vid_priv->bpix);
 
 	start = vid_priv->fb + vid_priv->ysize * vid_priv->line_length -
 		(row + 1) * VIDEO_FONT_HEIGHT * vid_priv->line_length;
 	line = start;
-	switch (vid_priv->bpix) {
-	case VIDEO_BPP8:
-		if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
-			uint8_t *dst = line;
-
-			for (i = 0; i < pixels; i++)
-				*dst++ = clr;
-			end = dst;
-			break;
-		}
-	case VIDEO_BPP16:
-		if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
-			uint16_t *dst = line;
-
-			for (i = 0; i < pixels; i++)
-				*dst++ = clr;
-			end = dst;
-			break;
-		}
-	case VIDEO_BPP32:
-		if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
-			uint32_t *dst = line;
-
-			for (i = 0; i < pixels; i++)
-				*dst++ = clr;
-			end = dst;
-			break;
-		}
-	default:
-		return -ENOSYS;
-	}
+	dst = line;
+	for (i = 0; i < pixels; i++)
+		fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
+	end = dst;
 	ret = vidconsole_sync_copy(dev, start, end);
 	if (ret)
 		return ret;
@@ -392,8 +427,9 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
 	struct udevice *vid = dev->parent;
 	struct video_priv *vid_priv = dev_get_uclass_priv(vid);
 	int pbytes = VNBYTES(vid_priv->bpix);
-	int i, row, x, linenum, ret;
+	int linenum, x, ret;
 	void *start, *line;
+	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
@@ -402,52 +438,10 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
 	start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes;
 	line = start;
 
-	for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
-		unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
-		uchar bits = video_fontdata[idx];
-
-		switch (vid_priv->bpix) {
-		case VIDEO_BPP8:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
-				uint8_t *dst = line;
+	ret = fill_char_vertically(pfont, &line, vid_priv, FLIPPED_DIRECTION);
+	if (ret)
+		return ret;
 
-				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-					*dst-- = (bits & 0x80) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-					bits <<= 1;
-				}
-				break;
-			}
-		case VIDEO_BPP16:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
-				uint16_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-					*dst-- = (bits & 0x80) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-					bits <<= 1;
-				}
-				break;
-			}
-		case VIDEO_BPP32:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
-				uint32_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-					*dst-- = (bits & 0x80) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-					bits <<= 1;
-				}
-				break;
-			}
-		default:
-			return -ENOSYS;
-		}
-		line -= vid_priv->line_length;
-	}
 	/* Add 4 bytes to allow for the first pixel writen */
 	ret = vidconsole_sync_copy(dev, start + 4, line);
 	if (ret)
@@ -460,40 +454,15 @@ static int console_set_row_3(struct udevice *dev, uint row, int clr)
 {
 	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
 	int pbytes = VNBYTES(vid_priv->bpix);
-	void *start, *line;
+	void *start, *dst, *line;
 	int i, j, ret;
 
 	start = vid_priv->fb + row * VIDEO_FONT_HEIGHT * pbytes;
 	line = start;
 	for (j = 0; j < vid_priv->ysize; j++) {
-		switch (vid_priv->bpix) {
-		case VIDEO_BPP8:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
-				uint8_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
-					*dst++ = clr;
-				break;
-			}
-		case VIDEO_BPP16:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
-				uint16_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
-					*dst++ = clr;
-				break;
-			}
-		case VIDEO_BPP32:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
-				uint32_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
-					*dst++ = clr;
-				break;
-			}
-		default:
-			return -ENOSYS;
-		}
+		dst = line;
+		for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
+			fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
 		line += vid_priv->line_length;
 	}
 	ret = vidconsole_sync_copy(dev, start, line);
@@ -517,7 +486,7 @@ static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
 
 	for (j = 0; j < vid_priv->ysize; j++) {
 		ret = vidconsole_memmove(dev, dst, src,
-					 VIDEO_FONT_HEIGHT * pbytes * count);
+					VIDEO_FONT_HEIGHT * pbytes * count);
 		if (ret)
 			return ret;
 		src += vid_priv->line_length;
@@ -532,58 +501,21 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
 	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
 	struct udevice *vid = dev->parent;
 	struct video_priv *vid_priv = dev_get_uclass_priv(vid);
-	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
 	int pbytes = VNBYTES(vid_priv->bpix);
-	int i, col, x, ret;
-	int mask = 0x80;
+	int linenum, x, ret;
 	void *start, *line;
+	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
-	x = vid_priv->ysize - VID_TO_PIXEL(x_frac) - 1;
-	start = vid_priv->fb + x * vid_priv->line_length + y * pbytes;
+	x = y;
+	linenum = vid_priv->ysize - VID_TO_PIXEL(x_frac) - 1;
+	start = vid_priv->fb + linenum * vid_priv->line_length + y * pbytes;
 	line = start;
-	for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
-		switch (vid_priv->bpix) {
-		case VIDEO_BPP8:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
-				uint8_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
-					*dst++ = (pfont[i] & mask) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-				}
-				break;
-			}
-		case VIDEO_BPP16:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
-				uint16_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
-					*dst++ = (pfont[i] & mask) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-				}
-				break;
-			}
-		case VIDEO_BPP32:
-			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
-				uint32_t *dst = line;
-
-				for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
-					*dst++ = (pfont[i] & mask) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-				}
-				break;
-			}
-		default:
-			return -ENOSYS;
-		}
-		line -= vid_priv->line_length;
-		mask >>= 1;
-	}
+
+	ret = fill_char_horizontally(pfont, &line, vid_priv, NORMAL_DIRECTION);
+	if (ret)
+		return ret;
 	/* Add a line to allow for the first pixels writen */
 	ret = vidconsole_sync_copy(dev, start + vid_priv->line_length, line);
 	if (ret)
@@ -593,20 +525,6 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
 }
 
 
-static int console_probe_2(struct udevice *dev)
-{
-	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
-	struct udevice *vid_dev = dev->parent;
-	struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
-
-	vc_priv->x_charsize = VIDEO_FONT_WIDTH;
-	vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
-	vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
-	vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
-
-	return 0;
-}
-
 static int console_probe_1_3(struct udevice *dev)
 {
 	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
@@ -651,7 +569,7 @@ U_BOOT_DRIVER(vidconsole_2) = {
 	.name	= "vidconsole2",
 	.id	= UCLASS_VIDEO_CONSOLE,
 	.ops	= &console_ops_2,
-	.probe	= console_probe_2,
+	.probe	= console_probe,
 };
 
 U_BOOT_DRIVER(vidconsole_3) = {
Signature · 1 line
2.30.2
#3 lore raw

PATCH v2 3/8 video console: add support for fonts wider than 1 byte

In reply to Dzmitry Sankouski

Devices with high ppi may benefit from wider fonts.

Current width implementation is limited by 1 byte, i.e. 8 bits. New version iterates VIDEO_FONT_BYTE_WIDTH times, to process all width bytes, thus allowing fonts wider than 1 byte.

---
Charges for v2:
- replace TAIL_BIT_COUNT macro with c code
- rename refactoring

 drivers/video/console_simple.c | 93 +++++++++++++++++++++-------------
 1 file changed, 59 insertions(+), 34 deletions(-)
drivers/video/console_simple.c +59 -34
index 1eb47be449..cdc26cac30 100644
@@ -13,6 +13,7 @@
 #include <video_font.h>		/* Get font data, width and height */
 
 #define VIDEO_FONT_BYTE_WIDTH	((VIDEO_FONT_WIDTH / 8) + (VIDEO_FONT_WIDTH % 8 > 0))
+#define VIDEO_FONT_CHAR_PIXEL_BYTES	(VIDEO_FONT_HEIGHT * VIDEO_FONT_BYTE_WIDTH)
 
 #define FLIPPED_DIRECTION 1
 #define NORMAL_DIRECTION 0
@@ -95,9 +96,9 @@ static inline void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes,
 static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *vid_priv,
 				  bool direction)
 {
-	int step, line_step, pbytes, ret;
+	int step, line_step, pbytes, bitcount = 8, width_remainder, ret;
 	void *dst;
-	u8 mask = 0x80;
+	u8 mask;
 
 	ret = check_bpix_support(vid_priv->bpix);
 	if (ret)
@@ -111,21 +112,32 @@ static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *
 		step = pbytes;
 		line_step = -vid_priv->line_length;
 	}
-	for (int col = 0; col < VIDEO_FONT_WIDTH; col++) {
-		dst = *line;
-		for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
-			u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH] & mask) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-
-			fill_pixel_and_goto_next(&dst,
-						 value,
-						 pbytes,
-						 step
-			);
+
+	width_remainder = VIDEO_FONT_WIDTH % 8;
+	for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+		mask = 0x80;
+		if (width_remainder) {
+			bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH - col == 1);
+
+			if (is_last_iteration)
+				bitcount = width_remainder;
+		}
+		for (int bit = 0; bit < bitcount; bit++) {
+			dst = *line;
+			for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+				u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH] & mask) ?
+							vid_priv->colour_fg :
+							vid_priv->colour_bg;
+
+				fill_pixel_and_goto_next(&dst,
+							 value,
+							 pbytes,
+							 step
+				);
+			}
+			*line += line_step;
+			mask >>= 1;
 		}
-		*line += line_step;
-		mask >>= 1;
 	}
 	return ret;
 }
@@ -158,7 +170,7 @@ static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *
 static int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vid_priv,
 				bool direction)
 {
-	int step, line_step, pbytes, ret;
+	int step, line_step, pbytes, bitcount, width_remainder, ret;
 	void *dst;
 
 	ret = check_bpix_support(vid_priv->bpix);
@@ -174,23 +186,36 @@ static int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vi
 		line_step = vid_priv->line_length;
 	}
 
+	width_remainder = VIDEO_FONT_WIDTH % 8;
 	for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+		uchar bits;
+
+		bitcount = 8;
 		dst = *line;
-		uchar bits = pfont[row];
-
-		for (int i = 0; i < VIDEO_FONT_WIDTH; i++) {
-			u32 value = (bits & 0x80) ?
-				vid_priv->colour_fg :
-				vid_priv->colour_bg;
-
-			fill_pixel_and_goto_next(&dst,
-						 value,
-						 pbytes,
-						 step
-			);
-			bits <<= 1;
+		for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+			if (width_remainder) {
+				bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH - col == 1);
+
+				if (is_last_iteration)
+					bitcount = width_remainder;
+			}
+			bits = pfont[col];
+
+			for (int bit = 0; bit < bitcount; bit++) {
+				u32 value = (bits & 0x80) ?
+					vid_priv->colour_fg :
+					vid_priv->colour_bg;
+
+				fill_pixel_and_goto_next(&dst,
+							 value,
+							 pbytes,
+							 step
+				);
+				bits <<= 1;
+			}
 		}
 		*line += line_step;
+		pfont += VIDEO_FONT_BYTE_WIDTH;
 	}
 	return ret;
 }
@@ -249,7 +274,7 @@ static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch)
 	int pbytes = VNBYTES(vid_priv->bpix);
 	int x, linenum, ret;
 	void *start, *line;
-	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
+	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_CHAR_PIXEL_BYTES;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
@@ -358,7 +383,7 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
 	int pbytes = VNBYTES(vid_priv->bpix);
 	int x, linenum, ret;
 	void *start, *line;
-	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
+	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_CHAR_PIXEL_BYTES;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
@@ -429,7 +454,7 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
 	int pbytes = VNBYTES(vid_priv->bpix);
 	int linenum, x, ret;
 	void *start, *line;
-	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
+	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_CHAR_PIXEL_BYTES;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
@@ -504,7 +529,7 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
 	int pbytes = VNBYTES(vid_priv->bpix);
 	int linenum, x, ret;
 	void *start, *line;
-	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
+	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_CHAR_PIXEL_BYTES;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
Signature · 1 line
2.30.2
#4 lore raw

PATCH v2 4/8 video console: add select font logic to vidconsole uclass driver

In reply to Dzmitry Sankouski

Select font logic at runtime needed to unit test different fonts. This commit is a preparation to enable runtime font selection in console_simple driver.

- move console true type select font logic to driver ops
- add select font logic to vidconsole-uclass.c

---
Changes for v2: N/A

 cmd/font.c                        |  7 ++++++-
 drivers/video/console_truetype.c  |  6 ++++--
 drivers/video/vidconsole-uclass.c | 22 ++++++++++++++++++++++
 include/video.h                   |  1 +
 include/video_console.h           | 18 +++++++++++++++++-
 5 files changed, 50 insertions(+), 4 deletions(-)
cmd/font.c +6 -1
index 3e522f3aaa..769796c5ec 100644
@@ -15,7 +15,12 @@
 static int do_font_list(struct cmd_tbl *cmdtp, int flag, int argc,
 			char *const argv[])
 {
-	vidconsole_list_fonts();
+	struct udevice *dev;
+
+	if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
+		return CMD_RET_FAILURE;
+
+	vidconsole_list_fonts(dev);
 
 	return 0;
 }
drivers/video/console_truetype.c +4 -2
index 6859c9fa11..389fa483fc 100644
@@ -584,7 +584,7 @@ static struct font_info *console_truetype_find_font(void)
 	return NULL;
 }
 
-void vidconsole_list_fonts(void)
+void console_truetype_list_fonts(struct udevice __maybe_unused *dev)
 {
 	struct font_info *tab;
 
@@ -674,7 +674,7 @@ static void select_metrics(struct udevice *dev, struct console_tt_metrics *met)
 	vc_priv->tab_width_frac = VID_TO_POS(met->font_size) * 8 / 2;
 }
 
-int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
+int console_truetype_select_font(struct udevice *dev, const char *name, uint size)
 {
 	struct console_tt_priv *priv = dev_get_priv(dev);
 	struct console_tt_metrics *met;
@@ -763,6 +763,8 @@ struct vidconsole_ops console_truetype_ops = {
 	.set_row	= console_truetype_set_row,
 	.backspace	= console_truetype_backspace,
 	.entry_start	= console_truetype_entry_start,
+	.list_fonts	= console_truetype_list_fonts,
+	.select_font	= console_truetype_select_font,
 };
 
 U_BOOT_DRIVER(vidconsole_truetype) = {
drivers/video/vidconsole-uclass.c +22 -0
index 6bdfb6e37d..5a08fdd689 100644
@@ -85,6 +85,28 @@ static int vidconsole_back(struct udevice *dev)
 	return video_sync(dev->parent, false);
 }
 
+void vidconsole_list_fonts(struct udevice *dev)
+{
+	struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+
+	if (ops->select_font)
+		ops->list_fonts(dev);
+}
+
+int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
+{
+	struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+	int ret;
+
+	if (ops->select_font) {
+		ret = ops->select_font(dev, name, size);
+		if (ret != -ENOSYS)
+			return ret;
+	}
+
+	return 0;
+}
+
 /* Move to a newline, scrolling the display if necessary */
 static void vidconsole_newline(struct udevice *dev)
 {
include/video.h +1 -0
index 43f2e2c02f..91c05fa9f0 100644
@@ -115,6 +115,7 @@ struct video_priv {
 	bool flush_dcache;
 	u8 fg_col_idx;
 	u8 bg_col_idx;
+	struct video_fontdata *fontdata;
 };
 
 /**
include/video_console.h +17 -1
index d755eb73cf..fc702cc165 100644
@@ -133,6 +133,22 @@ struct vidconsole_ops {
 	 * characters.
 	 */
 	int (*backspace)(struct udevice *dev);
+
+	/**
+	 * list_fonts() - List the available fonts
+	 *
+	 * This shows a list on the console
+	 */
+	void (*list_fonts)(struct udevice *dev);
+
+	/**
+	 * select_font() - Select a font to use
+	 *
+	 * @dev: vidconsole device
+	 * @name: Font name
+	 * @size: Size of the font (norminal pixel height) or 0 for default
+	 */
+	int (*select_font)(struct udevice *dev, const char *name, uint size);
 };
 
 /* Get a pointer to the driver operations for a video console device */
@@ -236,7 +252,7 @@ void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y);
  *
  * This shows a list on the console
  */
-void vidconsole_list_fonts(void);
+void vidconsole_list_fonts(struct udevice *dev);
 
 /**
  * vidconsole_select_font() - Select a font to use
Signature · 1 line
2.30.2
#5 lore raw

Re: [PATCH v2 4/8] video console: add select font logic to vidconsole uclass driver

Hi Dzmitry,

Quoted 42 lines · Dzmitry Sankouski

Select font logic at runtime needed to unit test different fonts. This commit is a preparation to enable runtime font selection in console_simple driver.

- move console true type select font logic to driver ops
- add select font logic to vidconsole-uclass.c

---
Changes for v2: N/A

 cmd/font.c                        |  7 ++++++-
 drivers/video/console_truetype.c  |  6 ++++--
 drivers/video/vidconsole-uclass.c | 22 ++++++++++++++++++++++
 include/video.h                   |  1 +
 include/video_console.h           | 18 +++++++++++++++++-
 5 files changed, 50 insertions(+), 4 deletions(-)
cmd/font.c +6 -1
index 3e522f3aaa..769796c5ec 100644
@@ -15,7 +15,12 @@
 static int do_font_list(struct cmd_tbl *cmdtp, int flag, int argc,
                        char *const argv[])
 {
-       vidconsole_list_fonts();
+       struct udevice *dev;
+
+       if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
+               return CMD_RET_FAILURE;
+
+       vidconsole_list_fonts(dev);
 
        return 0;
 }
drivers/video/console_truetype.c +0 -0
index 6859c9fa11..389fa483fc 100644

drivers/video/console_truetype.c static struct font_info *console_truetype_find_font(void) · line 587

Quoted 5 lines
drivers/video/console_truetype.c +1 -1
@@ -584,7 +584,7 @@ static struct font_info *console_truetype_find_font(void)
        return NULL;
 }
 
-void vidconsole_list_fonts(void)
+void console_truetype_list_fonts(struct udevice __maybe_unused *dev)

You should not need the __maybe_unused here?

Quoted 59 lines
drivers/video/console_truetype.c +3 -1
 {
        struct font_info *tab;
 
@@ -674,7 +674,7 @@ static void select_metrics(struct udevice *dev, struct console_tt_metrics *met)
        vc_priv->tab_width_frac = VID_TO_POS(met->font_size) * 8 / 2;
 }
 
-int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
+int console_truetype_select_font(struct udevice *dev, const char *name, uint size)
 {
        struct console_tt_priv *priv = dev_get_priv(dev);
        struct console_tt_metrics *met;
@@ -763,6 +763,8 @@ struct vidconsole_ops console_truetype_ops = {
        .set_row        = console_truetype_set_row,
        .backspace      = console_truetype_backspace,
        .entry_start    = console_truetype_entry_start,
+       .list_fonts     = console_truetype_list_fonts,
+       .select_font    = console_truetype_select_font,
 };
 
 U_BOOT_DRIVER(vidconsole_truetype) = {
drivers/video/vidconsole-uclass.c +22 -0
index 6bdfb6e37d..5a08fdd689 100644
@@ -85,6 +85,28 @@ static int vidconsole_back(struct udevice *dev)
        return video_sync(dev->parent, false);
 }
 
+void vidconsole_list_fonts(struct udevice *dev)
+{
+       struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+
+       if (ops->select_font)
+               ops->list_fonts(dev);
+}
+
+int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
+{
+       struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+       int ret;
+
+       if (ops->select_font) {
+               ret = ops->select_font(dev, name, size);
+               if (ret != -ENOSYS)
+                       return ret;
+       }
+
+       return 0;
+}
+
 /* Move to a newline, scrolling the display if necessary */
 static void vidconsole_newline(struct udevice *dev)
 {
include/video.h +0 -0
index 43f2e2c02f..91c05fa9f0 100644

include/video.h struct video_priv { · line 118

Quoted 4 lines
include/video.h +1 -0
@@ -115,6 +115,7 @@ struct video_priv {
        bool flush_dcache;
        u8 fg_col_idx;
        u8 bg_col_idx;
+       struct video_fontdata *fontdata;

please update comment for this new member

Quoted 8 lines
include/video.h +0 -0
 };
 
 /**
include/video_console.h +0 -0
index d755eb73cf..fc702cc165 100644

include/video_console.h struct vidconsole_ops { · line 140

Quoted 8 lines
include/video_console.h +5 -0
@@ -133,6 +133,22 @@ struct vidconsole_ops {
         * characters.
         */
        int (*backspace)(struct udevice *dev);
+
+       /**
+        * list_fonts() - List the available fonts
+        *
+        * This shows a list on the console

comments again, @dev and Returns

include/video_console.h struct vidconsole_ops { · line 149

Quoted 9 lines
include/video_console.h +9 -0
+        */
+       void (*list_fonts)(struct udevice *dev);
+
+       /**
+        * select_font() - Select a font to use
+        *
+        * @dev: vidconsole device
+        * @name: Font name
+        * @size: Size of the font (norminal pixel height) or 0 for default

Returns

include/video_console.h void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y); · line 253

Quoted 8 lines
include/video_console.h +2 -0
+        */
+       int (*select_font)(struct udevice *dev, const char *name, uint size);
 };
 
 /* Get a pointer to the driver operations for a video console device */
@@ -236,7 +252,7 @@ void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y);
  *
  * This shows a list on the console

add @dev

Quoted 9 lines
include/video_console.h +1 -2
  */
-void vidconsole_list_fonts(void);
+void vidconsole_list_fonts(struct udevice *dev);
 
 /**
  * vidconsole_select_font() - Select a font to use
--

2.30.2

Regards,
Simon

#6 lore raw

PATCH v2 5/8 video console: allow font size configuration at runtime

In reply to Dzmitry Sankouski

Allow font size configuration at runtime for console_simple.c driver. This needed for unit testing different fonts.

- move 8x16 font data to video_font_8x16.h file
- place common font macro in video_font_data.h file

---
Changes for v2: N/A

 cmd/Kconfig                    |    8 +
 cmd/Makefile                   |    2 +-
 common/splash.c                |    7 +-
 drivers/video/Kconfig          |   16 +
 drivers/video/console_simple.c |  178 +-
 include/video_font.h           |   19 +-
 include/video_font_4x6.h       |   11 +-
 include/video_font_8x16.h      | 4624 +++++++++++++++++++++++++++++++
 include/video_font_data.h      | 4644 +-------------------------------
 9 files changed, 4802 insertions(+), 4707 deletions(-)
 create mode 100644 include/video_font_8x16.h
cmd/Kconfig +8 -0
index 199a55383e..033095769b 100644
@@ -2211,6 +2211,14 @@ config CMD_VIDCONSOLE
 	  The name 'lcdputs' is a bit of a misnomer, but so named because the
 	  video device is often an LCD.
 
+config CMD_SELECT_FONT
+    bool "select font size"
+	depends on VIDEO
+	default n
+	help
+	  Enabling this will provide 'font' command.
+	  Allows font selection at runtime.
+
 endmenu
 
 source "cmd/ti/Kconfig"
cmd/Makefile +1 -1
index 0b6a96c1d9..80b2796c1d 100644
@@ -79,7 +79,7 @@ obj-$(CONFIG_CMD_EXT2) += ext2.o
 obj-$(CONFIG_CMD_FAT) += fat.o
 obj-$(CONFIG_CMD_FDT) += fdt.o
 obj-$(CONFIG_CMD_SQUASHFS) += sqfs.o
-obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
+obj-$(CONFIG_CMD_SELECT_FONT) += font.o
 obj-$(CONFIG_CMD_FLASH) += flash.o
 obj-$(CONFIG_CMD_FPGA) += fpga.o
 obj-$(CONFIG_CMD_FPGAD) += fpgad.o
common/splash.c +5 -2
index 2e466a8a0f..3b36876a79 100644
@@ -131,6 +131,7 @@ void splash_get_pos(int *x, int *y)
 void splash_display_banner(void)
 {
 	struct udevice *dev;
+	struct video_priv *vid_priv;
 	char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
 	int col, row, ret;
 
@@ -138,9 +139,11 @@ void splash_display_banner(void)
 	if (ret)
 		return;
 
+	vid_priv = dev_get_uclass_priv(dev->parent);
+
 #ifdef CONFIG_VIDEO_LOGO
-	col = BMP_LOGO_WIDTH / VIDEO_FONT_WIDTH + 1;
-	row = BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT + 1;
+	col = BMP_LOGO_WIDTH / vid_priv->fontdata->width + 1;
+	row = BMP_LOGO_HEIGHT / vid_priv->fontdata->height + 1;
 #else
 	col = 0;
 	row = 0;
drivers/video/Kconfig +16 -0
index 1dfe11d182..31dbf1f98d 100644
@@ -16,6 +16,21 @@ config VIDEO
 
 if VIDEO
 
+config VIDEO_FONT_4X6
+	bool "4 x 6 font size"
+	help
+	  Font for video console driver, 4 x 6 pixels.
+	  Provides character bitmap data in header file.
+	  When selecting multiple fonts, you may want to enable CMD_SELECT_FONT too.
+
+config VIDEO_FONT_8X16
+	bool "8 x 16 font size"
+	default y
+	help
+	  Font for video console driver, 8 x 16 pixels
+	  Provides character bitmap data in header file.
+	  When selecting multiple fonts, you may want to enable CMD_SELECT_FONT too.
+
 config VIDEO_LOGO
 	bool "Show the U-Boot logo on the display"
 	default y if !SPLASH_SCREEN
@@ -147,6 +162,7 @@ config CONSOLE_ROTATION
 
 config CONSOLE_TRUETYPE
 	bool "Support a console that uses TrueType fonts"
+	select CMD_SELECT_FONT
 	help
 	  TrueTrype fonts can provide outline-drawing capability rather than
 	  needing to provide a bitmap for each font and size that is needed.
drivers/video/console_simple.c +105 -73

379 lines not on this page · raw message

include/video_font.h +16 -3
index 5e23f70f85..fbb58b11a0 100644
@@ -7,10 +7,23 @@
 #ifndef _VIDEO_FONT_
 #define _VIDEO_FONT_
 
-#ifdef CONFIG_VIDEO_FONT_4X6
-#include <video_font_4x6.h>
-#else
 #include <video_font_data.h>
+
+#if defined(CONFIG_VIDEO_FONT_4X6)
+#include <video_font_4x6.h>
+#endif
+#if defined(CONFIG_VIDEO_FONT_8X16)
+#include <video_font_8x16.h>
+#endif
+
+static struct video_fontdata __maybe_unused fonts[] = {
+#if defined(CONFIG_VIDEO_FONT_4X6)
+	FONT_ENTRY(4, 6, 4x6),
+#endif
+#if defined(CONFIG_VIDEO_FONT_8X16)
+	FONT_ENTRY(8, 16, 8x16),
 #endif
+	{/* list terminator */}
+};
 
 #endif /* _VIDEO_FONT_ */
include/video_font_4x6.h +4 -7
index c7e6351b64..1b8c02510b 100644
@@ -38,15 +38,12 @@ __END__;
    MSBit to LSBit = left to right.
  */
 
-#ifndef _VIDEO_FONT_DATA_
-#define _VIDEO_FONT_DATA_
+#ifndef _VIDEO_FONT_4X6_
+#define _VIDEO_FONT_4X6_
 
-#define VIDEO_FONT_CHARS	256
-#define VIDEO_FONT_WIDTH	4
-#define VIDEO_FONT_HEIGHT	6
-#define VIDEO_FONT_SIZE		(VIDEO_FONT_CHARS * VIDEO_FONT_HEIGHT)
+#include <video_font_data.h>
 
-static unsigned char video_fontdata[VIDEO_FONT_SIZE] = {
+static unsigned char video_fontdata_4x6[VIDEO_FONT_SIZE(256, 4, 6)] = {
 
 	/*{*/
 		/*   Char 0: ' '  */
include/video_font_8x16.h new file +4624 -0

2,506 lines not on this page · raw message

include/video_font_data.h +23 -4621

4,644 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.30.2

Part of the diff is not shown here. View the raw message.

#7 lore raw

Re: [PATCH v2 5/8] video console: allow font size configuration at runtime

Hi Dzmitry,

Quoted 5 lines · Dzmitry Sankouski

Allow font size configuration at runtime for console_simple.c driver. This needed for unit testing different fonts.

- move 8x16 font data to video_font_8x16.h file

please do that in a separate patch

Quoted 140 lines

- place common font macro in video_font_data.h file

---
Changes for v2: N/A

 cmd/Kconfig                    |    8 +
 cmd/Makefile                   |    2 +-
 common/splash.c                |    7 +-
 drivers/video/Kconfig          |   16 +
 drivers/video/console_simple.c |  178 +-
 include/video_font.h           |   19 +-
 include/video_font_4x6.h       |   11 +-
 include/video_font_8x16.h      | 4624 +++++++++++++++++++++++++++++++
 include/video_font_data.h      | 4644 +-------------------------------
 9 files changed, 4802 insertions(+), 4707 deletions(-)
 create mode 100644 include/video_font_8x16.h
cmd/Kconfig +8 -0
index 199a55383e..033095769b 100644
@@ -2211,6 +2211,14 @@ config CMD_VIDCONSOLE
          The name 'lcdputs' is a bit of a misnomer, but so named because the
          video device is often an LCD.
 
+config CMD_SELECT_FONT
+    bool "select font size"
+       depends on VIDEO
+       default n
+       help
+         Enabling this will provide 'font' command.
+         Allows font selection at runtime.
+
 endmenu
 
 source "cmd/ti/Kconfig"
cmd/Makefile +1 -1
index 0b6a96c1d9..80b2796c1d 100644
@@ -79,7 +79,7 @@ obj-$(CONFIG_CMD_EXT2) += ext2.o
 obj-$(CONFIG_CMD_FAT) += fat.o
 obj-$(CONFIG_CMD_FDT) += fdt.o
 obj-$(CONFIG_CMD_SQUASHFS) += sqfs.o
-obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
+obj-$(CONFIG_CMD_SELECT_FONT) += font.o
 obj-$(CONFIG_CMD_FLASH) += flash.o
 obj-$(CONFIG_CMD_FPGA) += fpga.o
 obj-$(CONFIG_CMD_FPGAD) += fpgad.o
common/splash.c +5 -2
index 2e466a8a0f..3b36876a79 100644
@@ -131,6 +131,7 @@ void splash_get_pos(int *x, int *y)
 void splash_display_banner(void)
 {
        struct udevice *dev;
+       struct video_priv *vid_priv;
        char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
        int col, row, ret;
 
@@ -138,9 +139,11 @@ void splash_display_banner(void)
        if (ret)
                return;
 
+       vid_priv = dev_get_uclass_priv(dev->parent);
+
 #ifdef CONFIG_VIDEO_LOGO
-       col = BMP_LOGO_WIDTH / VIDEO_FONT_WIDTH + 1;
-       row = BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT + 1;
+       col = BMP_LOGO_WIDTH / vid_priv->fontdata->width + 1;
+       row = BMP_LOGO_HEIGHT / vid_priv->fontdata->height + 1;
 #else
        col = 0;
        row = 0;
drivers/video/Kconfig +16 -0
index 1dfe11d182..31dbf1f98d 100644
@@ -16,6 +16,21 @@ config VIDEO
 
 if VIDEO
 
+config VIDEO_FONT_4X6
+       bool "4 x 6 font size"
+       help
+         Font for video console driver, 4 x 6 pixels.
+         Provides character bitmap data in header file.
+         When selecting multiple fonts, you may want to enable CMD_SELECT_FONT too.
+
+config VIDEO_FONT_8X16
+       bool "8 x 16 font size"
+       default y
+       help
+         Font for video console driver, 8 x 16 pixels
+         Provides character bitmap data in header file.
+         When selecting multiple fonts, you may want to enable CMD_SELECT_FONT too.
+
 config VIDEO_LOGO
        bool "Show the U-Boot logo on the display"
        default y if !SPLASH_SCREEN
@@ -147,6 +162,7 @@ config CONSOLE_ROTATION
 
 config CONSOLE_TRUETYPE
        bool "Support a console that uses TrueType fonts"
+       select CMD_SELECT_FONT
        help
          TrueTrype fonts can provide outline-drawing capability rather than
          needing to provide a bitmap for each font and size that is needed.
drivers/video/console_simple.c +16 -3
index cdc26cac30..f50a01d22e 100644
@@ -12,12 +12,58 @@
 #include <video_console.h>
 #include <video_font.h>                /* Get font data, width and height */
 
-#define VIDEO_FONT_BYTE_WIDTH  ((VIDEO_FONT_WIDTH / 8) + (VIDEO_FONT_WIDTH % 8 > 0))
-#define VIDEO_FONT_CHAR_PIXEL_BYTES    (VIDEO_FONT_HEIGHT * VIDEO_FONT_BYTE_WIDTH)
-
 #define FLIPPED_DIRECTION 1
 #define NORMAL_DIRECTION 0
 
+static int console_set_font(struct udevice *dev, struct video_fontdata *fontdata)
+{
+       struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
+       struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+
+       debug("console_simple: setting %s font\n", fontdata->name);
+       debug("width: %d\n", fontdata->width);
+       debug("byte width: %d\n", fontdata->byte_width);
+       debug("height: %d\n", fontdata->height);
+
+       vid_priv->fontdata = fontdata;
+       vc_priv->x_charsize = vid_priv->fontdata->width;
+       vc_priv->y_charsize = vid_priv->fontdata->height;
+       if (vid_priv->rot % 2) {
+               vc_priv->cols = vid_priv->ysize / vid_priv->fontdata->width;
+               vc_priv->rows = vid_priv->xsize / vid_priv->fontdata->height;

drivers/video/console_simple.c line 43

Quoted 10 lines
drivers/video/console_simple.c +10 -0
+               vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize);
+       } else {
+               vc_priv->cols = vid_priv->xsize / vid_priv->fontdata->width;
+               vc_priv->rows = vid_priv->ysize / vid_priv->fontdata->height;
+       }
+
+       return 0;
+}
+
+void console_simple_list_fonts(struct udevice __maybe_unused *dev)

static?

drivers/video/console_simple.c line 52

Quoted 9 lines
drivers/video/console_simple.c +9 -0
+{
+       struct video_fontdata *font;
+
+       for (font = fonts; font->name; font++) {
+               printf("%s\n", font->name);
+       };
+}
+
+int console_simple_select_font(struct udevice *dev, const char *name, uint size)

static?

drivers/video/console_simple.c line 63

Quoted 11 lines
drivers/video/console_simple.c +11 -0
+{
+       console_set_font(dev, &fonts[1]);
+       struct video_fontdata *font;
+
+       for (font = fonts; font->name; font++) {
+               if (!strcmp(name, font->name)) {
+                       console_set_font(dev, font);
+                       return 0;
+               }
+       };
+       printf("no such font: %s, make sure it's name has <width>x<height> format\n", name);

its

but ideally we don't print out things in drivers. Could this go in the command instead, perhaps suggesting using 'list' to see the available fonts?

drivers/video/console_simple.c static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv * · line 162

Quoted 13 lines
drivers/video/console_simple.c +4 -2
+       return -ENOENT;
+}
+
 /**
  * Checks if bits per pixel supported.
  *
@@ -113,21 +159,20 @@ static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *
                line_step = -vid_priv->line_length;
        }
 
-       width_remainder = VIDEO_FONT_WIDTH % 8;
-       for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+       width_remainder = vid_priv->fontdata->width % 8;

Please put fontdata in a local var to reduce the indirection steps each time. Same below

Quoted 114 lines
drivers/video/console_simple.c +20 -28
+       for (int col = 0; col < vid_priv->fontdata->byte_width; col++) {
                mask = 0x80;
                if (width_remainder) {
-                       bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH - col == 1);
+                       bool is_last_col = (vid_priv->fontdata->byte_width - col == 1);
 
-                       if (is_last_iteration)
+                       if (is_last_col)
                                bitcount = width_remainder;
                }
                for (int bit = 0; bit < bitcount; bit++) {
                        dst = *line;
-                       for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
-                               u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH] & mask) ?
-                                                       vid_priv->colour_fg :
-                                                       vid_priv->colour_bg;
+                       for (int row = 0; row < vid_priv->fontdata->height; row++) {
+                               u32 value = (pfont[row * vid_priv->fontdata->byte_width + col]
+                                            & mask) ? vid_priv->colour_fg : vid_priv->colour_bg;
 
                                fill_pixel_and_goto_next(&dst,
                                                         value,
@@ -186,17 +231,17 @@ static int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vi
                line_step = vid_priv->line_length;
        }
 
-       width_remainder = VIDEO_FONT_WIDTH % 8;
-       for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+       width_remainder = vid_priv->fontdata->width % 8;
+       for (int row = 0; row < vid_priv->fontdata->height; row++) {
                uchar bits;
 
                bitcount = 8;
                dst = *line;
-               for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+               for (int col = 0; col < vid_priv->fontdata->byte_width; col++) {
                        if (width_remainder) {
-                               bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH - col == 1);
+                               bool is_last_col = (vid_priv->fontdata->byte_width - col == 1);
 
-                               if (is_last_iteration)
+                               if (is_last_col)
                                        bitcount = width_remainder;
                        }
                        bits = pfont[col];
@@ -215,7 +260,7 @@ static int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vi
                        }
                }
                *line += line_step;
-               pfont += VIDEO_FONT_BYTE_WIDTH;
+               pfont += vid_priv->fontdata->byte_width;
        }
        return ret;
 }
@@ -224,7 +269,7 @@ static int console_set_row(struct udevice *dev, uint row, int clr)
 {
        struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
        void *line, *dst, *end;
-       int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
+       int pixels = vid_priv->fontdata->height * vid_priv->xsize;
        int ret;
        int i;
        int pbytes;
@@ -233,7 +278,7 @@ static int console_set_row(struct udevice *dev, uint row, int clr)
        if (ret)
                return ret;
 
-       line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
+       line = vid_priv->fb + row * vid_priv->fontdata->height * vid_priv->line_length;
        dst = line;
        pbytes = VNBYTES(vid_priv->bpix);
        for (i = 0; i < pixels; i++)
@@ -256,9 +301,9 @@ static int console_move_rows(struct udevice *dev, uint rowdst,
        int size;
        int ret;
 
-       dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length;
-       src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length;
-       size = VIDEO_FONT_HEIGHT * vid_priv->line_length * count;
+       dst = vid_priv->fb + rowdst * vid_priv->fontdata->height * vid_priv->line_length;
+       src = vid_priv->fb + rowsrc * vid_priv->fontdata->height * vid_priv->line_length;
+       size = vid_priv->fontdata->height * vid_priv->line_length * count;
        ret = vidconsole_memmove(dev, dst, src, size);
        if (ret)
                return ret;
@@ -274,7 +319,8 @@ static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch)
        int pbytes = VNBYTES(vid_priv->bpix);
        int x, linenum, ret;
        void *start, *line;
-       uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_CHAR_PIXEL_BYTES;
+       uchar *pfont = vid_priv->fontdata->video_fontdata +
+                       (u8)ch * vid_priv->fontdata->char_pixel_bytes;
 
        if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
                return -EAGAIN;
@@ -294,27 +340,20 @@ static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch)
        if (ret)
                return ret;
 
-       return VID_TO_POS(VIDEO_FONT_WIDTH);
+       return VID_TO_POS(vid_priv->fontdata->width);
 }
 
 static int console_probe(struct udevice *dev)
 {
-       struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
-       struct udevice *vid_dev = dev->parent;
-       struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
-
-       vc_priv->x_charsize = VIDEO_FONT_WIDTH;
-       vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
-       vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
-       vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
-

drivers/video/console_simple.c static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch) · line 356

Quoted 10 lines
drivers/video/console_simple.c +3 -1
-       return 0;
+       return console_set_font(dev, &fonts[0]);
 }
 
 struct vidconsole_ops console_ops = {
        .putc_xy        = console_putc_xy,
        .move_rows      = console_move_rows,
        .set_row        = console_set_row,
+       .list_fonts     = console_simple_list_fonts,
+       .select_font    = console_simple_select_font,

Hmm can you split out the addition of these two items to a separate patch? There is too much going on in this patch.

[..]

Regards,
Simon

#8 lore raw

Re: [PATCH v2 5/8] video console: allow font size configuration at runtime

Am 14. Februar 2023 20:48:53 MEZ schrieb Simon Glass <[email protected]>:

Quoted 26 lines

Hi Dzmitry,

Quoted 5 lines · Dzmitry Sankouski

Allow font size configuration at runtime for console_simple.c driver. This needed for unit testing different fonts.

- move 8x16 font data to video_font_8x16.h file

please do that in a separate patch

Quoted 15 lines

- place common font macro in video_font_data.h file

---
Changes for v2: N/A

 cmd/Kconfig                    |    8 +
 cmd/Makefile                   |    2 +-
 common/splash.c                |    7 +-
 drivers/video/Kconfig          |   16 +
 drivers/video/console_simple.c |  178 +-
 include/video_font.h           |   19 +-
 include/video_font_4x6.h       |   11 +-
 include/video_font_8x16.h      | 4624 +++++++++++++++++++++++++++++++
 include/video_font_data.h      | 4644

Shouldn't we have a font that is somehow legible on a 4k display, e.g. 16x32?

Best regards

Heinrich

 +-------------------------------
>>  9 files changed, 4802 insertions(+), 4707 deletions(-)
>>  create mode 100644 include/video_font_8x16.h
Quoted 314 lines
Quoted 123 lines
cmd/Kconfig +8 -0
index 199a55383e..033095769b 100644
@@ -2211,6 +2211,14 @@ config CMD_VIDCONSOLE
          The name 'lcdputs' is a bit of a misnomer, but so named because the
          video device is often an LCD.
 
+config CMD_SELECT_FONT
+    bool "select font size"
+       depends on VIDEO
+       default n
+       help
+         Enabling this will provide 'font' command.
+         Allows font selection at runtime.
+
 endmenu
 
 source "cmd/ti/Kconfig"
cmd/Makefile +1 -1
index 0b6a96c1d9..80b2796c1d 100644
@@ -79,7 +79,7 @@ obj-$(CONFIG_CMD_EXT2) += ext2.o
 obj-$(CONFIG_CMD_FAT) += fat.o
 obj-$(CONFIG_CMD_FDT) += fdt.o
 obj-$(CONFIG_CMD_SQUASHFS) += sqfs.o
-obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
+obj-$(CONFIG_CMD_SELECT_FONT) += font.o
 obj-$(CONFIG_CMD_FLASH) += flash.o
 obj-$(CONFIG_CMD_FPGA) += fpga.o
 obj-$(CONFIG_CMD_FPGAD) += fpgad.o
common/splash.c +5 -2
index 2e466a8a0f..3b36876a79 100644
@@ -131,6 +131,7 @@ void splash_get_pos(int *x, int *y)
 void splash_display_banner(void)
 {
        struct udevice *dev;
+       struct video_priv *vid_priv;
        char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
        int col, row, ret;
 
@@ -138,9 +139,11 @@ void splash_display_banner(void)
        if (ret)
                return;
 
+       vid_priv = dev_get_uclass_priv(dev->parent);
+
 #ifdef CONFIG_VIDEO_LOGO
-       col = BMP_LOGO_WIDTH / VIDEO_FONT_WIDTH + 1;
-       row = BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT + 1;
+       col = BMP_LOGO_WIDTH / vid_priv->fontdata->width + 1;
+       row = BMP_LOGO_HEIGHT / vid_priv->fontdata->height + 1;
 #else
        col = 0;
        row = 0;
drivers/video/Kconfig +16 -0
index 1dfe11d182..31dbf1f98d 100644
@@ -16,6 +16,21 @@ config VIDEO
 
 if VIDEO
 
+config VIDEO_FONT_4X6
+       bool "4 x 6 font size"
+       help
+         Font for video console driver, 4 x 6 pixels.
+         Provides character bitmap data in header file.
+         When selecting multiple fonts, you may want to enable CMD_SELECT_FONT too.
+
+config VIDEO_FONT_8X16
+       bool "8 x 16 font size"
+       default y
+       help
+         Font for video console driver, 8 x 16 pixels
+         Provides character bitmap data in header file.
+         When selecting multiple fonts, you may want to enable CMD_SELECT_FONT too.
+
 config VIDEO_LOGO
        bool "Show the U-Boot logo on the display"
        default y if !SPLASH_SCREEN
@@ -147,6 +162,7 @@ config CONSOLE_ROTATION
 
 config CONSOLE_TRUETYPE
        bool "Support a console that uses TrueType fonts"
+       select CMD_SELECT_FONT
        help
          TrueTrype fonts can provide outline-drawing capability rather than
          needing to provide a bitmap for each font and size that is needed.
drivers/video/console_simple.c +16 -3
index cdc26cac30..f50a01d22e 100644
@@ -12,12 +12,58 @@
 #include <video_console.h>
 #include <video_font.h>                /* Get font data, width and height */
 
-#define VIDEO_FONT_BYTE_WIDTH  ((VIDEO_FONT_WIDTH / 8) + (VIDEO_FONT_WIDTH % 8 > 0))
-#define VIDEO_FONT_CHAR_PIXEL_BYTES    (VIDEO_FONT_HEIGHT * VIDEO_FONT_BYTE_WIDTH)
-
 #define FLIPPED_DIRECTION 1
 #define NORMAL_DIRECTION 0
 
+static int console_set_font(struct udevice *dev, struct video_fontdata *fontdata)
+{
+       struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
+       struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+
+       debug("console_simple: setting %s font\n", fontdata->name);
+       debug("width: %d\n", fontdata->width);
+       debug("byte width: %d\n", fontdata->byte_width);
+       debug("height: %d\n", fontdata->height);
+
+       vid_priv->fontdata = fontdata;
+       vc_priv->x_charsize = vid_priv->fontdata->width;
+       vc_priv->y_charsize = vid_priv->fontdata->height;
+       if (vid_priv->rot % 2) {
+               vc_priv->cols = vid_priv->ysize / vid_priv->fontdata->width;
+               vc_priv->rows = vid_priv->xsize / vid_priv->fontdata->height;

drivers/video/console_simple.c line 43

Quoted 10 lines
drivers/video/console_simple.c +10 -0
+               vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize);
+       } else {
+               vc_priv->cols = vid_priv->xsize / vid_priv->fontdata->width;
+               vc_priv->rows = vid_priv->ysize / vid_priv->fontdata->height;
+       }
+
+       return 0;
+}
+
+void console_simple_list_fonts(struct udevice __maybe_unused *dev)

static?

drivers/video/console_simple.c line 52

Quoted 9 lines
drivers/video/console_simple.c +9 -0
+{
+       struct video_fontdata *font;
+
+       for (font = fonts; font->name; font++) {
+               printf("%s\n", font->name);
+       };
+}
+
+int console_simple_select_font(struct udevice *dev, const char *name, uint size)

static?

drivers/video/console_simple.c line 63

Quoted 11 lines
drivers/video/console_simple.c +11 -0
+{
+       console_set_font(dev, &fonts[1]);
+       struct video_fontdata *font;
+
+       for (font = fonts; font->name; font++) {
+               if (!strcmp(name, font->name)) {
+                       console_set_font(dev, font);
+                       return 0;
+               }
+       };
+       printf("no such font: %s, make sure it's name has <width>x<height> format\n", name);

its

but ideally we don't print out things in drivers. Could this go in the command instead, perhaps suggesting using 'list' to see the available fonts?

drivers/video/console_simple.c static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv * · line 162

Quoted 13 lines
drivers/video/console_simple.c +4 -2
+       return -ENOENT;
+}
+
 /**
  * Checks if bits per pixel supported.
  *
@@ -113,21 +159,20 @@ static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *
                line_step = -vid_priv->line_length;
        }
 
-       width_remainder = VIDEO_FONT_WIDTH % 8;
-       for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+       width_remainder = vid_priv->fontdata->width % 8;

Please put fontdata in a local var to reduce the indirection steps each time. Same below

Quoted 114 lines
drivers/video/console_simple.c +20 -28
+       for (int col = 0; col < vid_priv->fontdata->byte_width; col++) {
                mask = 0x80;
                if (width_remainder) {
-                       bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH - col == 1);
+                       bool is_last_col = (vid_priv->fontdata->byte_width - col == 1);
 
-                       if (is_last_iteration)
+                       if (is_last_col)
                                bitcount = width_remainder;
                }
                for (int bit = 0; bit < bitcount; bit++) {
                        dst = *line;
-                       for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
-                               u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH] & mask) ?
-                                                       vid_priv->colour_fg :
-                                                       vid_priv->colour_bg;
+                       for (int row = 0; row < vid_priv->fontdata->height; row++) {
+                               u32 value = (pfont[row * vid_priv->fontdata->byte_width + col]
+                                            & mask) ? vid_priv->colour_fg : vid_priv->colour_bg;
 
                                fill_pixel_and_goto_next(&dst,
                                                         value,
@@ -186,17 +231,17 @@ static int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vi
                line_step = vid_priv->line_length;
        }
 
-       width_remainder = VIDEO_FONT_WIDTH % 8;
-       for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+       width_remainder = vid_priv->fontdata->width % 8;
+       for (int row = 0; row < vid_priv->fontdata->height; row++) {
                uchar bits;
 
                bitcount = 8;
                dst = *line;
-               for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+               for (int col = 0; col < vid_priv->fontdata->byte_width; col++) {
                        if (width_remainder) {
-                               bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH - col == 1);
+                               bool is_last_col = (vid_priv->fontdata->byte_width - col == 1);
 
-                               if (is_last_iteration)
+                               if (is_last_col)
                                        bitcount = width_remainder;
                        }
                        bits = pfont[col];
@@ -215,7 +260,7 @@ static int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vi
                        }
                }
                *line += line_step;
-               pfont += VIDEO_FONT_BYTE_WIDTH;
+               pfont += vid_priv->fontdata->byte_width;
        }
        return ret;
 }
@@ -224,7 +269,7 @@ static int console_set_row(struct udevice *dev, uint row, int clr)
 {
        struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
        void *line, *dst, *end;
-       int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
+       int pixels = vid_priv->fontdata->height * vid_priv->xsize;
        int ret;
        int i;
        int pbytes;
@@ -233,7 +278,7 @@ static int console_set_row(struct udevice *dev, uint row, int clr)
        if (ret)
                return ret;
 
-       line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
+       line = vid_priv->fb + row * vid_priv->fontdata->height * vid_priv->line_length;
        dst = line;
        pbytes = VNBYTES(vid_priv->bpix);
        for (i = 0; i < pixels; i++)
@@ -256,9 +301,9 @@ static int console_move_rows(struct udevice *dev, uint rowdst,
        int size;
        int ret;
 
-       dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length;
-       src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length;
-       size = VIDEO_FONT_HEIGHT * vid_priv->line_length * count;
+       dst = vid_priv->fb + rowdst * vid_priv->fontdata->height * vid_priv->line_length;
+       src = vid_priv->fb + rowsrc * vid_priv->fontdata->height * vid_priv->line_length;
+       size = vid_priv->fontdata->height * vid_priv->line_length * count;
        ret = vidconsole_memmove(dev, dst, src, size);
        if (ret)
                return ret;
@@ -274,7 +319,8 @@ static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch)
        int pbytes = VNBYTES(vid_priv->bpix);
        int x, linenum, ret;
        void *start, *line;
-       uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_CHAR_PIXEL_BYTES;
+       uchar *pfont = vid_priv->fontdata->video_fontdata +
+                       (u8)ch * vid_priv->fontdata->char_pixel_bytes;
 
        if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
                return -EAGAIN;
@@ -294,27 +340,20 @@ static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch)
        if (ret)
                return ret;
 
-       return VID_TO_POS(VIDEO_FONT_WIDTH);
+       return VID_TO_POS(vid_priv->fontdata->width);
 }
 
 static int console_probe(struct udevice *dev)
 {
-       struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
-       struct udevice *vid_dev = dev->parent;
-       struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
-
-       vc_priv->x_charsize = VIDEO_FONT_WIDTH;
-       vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
-       vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
-       vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
-

drivers/video/console_simple.c static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch) · line 356

Quoted 10 lines
drivers/video/console_simple.c +3 -1
-       return 0;
+       return console_set_font(dev, &fonts[0]);
 }
 
 struct vidconsole_ops console_ops = {
        .putc_xy        = console_putc_xy,
        .move_rows      = console_move_rows,
        .set_row        = console_set_row,
+       .list_fonts     = console_simple_list_fonts,
+       .select_font    = console_simple_select_font,

Hmm can you split out the addition of these two items to a separate patch? There is too much going on in this patch.

[..]

Regards,
Simon

#9 lore raw

Re: [PATCH v2 5/8] video console: allow font size configuration at runtime

вт, 14 февр. 2023 г. в 23:13, Heinrich Schuchardt <[email protected]>:

Quoted 8 lines

Am 14. Februar 2023 20:48:53 MEZ schrieb Simon Glass <[email protected]>:

Quoted 4 lines

Hi Dzmitry,

Quoted 1 line · Dzmitry Sankouski

(...)

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
 drivers/video/Kconfig          |   16 +
 drivers/video/console_simple.c |  178 +-
 include/video_font.h           |   19 +-
 include/video_font_4x6.h       |   11 +-
 include/video_font_8x16.h      | 4624 +++++++++++++++++++++++++++++++
 include/video_font_data.h      | 4644
Quoted 7 lines

Shouldn't we have a font that is somehow legible on a 4k display, e.g. 16x32?

Best regards

Heinrich

There're new fonts in this patch series

Quoted 4 lines
 +-------------------------------
>>  9 files changed, 4802 insertions(+), 4707 deletions(-)
>>  create mode 100644 include/video_font_8x16.h
Quoted 1 line
Quoted 1 line

(...)

#10 lore raw

PATCH v2 6/8 video console: add 12x22 Sun font from linux

In reply to Dzmitry Sankouski

Modern mobile phones typically have high pixel density. Bootmenu is hardly readable on those with 8x16 font.

---
Changes for v2: N/A

 drivers/video/Kconfig         |    7 +
 include/video_font.h          |    6 +
 include/video_font_sun12x22.h | 6158 +++++++++++++++++++++++++++++++++
 3 files changed, 6171 insertions(+)
 create mode 100644 include/video_font_sun12x22.h
drivers/video/Kconfig +7 -0
index 31dbf1f98d..2023572aa2 100644
@@ -31,6 +31,13 @@ config VIDEO_FONT_8X16
 	  Provides character bitmap data in header file.
 	  When selecting multiple fonts, you may want to enable CMD_SELECT_FONT too.
 
+config VIDEO_FONT_SUN12X22
+	bool "12 x 22 font size"
+	help
+	  Font for video console driver, 12 x 22 pixels
+	  Provides character bitmap data in header file.
+	  When selecting multiple fonts, you may want to enable CMD_SELECT_FONT too.
+
 config VIDEO_LOGO
 	bool "Show the U-Boot logo on the display"
 	default y if !SPLASH_SCREEN
include/video_font.h +6 -0
index fbb58b11a0..03622adc7a 100644
@@ -15,6 +15,9 @@
 #if defined(CONFIG_VIDEO_FONT_8X16)
 #include <video_font_8x16.h>
 #endif
+#if defined(CONFIG_VIDEO_FONT_SUN12X22)
+#include <video_font_sun12x22.h>
+#endif
 
 static struct video_fontdata __maybe_unused fonts[] = {
 #if defined(CONFIG_VIDEO_FONT_4X6)
@@ -22,6 +25,9 @@ static struct video_fontdata __maybe_unused fonts[] = {
 #endif
 #if defined(CONFIG_VIDEO_FONT_8X16)
 	FONT_ENTRY(8, 16, 8x16),
+#endif
+#if defined(CONFIG_VIDEO_FONT_SUN12X22)
+	FONT_ENTRY(12, 22, 12x22),
 #endif
 	{/* list terminator */}
 };
include/video_font_sun12x22.h new file +6158 -0

2,969 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.30.2

Part of the diff is not shown here. View the raw message.

Reviewed-by on v2 6/8
#11 lore raw

Re: [PATCH v2 6/8] video console: add 12x22 Sun font from linux

Quoted 5 lines · Dzmitry Sankouski

Modern mobile phones typically have high pixel density. Bootmenu is hardly readable on those with 8x16 font.

Quoted 8 lines

---
Changes for v2: N/A

 drivers/video/Kconfig         |    7 +
 include/video_font.h          |    6 +
 include/video_font_sun12x22.h | 6158 +++++++++++++++++++++++++++++++++
 3 files changed, 6171 insertions(+)
 create mode 100644 include/video_font_sun12x22.h
#12 lore raw

PATCH v2 7/8 video console: add 16x32 Terminus font from linux

In reply to Dzmitry Sankouski

Modern mobile phones typically have high pixel density. Bootmenu is hardly readable on those with 8x16 font.

---
Changes for v2:
- edit for runtime configuration

 drivers/video/Kconfig         |    7 +
 include/video_font.h          |    6 +
 include/video_font_ter16x32.h | 2062 +++++++++++++++++++++++++++++++++
 3 files changed, 2075 insertions(+)
 create mode 100644 include/video_font_ter16x32.h
drivers/video/Kconfig +7 -0
index 2023572aa2..4d42c3fc56 100644
@@ -38,6 +38,13 @@ config VIDEO_FONT_SUN12X22
 	  Provides character bitmap data in header file.
 	  When selecting multiple fonts, you may want to enable CMD_SELECT_FONT too.
 
+config VIDEO_FONT_16X32
+	bool "16 x 32 font size"
+	help
+	  Font for video console driver, 16 x 32 pixels
+	  Provides character bitmap data in header file.
+	  When selecting multiple fonts, you may want to enable CMD_SELECT_FONT too.
+
 config VIDEO_LOGO
 	bool "Show the U-Boot logo on the display"
 	default y if !SPLASH_SCREEN
include/video_font.h +6 -0
index 03622adc7a..d4dd2b5eed 100644
@@ -18,6 +18,9 @@
 #if defined(CONFIG_VIDEO_FONT_SUN12X22)
 #include <video_font_sun12x22.h>
 #endif
+#if defined(CONFIG_VIDEO_FONT_16X32)
+#include <video_font_ter16x32.h>
+#endif
 
 static struct video_fontdata __maybe_unused fonts[] = {
 #if defined(CONFIG_VIDEO_FONT_4X6)
@@ -28,6 +31,9 @@ static struct video_fontdata __maybe_unused fonts[] = {
 #endif
 #if defined(CONFIG_VIDEO_FONT_SUN12X22)
 	FONT_ENTRY(12, 22, 12x22),
+#endif
+#if defined(CONFIG_VIDEO_FONT_16X32)
+	FONT_ENTRY(16, 32, 16x32),
 #endif
 	{/* list terminator */}
 };
include/video_font_ter16x32.h new file +2062 -0

2,062 lines not on this page · raw message

Signature · 1 line
2.30.2
Reviewed-by on v2 7/8
#13 lore raw

Re: [PATCH v2 7/8] video console: add 16x32 Terminus font from linux

Quoted 9 lines · Dzmitry Sankouski

Modern mobile phones typically have high pixel density. Bootmenu is hardly readable on those with 8x16 font.

---
Changes for v2:
- edit for runtime configuration

Quoted 5 lines
 drivers/video/Kconfig         |    7 +
 include/video_font.h          |    6 +
 include/video_font_ter16x32.h | 2062 +++++++++++++++++++++++++++++++++
 3 files changed, 2075 insertions(+)
 create mode 100644 include/video_font_ter16x32.h
#14 lore raw

PATCH v2 8/8 video console: add 12x22 console simple font test

In reply to Dzmitry Sankouski

Tests fonts wider than a byte.

---
Changes for v2: N/A

 configs/sandbox_defconfig |  3 +++
 test/dm/video.c           | 41 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
configs/sandbox_defconfig +3 -0
index de799b5cea..0d501c8f15 100644
@@ -335,3 +335,6 @@ CONFIG_TEST_FDTDEC=y
 CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
+CONFIG_CMD_SELECT_FONT=y
+CONFIG_VIDEO_FONT_8X16=y
+CONFIG_VIDEO_FONT_SUN12X22=y
test/dm/video.c +41 -0

71 lines not on this page · raw message

Signature · 1 line
2.30.2
Reviewed-by on v2 8/8
#15 lore raw

Re: [PATCH v2 8/8] video console: add 12x22 console simple font test

Quoted 10 lines · Dzmitry Sankouski

Tests fonts wider than a byte.

---
Changes for v2: N/A

 configs/sandbox_defconfig |  3 +++
 test/dm/video.c           | 41 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

very nice

#16 lore raw
In reply to Dzmitry Sankouski

Hi Dzmitry,

Quoted 53 lines · Dzmitry Sankouski

Modern mobile phones typically have high pixel density. Bootmenu is hardly readable on those with 8x16 font.

This patch series aims to add wider fonts for devices with high ppi.

Add 16x32, 12x22 fonts from linux, and allow font size configuration.

There was significant changes in version 3:
- fix video tests failures
- add runtime font size configuration
- add test for 12x22 font

Dzmitry Sankouski (8):
video console: unite normal and rotated files
video console: refactoring and optimization
video console: add support for fonts wider than 1 byte video console: add select font logic to vidconsole uclass driver video console: allow font size configuration at runtime video console: add 12x22 Sun font from linux
video console: add 16x32 Terminus font from linux video console: add 12x22 console simple font test

 cmd/Kconfig                       |    8 +
 cmd/Makefile                      |    2 +-
 cmd/font.c                        |    7 +-
 common/splash.c                   |    7 +-
 configs/qemu-x86_defconfig        |    1 +
 configs/sandbox_defconfig         |    3 +
 drivers/video/Kconfig             |   38 +-
 drivers/video/Makefile            |    3 +-
 drivers/video/console_normal.c    |  178 -
 drivers/video/console_rotate.c    |  497 ---
 drivers/video/console_simple.c    |  638 +++
 drivers/video/console_truetype.c  |    6 +-
 drivers/video/vidconsole-uclass.c |   22 +
 include/video.h                   |    1 +
 include/video_console.h           |   18 +-
 include/video_font.h              |   31 +-
 include/video_font_4x6.h          |   11 +-
 include/video_font_8x16.h         | 4624 ++++++++++++++++++++++
 include/video_font_data.h         | 4644 +---------------------
 include/video_font_sun12x22.h     | 6158 +++++++++++++++++++++++++++++
 include/video_font_ter16x32.h     | 2062 ++++++++++
 test/dm/video.c                   |   41 +
 22 files changed, 13681 insertions(+), 5319 deletions(-)
 delete mode 100644 drivers/video/console_normal.c
 delete mode 100644 drivers/video/console_rotate.c
 create mode 100644 drivers/video/console_simple.c
 create mode 100644 include/video_font_8x16.h
 create mode 100644 include/video_font_sun12x22.h
 create mode 100644 include/video_font_ter16x32.h
Quoted 3 lines

--
2.30.2

I am unable to apply these. Can you please check that they are against -master or -next ?

Thanks,
Simon

#17 lore raw

Hi, I'll rebase it

вт, 14 февр. 2023 г. в 16:14, Simon Glass <[email protected]>:

Quoted 66 lines

Hi Dzmitry,

Quoted 53 lines · Dzmitry Sankouski

Modern mobile phones typically have high pixel density. Bootmenu is hardly readable on those with 8x16 font.

This patch series aims to add wider fonts for devices with high ppi.

Add 16x32, 12x22 fonts from linux, and allow font size configuration.

There was significant changes in version 3:
- fix video tests failures
- add runtime font size configuration
- add test for 12x22 font

Dzmitry Sankouski (8):
video console: unite normal and rotated files
video console: refactoring and optimization
video console: add support for fonts wider than 1 byte video console: add select font logic to vidconsole uclass driver video console: allow font size configuration at runtime video console: add 12x22 Sun font from linux
video console: add 16x32 Terminus font from linux video console: add 12x22 console simple font test

 cmd/Kconfig                       |    8 +
 cmd/Makefile                      |    2 +-
 cmd/font.c                        |    7 +-
 common/splash.c                   |    7 +-
 configs/qemu-x86_defconfig        |    1 +
 configs/sandbox_defconfig         |    3 +
 drivers/video/Kconfig             |   38 +-
 drivers/video/Makefile            |    3 +-
 drivers/video/console_normal.c    |  178 -
 drivers/video/console_rotate.c    |  497 ---
 drivers/video/console_simple.c    |  638 +++
 drivers/video/console_truetype.c  |    6 +-
 drivers/video/vidconsole-uclass.c |   22 +
 include/video.h                   |    1 +
 include/video_console.h           |   18 +-
 include/video_font.h              |   31 +-
 include/video_font_4x6.h          |   11 +-
 include/video_font_8x16.h         | 4624 ++++++++++++++++++++++
 include/video_font_data.h         | 4644 +---------------------
 include/video_font_sun12x22.h     | 6158 +++++++++++++++++++++++++++++
 include/video_font_ter16x32.h     | 2062 ++++++++++
 test/dm/video.c                   |   41 +
 22 files changed, 13681 insertions(+), 5319 deletions(-)
 delete mode 100644 drivers/video/console_normal.c
 delete mode 100644 drivers/video/console_rotate.c
 create mode 100644 drivers/video/console_simple.c
 create mode 100644 include/video_font_8x16.h
 create mode 100644 include/video_font_sun12x22.h
 create mode 100644 include/video_font_ter16x32.h
Quoted 3 lines

--
2.30.2

I am unable to apply these. Can you please check that they are against -master or -next ?

Thanks,
Simon