mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-16 12:11:32 +00:00
video: sandbox: Avoid duplicate display windows
When unit tests are run they currently create a new window. Update the code so that the old one is removed first. This avoids the confusion as to which one is active. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
0fe5e9481e
commit
250e735c69
3 changed files with 49 additions and 6 deletions
|
@ -44,6 +44,7 @@ struct buf_info {
|
|||
* @stopping: true if audio will stop once it runs out of data
|
||||
* @texture: SDL texture to use for U-Boot display contents
|
||||
* @renderer: SDL renderer to use
|
||||
* @screen: SDL window to use
|
||||
* @src_depth: Number of bits per pixel in the source frame buffer (that we read
|
||||
* from and render to SDL)
|
||||
*/
|
||||
|
@ -63,6 +64,7 @@ static struct sdl_info {
|
|||
bool stopping;
|
||||
SDL_Texture *texture;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Window *screen;
|
||||
int src_depth;
|
||||
} sdl;
|
||||
|
||||
|
@ -101,6 +103,23 @@ static int sandbox_sdl_ensure_init(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int sandbox_sdl_remove_display(void)
|
||||
{
|
||||
if (!sdl.renderer) {
|
||||
printf("SDL renderer does not exist\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
SDL_DestroyTexture(sdl.texture);
|
||||
SDL_DestroyRenderer(sdl.renderer);
|
||||
SDL_DestroyWindow(sdl.screen);
|
||||
sdl.texture = NULL;
|
||||
sdl.renderer = NULL;
|
||||
sdl.screen = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sandbox_sdl_init_display(int width, int height, int log2_bpp,
|
||||
bool double_size)
|
||||
{
|
||||
|
@ -112,6 +131,9 @@ int sandbox_sdl_init_display(int width, int height, int log2_bpp,
|
|||
err = sandbox_sdl_ensure_init();
|
||||
if (err)
|
||||
return err;
|
||||
if (sdl.renderer)
|
||||
sandbox_sdl_remove_display();
|
||||
|
||||
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
|
||||
printf("Unable to initialise SDL LCD: %s\n", SDL_GetError());
|
||||
return -EPERM;
|
||||
|
@ -134,16 +156,15 @@ int sandbox_sdl_init_display(int width, int height, int log2_bpp,
|
|||
log2_bpp = 5;
|
||||
sdl.depth = 1 << log2_bpp;
|
||||
sdl.pitch = sdl.width * sdl.depth / 8;
|
||||
SDL_Window *screen = SDL_CreateWindow("U-Boot", SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
sdl.vis_width, sdl.vis_height,
|
||||
SDL_WINDOW_RESIZABLE);
|
||||
if (!screen) {
|
||||
sdl.screen = SDL_CreateWindow("U-Boot", SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED, sdl.vis_width,
|
||||
sdl.vis_height, SDL_WINDOW_RESIZABLE);
|
||||
if (!sdl.screen) {
|
||||
printf("Unable to initialise SDL screen: %s\n",
|
||||
SDL_GetError());
|
||||
return -EIO;
|
||||
}
|
||||
sdl.renderer = SDL_CreateRenderer(screen, -1,
|
||||
sdl.renderer = SDL_CreateRenderer(sdl.screen, -1,
|
||||
SDL_RENDERER_ACCELERATED |
|
||||
SDL_RENDERER_PRESENTVSYNC);
|
||||
if (!sdl.renderer) {
|
||||
|
|
|
@ -25,6 +25,13 @@
|
|||
int sandbox_sdl_init_display(int width, int height, int log2_bpp,
|
||||
bool double_size);
|
||||
|
||||
/**
|
||||
* sandbox_sdl_remove_display() - Remove the SDL screen
|
||||
*
|
||||
* @return 0 if OK, -ENOENT if the SDL had not been inited.
|
||||
*/
|
||||
int sandbox_sdl_remove_display(void);
|
||||
|
||||
/**
|
||||
* sandbox_sdl_sync() - Sync current U-Boot LCD frame buffer to SDL
|
||||
*
|
||||
|
|
|
@ -63,6 +63,20 @@ static void set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp)
|
|||
uc_plat->size *= 2;
|
||||
}
|
||||
|
||||
static int sandbox_sdl_remove(struct udevice *dev)
|
||||
{
|
||||
/*
|
||||
* Removing the display it a bit annoying when running unit tests, since
|
||||
* they remove all devices. It is nice to be able to see what the test
|
||||
* wrote onto the display. So this comment is just here to show how to
|
||||
* do it, if we want to make it optional one day.
|
||||
*
|
||||
* sandbox_sdl_remove_display();
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sandbox_sdl_bind(struct udevice *dev)
|
||||
{
|
||||
struct sandbox_sdl_plat *plat = dev_get_plat(dev);
|
||||
|
@ -90,5 +104,6 @@ U_BOOT_DRIVER(sandbox_lcd_sdl) = {
|
|||
.of_match = sandbox_sdl_ids,
|
||||
.bind = sandbox_sdl_bind,
|
||||
.probe = sandbox_sdl_probe,
|
||||
.remove = sandbox_sdl_remove,
|
||||
.plat_auto = sizeof(struct sandbox_sdl_plat),
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue