[coreboot-gerrit] Change in coreboot[master]: libpayload: video: Introduce helpers for font access

Paul Kocialkowski (Code Review) gerrit at coreboot.org
Sun Jul 23 15:13:45 CEST 2017


Paul Kocialkowski has uploaded this change for review. ( https://review.coreboot.org/20708


Change subject: libpayload: video: Introduce helpers for font access
......................................................................

libpayload: video: Introduce helpers for font access

This introduces helpers for accessing the included font, instead of
using hardcoded values provided by the font's header itself.

It will allow painlessly adding support for font scaling in a subsequent
change. It should not introduce any functionality change.

Change-Id: I0277984ec01f49dc51bfc8237ef806f13e3547e2
Signed-off-by: Paul Kocialkowski <contact at paulk.fr>
---
M payloads/libpayload/drivers/Makefile.inc
M payloads/libpayload/drivers/video/corebootfb.c
A payloads/libpayload/drivers/video/font.c
A payloads/libpayload/drivers/video/font.h
M payloads/libpayload/drivers/video/geodelx.c
5 files changed, 133 insertions(+), 34 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/20708/1

diff --git a/payloads/libpayload/drivers/Makefile.inc b/payloads/libpayload/drivers/Makefile.inc
index c6f6575..8dc6e8b 100644
--- a/payloads/libpayload/drivers/Makefile.inc
+++ b/payloads/libpayload/drivers/Makefile.inc
@@ -63,10 +63,12 @@
 # Geode LX console drivers
 libc-$(CONFIG_LP_GEODELX_VIDEO_CONSOLE) += video/geodelx.c
 libc-$(CONFIG_LP_GEODELX_VIDEO_CONSOLE) += video/font8x16.c
+libc-$(CONFIG_LP_GEODELX_VIDEO_CONSOLE) += video/font.c
 
 # coreboot generic framebuffer driver
 libc-$(CONFIG_LP_COREBOOT_VIDEO_CONSOLE) += video/corebootfb.c
 libc-$(CONFIG_LP_COREBOOT_VIDEO_CONSOLE) += video/font8x16.c
+libc-$(CONFIG_LP_COREBOOT_VIDEO_CONSOLE) += video/font.c
 
 # cbgfx: coreboot graphics library
 libc-y += video/graphics.c
diff --git a/payloads/libpayload/drivers/video/corebootfb.c b/payloads/libpayload/drivers/video/corebootfb.c
index 572a02b..6c2d242 100644
--- a/payloads/libpayload/drivers/video/corebootfb.c
+++ b/payloads/libpayload/drivers/video/corebootfb.c
@@ -32,7 +32,7 @@
 #include <coreboot_tables.h>
 #include <pci.h>
 #include <video_console.h>
-#include "font8x16.h"
+#include "font.h"
 
 struct video_console coreboot_video_console;
 
@@ -73,11 +73,11 @@
 static void corebootfb_scroll_up(void)
 {
 	unsigned char *dst = FB;
-	unsigned char *src = FB + (FI->bytes_per_line * FONT_HEIGHT);
+	unsigned char *src = FB + (FI->bytes_per_line * font_height());
 	int y;
 
 	/* Scroll all lines up */
-	for(y = 0; y < FI->y_resolution - FONT_HEIGHT; y++) {
+	for(y = 0; y < FI->y_resolution - font_height(); y++) {
 		memcpy(dst, src, FI->x_resolution * (FI->bits_per_pixel >> 3));
 
 		dst += FI->bytes_per_line;
@@ -85,7 +85,7 @@
 	}
 
 	/* Erase last line */
-	dst = FB + (FI->y_resolution - FONT_HEIGHT) * FI->bytes_per_line;
+	dst = FB + (FI->y_resolution - font_height()) * FI->bytes_per_line;
 
 	for(; y < FI->y_resolution; y++) {
 		memset(dst, 0, FI->x_resolution * (FI->bits_per_pixel >> 3));
@@ -124,7 +124,6 @@
 static void corebootfb_putchar(u8 row, u8 col, unsigned int ch)
 {
 	unsigned char *dst;
-	unsigned char *glyph = font8x16 + ((ch & 0xFF) * FONT_HEIGHT);
 
 	unsigned char bg = (ch >> 12) & 0xF;
 	unsigned char fg = (ch >> 8) & 0xF;
@@ -144,40 +143,39 @@
 	}
 
 
-	dst = FB + ((row * FONT_HEIGHT) * FI->bytes_per_line);
-	dst += (col * FONT_WIDTH * (FI->bits_per_pixel >> 3));
+	dst = FB + ((row * font_height()) * FI->bytes_per_line);
+	dst += (col * font_width() * (FI->bits_per_pixel >> 3));
 
-	for(y = 0; y < FONT_HEIGHT; y++) {
-		for(x = FONT_WIDTH - 1; x >= 0; x--) {
+	for(y = 0; y < font_height(); y++) {
+		for(x = font_width() - 1; x >= 0; x--) {
 
 			switch (FI->bits_per_pixel) {
 			case 8: /* Indexed */
-				dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3)] = (*glyph & (1 << x)) ?  fg : bg;
+				dst[(font_width() - x) * (FI->bits_per_pixel >> 3)] = font_glyph_filled(ch, x, y) ?  fg : bg;
 				break;
 			case 16: /* 16 bpp */
-				dst16 = (u16 *)(dst + (FONT_WIDTH - x) * (FI->bits_per_pixel >> 3));
-				*dst16 = (*glyph & (1 << x)) ? fgval : bgval;
+				dst16 = (u16 *)(dst + (font_width() - x) * (FI->bits_per_pixel >> 3));
+				*dst16 = font_glyph_filled(ch, x, y) ? fgval : bgval;
 				break;
 			case 24: /* 24 bpp */
-				if (*glyph & (1 << x)) {
-					dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3) + 0] = fgval & 0xff;
-					dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3) + 1] = (fgval >> 8) & 0xff;
-					dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3) + 2] = (fgval >> 16) & 0xff;
+				if (font_glyph_filled(ch, x, y)) {
+					dst[(font_width() - x) * (FI->bits_per_pixel >> 3) + 0] = fgval & 0xff;
+					dst[(font_width() - x) * (FI->bits_per_pixel >> 3) + 1] = (fgval >> 8) & 0xff;
+					dst[(font_width() - x) * (FI->bits_per_pixel >> 3) + 2] = (fgval >> 16) & 0xff;
 				} else {
-					dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3) + 0] = bgval & 0xff;
-					dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3) + 1] = (bgval >> 8) & 0xff;
-					dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3) + 2] = (bgval >> 16) & 0xff;
+					dst[(font_width() - x) * (FI->bits_per_pixel >> 3) + 0] = bgval & 0xff;
+					dst[(font_width() - x) * (FI->bits_per_pixel >> 3) + 1] = (bgval >> 8) & 0xff;
+					dst[(font_width() - x) * (FI->bits_per_pixel >> 3) + 2] = (bgval >> 16) & 0xff;
 				}
 				break;
 			case 32: /* 32 bpp */
