diff mbox series

[v2,18/26] video: sandbox: Add support for the copy framebuffer

Message ID 20200524194852.v2.18.I43794bcb7a8a65f9ffa7a0821642ba4b602dcf47@changeid
State Accepted
Commit f578ca799eec188fc96da3a1680c78c5f924b928
Headers show
Series x86: video: Speed up the framebuffer | expand

Commit Message

Simon Glass May 25, 2020, 1:48 a.m. UTC
Enable this feature on sandbox by updating the SDL driver to have two
framebuffers.

Update the video tests to check that the copy framebuffer is kept in sync.

Signed-off-by: Simon Glass <sjg at chromium.org>
Reviewed-by: Anatolij Gustschin <agust at denx.de>
---

Changes in v2: None

 configs/sandbox_defconfig   |  1 +
 drivers/video/sandbox_sdl.c |  9 +++++-
 test/dm/video.c             | 55 +++++++++++++++++++++++--------------
 3 files changed, 43 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 9445d78118..ea567506e5 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -215,6 +215,7 @@  CONFIG_DM_USB=y
 CONFIG_USB_EMUL=y
 CONFIG_USB_KEYBOARD=y
 CONFIG_DM_VIDEO=y
+CONFIG_VIDEO_COPY=y
 CONFIG_CONSOLE_ROTATION=y
 CONFIG_CONSOLE_TRUETYPE=y
 CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
diff --git a/drivers/video/sandbox_sdl.c b/drivers/video/sandbox_sdl.c
index c678e728db..f529a350fb 100644
--- a/drivers/video/sandbox_sdl.c
+++ b/drivers/video/sandbox_sdl.c
@@ -23,6 +23,7 @@  enum {
 
 static int sandbox_sdl_probe(struct udevice *dev)
 {
+	struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
 	struct sandbox_sdl_plat *plat = dev_get_platdata(dev);
 	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
 	struct sandbox_state *state = state_get_current();
@@ -40,6 +41,8 @@  static int sandbox_sdl_probe(struct udevice *dev)
 	uc_priv->rot = plat->rot;
 	uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name;
 	uc_priv->font_size = plat->font_size;
+	if (IS_ENABLED(CONFIG_VIDEO_COPY))
+		uc_plat->copy_base = uc_plat->base - uc_plat->size / 2;
 
 	return 0;
 }
@@ -55,7 +58,11 @@  static int sandbox_sdl_bind(struct udevice *dev)
 	plat->bpix = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16);
 	plat->rot = dev_read_u32_default(dev, "rotate", 0);
 	uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8;
-	debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
+
+	/* Allow space for two buffers, the lower one being the copy buffer */
+	log_debug("Frame buffer size %x\n", uc_plat->size);
+	if (IS_ENABLED(CONFIG_VIDEO_COPY))
+		uc_plat->size *= 2;
 
 	return ret;
 }
diff --git a/test/dm/video.c b/test/dm/video.c
index 729c31b47d..19f78b6239 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -51,12 +51,18 @@  DM_TEST(dm_test_video_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  * size of the compressed data. This provides a pretty good level of
  * certainty and the resulting tests need only check a single value.
  *
+ * If the copy framebuffer is enabled, this compares it to the main framebuffer
+ * too.
+ *
+ * @uts:	Test state
  * @dev:	Video device
  * @return compressed size of the frame buffer, or -ve on error
  */
-static int compress_frame_buffer(struct udevice *dev)
+static int compress_frame_buffer(struct unit_test_state *uts,
+				 struct udevice *dev)
 {
 	struct video_priv *priv = dev_get_uclass_priv(dev);
+	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
 	uint destlen;
 	void *dest;
 	int ret;
@@ -72,6 +78,13 @@  static int compress_frame_buffer(struct udevice *dev)
 	if (ret)
 		return ret;
 
+	/* Check here that the copy frame buffer is working correctly */
+	if (IS_ENABLED(CONFIG_VIDEO_COPY)) {
+		ut_assertf(!memcmp(uc_priv->fb, uc_priv->copy_fb,
+				   uc_priv->fb_size),
+				   "Copy framebuffer does not match fb");
+	}
+
 	return destlen;
 }
 
@@ -110,25 +123,25 @@  static int dm_test_video_text(struct unit_test_state *uts)
 
 	ut_assertok(select_vidconsole(uts, "vidconsole0"));
 	ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
-	ut_asserteq(46, compress_frame_buffer(dev));
+	ut_asserteq(46, compress_frame_buffer(uts, dev));
 
 	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
 	vidconsole_putc_xy(con, 0, 0, 'a');
-	ut_asserteq(79, compress_frame_buffer(dev));
+	ut_asserteq(79, compress_frame_buffer(uts, dev));
 
 	vidconsole_putc_xy(con, 0, 0, ' ');
-	ut_asserteq(46, compress_frame_buffer(dev));
+	ut_asserteq(46, compress_frame_buffer(uts, dev));
 
 	for (i = 0; i < 20; i++)
 		vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
-	ut_asserteq(273, compress_frame_buffer(dev));
+	ut_asserteq(273, compress_frame_buffer(uts, dev));
 
 	vidconsole_set_row(con, 0, WHITE);
-	ut_asserteq(46, compress_frame_buffer(dev));
+	ut_asserteq(46, compress_frame_buffer(uts, dev));
 
 	for (i = 0; i < 20; i++)
 		vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
-	ut_asserteq(273, compress_frame_buffer(dev));
+	ut_asserteq(273, compress_frame_buffer(uts, dev));
 
 	return 0;
 }
