SDL: Detect the desktop resolution earlier
So that nothing has a chance to change it beforehand.
This commit is contained in:
parent
8927dcdcf6
commit
2141277df9
8 changed files with 49 additions and 34 deletions
|
@ -46,9 +46,9 @@
|
|||
|
||||
#include "graphics/opengl/context.h"
|
||||
|
||||
OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
|
||||
OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window, const Capabilities &capabilities)
|
||||
:
|
||||
ResVmSdlGraphicsManager(sdlEventSource, window),
|
||||
ResVmSdlGraphicsManager(sdlEventSource, window, capabilities),
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
_glContext(nullptr),
|
||||
#endif
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
*/
|
||||
class OpenGLSdlGraphicsManager : public ResVmSdlGraphicsManager {
|
||||
public:
|
||||
OpenGLSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
|
||||
OpenGLSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window, const Capabilities &capabilities);
|
||||
virtual ~OpenGLSdlGraphicsManager();
|
||||
|
||||
virtual bool hasFeature(OSystem::Feature f);
|
||||
|
|
|
@ -32,7 +32,7 @@ static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
|
|||
{0, 0, 0}
|
||||
};
|
||||
|
||||
ResVmSdlGraphicsManager::ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window) :
|
||||
ResVmSdlGraphicsManager::ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window, const Capabilities &capabilities) :
|
||||
SdlGraphicsManager(source, window),
|
||||
_fullscreen(false),
|
||||
_lockAspectRatio(true),
|
||||
|
@ -43,8 +43,6 @@ ResVmSdlGraphicsManager::ResVmSdlGraphicsManager(SdlEventSource *source, SdlWind
|
|||
_capabilities(capabilities) {
|
||||
ConfMan.registerDefault("fullscreen_res", "desktop");
|
||||
ConfMan.registerDefault("aspect_ratio", true);
|
||||
|
||||
detectDesktopResolution();
|
||||
}
|
||||
|
||||
ResVmSdlGraphicsManager::~ResVmSdlGraphicsManager() {
|
||||
|
@ -131,26 +129,10 @@ bool ResVmSdlGraphicsManager::canUsePreferredResolution(GameRenderTarget gameRen
|
|||
}
|
||||
}
|
||||
|
||||
void ResVmSdlGraphicsManager::detectDesktopResolution() {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_DisplayMode di;
|
||||
if (SDL_GetCurrentDisplayMode(0, &di) != 0) {
|
||||
warning("Error: %s", SDL_GetError());
|
||||
g_system->quit();
|
||||
}
|
||||
_desktopW = di.w;
|
||||
_desktopH = di.h;
|
||||
#else
|
||||
const SDL_VideoInfo *vi = SDL_GetVideoInfo();
|
||||
_desktopW = vi->current_w;
|
||||
_desktopH = vi->current_h;
|
||||
#endif
|
||||
}
|
||||
|
||||
Common::Rect ResVmSdlGraphicsManager::getPreferredFullscreenResolution() {
|
||||
// Default to the desktop resolution ...
|
||||
uint preferredWidth = _desktopW;
|
||||
uint preferredHeight = _desktopH;
|
||||
uint preferredWidth = _capabilities.desktopWidth;
|
||||
uint preferredHeight = _capabilities.desktopHeight;
|
||||
|
||||
// ... unless the user has set a resolution in the configuration file
|
||||
const Common::String &fsres = ConfMan.get("fullscreen_res");
|
||||
|
|
|
@ -39,7 +39,13 @@ class SdlEventSource;
|
|||
*/
|
||||
class ResVmSdlGraphicsManager : public SdlGraphicsManager, public Common::EventObserver {
|
||||
public:
|
||||
ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window);
|
||||
struct Capabilities {
|
||||
uint desktopWidth, desktopHeight;
|
||||
|
||||
Capabilities() : desktopWidth(0), desktopHeight(0) {}
|
||||
};
|
||||
|
||||
ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window, const Capabilities &capabilities);
|
||||
virtual ~ResVmSdlGraphicsManager();
|
||||
|
||||
// SdlGraphicsManager API
|
||||
|
@ -98,9 +104,7 @@ public:
|
|||
bool notifyEvent(const Common::Event &event) override;
|
||||
|
||||
protected:
|
||||
uint _desktopW, _desktopH;
|
||||
|
||||
void detectDesktopResolution();
|
||||
const Capabilities &_capabilities;
|
||||
|
||||
bool _fullscreen;
|
||||
bool _lockAspectRatio;
|
||||
|
|
|
@ -44,9 +44,9 @@
|
|||
#include "graphics/pixelbuffer.h"
|
||||
#include "gui/EventRecorder.h"
|
||||
|
||||
SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
|
||||
SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window, const Capabilities &capabilities)
|
||||
:
|
||||
ResVmSdlGraphicsManager(sdlEventSource, window),
|
||||
ResVmSdlGraphicsManager(sdlEventSource, window, capabilities),
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
_renderer(nullptr), _screenTexture(nullptr),
|
||||
#endif
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
*/
|
||||
class SurfaceSdlGraphicsManager : public ResVmSdlGraphicsManager {
|
||||
public:
|
||||
SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
|
||||
SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window, const Capabilities &capabilities);
|
||||
virtual ~SurfaceSdlGraphicsManager();
|
||||
|
||||
virtual bool hasFeature(OSystem::Feature f);
|
||||
|
|
|
@ -165,6 +165,8 @@ void OSystem_SDL::initBackend() {
|
|||
// is not active by this point.
|
||||
debug(1, "Using SDL Video Driver \"%s\"", sdlDriverName);
|
||||
|
||||
detectDesktopResolution();
|
||||
|
||||
// Create the default event source, in case a custom backend
|
||||
// manager didn't provide one yet.
|
||||
if (_eventSource == 0)
|
||||
|
@ -172,7 +174,7 @@ void OSystem_SDL::initBackend() {
|
|||
|
||||
if (_graphicsManager == 0) {
|
||||
if (_graphicsManager == 0) {
|
||||
_graphicsManager = new SurfaceSdlGraphicsManager(_eventSource, _window);
|
||||
_graphicsManager = new SurfaceSdlGraphicsManager(_eventSource, _window, _capabilities);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,6 +220,26 @@ void OSystem_SDL::initBackend() {
|
|||
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->activateManager();
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
// End of ResidualVM specific code
|
||||
|
||||
#if defined(USE_TASKBAR)
|
||||
void OSystem_SDL::engineInit() {
|
||||
// Add the started engine to the list of recent tasks
|
||||
|
@ -299,9 +321,9 @@ void OSystem_SDL::setupScreen(uint screenW, uint screenH, bool fullscreen, bool
|
|||
delete _graphicsManager;
|
||||
|
||||
if (accel3d) {
|
||||
_graphicsManager = sdlGraphicsManager = new OpenGLSdlGraphicsManager(_eventSource, _window);
|
||||
_graphicsManager = sdlGraphicsManager = new OpenGLSdlGraphicsManager(_eventSource, _window, _capabilities);
|
||||
} else {
|
||||
_graphicsManager = sdlGraphicsManager = new SurfaceSdlGraphicsManager(_eventSource, _window);
|
||||
_graphicsManager = sdlGraphicsManager = new SurfaceSdlGraphicsManager(_eventSource, _window, _capabilities);
|
||||
}
|
||||
sdlGraphicsManager->activateManager();
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "backends/events/sdl/sdl-events.h"
|
||||
#include "backends/log/log.h"
|
||||
#include "backends/platform/sdl/sdl-window.h"
|
||||
#include "backends/graphics/sdl/resvm-sdl-graphics.h"
|
||||
|
||||
#include "common/array.h"
|
||||
|
||||
|
@ -104,6 +105,12 @@ protected:
|
|||
*/
|
||||
SdlWindow *_window;
|
||||
|
||||
// ResidualVM specific code
|
||||
// Graphics capabilities
|
||||
void detectDesktopResolution();
|
||||
ResVmSdlGraphicsManager::Capabilities _capabilities;
|
||||
// End of ResidualVM specific code
|
||||
|
||||
virtual Common::EventSource *getDefaultEventSource() { return _eventSource; }
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue