sandbox: video: Add BMP tests for 32bpp and 8bpp modes

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>
This commit is contained in:
Simon Glass 2021-11-19 13:23:50 -07:00 committed by Anatolij Gustschin
parent 8405174391
commit 8657ad43f3
4 changed files with 95 additions and 1 deletions

View 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

View 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;

View 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;
}

View 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)
{