aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics
diff options
context:
space:
mode:
authorColin Snover2017-02-12 19:17:33 -0600
committerColin Snover2017-07-06 19:11:54 -0500
commit332fabcb8a0ff3957f0198ad3b93b4f3861f7eba (patch)
tree0568f55085e32c4a6497edfb986ef635f9f4351a /backends/graphics
parent6d37e1e88cf5c34e48c47cba74c21f89daa94178 (diff)
downloadscummvm-rg350-332fabcb8a0ff3957f0198ad3b93b4f3861f7eba.tar.gz
scummvm-rg350-332fabcb8a0ff3957f0198ad3b93b4f3861f7eba.tar.bz2
scummvm-rg350-332fabcb8a0ff3957f0198ad3b93b4f3861f7eba.zip
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 <bastien.bouclet@gmail.com>
Diffstat (limited to 'backends/graphics')
-rw-r--r--backends/graphics/openglsdl/openglsdl-graphics.cpp30
-rw-r--r--backends/graphics/surfacesdl/surfacesdl-graphics.cpp11
-rw-r--r--backends/graphics/surfacesdl/surfacesdl-graphics.h2
3 files changed, 24 insertions, 19 deletions
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index e41148062f..f664314862 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -463,10 +463,6 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
// Remember our choice.
ConfMan.setInt("last_fullscreen_mode_width", _desiredFullscreenWidth, Common::ConfigManager::kApplicationDomain);
ConfMan.setInt("last_fullscreen_mode_height", _desiredFullscreenHeight, Common::ConfigManager::kApplicationDomain);
-
- // Use our choice.
- width = _desiredFullscreenWidth;
- height = _desiredFullscreenHeight;
}
// This is pretty confusing since RGBA8888 talks about the memory
@@ -489,13 +485,23 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
_glContext = nullptr;
}
- _window->destroyWindow();
-
- uint32 flags = SDL_WINDOW_OPENGL;
+ uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
if (_wantsFullScreen) {
+ // On Linux/X11, when toggling to fullscreen, the window manager saves
+ // the window size to be able to restore it when going back to windowed mode.
+ // If the user configured ScummVM to start in fullscreen mode, we first
+ // create a window and then toggle it to fullscreen to give the window manager
+ // a chance to save the window size. That way if the user switches back
+ // to windowed mode, the window manager has a window size to apply instead
+ // of leaving the window at the fullscreen resolution size.
+ if (!_window->getSDLWindow()) {
+ _window->createOrUpdateWindow(width, height, flags);
+ }
+
+ width = _desiredFullscreenWidth;
+ height = _desiredFullscreenHeight;
+
flags |= SDL_WINDOW_FULLSCREEN;
- } else {
- flags |= SDL_WINDOW_RESIZABLE;
}
// Request a OpenGL (ES) context we can use.
@@ -503,11 +509,11 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, _glContextMajor);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, _glContextMinor);
- if (!_window->createWindow(width, height, flags)) {
+ if (!_window->createOrUpdateWindow(width, height, flags)) {
// We treat fullscreen requests as a "hint" for now. This means in
// case it is not available we simply ignore it.
if (_wantsFullScreen) {
- _window->createWindow(width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
+ _window->createOrUpdateWindow(width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
}
if (!_window->getSDLWindow()) {
@@ -541,6 +547,8 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
uint32 flags = SDL_OPENGL;
if (_wantsFullScreen) {
+ width = _desiredFullscreenWidth;
+ height = _desiredFullscreenHeight;
flags |= SDL_FULLSCREEN;
} else {
flags |= SDL_RESIZABLE;
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);