summaryrefslogtreecommitdiff
path: root/arch/sandbox/cpu
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-11-19 13:23:46 -0700
committerAnatolij Gustschin <agust@denx.de>2021-12-26 23:02:19 +0100
commit250e735c692bd12ea86dcea5de2cd1cfe225a0a4 (patch)
treebd7e5b14f1706db1a7e88c2edc46d4ce16b084cd /arch/sandbox/cpu
parent0fe5e9481e8ad39393523a23ebb090a249da18b7 (diff)
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>
Diffstat (limited to 'arch/sandbox/cpu')
-rw-r--r--arch/sandbox/cpu/sdl.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c
index 7ff0df2ee5..f4ca36b35c 100644
--- a/arch/sandbox/cpu/sdl.c
+++ b/arch/sandbox/cpu/sdl.c
@@ -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) {