]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sandbox: video: Add BMP tests for 32bpp and 8bpp modes
authorSimon Glass <sjg@chromium.org>
Fri, 19 Nov 2021 20:23:50 +0000 (13:23 -0700)
committerAnatolij Gustschin <agust@denx.de>
Sun, 26 Dec 2021 22:02:19 +0000 (23:02 +0100)
Add a few more tests for BMP rendering. Use a back door into the sandbox
SDL driver to adjust the resolution at runtime.

The truetype code does not support 8bpp. Add this so that the display is
not blank when running in this mode.

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/sandbox/include/asm/test.h
drivers/video/console_truetype.c
drivers/video/sandbox_sdl.c
test/dm/video.c

index dab1a4ea01b3500ec001cba4d5cebec6e6289c83..0aad827e9c67a9bd31728de26babed6f006789e2 100644 (file)
@@ -8,6 +8,8 @@
 #ifndef __ASM_TEST_H
 #define __ASM_TEST_H
 
+#include <video.h>
+
 /* The sandbox driver always permits an I2C device with this address */
 #define SANDBOX_I2C_TEST_ADDR          0x59
 
@@ -285,4 +287,20 @@ void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags);
  */
 int sandbox_cros_ec_get_pwm_duty(struct udevice *dev, uint index, uint *duty);
 
+/**
+ * sandbox_sdl_set_bpp() - Set the depth of the sandbox display
+ *
+ * The device must not be active when this function is called. It activiates it
+ * before returning.
+ *
+ * This updates the depth value and adjusts a few other settings accordingly.
+ * It must be called before the display is probed.
+ *
+ * @dev: Device to adjust
+ * @l2bpp: depth to set
+ * @return 0 if the device was already active, other error if it fails to probe
+ * after the change
+ */
+int sandbox_sdl_set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp);
+
 #endif
index 98427f4c618ccabf02115cfd393d79c9d604f61f..de8b86bbacc79b9e64ae1a659ab1496248caeb77 100644 (file)
@@ -274,6 +274,27 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
         */
        for (row = 0; row < height; row++) {
                switch (vid_priv->bpix) {
+               case VIDEO_BPP8:
+                       if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
+                               u8 *dst = line + xoff;
+                               int i;
+
+                               for (i = 0; i < width; i++) {
+                                       int val = *bits;
+                                       int out;
+
+                                       if (vid_priv->colour_bg)
+                                               val = 255 - val;
+                                       out = val;
+                                       if (vid_priv->colour_fg)
+                                               *dst++ |= out;
+                                       else
+                                               *dst++ &= out;
+                                       bits++;
+                               }
+                               end = dst;
+                       }
+                       break;
 #ifdef CONFIG_VIDEO_BPP16
                case VIDEO_BPP16: {
                        uint16_t *dst = (uint16_t *)line + xoff;
index eb321ad17f5dbff451dfb35a6924a86e17c766cf..2afe66fab1a23db1c1f8784faed7a0eac12e365b 100644 (file)
@@ -12,6 +12,7 @@
 #include <asm/sdl.h>
 #include <asm/state.h>
 #include <asm/u-boot-sandbox.h>
+#include <dm/device-internal.h>
 #include <dm/test.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -79,6 +80,23 @@ static void set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp)
                uc_plat->size *= 2;
 }
 
+int sandbox_sdl_set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp)
+{
+       int ret;
+
+       if (device_active(dev))
+               return -EINVAL;
+       sandbox_sdl_remove_display();
+
+       set_bpp(dev, l2bpp);
+
+       ret = device_probe(dev);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
 static int sandbox_sdl_remove(struct udevice *dev)
 {
        /*
@@ -89,7 +107,6 @@ static int sandbox_sdl_remove(struct udevice *dev)
         *
         * sandbox_sdl_remove_display();
         */
-
        return 0;
 }
 
index da0ae3622f77b2fcde722d2663d1bcec7645ac70..c8c6668c8b3279797d7c1c21b273599586e8fe9a 100644 (file)
@@ -13,6 +13,7 @@
 #include <os.h>
 #include <video.h>
 #include <video_console.h>
+#include <asm/test.h>
 #include <dm/test.h>
 #include <dm/uclass-internal.h>
 #include <test/test.h>
@@ -319,6 +320,43 @@ static int dm_test_video_bmp(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_video_bmp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
+/* Test drawing a bitmap file on a 8bpp display */
+static int dm_test_video_bmp8(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+       ulong addr;
+
+       ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+       ut_assertnonnull(dev);
+       ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8));
+
+       ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
+
+       ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
+       ut_asserteq(1247, compress_frame_buffer(uts, dev));
+
+       return 0;
+}
+DM_TEST(dm_test_video_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Test drawing a bitmap file on a 32bpp display */
+static int dm_test_video_bmp32(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+       ulong addr;
+
+       ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+       ut_assertnonnull(dev);
+       ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
+       ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
+
+       ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
+       ut_asserteq(2024, compress_frame_buffer(uts, dev));
+
+       return 0;
+}
+DM_TEST(dm_test_video_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
 /* Test drawing a compressed bitmap file */
 static int dm_test_video_bmp_comp(struct unit_test_state *uts)
 {