aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/sdl
diff options
context:
space:
mode:
authorColin Snover2017-10-01 16:23:22 -0500
committerColin Snover2017-10-07 12:30:29 -0500
commit6e157429b7a5a64af6265d075c88595df2d6fd79 (patch)
tree6e16e359d2f427ff0aa17ae229780509595ee1b1 /backends/graphics/sdl
parent24f5d456195df3b65ed2876cbca2e2981f3d1a07 (diff)
downloadscummvm-rg350-6e157429b7a5a64af6265d075c88595df2d6fd79.tar.gz
scummvm-rg350-6e157429b7a5a64af6265d075c88595df2d6fd79.tar.bz2
scummvm-rg350-6e157429b7a5a64af6265d075c88595df2d6fd79.zip
BACKENDS: Fix window sizing of games that switch between multiple resolutions
Diffstat (limited to 'backends/graphics/sdl')
-rw-r--r--backends/graphics/sdl/sdl-graphics.cpp89
-rw-r--r--backends/graphics/sdl/sdl-graphics.h14
2 files changed, 99 insertions, 4 deletions
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index aa6087beae..a181582235 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -23,12 +23,14 @@
#include "backends/graphics/sdl/sdl-graphics.h"
#include "backends/platform/sdl/sdl-sys.h"
#include "backends/events/sdl/sdl-events.h"
+#include "common/config-manager.h"
#include "common/textconsole.h"
+#include "graphics/scaler/aspect.h"
SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source, SdlWindow *window)
: _eventSource(source), _window(window)
#if SDL_VERSION_ATLEAST(2, 0, 0)
- , _allowWindowSizeReset(false), _lastFlags(0)
+ , _allowWindowSizeReset(false), _hintedWidth(0), _hintedHeight(0), _lastFlags(0)
#endif
{
}
@@ -63,7 +65,7 @@ bool SdlGraphicsManager::setState(const State &state) {
#ifdef USE_RGB_COLOR
initSize(state.screenWidth, state.screenHeight, &state.pixelFormat);
#else
- initSize(state.screenWidth, state.screenHeight, 0);
+ initSize(state.screenWidth, state.screenHeight, nullptr);
#endif
setFeatureState(OSystem::kFeatureAspectRatioCorrection, state.aspectRatio);
setFeatureState(OSystem::kFeatureFullscreenMode, state.fullscreen);
@@ -76,8 +78,82 @@ bool SdlGraphicsManager::setState(const State &state) {
}
}
+bool SdlGraphicsManager::defaultGraphicsModeConfig() const {
+ const Common::ConfigManager::Domain *transientDomain = ConfMan.getDomain(Common::ConfigManager::kTransientDomain);
+ if (transientDomain && transientDomain->contains("gfx_mode")) {
+ const Common::String &mode = transientDomain->getVal("gfx_mode");
+ if (!mode.equalsIgnoreCase("normal") && !mode.equalsIgnoreCase("default")) {
+ return false;
+ }
+ }
+
+ const Common::ConfigManager::Domain *gameDomain = ConfMan.getActiveDomain();
+ if (gameDomain && gameDomain->contains("gfx_mode")) {
+ const Common::String &mode = gameDomain->getVal("gfx_mode");
+ if (!mode.equalsIgnoreCase("normal") && !mode.equalsIgnoreCase("default")) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+int SdlGraphicsManager::getGraphicsModeIdByName(const Common::String &name) const {
+ const OSystem::GraphicsMode *mode = getSupportedGraphicsModes();
+ while (mode && mode->name != nullptr) {
+ if (name.equalsIgnoreCase(mode->name)) {
+ return mode->id;
+ }
+ ++mode;
+ }
+ return -1;
+}
+
+void SdlGraphicsManager::initSizeHint(const Graphics::ModeList &modes) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
-bool SdlGraphicsManager::createOrUpdateWindow(const int width, const int height, const Uint32 flags) {
+ const bool useDefault = defaultGraphicsModeConfig();
+
+ int scale = getGraphicsModeScale(getGraphicsModeIdByName(ConfMan.get("gfx_mode")));
+ if (scale == -1) {
+ warning("Unknown scaler; defaulting to 1");
+ scale = 1;
+ }
+
+ int16 bestWidth = 0, bestHeight = 0;
+ const Graphics::ModeList::const_iterator end = modes.end();
+ for (Graphics::ModeList::const_iterator it = modes.begin(); it != end; ++it) {
+ int16 width = it->width, height = it->height;
+
+ // TODO: Normalize AR correction by passing a PAR in the mode list
+ // instead of checking the dimensions here like this, since not all
+ // 320x200/640x400 uses are with non-square pixels (e.g. DreamWeb).
+ if (ConfMan.getBool("aspect_ratio")) {
+ if ((width == 320 && height == 200) || (width == 640 && height == 400)) {
+ height = real2Aspect(height);
+ }
+ }
+
+ if (!useDefault || width <= 320) {
+ width *= scale;
+ height *= scale;
+ }
+
+ if (bestWidth < width) {
+ bestWidth = width;
+ }
+
+ if (bestHeight < height) {
+ bestHeight = height;
+ }
+ }
+
+ _hintedWidth = bestWidth;
+ _hintedHeight = bestHeight;
+#endif
+}
+
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+bool SdlGraphicsManager::createOrUpdateWindow(int width, int height, const Uint32 flags) {
if (!_window) {
return false;
}
@@ -88,6 +164,13 @@ bool SdlGraphicsManager::createOrUpdateWindow(const int width, const int height,
// size or pixel format of the internal game surface (since a user may have
// resized the game window)
if (!_window->getSDLWindow() || _lastFlags != flags || _allowWindowSizeReset) {
+ if (_hintedWidth) {
+ width = _hintedWidth;
+ }
+ if (_hintedHeight) {
+ height = _hintedHeight;
+ }
+
if (!_window->createOrUpdateWindow(width, height, flags)) {
return false;
}
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index 937beef9b4..74ee2838ea 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -122,14 +122,26 @@ public:
*/
SdlWindow *getWindow() const { return _window; }
+ virtual void initSizeHint(const Graphics::ModeList &modes) override;
+
protected:
+ virtual int getGraphicsModeScale(int mode) const = 0;
+
+ bool defaultGraphicsModeConfig() const;
+ int getGraphicsModeIdByName(const Common::String &name) const;
+
#if SDL_VERSION_ATLEAST(2, 0, 0)
public:
- void unlockWindowSize() { _allowWindowSizeReset = true; }
+ void unlockWindowSize() {
+ _allowWindowSizeReset = true;
+ _hintedWidth = 0;
+ _hintedHeight = 0;
+ }
protected:
Uint32 _lastFlags;
bool _allowWindowSizeReset;
+ int _hintedWidth, _hintedHeight;
bool createOrUpdateWindow(const int width, const int height, const Uint32 flags);
#endif