From f4f854841031f39f64477fc410e661d04a9da106 Mon Sep 17 00:00:00 2001 From: ANSI TV Admin Date: Wed, 11 Nov 2026 09:48:56 -0800 Subject: [PATCH 16/24] sdl_con: open the window once (no open-close-open at start) With GPU Accelerated on, the GPU patch forces the SDL output and the OpenGL renderer (SDL_RENDER_DRIVER=opengl). setup_surfaces() created the window with SDL_CreateWindowAndRenderer() and no SDL_WINDOW_OPENGL, so SDL showed a window, then its GL renderer found the window was not an OpenGL one and called SDL_RecreateWindow(): hide, destroy the native window, create a new one, show it. On Windows that is a window that opens, closes and opens again at every start. Ask for SDL_WINDOW_OPENGL when the render driver is "opengl", so the first window is the one the renderer keeps, and create the window SDL_WINDOW_HIDDEN, showing it once its renderer, texture and minimum size are set, so no renderer that still swaps the window can flash. SDL_ShowWindow is loaded NULL-tolerant; without it the window is created visible as before. Co-Authored-By: Claude Opus 5.5 --- src/conio/sdl_con.c | 16 ++++++++++++++++ src/conio/sdlfuncs.c | 1 + src/conio/sdlfuncs.h | 3 +++ 3 files changed, 20 insertions(+) diff --git a/src/conio/sdl_con.c b/src/conio/sdl_con.c index bdcc7945..81788c33 100644 --- a/src/conio/sdl_con.c +++ b/src/conio/sdl_con.c @@ -798,8 +798,22 @@ static void setup_surfaces(struct video_stats *vs) texscale = (!internal_scaling && (cio_api.options & CONIO_OPT_HIRES_EXTERNAL)) ? 2 : 1; if (win == NULL) { + const char *rdrv; + if (cio_api.options & (CONIO_OPT_POINTY_EXTERNAL | CONIO_OPT_HIRES_EXTERNAL)) sdl.SetHint(SDL_HINT_RENDER_DRIVER,"opengl"); + /* One window, opened once. SDL's OpenGL renderer cannot use a + * window made without SDL_WINDOW_OPENGL: it destroys the native + * window and creates another (SDL_RecreateWindow), which the user + * sees as a window opening, closing and opening again. So ask + * for an OpenGL window up front when that is the renderer, and + * keep the window hidden until it is final (renderer, texture, + * minimum size) for any renderer that still swaps it. */ + rdrv = sdl.GetHint(SDL_HINT_RENDER_DRIVER); + if (rdrv != NULL && strcasecmp(rdrv, "opengl") == 0) + flags |= SDL_WINDOW_OPENGL; + if (sdl.ShowWindow != NULL) + flags |= SDL_WINDOW_HIDDEN; // SDL2: This is slow sometimes... not sure why. new_win = true; if (sdl.CreateWindowAndRenderer(vs->winwidth, vs->winheight, flags, &win, &renderer) == 0) { @@ -867,6 +881,8 @@ static void setup_surfaces(struct video_stats *vs) } sdl_bughack_minsize(idealmw, idealmh, new_win); + if (new_win && win != NULL && sdl.ShowWindow != NULL) + sdl.ShowWindow(win); if(win!=NULL) { bitmap_drv_request_pixels(); } diff --git a/src/conio/sdlfuncs.c b/src/conio/sdlfuncs.c index 7b7a4115..bda30894 100644 --- a/src/conio/sdlfuncs.c +++ b/src/conio/sdlfuncs.c @@ -106,6 +106,7 @@ int load_sdl_funcs(struct sdlfuncs *sdlf) sdlf->RenderFlush=xp_dlsym(sdl_dll, SDL_RenderFlush); sdlf->GetRendererInfo=xp_dlsym(sdl_dll, SDL_GetRendererInfo); sdlf->ShowSimpleMessageBox=xp_dlsym(sdl_dll, SDL_ShowSimpleMessageBox); + sdlf->ShowWindow=xp_dlsym(sdl_dll, SDL_ShowWindow); if((sdlf->WasInit=xp_dlsym(sdl_dll, SDL_WasInit))==NULL) { xp_dlclose(sdl_dll); return(-1); diff --git a/src/conio/sdlfuncs.h b/src/conio/sdlfuncs.h index 31e63088..d84b0728 100644 --- a/src/conio/sdlfuncs.h +++ b/src/conio/sdlfuncs.h @@ -53,6 +53,9 @@ struct sdlfuncs { int (HACK_HACK_HACK *RenderFlush)(SDL_Renderer *renderer); int (HACK_HACK_HACK *GetRendererInfo)(SDL_Renderer *renderer, SDL_RendererInfo *info); int (HACK_HACK_HACK *ShowSimpleMessageBox)(Uint32 flags, const char *title, const char *message, SDL_Window *window); + /* NULL-tolerant: the window is created hidden and shown once it is + * final; without this the caller creates it visible as before. */ + void (HACK_HACK_HACK *ShowWindow)(SDL_Window *window); SDL_bool (HACK_HACK_HACK *SetHint) (const char *name, const char *value); const char * (HACK_HACK_HACK *GetHint) (const char *name); SDL_Keymod (HACK_HACK_HACK *GetModState) (void); -- 2.47.3