Revert "SDL: Move detection of the desktop resolution into the SdlWindow class"

This commit is contained in:
Paweł Kołodziejski 2020-04-17 17:58:45 +02:00
parent d195f77c40
commit b5d73d4c22
6 changed files with 55 additions and 35 deletions

View file

@ -68,20 +68,42 @@ void ResVmSdlGraphicsManager::deactivateManager() {
} }
Common::Rect ResVmSdlGraphicsManager::getPreferredFullscreenResolution() { Common::Rect ResVmSdlGraphicsManager::getPreferredFullscreenResolution() {
// Default to the desktop resolution, unless the user has set a // Default to the desktop resolution ...
// resolution in the configuration file 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
const Common::String &fsres = ConfMan.get("fullscreen_res"); const Common::String &fsres = ConfMan.get("fullscreen_res");
if (fsres != "desktop") { if (fsres != "desktop") {
uint newW, newH; uint newW, newH;
int converted = sscanf(fsres.c_str(), "%ux%u", &newW, &newH); int converted = sscanf(fsres.c_str(), "%ux%u", &newW, &newH);
if (converted == 2) { if (converted == 2) {
return Common::Rect(newW, newH); preferredWidth = newW;
preferredHeight = newH;
} else { } else {
warning("Could not parse 'fullscreen_res' option: expected WWWxHHH, got %s", fsres.c_str()); warning("Could not parse 'fullscreen_res' option: expected WWWxHHH, got %s", fsres.c_str());
} }
} }
return _window->getDesktopResolution(); return Common::Rect(preferredWidth, preferredHeight);
} }
void ResVmSdlGraphicsManager::resetGraphicsScale() { void ResVmSdlGraphicsManager::resetGraphicsScale() {

View file

@ -43,6 +43,12 @@ public:
* Capabilities of the current device * Capabilities of the current device
*/ */
struct Capabilities { struct Capabilities {
/**
* Desktop resolution
*/
uint desktopWidth;
uint desktopHeight;
/** /**
* Is the device capable of rendering to OpenGL framebuffers * Is the device capable of rendering to OpenGL framebuffers
*/ */
@ -51,7 +57,9 @@ public:
/** Supported levels of MSAA when using the OpenGL renderers */ /** Supported levels of MSAA when using the OpenGL renderers */
Common::Array<uint> openGLAntiAliasLevels; Common::Array<uint> openGLAntiAliasLevels;
Capabilities() : openGLFrameBuffer(false) {} Capabilities() :
desktopWidth(0), desktopHeight(0),
openGLFrameBuffer(false) {}
}; };
ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window, const Capabilities &capabilities); ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window, const Capabilities &capabilities);

View file

@ -38,15 +38,6 @@ SdlWindow::SdlWindow()
_lastFlags(0), _lastX(SDL_WINDOWPOS_UNDEFINED), _lastY(SDL_WINDOWPOS_UNDEFINED) _lastFlags(0), _lastX(SDL_WINDOWPOS_UNDEFINED), _lastY(SDL_WINDOWPOS_UNDEFINED)
#endif #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() { SdlWindow::~SdlWindow() {
@ -201,19 +192,6 @@ bool SdlWindow::getSDLWMInformation(SDL_SysWMinfo *info) const {
#endif #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) #if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Surface *copySDLSurface(SDL_Surface *src) { SDL_Surface *copySDLSurface(SDL_Surface *src) {
const bool locked = SDL_MUSTLOCK(src) == SDL_TRUE; const bool locked = SDL_MUSTLOCK(src) == SDL_TRUE;

View file

@ -25,7 +25,6 @@
#include "backends/platform/sdl/sdl-sys.h" #include "backends/platform/sdl/sdl-sys.h"
#include "common/rect.h"
#include "common/str.h" #include "common/str.h"
class SdlWindow { class SdlWindow {
@ -77,11 +76,6 @@ public:
*/ */
bool getSDLWMInformation(SDL_SysWMinfo *info) const; bool getSDLWMInformation(SDL_SysWMinfo *info) const;
/*
* Retrieve the current desktop resolution.
*/
Common::Rect getDesktopResolution();
bool mouseIsGrabbed() const { bool mouseIsGrabbed() const {
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
if (_window) { if (_window) {
@ -94,8 +88,6 @@ public:
private: private:
bool _inputGrabState; bool _inputGrabState;
Common::Rect _desktopRes;
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
public: public:
/** /**

View file

@ -194,6 +194,7 @@ void OSystem_SDL::initBackend() {
debug(1, "Using SDL Video Driver \"%s\"", sdlDriverName); debug(1, "Using SDL Video Driver \"%s\"", sdlDriverName);
// ResidualVM specific code start // ResidualVM specific code start
detectDesktopResolution();
#ifdef USE_OPENGL #ifdef USE_OPENGL
detectFramebufferSupport(); detectFramebufferSupport();
detectAntiAliasingSupport(); detectAntiAliasingSupport();
@ -255,6 +256,24 @@ void OSystem_SDL::initBackend() {
} }
// ResidualVM specific code // 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 #ifdef USE_OPENGL
void OSystem_SDL::detectFramebufferSupport() { void OSystem_SDL::detectFramebufferSupport() {
_capabilities.openGLFrameBuffer = false; _capabilities.openGLFrameBuffer = false;

View file

@ -131,6 +131,7 @@ protected:
// ResidualVM specific code // ResidualVM specific code
// Graphics capabilities // Graphics capabilities
void detectDesktopResolution();
void detectFramebufferSupport(); void detectFramebufferSupport();
void detectAntiAliasingSupport(); void detectAntiAliasingSupport();
ResVmSdlGraphicsManager::Capabilities _capabilities; ResVmSdlGraphicsManager::Capabilities _capabilities;