From eb9b86269d83f9ba61469eb8f1fc0693e622cf90 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Fri, 7 Feb 2020 14:25:52 +0000 Subject: [PATCH] Some graphics cards return a too small overlay when the size is larger than 1024. Fall back in that case. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4315 --- src/gui/sdlmain.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index 846e8e9f..83d2fe40 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -720,16 +720,24 @@ dosurface: case SCREEN_OVERLAY: if (sdl.overlay) { SDL_FreeYUVOverlay(sdl.overlay); - sdl.overlay=0; + sdl.overlay = 0; } - if (!(flags&GFX_CAN_32) || (flags & GFX_RGBONLY)) goto dosurface; + if (!(flags & GFX_CAN_32) || (flags & GFX_RGBONLY)) goto dosurface; if (!GFX_SetupSurfaceScaled(0,0)) goto dosurface; - sdl.overlay=SDL_CreateYUVOverlay(width*2,height,SDL_UYVY_OVERLAY,sdl.surface); + sdl.overlay = SDL_CreateYUVOverlay(width * 2, height, SDL_UYVY_OVERLAY, sdl.surface); + + if (sdl.overlay && sdl.overlay->pitches[0] < 4 * width) { + // We get a distorted image in this case. Cleanup and go to surface. + LOG_MSG("SDL: overlay pitch is too small. (%u < %u)", sdl.overlay->pitches[0], width * 4); + SDL_FreeYUVOverlay(sdl.overlay); + sdl.overlay = 0; + } if (!sdl.overlay) { - LOG_MSG("SDL: Failed to create overlay, switching back to surface"); + LOG_MSG("SDL: Failed to create overlay, switching back to surface."); goto dosurface; } - sdl.desktop.type=SCREEN_OVERLAY; + + sdl.desktop.type = SCREEN_OVERLAY; retFlags = GFX_CAN_32 | GFX_SCALING | GFX_HARDWARE; break; #if C_OPENGL