@@ -144,7 +157,7 @@  static int dm_test_video_chars(struct unit_test_state *uts)
 	ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
 	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
 	vidconsole_put_string(con, test_string);
-	ut_asserteq(466, compress_frame_buffer(dev));
+	ut_asserteq(466, compress_frame_buffer(uts, dev));
 
 	return 0;
 }
@@ -164,20 +177,20 @@  static int dm_test_video_ansi(struct unit_test_state *uts)
 	/* reference clear: */
 	video_clear(con->parent);
 	video_sync(con->parent, false);
-	ut_asserteq(46, compress_frame_buffer(dev));
+	ut_asserteq(46, compress_frame_buffer(uts, dev));
 
 	/* test clear escape sequence: [2J */
 	vidconsole_put_string(con, "A\tB\tC"ANSI_ESC"[2J");
-	ut_asserteq(46, compress_frame_buffer(dev));
+	ut_asserteq(46, compress_frame_buffer(uts, dev));
 
 	/* test set-cursor: [%d;%df */
 	vidconsole_put_string(con, "abc"ANSI_ESC"[2;2fab"ANSI_ESC"[4;4fcd");
-	ut_asserteq(143, compress_frame_buffer(dev));
+	ut_asserteq(143, compress_frame_buffer(uts, dev));
 
 	/* test colors (30-37 fg color, 40-47 bg color) */
 	vidconsole_put_string(con, ANSI_ESC"[30;41mfoo"); /* black on red */
 	vidconsole_put_string(con, ANSI_ESC"[33;44mbar"); /* yellow on blue */
-	ut_asserteq(272, compress_frame_buffer(dev));
+	ut_asserteq(272, compress_frame_buffer(uts, dev));
 
 	return 0;
 }
@@ -208,24 +221,24 @@  static int check_vidconsole_output(struct unit_test_state *uts, int rot,
 
 	ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
 	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
-	ut_asserteq(46, compress_frame_buffer(dev));
+	ut_asserteq(46, compress_frame_buffer(uts, dev));
 
 	/* Check display wrap */
 	for (i = 0; i < 120; i++)
 		vidconsole_put_char(con, 'A' + i % 50);
-	ut_asserteq(wrap_size, compress_frame_buffer(dev));
+	ut_asserteq(wrap_size, compress_frame_buffer(uts, dev));
 
 	/* Check display scrolling */
 	for (i = 0; i < SCROLL_LINES; i++) {
 		vidconsole_put_char(con, 'A' + i % 50);
 		vidconsole_put_char(con, '\n');
 	}
-	ut_asserteq(scroll_size, compress_frame_buffer(dev));
+	ut_asserteq(scroll_size, compress_frame_buffer(uts, dev));
 
 	/* If we scroll enough, the screen becomes blank again */
 	for (i = 0; i < SCROLL_LINES; i++)
 		vidconsole_put_char(con, '\n');
-	ut_asserteq(46, compress_frame_buffer(dev));
+	ut_asserteq(46, compress_frame_buffer(uts, dev));
 
 	return 0;
 }
@@ -299,7 +312,7 @@  static int dm_test_video_bmp(struct unit_test_state *uts)
 	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
 
 	ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
-	ut_asserteq(1368, compress_frame_buffer(dev));
+	ut_asserteq(1368, compress_frame_buffer(uts, dev));
 
 	return 0;
 }
@@ -315,7 +328,7 @@  static int dm_test_video_bmp_comp(struct unit_test_state *uts)
 	ut_assertok(read_file(uts, "tools/logos/denx-comp.bmp", &addr));
 
 	ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
-	ut_asserteq(1368, compress_frame_buffer(dev));
+	ut_asserteq(1368, compress_frame_buffer(uts, dev));
 
 	return 0;
 }
@@ -330,7 +343,7 @@  static int dm_test_video_truetype(struct unit_test_state *uts)
 	ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
 	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
 	vidconsole_put_string(con, test_string);
-	ut_asserteq(12237, compress_frame_buffer(dev));
+	ut_asserteq(12237, compress_frame_buffer(uts, dev));
 
 	return 0;
 }
@@ -351,7 +364,7 @@  static int dm_test_video_truetype_scroll(struct unit_test_state *uts)
 	ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
 	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
 	vidconsole_put_string(con, test_string);
-	ut_asserteq(35030, compress_frame_buffer(dev));
+	ut_asserteq(35030, compress_frame_buffer(uts, dev));
 
 	return 0;
 }
@@ -372,7 +385,7 @@  static int dm_test_video_truetype_bs(struct unit_test_state *uts)
 	ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
 	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
 	vidconsole_put_string(con, test_string);
-	ut_asserteq(29018, compress_frame_buffer(dev));
+	ut_asserteq(29018, compress_frame_buffer(uts, dev));
 
 	return 0;
 }