diff --git a/backends/graphics/sdl/resvm-sdl-graphics.cpp b/backends/graphics/sdl/resvm-sdl-graphics.cpp index 9cbbe12ef9a..9dcb9d49f8c 100644 --- a/backends/graphics/sdl/resvm-sdl-graphics.cpp +++ b/backends/graphics/sdl/resvm-sdl-graphics.cpp @@ -68,42 +68,20 @@ void ResVmSdlGraphicsManager::deactivateManager() { } Common::Rect ResVmSdlGraphicsManager::getPreferredFullscreenResolution() { - // Default to the desktop resolution ... - uint preferredWidth = _capabilities.desktopWidth; - uint preferredHeight = _capabilities.desktopHeight; - -#if SDL_VERSION_ATLEAST(2, 0, 0) - // When using SDL2, we can query the desktop resolution for the screen our window sits in - int displayIndex = -1; - - SDL_Window *sdlWindow = _window->getSDLWindow(); - if (sdlWindow) { - displayIndex = SDL_GetWindowDisplayIndex(sdlWindow); - } - - if (displayIndex >= 0) { - SDL_DisplayMode displayMode; - if (!SDL_GetDesktopDisplayMode(displayIndex, &displayMode)) { - preferredWidth = displayMode.w; - preferredHeight = displayMode.h; - } - } -#endif - - // ... unless the user has set a resolution in the configuration file + // Default to the desktop resolution, unless the user has set a + // resolution in the configuration file const Common::String &fsres = ConfMan.get("fullscreen_res"); if (fsres != "desktop") { uint newW, newH; int converted = sscanf(fsres.c_str(), "%ux%u", &newW, &newH); if (converted == 2) { - preferredWidth = newW; - preferredHeight = newH; + return Common::Rect(newW, newH); } else { warning("Could not parse 'fullscreen_res' option: expected WWWxHHH, got %s", fsres.c_str()); } } - return Common::Rect(preferredWidth, preferredHeight); + return _window->getDesktopResolution(); } void ResVmSdlGraphicsManager::resetGraphicsScale() { diff --git a/backends/graphics/sdl/resvm-sdl-graphics.h b/backends/graphics/sdl/resvm-sdl-graphics.h index 2b7fd450efc..e252c4e0404 100644 --- a/backends/graphics/sdl/resvm-sdl-graphics.h +++ b/backends/graphics/sdl/resvm-sdl-graphics.h @@ -43,12 +43,6 @@ public: * Capabilities of the current device */ struct Capabilities { - /** - * Desktop resolution - */ - uint desktopWidth; - uint desktopHeight; - /** * Is the device capable of rendering to OpenGL framebuffers */ @@ -57,9 +51,7 @@ public: /** Supported levels of MSAA when using the OpenGL renderers */ Common::Array openGLAntiAliasLevels; - Capabilities() : - desktopWidth(0), desktopHeight(0), - openGLFrameBuffer(false) {} + Capabilities() : openGLFrameBuffer(false) {} }; ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window, const Capabilities &capabilities); diff --git a/backends/platform/sdl/sdl-window.cpp b/backends/platform/sdl/sdl-window.cpp index 972d908545f..43ceb1bb642 100644 --- a/backends/platform/sdl/sdl-window.cpp +++ b/backends/platform/sdl/sdl-window.cpp @@ -38,6 +38,15 @@ SdlWindow::SdlWindow() _lastFlags(0), _lastX(SDL_WINDOWPOS_UNDEFINED), _lastY(SDL_WINDOWPOS_UNDEFINED) #endif { + +#if !SDL_VERSION_ATLEAST(2, 0, 0) + // Query the desktop resolution. We simply hope nothing tried to change + // the resolution so far. + const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); + if (videoInfo && videoInfo->current_w > 0 && videoInfo->current_h > 0) { + _desktopRes = Common::Rect(videoInfo->current_w, videoInfo->current_h); + } +#endif } SdlWindow::~SdlWindow() { @@ -192,6 +201,19 @@ bool SdlWindow::getSDLWMInformation(SDL_SysWMinfo *info) const { #endif } +Common::Rect SdlWindow::getDesktopResolution() { +#if SDL_VERSION_ATLEAST(2, 0, 0) + int displayIndex = _window ? SDL_GetWindowDisplayIndex(_window) : 0; + SDL_DisplayMode displayMode; + if (!SDL_GetDesktopDisplayMode(displayIndex, &displayMode)) { + _desktopRes = Common::Rect(displayMode.w, displayMode.h); + } +#endif + + return _desktopRes; +} + + #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_Surface *copySDLSurface(SDL_Surface *src) { const bool locked = SDL_MUSTLOCK(src) == SDL_TRUE; diff --git a/backends/platform/sdl/sdl-window.h b/backends/platform/sdl/sdl-window.h index 05893c47d3f..b46ae7015b7 100644 --- a/backends/platform/sdl/sdl-window.h +++ b/backends/platform/sdl/sdl-window.h @@ -25,6 +25,7 @@ #include "backends/platform/sdl/sdl-sys.h" +#include "common/rect.h" #include "common/str.h" class SdlWindow { @@ -76,6 +77,11 @@ public: */ bool getSDLWMInformation(SDL_SysWMinfo *info) const; + /* + * Retrieve the current desktop resolution. + */ + Common::Rect getDesktopResolution(); + bool mouseIsGrabbed() const { #if SDL_VERSION_ATLEAST(2, 0, 0) if (_window) { @@ -88,6 +94,8 @@ public: private: bool _inputGrabState; + Common::Rect _desktopRes; + #if SDL_VERSION_ATLEAST(2, 0, 0) public: /** diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 88d295650aa..de4c4b9bef7 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -194,7 +194,6 @@ void OSystem_SDL::initBackend() { debug(1, "Using SDL Video Driver \"%s\"", sdlDriverName); // ResidualVM specific code start - detectDesktopResolution(); #ifdef USE_OPENGL detectFramebufferSupport(); detectAntiAliasingSupport(); @@ -256,24 +255,6 @@ void OSystem_SDL::initBackend() { } // ResidualVM specific code -void OSystem_SDL::detectDesktopResolution() { -#if SDL_VERSION_ATLEAST(2, 0, 0) - SDL_DisplayMode displayMode; - if (!SDL_GetDesktopDisplayMode(0, &displayMode)) { - _capabilities.desktopWidth = displayMode.w; - _capabilities.desktopHeight = displayMode.h; - } -#else - // Query the desktop resolution. We simply hope nothing tried to change - // the resolution so far. - const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); - if (videoInfo && videoInfo->current_w > 0 && videoInfo->current_h > 0) { - _capabilities.desktopWidth = videoInfo->current_w; - _capabilities.desktopHeight = videoInfo->current_h; - } -#endif -} - #ifdef USE_OPENGL void OSystem_SDL::detectFramebufferSupport() { _capabilities.openGLFrameBuffer = false; diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index c8c3edfb41e..23356534711 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -131,7 +131,6 @@ protected: // ResidualVM specific code // Graphics capabilities - void detectDesktopResolution(); void detectFramebufferSupport(); void detectAntiAliasingSupport(); ResVmSdlGraphicsManager::Capabilities _capabilities;