diff options
author | Colin Snover | 2017-08-27 22:21:05 -0500 |
---|---|---|
committer | Colin Snover | 2017-10-07 12:30:29 -0500 |
commit | ebe6c40a6abb2789349c2b6471eef24ac270ab94 (patch) | |
tree | a54844f3eadc19e0cb168879466da165843d7c9f /backends/graphics/sdl | |
parent | 83436e685fe5c0fd05fa49c8e85386a1115dee58 (diff) | |
download | scummvm-rg350-ebe6c40a6abb2789349c2b6471eef24ac270ab94.tar.gz scummvm-rg350-ebe6c40a6abb2789349c2b6471eef24ac270ab94.tar.bz2 scummvm-rg350-ebe6c40a6abb2789349c2b6471eef24ac270ab94.zip |
SDL: Do not reset window size when engines update rendering surface
This change allows:
* Engines to update their target rendering surface/size and pixel
format with the backend multiple times during gameplay;
* Users to resize the ScummVM window without having it reset
size/position every time an engine updates its target surface
format;
* Conversions/scaling to continue to run efficiently in hardware,
instead of requiring engines to pick their maximum possible
output format once and upscale inefficiently in software;
* The window to reset size once when an engine calls to set its
initial output size, and to reset again once ScummVM returns to
the launcher.
This is relevant for at least SCI32 and DreamWeb engines, which
perform graphics mode switches during games.
Diffstat (limited to 'backends/graphics/sdl')
-rw-r--r-- | backends/graphics/sdl/sdl-graphics.cpp | 30 | ||||
-rw-r--r-- | backends/graphics/sdl/sdl-graphics.h | 11 |
2 files changed, 39 insertions, 2 deletions
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp index a13ca45477..aa6087beae 100644 --- a/backends/graphics/sdl/sdl-graphics.cpp +++ b/backends/graphics/sdl/sdl-graphics.cpp @@ -21,13 +21,16 @@ */ #include "backends/graphics/sdl/sdl-graphics.h" - #include "backends/platform/sdl/sdl-sys.h" #include "backends/events/sdl/sdl-events.h" #include "common/textconsole.h" SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source, SdlWindow *window) - : _eventSource(source), _window(window) { + : _eventSource(source), _window(window) +#if SDL_VERSION_ATLEAST(2, 0, 0) + , _allowWindowSizeReset(false), _lastFlags(0) +#endif + { } SdlGraphicsManager::~SdlGraphicsManager() { @@ -73,3 +76,26 @@ bool SdlGraphicsManager::setState(const State &state) { } } +#if SDL_VERSION_ATLEAST(2, 0, 0) +bool SdlGraphicsManager::createOrUpdateWindow(const int width, const int height, const Uint32 flags) { + if (!_window) { + return false; + } + + // We only update the actual window when flags change (which usually means + // fullscreen mode is entered/exited) or when updates are forced so that we + // do not reset the window size whenever a game makes a call to change the + // 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 (!_window->createOrUpdateWindow(width, height, flags)) { + return false; + } + + _lastFlags = flags; + _allowWindowSizeReset = false; + } + + return true; +} +#endif diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h index 7f8790a9b4..937beef9b4 100644 --- a/backends/graphics/sdl/sdl-graphics.h +++ b/backends/graphics/sdl/sdl-graphics.h @@ -123,6 +123,17 @@ public: SdlWindow *getWindow() const { return _window; } protected: +#if SDL_VERSION_ATLEAST(2, 0, 0) +public: + void unlockWindowSize() { _allowWindowSizeReset = true; } + +protected: + Uint32 _lastFlags; + bool _allowWindowSizeReset; + + bool createOrUpdateWindow(const int width, const int height, const Uint32 flags); +#endif + SdlEventSource *_eventSource; SdlWindow *_window; }; |