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@paulk.fr> Reviewed-on: https://review.coreboot.org/20708 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
parent
5a752f7b8f
commit
1c0b603673
|
@ -63,10 +63,12 @@ libc-$(CONFIG_LP_VGA_VIDEO_CONSOLE) += video/vga.c
|
|||
# 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
|
||||
|
|
|
@ -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 unsigned long chars;
|
|||
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 @@ static void corebootfb_scroll_up(void)
|
|||
}
|
||||
|
||||
/* 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_clear(void)
|
|||
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 @@ static void corebootfb_putchar(u8 row, u8 col, unsigned int ch)
|
|||
}
|
||||
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,8 +238,10 @@ static int corebootfb_init(void)
|
|||
if (fbaddr == 0)
|
||||
return -1;
|
||||
|
||||
coreboot_video_console.columns = FI->x_resolution / FONT_WIDTH;
|
||||
coreboot_video_console.rows = FI->y_resolution / FONT_HEIGHT;
|
||||
font_init();
|
||||
|
||||
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 *
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* This file is part of the libpayload project.
|
||||
*
|
||||
* Copyright (C) 2017 Paul Kocialkowski <contact@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"
|
||||
|
||||
int font_width;
|
||||
int font_height;
|
||||
|
||||
void font_init(void)
|
||||
{
|
||||
font_width = FONT_WIDTH;
|
||||
font_height = FONT_HEIGHT;
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* This file is part of the libpayload project.
|
||||
*
|
||||
* Copyright (C) 2017 Paul Kocialkowski <contact@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
|
||||
|
||||
#include "font8x16.h"
|
||||
|
||||
extern int font_width;
|
||||
extern int font_height;
|
||||
|
||||
inline int font_glyph_filled(unsigned int ch, int x, int y)
|
||||
{
|
||||
unsigned char *glyph = font8x16 + ((ch & 0xFF) * FONT_HEIGHT);
|
||||
return glyph[y] & (1 << x);
|
||||
}
|
||||
|
||||
void font_init(void);
|
||||
|
||||
#endif
|
|
@ -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_set_palette(int entry, unsigned int color)
|
|||
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_clear(void)
|
|||
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 @@ static int geodelx_init(void)
|
|||
dcaddr = pci_read_resource(dev, 2);
|
||||
vgaddr = pci_read_resource(dev, 3);
|
||||
|
||||
font_init();
|
||||
|
||||
init_video_mode();
|
||||
|
||||
/* Set up the palette */
|
||||
|
|
Loading…
Reference in New Issue