From 332fabcb8a0ff3957f0198ad3b93b4f3861f7eba Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Sun, 12 Feb 2017 19:17:33 -0600 Subject: SDL: Only recreate SDL2 window when necessary Destroying and recreating the SDL window whenever the video mode changes in SDL2 is not necessary and causes several problems: 1. In windowed mode, the game window shifts position; 2. In fullscreen mode in macOS, every time the window is recreated, it causes the OS to play its switch-to-fullscreen animation again and emit system alert noises; 3. The window content flickers; and 4. The engine loses events from the old destroyed window. This patch changes the SDL backend code to avoid destroying and recreating the SDL window when using SDL2, except when switching OpenGL modes, since there is no way to change the OpenGL feature of a window. There are still some outstanding issues with OpenGL where window size ends up getting reset even though the user has resized it; this will probably need to be addressed at some point in another patch. Thanks to @bgK and @criezy for their feedback which made this patch much better. Co-Authored-By: Bastien Bouclet --- backends/graphics/surfacesdl/surfacesdl-graphics.cpp | 11 +++++------ backends/graphics/surfacesdl/surfacesdl-graphics.h | 2 -- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'backends/graphics/surfacesdl') diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 9594587d88..2e658bca3b 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -214,6 +214,10 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou SurfaceSdlGraphicsManager::~SurfaceSdlGraphicsManager() { unloadGFXMode(); +#if SDL_VERSION_ATLEAST(2, 0, 0) + if (_window) + _window->destroyWindow(); +#endif if (_mouseSurface) SDL_FreeSurface(_mouseSurface); _mouseSurface = 0; @@ -2644,13 +2648,11 @@ void SurfaceSdlGraphicsManager::notifyVideoExpose() { _forceFull = true; } -#ifdef USE_SDL_RESIZABLE_WINDOW void SurfaceSdlGraphicsManager::notifyResize(const uint width, const uint height) { #if SDL_VERSION_ATLEAST(2, 0, 0) setWindowResolution(width, height); #endif } -#endif void SurfaceSdlGraphicsManager::transformMouseCoordinates(Common::Point &point) { #if SDL_VERSION_ATLEAST(2, 0, 0) @@ -2683,9 +2685,6 @@ void SurfaceSdlGraphicsManager::deinitializeRenderer() { SDL_DestroyRenderer(_renderer); _renderer = nullptr; - - if (_window) - _window->destroyWindow(); } void SurfaceSdlGraphicsManager::setWindowResolution(int width, int height) { @@ -2746,7 +2745,7 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, createWindowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP; } - if (!_window->createWindow(width, height, createWindowFlags)) { + if (!_window->createOrUpdateWindow(width, height, createWindowFlags)) { return nullptr; } diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h index fa130cd9a5..532399ed66 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.h +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h @@ -156,9 +156,7 @@ public: // SdlGraphicsManager interface virtual void notifyVideoExpose(); -#ifdef USE_SDL_RESIZABLE_WINDOW virtual void notifyResize(const uint width, const uint height); -#endif virtual void transformMouseCoordinates(Common::Point &point); virtual void notifyMousePos(Common::Point mouse); -- cgit v1.2.3