SDL: Move detection of the desktop resolution into the SdlWindow class
This commit is contained in:
parent
d8607341d4
commit
d01d06216f
6 changed files with 35 additions and 55 deletions
|
@ -68,42 +68,20 @@ void ResVmSdlGraphicsManager::deactivateManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::Rect ResVmSdlGraphicsManager::getPreferredFullscreenResolution() {
|
Common::Rect ResVmSdlGraphicsManager::getPreferredFullscreenResolution() {
|
||||||
// Default to the desktop resolution ...
|
// Default to the desktop resolution, unless the user has set a
|
||||||
uint preferredWidth = _capabilities.desktopWidth;
|
// resolution in the configuration file
|
||||||
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) {
|
||||||
preferredWidth = newW;
|
return Common::Rect(newW, newH);
|
||||||
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 Common::Rect(preferredWidth, preferredHeight);
|
return _window->getDesktopResolution();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResVmSdlGraphicsManager::resetGraphicsScale() {
|
void ResVmSdlGraphicsManager::resetGraphicsScale() {
|
||||||
|
|
|
@ -43,12 +43,6 @@ 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
|
||||||
*/
|
*/
|
||||||
|
@ -57,9 +51,7 @@ 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() :
|
Capabilities() : openGLFrameBuffer(false) {}
|
||||||
desktopWidth(0), desktopHeight(0),
|
|
||||||
openGLFrameBuffer(false) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window, const Capabilities &capabilities);
|
ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window, const Capabilities &capabilities);
|
||||||
|
|
|
@ -38,6 +38,15 @@ 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() {
|
||||||
|
@ -192,6 +201,19 @@ 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;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#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 {
|
||||||
|
@ -76,6 +77,11 @@ 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) {
|
||||||
|
@ -88,6 +94,8 @@ 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:
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -197,7 +197,6 @@ 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();
|
||||||
|
@ -261,24 +260,6 @@ 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;
|
||||||
|
|
|
@ -135,7 +135,6 @@ 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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue