With VIDEO_COPY enabled, only the modified parts of the frame buffer are
intended to be copied to the hardware. Add a test that checks this, by
overwriting contents we prepared without telling the video uclass and
then checking if the overwritten contents have been redrawn on the next
sync.

Signed-off-by: Alper Nebi Yasak <alpernebiya...@gmail.com>
---

Changes in v5:
- Add patch "video: test: Test partial updates of hardware frame buffer"

 test/dm/video.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/test/dm/video.c b/test/dm/video.c
index b9ff3da10c18..e4bd27a6b76f 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -657,3 +657,57 @@ static int dm_test_video_truetype_bs(struct 
unit_test_state *uts)
        return 0;
 }
 DM_TEST(dm_test_video_truetype_bs, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Test partial rendering onto hardware frame buffer */
+static int dm_test_video_copy(struct unit_test_state *uts)
+{
+       struct sandbox_sdl_plat *plat;
+       struct video_uc_plat *uc_plat;
+       struct udevice *dev, *con;
+       struct video_priv *priv;
+       const char *test_string = "\n\tCriticism may not be agreeable, but it 
is necessary.\t";
+       ulong addr;
+
+       if (!IS_ENABLED(CONFIG_VIDEO_COPY))
+               return -EAGAIN;
+
+       ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+       ut_assertnonnull(dev);
+       uc_plat = dev_get_uclass_plat(dev);
+       uc_plat->hide_logo = true;
+       plat = dev_get_plat(dev);
+       plat->font_size = 32;
+       ut_assert(!device_active(dev));
+       ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
+       ut_assertnonnull(dev);
+       priv = dev_get_uclass_priv(dev);
+
+       ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
+       ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
+
+       ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
+       vidconsole_put_string(con, "\n\n\n\n\n");
+       vidconsole_put_string(con, test_string);
+       vidconsole_put_string(con, test_string);
+
+       ut_asserteq(6678, compress_frame_buffer(uts, dev, false));
+       ut_assertok(check_copy_frame_buffer(uts, dev));
+
+       /*
+        * Secretly clear the hardware frame buffer, but in a different
+        * color (black) to see which parts will be overwritten.
+        */
+       memset(priv->copy_fb, 0, priv->fb_size);
+
+       /*
+        * We should have the full content on the main buffer, but only
+        * the new content should have been copied to the copy buffer.
+        */
+       vidconsole_put_string(con, test_string);
+       vidconsole_put_string(con, test_string);
+       ut_asserteq(7589, compress_frame_buffer(uts, dev, false));
+       ut_asserteq(5278, compress_frame_buffer(uts, dev, true));
+
+       return 0;
+}
+DM_TEST(dm_test_video_copy, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
-- 
2.40.1

Reply via email to