-				dst32 = (u32 *)(dst + (FONT_WIDTH - x) * (FI->bits_per_pixel >> 3));
-				*dst32 = (*glyph & (1 << x)) ? fgval : bgval;
+				dst32 = (u32 *)(dst + (font_width() - x) * (FI->bits_per_pixel >> 3));
+				*dst32 = font_glyph_filled(ch, x, y) ? fgval : bgval;
 				break;
 			}
 		}
 
 		dst += FI->bytes_per_line;
-		glyph++;
 	}
 }
 
@@ -232,6 +230,8 @@
 	if (lib_sysinfo.framebuffer == NULL)
 		return -1;
 
+	font_init();
+
 	/* We might have been called before relocation (like FILO does). So
 	   just keep the physical address which won't break on relocation. */
 	fbinfo = virt_to_phys(lib_sysinfo.framebuffer);
@@ -240,8 +240,8 @@
 	if (fbaddr == 0)
 		return -1;
 
-	coreboot_video_console.columns = FI->x_resolution / FONT_WIDTH;
-	coreboot_video_console.rows = FI->y_resolution / FONT_HEIGHT;
+	coreboot_video_console.columns = FI->x_resolution / font_width();
+	coreboot_video_console.rows = FI->y_resolution / font_height();
 
 	/* See setting of fbinfo above. */
 	chars = virt_to_phys(malloc(coreboot_video_console.rows *
diff --git a/payloads/libpayload/drivers/video/font.c b/payloads/libpayload/drivers/video/font.c
new file mode 100644
index 0000000..3e02b00
--- /dev/null
+++ b/payloads/libpayload/drivers/video/font.c
@@ -0,0 +1,59 @@
+/*
+ * This file is part of the libpayload project.
+ *
+ * Copyright (C) 2017 Paul Kocialkowski <contact at paulk.fr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "font8x16.h"
+#include "font.h"
+
+static unsigned char *font;
+static int width;
+static int height;
+
+int font_width(void)
+{
+	return width;
+}
+
+int font_height(void)
+{
+	return height;
+}
+
+int font_glyph_filled(unsigned int ch, int x, int y)
+{
+	unsigned char *glyph = font + ((ch & 0xFF) * FONT_HEIGHT);
+	return glyph[y] & (1 << x);
+}
+
+void font_init(void)
+{
+	width = FONT_WIDTH;
+	height = FONT_HEIGHT;
+
+	font = font8x16;
+}
diff --git a/payloads/libpayload/drivers/video/font.h b/payloads/libpayload/drivers/video/font.h
new file mode 100644
index 0000000..8dd855a
--- /dev/null
+++ b/payloads/libpayload/drivers/video/font.h
@@ -0,0 +1,38 @@
+/*
+ * This file is part of the libpayload project.
+ *
+ * Copyright (C) 2017 Paul Kocialkowski <contact at paulk.fr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _DRIVERS_VIDEO_FONT_H
+#define _DRIVERS_VIDEO_FONT_H
+
+int font_width(void);
+int font_height(void);
+int font_glyph_filled(unsigned int ch, int x, int y);
+void font_init(void);
+
+#endif
diff --git a/payloads/libpayload/drivers/video/geodelx.c b/payloads/libpayload/drivers/video/geodelx.c
index ede997c..b8ff1b7 100644
--- a/payloads/libpayload/drivers/video/geodelx.c
+++ b/payloads/libpayload/drivers/video/geodelx.c
@@ -31,7 +31,7 @@
 #include <pci.h>
 #include <video_console.h>
 #include <arch/msr.h>
-#include "font8x16.h"
+#include "font.h"
 
 /* This is the video mode that we're going to use for our VGA screen */
 
@@ -206,10 +206,10 @@
 static void geodelx_scroll_up(void)
 {
 	unsigned char *dst = FB;
-	unsigned char *src = FB + FONT_HEIGHT * vga_mode.hactive;
+	unsigned char *src = FB + font_height() * vga_mode.hactive;
 	int y;
 
-	for(y = 0; y < vga_mode.vactive - FONT_HEIGHT; y++) {
+	for(y = 0; y < vga_mode.vactive - font_height(); y++) {
 		memcpy(dst, src, vga_mode.hactive);
 
 		dst += vga_mode.hactive;
@@ -236,24 +236,22 @@
 static void geodelx_putc(u8 row, u8 col, unsigned int ch)
 {
 	unsigned char *dst;
-	unsigned char *glyph = font8x16 + ((ch & 0xFF) * FONT_HEIGHT);
 
 	unsigned char bg = (ch >> 12) & 0xF;
 	unsigned char fg = (ch >> 8) & 0xF;
 
 	int x, y;
 
-	dst = FB + ((row * FONT_HEIGHT) * vga_mode.hactive);
-	dst += (col * FONT_WIDTH);
+	dst = FB + ((row * font_height()) * vga_mode.hactive);
+	dst += (col * font_width());
 
-	for(y = 0; y < FONT_HEIGHT; y++) {
+	for(y = 0; y < font_height(); y++) {
 
-		for(x = FONT_WIDTH - 1; x >= 0; x--)
-			dst[FONT_WIDTH - x] = (*glyph & (1 << x)) ?
+		for(x = font_width() - 1; x >= 0; x--)
+			dst[font_width() - x] = font_glyph_filled(ch, x, y) ?
 				fg : bg;
 
 		dst += vga_mode.hactive;
-		glyph++;
 	}
 }
 
@@ -270,6 +268,8 @@
 	dcaddr = pci_read_resource(dev, 2);
 	vgaddr = pci_read_resource(dev, 3);
 
+	font_init();
+
 	init_video_mode();
 
 	/* Set up the palette */

-- 
To view, visit https://review.coreboot.org/20708
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0277984ec01f49dc51bfc8237ef806f13e3547e2
Gerrit-Change-Number: 20708
Gerrit-PatchSet: 1
Gerrit-Owner: Paul Kocialkowski <contact at paulk.fr>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20170723/441da5eb/attachment-0001.html>


More information about the coreboot-gerrit mailing list