vboot: display: Use the new graphics stack.

Also temporarily drop support for composing screens in depthcharge. This
support will be reworked at least use the new stack, and likely to use a
different structure.

Change-Id: I2347474d3d0cb1ae42a1e2455f84f29a9384c852
diff --git a/src/vboot/callbacks/display.c b/src/vboot/callbacks/display.c
index cbeb46a..bb694a4 100644
--- a/src/vboot/callbacks/display.c
+++ b/src/vboot/callbacks/display.c
@@ -21,64 +21,43 @@
  */
 
 #include <assert.h>
-#include <cbgfx.h>
-#include <libpayload.h>
-#include <sysinfo.h>
 #include <vboot_api.h>
 #include <vboot_struct.h>
 
-#include "drivers/video/coreboot_fb.h"
-#include "drivers/video/display.h"
+#include "base/graphics/graphics.h"
+#include "drivers/board/board.h"
+#include "drivers/console/display.h"
+#include "drivers/display/display.h"
 #include "vboot/firmware_id.h"
 #include "vboot/util/commonparams.h"
-#include "vboot/screens.h"
 
 VbError_t VbExDisplayInit(uint32_t *width, uint32_t *height)
 {
-	if (display_init())
+	DisplayOps *display = board_display();
+
+	if (display_dimensions(display, height, width))
 		return VBERROR_UNKNOWN;
 
-	video_init();
-
-	if (lib_sysinfo.framebuffer) {
-		*width = lib_sysinfo.framebuffer->x_resolution;
-		*height = lib_sysinfo.framebuffer->y_resolution;
-	} else {
-		*width = *height = 0;
-	}
-
 	return VBERROR_SUCCESS;
 }
 
 VbError_t VbExDisplayBacklight(uint8_t enable)
 {
-	if (backlight_update(enable))
-		return VBERROR_UNKNOWN;
-
+	printf("Ignoring VbExDisplayBacklight.\n");
 	return VBERROR_SUCCESS;
 }
 
 static void print_string(const char *str)
 {
-	int str_len = strlen(str);
-	while (str_len--) {
-		if (*str == '\n')
-			video_console_putchar('\r');
-		video_console_putchar(*str++);
-	}
-}
-
-static void print_string_newline(const char *str)
-{
-	print_string(str);
-	print_string("\n");
+	while (*str)
+		display_console_put_char(*str++);
 }
 
 void print_on_center(const char *msg)
 {
-	unsigned int rows, cols;
-	video_get_rows_cols(&rows, &cols);
-	video_console_set_cursor((cols - strlen(msg)) / 2, rows / 2);
+	uint32_t rows, cols;
+	display_console_dimensions(&rows, &cols);
+	display_console_set_cursor((cols - strlen(msg)) / 2, rows / 2);
 	print_string(msg);
 }
 
@@ -86,17 +65,28 @@
 {
 	const char *msg = NULL;
 
-	if (vboot_draw_screen(screen_type, locale) == CBGFX_SUCCESS)
-		return VBERROR_SUCCESS;
-
 	/*
 	 * Show the debug messages for development. It is a backup method
 	 * when GBB does not contain a full set of bitmaps.
 	 */
 	switch (screen_type) {
 	case VB_SCREEN_BLANK:
-		// clear the screen
-		video_console_clear();
+		{
+			const DcColor Black = {
+				.red = 0,
+				.green = 0,
+				.blue = 0,
+			};
+
+			// clear the screen
+			DisplayOps *display = board_display();
+			uint32_t height, width;
+			if (display_dimensions(display, &height, &width) ||
+			    display_fill(display, 0, 0,
+					 height, width, &Black)) {
+				return VBERROR_UNKNOWN;
+			}
+		}
 		break;
 	case VB_SCREEN_DEVELOPER_WARNING:
 		msg = "developer mode warning";
@@ -130,10 +120,17 @@
 VbError_t VbExDisplayImage(uint32_t x, uint32_t y,
 			   void *buffer, uint32_t buffersize)
 {
-	if (dc_corebootfb_draw_bitmap(x, y, buffer))
+	static DcBitmap image;
+
+	if (graphics_load_bitmap_file(&image, buffer))
 		return VBERROR_UNKNOWN;
 
-	return VBERROR_SUCCESS;
+	int ret = display_draw(board_display(), x, y, &image);
+
+	free(image.pixels);
+	image.pixels = NULL;
+
+	return ret ? VBERROR_UNKNOWN : VBERROR_SUCCESS;
 }
 
 VbError_t VbExDisplaySetDimension(uint32_t width, uint32_t height)
@@ -145,26 +142,31 @@
 
 VbError_t VbExDisplayDebugInfo(const char *info_str)
 {
-	video_console_set_cursor(0, 0);
+	if (display_console_set_cursor(0, 0))
+		return VBERROR_UNKNOWN;
 	print_string(info_str);
 
 	print_string("read-only firmware id: ");
 	const char *id = firmware_id_for(VDAT_RO, NULL);
 	if (!id)
 		id = "NOT FOUND";
-	print_string_newline(id);
+	print_string(id);
+	print_string("\n");
 
 	print_string("active firmware id: ");
 	id = firmware_id_active(NULL);
 	if (!id)
 		id = "NOT FOUND";
-	print_string_newline(id);
+	print_string(id);
+	print_string("\n");
 
 	return VBERROR_SUCCESS;
 }
 
 VbError_t VbExGetLocalizationCount(uint32_t *count)
 {
-	*count = vboot_get_locale_count();
-	return VBERROR_SUCCESS;
+	if (board_storage_locale_count(count))
+		return VBERROR_UNKNOWN;
+	else
+		return VBERROR_SUCCESS;
 }