[coreboot-gerrit] New patch to review for coreboot: video_printf: align text
Patrick Georgi (pgeorgi@google.com)
gerrit at coreboot.org
Mon Sep 7 18:47:18 CET 2015
Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11583
-gerrit
commit 18133055d4697210662fede22074c5c61c12b0d6
Author: Daisuke Nojiri <dnojiri at chromium.org>
Date: Wed Aug 12 18:49:50 2015 -0700
video_printf: align text
This change allows video_printf to left/center/right-align text depending on
the enum value provided by the caller. This is useful especially because usually
the length of formatted string is unknown before calling video_printf.
BUG=none
BRANCH=smaug
TEST=drew fastboot screens on Smaug
CQ-DEPEND=CL:296460
Reviewed-on: https://chromium-review.googlesource.com/292929
Reviewed-by: Aaron Durbin <adurbin at chromium.org>
(cherry picked from commit 436f05f60c1b88626740a35913e3ad37b5c777a3)
Change-Id: If1d50b7d8ddaa86eddc1618946756184cb87bfe1
Signed-off-by: Daisuke Nojiri <dnojiri at chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/295413
---
payloads/libpayload/drivers/video/video.c | 26 +++++++++++++++++++++++++-
payloads/libpayload/include/libpayload.h | 9 ++++++++-
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/payloads/libpayload/drivers/video/video.c b/payloads/libpayload/drivers/video/video.c
index f183517..71140f0 100644
--- a/payloads/libpayload/drivers/video/video.c
+++ b/payloads/libpayload/drivers/video/video.c
@@ -162,7 +162,8 @@ void video_console_putchar(unsigned int ch)
video_console_fixup_cursor();
}
-void video_printf(int foreground, int background, const char *fmt, ...)
+void video_printf(int foreground, int background, enum video_printf_align align,
+ const char *fmt, ...)
{
int i = 0, len;
char str[200];
@@ -174,6 +175,29 @@ void video_printf(int foreground, int background, const char *fmt, ...)
if (len <= 0)
return;
+ /* vsnprintf can return len larger than size. when it happens,
+ * only size-1 characters have been actually written. */
+ if (len >= ARRAY_SIZE(str))
+ len = ARRAY_SIZE(str) - 1;
+
+ if (len > console->columns) {
+ cursorx = 0;
+ } else {
+ switch (align) {
+ case VIDEO_PRINTF_ALIGN_LEFT:
+ cursorx = 0;
+ break;
+ case VIDEO_PRINTF_ALIGN_CENTER:
+ cursorx = (console->columns - len) / 2;
+ break;
+ case VIDEO_PRINTF_ALIGN_RIGHT:
+ cursorx = console->columns - len;
+ break;
+ default:
+ break;
+ }
+ }
+
foreground &= 0xf;
foreground <<= 8;
background &= 0xf;
diff --git a/payloads/libpayload/include/libpayload.h b/payloads/libpayload/include/libpayload.h
index 538f2d8..a1dbb01 100644
--- a/payloads/libpayload/include/libpayload.h
+++ b/payloads/libpayload/include/libpayload.h
@@ -211,7 +211,14 @@ void video_console_set_cursor(unsigned int cursorx, unsigned int cursory);
* print characters on video console with colors. note that there is a size
* restriction for the internal buffer. so, output string can be truncated.
*/
-void video_printf(int foreground, int background, const char *fmt, ...);
+enum video_printf_align {
+ VIDEO_PRINTF_ALIGN_KEEP = 0,
+ VIDEO_PRINTF_ALIGN_LEFT,
+ VIDEO_PRINTF_ALIGN_CENTER,
+ VIDEO_PRINTF_ALIGN_RIGHT,
+};
+void video_printf(int foreground, int background, enum video_printf_align align,
+ const char *fmt, ...);
/** @} */
/**
More information about the coreboot-gerrit
mailing list