From 59ba9cb71520cc9f58fbe9b72c6a661fff5a372f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Ko=C5=82odziejski?= Date: Tue, 13 Oct 2020 20:27:58 +0200 Subject: [PATCH] SDL: Do not allow toggle fullscreen for backends which can lose opengl context used for 3d games. (#2514) --- backends/graphics/opengl/opengl-graphics.cpp | 3 +++ backends/graphics/openglsdl/openglsdl-graphics.cpp | 3 +++ backends/graphics/sdl/sdl-graphics.cpp | 4 +++- backends/graphics/surfacesdl/surfacesdl-graphics.cpp | 1 + backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp | 2 +- backends/graphics3d/sdl/sdl-graphics3d.cpp | 4 +++- backends/graphics3d/surfacesdl/surfacesdl-graphics3d.cpp | 2 -- common/system.h | 4 ++-- 8 files changed, 16 insertions(+), 7 deletions(-) diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 49ee47ab83c..d4063a2199d 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -94,6 +94,9 @@ bool OpenGLGraphicsManager::hasFeature(OSystem::Feature f) const { case OSystem::kFeatureAspectRatioCorrection: case OSystem::kFeatureCursorPalette: case OSystem::kFeatureFilteringMode: +#if SDL_VERSION_ATLEAST(2, 0, 0) + case OSystem::kFeatureFullscreenToggleKeepsContext: +#endif case OSystem::kFeatureStretchMode: return true; diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index b4857989f78..fa20f647f58 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -205,6 +205,9 @@ bool OpenGLSdlGraphicsManager::hasFeature(OSystem::Feature f) const { switch (f) { case OSystem::kFeatureFullscreenMode: case OSystem::kFeatureIconifyWindow: +#if SDL_VERSION_ATLEAST(2, 0, 0) + case OSystem::kFeatureFullscreenToggleKeepsContext: +#endif return true; default: diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp index d5e766a690a..38cf0dea7e8 100644 --- a/backends/graphics/sdl/sdl-graphics.cpp +++ b/backends/graphics/sdl/sdl-graphics.cpp @@ -348,8 +348,10 @@ bool SdlGraphicsManager::notifyEvent(const Common::Event &event) { } void SdlGraphicsManager::toggleFullScreen() { - if (!g_system->hasFeature(OSystem::kFeatureFullscreenMode)) + if (!g_system->hasFeature(OSystem::kFeatureFullscreenMode) || + (!g_system->hasFeature(OSystem::kFeatureFullscreenToggleKeepsContext) && g_system->hasFeature(OSystem::kFeatureOpenGLForGame))) { return; + } beginGFXTransaction(); setFeatureState(OSystem::kFeatureFullscreenMode, !getFeatureState(OSystem::kFeatureFullscreenMode)); diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index ad2a5d14881..746f801ab0e 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -222,6 +222,7 @@ bool SurfaceSdlGraphicsManager::hasFeature(OSystem::Feature f) const { (f == OSystem::kFeatureAspectRatioCorrection) || (f == OSystem::kFeatureFilteringMode) || #if SDL_VERSION_ATLEAST(2, 0, 0) + (f == OSystem::kFeatureFullscreenToggleKeepsContext) || (f == OSystem::kFeatureStretchMode) || #endif (f == OSystem::kFeatureCursorPalette) || diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp index c21f94e6ec9..39114c162b8 100644 --- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp +++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp @@ -78,7 +78,7 @@ OpenGLSdlGraphics3dManager::~OpenGLSdlGraphics3dManager() { bool OpenGLSdlGraphics3dManager::hasFeature(OSystem::Feature f) const { return (f == OSystem::kFeatureFullscreenMode) || - (f == OSystem::kFeatureOpenGL) || + (f == OSystem::kFeatureOpenGLForGame) || #if SDL_VERSION_ATLEAST(2, 0, 0) (f == OSystem::kFeatureFullscreenToggleKeepsContext) || #endif diff --git a/backends/graphics3d/sdl/sdl-graphics3d.cpp b/backends/graphics3d/sdl/sdl-graphics3d.cpp index c3a3284ac05..c66340b794f 100644 --- a/backends/graphics3d/sdl/sdl-graphics3d.cpp +++ b/backends/graphics3d/sdl/sdl-graphics3d.cpp @@ -123,8 +123,10 @@ bool SdlGraphics3dManager::notifyEvent(const Common::Event &event) { } void SdlGraphics3dManager::toggleFullScreen() { - if (!g_system->hasFeature(OSystem::kFeatureFullscreenMode)) + if (!g_system->hasFeature(OSystem::kFeatureFullscreenMode) || + (!g_system->hasFeature(OSystem::kFeatureFullscreenToggleKeepsContext) && g_system->hasFeature(OSystem::kFeatureOpenGLForGame))) { return; + } setFeatureState(OSystem::kFeatureFullscreenMode, !getFeatureState(OSystem::kFeatureFullscreenMode)); } diff --git a/backends/graphics3d/surfacesdl/surfacesdl-graphics3d.cpp b/backends/graphics3d/surfacesdl/surfacesdl-graphics3d.cpp index 1f752eba2ed..d9db46a1992 100644 --- a/backends/graphics3d/surfacesdl/surfacesdl-graphics3d.cpp +++ b/backends/graphics3d/surfacesdl/surfacesdl-graphics3d.cpp @@ -76,9 +76,7 @@ SurfaceSdlGraphics3dManager::~SurfaceSdlGraphics3dManager() { bool SurfaceSdlGraphics3dManager::hasFeature(OSystem::Feature f) const { return -#if SDL_VERSION_ATLEAST(2, 0, 0) (f == OSystem::kFeatureFullscreenToggleKeepsContext) || -#endif (f == OSystem::kFeatureAspectRatioCorrection) || (f == OSystem::kFeatureFullscreenMode); } diff --git a/common/system.h b/common/system.h index cee39bcd867..a5c38be17f8 100644 --- a/common/system.h +++ b/common/system.h @@ -375,9 +375,9 @@ public: /** * This feature flag can be used to check if hardware accelerated - * OpenGl is supported. + * OpenGL is supported and can be used for 3D game rendering. */ - kFeatureOpenGL, + kFeatureOpenGLForGame, /** * If supported, this feature flag can be used to check if