diff options
author | vanfanel | 2015-11-11 17:56:12 +0100 |
---|---|---|
committer | vanfanel | 2015-11-11 17:56:12 +0100 |
commit | 99739a13fe844c807d3cdd87e67e207e888fd48a (patch) | |
tree | 6afbf4763326277efbf528f0bb9e587bf7a01788 /backends/graphics | |
parent | 37e157a11c3fc731dfdcf6ec6b6a5a448550219b (diff) | |
parent | 7e44493fe8877a3c6a65f83b9ed84a5f59169005 (diff) | |
download | scummvm-rg350-99739a13fe844c807d3cdd87e67e207e888fd48a.tar.gz scummvm-rg350-99739a13fe844c807d3cdd87e67e207e888fd48a.tar.bz2 scummvm-rg350-99739a13fe844c807d3cdd87e67e207e888fd48a.zip |
Merge branch 'master' into dispmanx
Diffstat (limited to 'backends/graphics')
22 files changed, 355 insertions, 68 deletions
diff --git a/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp b/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp index 343efa4da6..0b9cc0c7e8 100644 --- a/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp +++ b/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp @@ -35,8 +35,8 @@ static const OSystem::GraphicsMode s_supportedGraphicsModes[] = { {0, 0, 0} }; -DINGUXSdlGraphicsManager::DINGUXSdlGraphicsManager(SdlEventSource *boss) - : SurfaceSdlGraphicsManager(boss) { +DINGUXSdlGraphicsManager::DINGUXSdlGraphicsManager(SdlEventSource *boss, SdlWindow *window) + : SurfaceSdlGraphicsManager(boss, window) { } const OSystem::GraphicsMode *DINGUXSdlGraphicsManager::getSupportedGraphicsModes() const { @@ -122,7 +122,7 @@ void DINGUXSdlGraphicsManager::initSize(uint w, uint h) { if (w > 320 || h > 240) { setGraphicsMode(GFX_HALF); setGraphicsModeIntern(); - _eventSource->toggleMouseGrab(); + _window->toggleMouseGrab(); } _transactionDetails.sizeChanged = true; diff --git a/backends/graphics/dinguxsdl/dinguxsdl-graphics.h b/backends/graphics/dinguxsdl/dinguxsdl-graphics.h index fc70e721cf..8a356106ad 100644 --- a/backends/graphics/dinguxsdl/dinguxsdl-graphics.h +++ b/backends/graphics/dinguxsdl/dinguxsdl-graphics.h @@ -34,7 +34,7 @@ enum { class DINGUXSdlGraphicsManager : public SurfaceSdlGraphicsManager { public: - DINGUXSdlGraphicsManager(SdlEventSource *boss); + DINGUXSdlGraphicsManager(SdlEventSource *boss, SdlWindow *window); bool hasFeature(OSystem::Feature f); void setFeatureState(OSystem::Feature f, bool enable); diff --git a/backends/graphics/gph/gph-graphics.cpp b/backends/graphics/gph/gph-graphics.cpp index 247e5ed490..65cb3d1d65 100644 --- a/backends/graphics/gph/gph-graphics.cpp +++ b/backends/graphics/gph/gph-graphics.cpp @@ -35,8 +35,8 @@ static const OSystem::GraphicsMode s_supportedGraphicsModes[] = { {0, 0, 0} }; -GPHGraphicsManager::GPHGraphicsManager(SdlEventSource *sdlEventSource) - : SurfaceSdlGraphicsManager(sdlEventSource) { +GPHGraphicsManager::GPHGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window) + : SurfaceSdlGraphicsManager(sdlEventSource, window) { } const OSystem::GraphicsMode *GPHGraphicsManager::getSupportedGraphicsModes() const { @@ -141,7 +141,7 @@ void GPHGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat *f if (w > 320 || h > 240) { setGraphicsMode(GFX_HALF); setGraphicsModeIntern(); - _eventSource->toggleMouseGrab(); + _window->toggleMouseGrab(); } _videoMode.overlayWidth = 320; diff --git a/backends/graphics/gph/gph-graphics.h b/backends/graphics/gph/gph-graphics.h index 4a68ea6eed..152d29ddf4 100644 --- a/backends/graphics/gph/gph-graphics.h +++ b/backends/graphics/gph/gph-graphics.h @@ -33,7 +33,7 @@ enum { class GPHGraphicsManager : public SurfaceSdlGraphicsManager { public: - GPHGraphicsManager(SdlEventSource *boss); + GPHGraphicsManager(SdlEventSource *boss, SdlWindow *window); bool hasFeature(OSystem::Feature f); void setFeatureState(OSystem::Feature f, bool enable); diff --git a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp index 22b271ae1a..52e5b42e8b 100644 --- a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp +++ b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp @@ -45,8 +45,8 @@ static const OSystem::GraphicsMode s_supportedGraphicsModes[] = { {0, 0, 0} }; -LinuxmotoSdlGraphicsManager::LinuxmotoSdlGraphicsManager(SdlEventSource *sdlEventSource) - : SurfaceSdlGraphicsManager(sdlEventSource) { +LinuxmotoSdlGraphicsManager::LinuxmotoSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window) + : SurfaceSdlGraphicsManager(sdlEventSource, window) { } const OSystem::GraphicsMode *LinuxmotoSdlGraphicsManager::getSupportedGraphicsModes() const { @@ -134,7 +134,7 @@ void LinuxmotoSdlGraphicsManager::initSize(uint w, uint h) { if (w > 320 || h > 240) { setGraphicsMode(GFX_HALF); setGraphicsModeIntern(); - _eventSource->toggleMouseGrab(); + _window->toggleMouseGrab(); } _transactionDetails.sizeChanged = true; diff --git a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h index 8760c5004d..d7a13b1cb4 100644 --- a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h +++ b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h @@ -27,7 +27,7 @@ class LinuxmotoSdlGraphicsManager : public SurfaceSdlGraphicsManager { public: - LinuxmotoSdlGraphicsManager(SdlEventSource *sdlEventSource); + LinuxmotoSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window); virtual void initSize(uint w, uint h); virtual void setGraphicsModeIntern(); diff --git a/backends/graphics/maemosdl/maemosdl-graphics.cpp b/backends/graphics/maemosdl/maemosdl-graphics.cpp index 07d6d32d3a..d954333537 100644 --- a/backends/graphics/maemosdl/maemosdl-graphics.cpp +++ b/backends/graphics/maemosdl/maemosdl-graphics.cpp @@ -21,16 +21,14 @@ */ #if defined(MAEMO) -#include "SDL_syswm.h" - #include "common/scummsys.h" #include "backends/platform/maemo/maemo.h" #include "backends/events/maemosdl/maemosdl-events.h" #include "backends/graphics/maemosdl/maemosdl-graphics.h" -MaemoSdlGraphicsManager::MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource) - : SurfaceSdlGraphicsManager(sdlEventSource) { +MaemoSdlGraphicsManager::MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window) + : SurfaceSdlGraphicsManager(sdlEventSource, window) { } bool MaemoSdlGraphicsManager::loadGFXMode() { diff --git a/backends/graphics/maemosdl/maemosdl-graphics.h b/backends/graphics/maemosdl/maemosdl-graphics.h index c255e94653..4cb84c81ee 100644 --- a/backends/graphics/maemosdl/maemosdl-graphics.h +++ b/backends/graphics/maemosdl/maemosdl-graphics.h @@ -29,7 +29,7 @@ class MaemoSdlGraphicsManager : public SurfaceSdlGraphicsManager { public: - MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource); + MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window); protected: virtual bool loadGFXMode(); diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index b028cd5b1a..a2b172f14a 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -28,8 +28,13 @@ #include "common/translation.h" #endif -OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource) - : SdlGraphicsManager(eventSource), _lastVideoModeLoad(0), _hwScreen(nullptr), _lastRequestedWidth(0), _lastRequestedHeight(0), +OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource, SdlWindow *window) + : SdlGraphicsManager(eventSource, window), _lastRequestedHeight(0), +#if SDL_VERSION_ATLEAST(2, 0, 0) + _glContext(), +#else + _lastVideoModeLoad(0), _hwScreen(nullptr), +#endif _graphicsScale(2), _ignoreLoadVideoMode(false), _gotResize(false), _wantsFullScreen(false), _ignoreResizeEvents(0), _desiredFullscreenWidth(0), _desiredFullscreenHeight(0) { // Setup OpenGL attributes for SDL @@ -40,16 +45,40 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // Retrieve a list of working fullscreen modes +#if SDL_VERSION_ATLEAST(2, 0, 0) + const int numModes = SDL_GetNumDisplayModes(0); + for (int i = 0; i < numModes; ++i) { + SDL_DisplayMode mode; + if (SDL_GetDisplayMode(0, i, &mode)) { + continue; + } + + _fullscreenVideoModes.push_back(VideoMode(mode.w, mode.h)); + } +#else const SDL_Rect *const *availableModes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN); - if (availableModes != (void *)-1) { + // TODO: NULL means that there are no fullscreen modes supported. We + // should probably use this information and disable any fullscreen support + // in this case. + if (availableModes != NULL && availableModes != (void *)-1) { for (;*availableModes; ++availableModes) { const SDL_Rect *mode = *availableModes; _fullscreenVideoModes.push_back(VideoMode(mode->w, mode->h)); } + } +#endif + + // Sort the modes in ascending order. + Common::sort(_fullscreenVideoModes.begin(), _fullscreenVideoModes.end()); - // Sort the modes in ascending order. - Common::sort(_fullscreenVideoModes.begin(), _fullscreenVideoModes.end()); + // Strip duplicates in video modes. + for (uint i = 0; i + 1 < _fullscreenVideoModes.size();) { + if (_fullscreenVideoModes[i] == _fullscreenVideoModes[i + 1]) { + _fullscreenVideoModes.remove_at(i); + } else { + ++i; + } } // In case SDL is fine with every mode we will force the desktop mode. @@ -108,7 +137,7 @@ void OpenGLSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) case OSystem::kFeatureIconifyWindow: if (enable) { - SDL_WM_IconifyWindow(); + _window->iconifyWindow(); } break; @@ -120,11 +149,19 @@ void OpenGLSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) bool OpenGLSdlGraphicsManager::getFeatureState(OSystem::Feature f) { switch (f) { case OSystem::kFeatureFullscreenMode: +#if SDL_VERSION_ATLEAST(2, 0, 0) + if (_window) { + return (SDL_GetWindowFlags(_window->getSDLWindow()) & SDL_WINDOW_FULLSCREEN) != 0; + } else { + return _wantsFullScreen; + } +#else if (_hwScreen) { return (_hwScreen->flags & SDL_FULLSCREEN) != 0; } else { return _wantsFullScreen; } +#endif default: return OpenGLGraphicsManager::getFeatureState(f); @@ -201,13 +238,20 @@ void OpenGLSdlGraphicsManager::updateScreen() { OpenGLGraphicsManager::updateScreen(); // Swap OpenGL buffers +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_GL_SwapWindow(_window->getSDLWindow()); +#else SDL_GL_SwapBuffers(); +#endif } void OpenGLSdlGraphicsManager::notifyVideoExpose() { } void OpenGLSdlGraphicsManager::notifyResize(const uint width, const uint height) { +#if SDL_VERSION_ATLEAST(2, 0, 0) + setActualScreenSize(width, height); +#else if (!_ignoreResizeEvents && _hwScreen && !(_hwScreen->flags & SDL_FULLSCREEN)) { // We save that we handled a resize event here. We need to know this // so we do not overwrite the users requested window size whenever we @@ -218,6 +262,7 @@ void OpenGLSdlGraphicsManager::notifyResize(const uint width, const uint height) g_system->quit(); } } +#endif } void OpenGLSdlGraphicsManager::transformMouseCoordinates(Common::Point &point) { @@ -229,7 +274,7 @@ void OpenGLSdlGraphicsManager::notifyMousePos(Common::Point mouse) { } void OpenGLSdlGraphicsManager::setInternalMousePosition(int x, int y) { - SDL_WarpMouse(x, y); + _window->warpMouseInWindow(x, y); } bool OpenGLSdlGraphicsManager::loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) { @@ -300,6 +345,58 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) { height = _desiredFullscreenHeight; } + // This is pretty confusing since RGBA8888 talks about the memory + // layout here. This is a different logical layout depending on + // whether we run on little endian or big endian. However, we can + // only safely assume that RGBA8888 in memory layout is supported. + // Thus, we chose this one. + const Graphics::PixelFormat rgba8888 = +#ifdef SCUMM_LITTLE_ENDIAN + Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24); +#else + Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0); +#endif + +#if SDL_VERSION_ATLEAST(2, 0, 0) + if (_glContext) { + notifyContextDestroy(); + + SDL_GL_DeleteContext(_glContext); + _glContext = nullptr; + } + + _window->destroyWindow(); + + uint32 flags = SDL_WINDOW_OPENGL; + if (_wantsFullScreen) { + flags |= SDL_WINDOW_FULLSCREEN; + } else { + flags |= SDL_WINDOW_RESIZABLE; + } + + if (!_window->createWindow(width, height, flags)) { + // We treat fullscreen requests as a "hint" for now. This means in + // case it is not available we simply ignore it. + if (_wantsFullScreen) { + _window->createWindow(width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); + } + + if (!_window->getSDLWindow()) { + return false; + } + } + + _glContext = SDL_GL_CreateContext(_window->getSDLWindow()); + if (!_glContext) { + return false; + } + + notifyContextCreate(rgba8888, rgba8888); + int actualWidth, actualHeight; + getWindowDimensions(&actualWidth, &actualHeight); + setActualScreenSize(actualWidth, actualHeight); + return true; +#else // WORKAROUND: Working around infamous SDL bugs when switching // resolutions too fast. This might cause the event system to supply // incorrect mouse position events otherwise. @@ -341,17 +438,6 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) { _lastVideoModeLoad = SDL_GetTicks(); if (_hwScreen) { - // This is pretty confusing since RGBA8888 talks about the memory - // layout here. This is a different logical layout depending on - // whether we run on little endian or big endian. However, we can - // only safely assume that RGBA8888 in memory layout is supported. - // Thus, we chose this one. - const Graphics::PixelFormat rgba8888 = -#ifdef SCUMM_LITTLE_ENDIAN - Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24); -#else - Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0); -#endif notifyContextCreate(rgba8888, rgba8888); setActualScreenSize(_hwScreen->w, _hwScreen->h); } @@ -363,6 +449,21 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) { _ignoreResizeEvents = 10; return _hwScreen != nullptr; +#endif +} + +void OpenGLSdlGraphicsManager::getWindowDimensions(int *width, int *height) { +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_GetWindowSize(_window->getSDLWindow(), width, height); +#else + if (width) { + *width = _hwScreen->w; + } + + if (height) { + *height = _hwScreen->h; + } +#endif } bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) { @@ -456,7 +557,9 @@ bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) { // Calculate the next scaling setting. We approximate the // current scale setting in case the user resized the // window. Then we apply the direction change. - _graphicsScale = MAX<int>(_hwScreen->w / _lastRequestedWidth, _hwScreen->h / _lastRequestedHeight); + int windowWidth = 0, windowHeight = 0; + getWindowDimensions(&windowWidth, &windowHeight); + _graphicsScale = MAX<int>(windowWidth / _lastRequestedWidth, windowHeight / _lastRequestedHeight); _graphicsScale = MAX<int>(_graphicsScale + direction, 1); // Since we overwrite a user resize here we reset its @@ -472,7 +575,9 @@ bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) { } #ifdef USE_OSD - const Common::String osdMsg = Common::String::format("Resolution: %dx%d", _hwScreen->w, _hwScreen->h); + int windowWidth = 0, windowHeight = 0; + getWindowDimensions(&windowWidth, &windowHeight); + const Common::String osdMsg = Common::String::format("Resolution: %dx%d", windowWidth, windowHeight); displayMessageOnOSD(osdMsg.c_str()); #endif diff --git a/backends/graphics/openglsdl/openglsdl-graphics.h b/backends/graphics/openglsdl/openglsdl-graphics.h index 9934ca79e2..845880eb14 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.h +++ b/backends/graphics/openglsdl/openglsdl-graphics.h @@ -32,7 +32,7 @@ class OpenGLSdlGraphicsManager : public OpenGL::OpenGLGraphicsManager, public SdlGraphicsManager, public Common::EventObserver { public: - OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource); + OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource, SdlWindow *window); virtual ~OpenGLSdlGraphicsManager(); // GraphicsManager API @@ -68,8 +68,14 @@ protected: private: bool setupMode(uint width, uint height); +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_GLContext _glContext; +#else uint32 _lastVideoModeLoad; SDL_Surface *_hwScreen; +#endif + + void getWindowDimensions(int *width, int *height); uint _lastRequestedWidth; uint _lastRequestedHeight; diff --git a/backends/graphics/openpandora/op-graphics.cpp b/backends/graphics/openpandora/op-graphics.cpp index 1ded1614de..f4c9dc16cc 100644 --- a/backends/graphics/openpandora/op-graphics.cpp +++ b/backends/graphics/openpandora/op-graphics.cpp @@ -32,8 +32,8 @@ static SDL_Cursor *hiddenCursor; -OPGraphicsManager::OPGraphicsManager(SdlEventSource *sdlEventSource) - : SurfaceSdlGraphicsManager(sdlEventSource) { +OPGraphicsManager::OPGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window) + : SurfaceSdlGraphicsManager(sdlEventSource, window) { } bool OPGraphicsManager::loadGFXMode() { diff --git a/backends/graphics/openpandora/op-graphics.h b/backends/graphics/openpandora/op-graphics.h index 8b498d632b..50994072bb 100644 --- a/backends/graphics/openpandora/op-graphics.h +++ b/backends/graphics/openpandora/op-graphics.h @@ -32,7 +32,7 @@ enum { class OPGraphicsManager : public SurfaceSdlGraphicsManager { public: - OPGraphicsManager(SdlEventSource *sdlEventSource); + OPGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window); bool loadGFXMode(); void unloadGFXMode(); diff --git a/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.cpp b/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.cpp index 3603d8a861..0c98462891 100644 --- a/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.cpp +++ b/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.cpp @@ -28,8 +28,8 @@ #include "backends/events/samsungtvsdl/samsungtvsdl-events.h" #include "backends/graphics/samsungtvsdl/samsungtvsdl-graphics.h" -SamsungTVSdlGraphicsManager::SamsungTVSdlGraphicsManager(SdlEventSource *sdlEventSource) - : SurfaceSdlGraphicsManager(sdlEventSource) { +SamsungTVSdlGraphicsManager::SamsungTVSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window) + : SurfaceSdlGraphicsManager(sdlEventSource, window) { } bool SamsungTVSdlGraphicsManager::hasFeature(OSystem::Feature f) { diff --git a/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.h b/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.h index 15ba3dca48..8699d77bc8 100644 --- a/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.h +++ b/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.h @@ -29,7 +29,7 @@ class SamsungTVSdlGraphicsManager : public SurfaceSdlGraphicsManager { public: - SamsungTVSdlGraphicsManager(SdlEventSource *sdlEventSource); + SamsungTVSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window); bool hasFeature(OSystem::Feature f); void setFeatureState(OSystem::Feature f, bool enable); diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp index b5e49fa397..a13ca45477 100644 --- a/backends/graphics/sdl/sdl-graphics.cpp +++ b/backends/graphics/sdl/sdl-graphics.cpp @@ -22,10 +22,12 @@ #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) - : _eventSource(source) { +SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source, SdlWindow *window) + : _eventSource(source), _window(window) { } SdlGraphicsManager::~SdlGraphicsManager() { @@ -38,3 +40,36 @@ void SdlGraphicsManager::activateManager() { void SdlGraphicsManager::deactivateManager() { _eventSource->setGraphicsManager(0); } + +SdlGraphicsManager::State SdlGraphicsManager::getState() { + State state; + + state.screenWidth = getWidth(); + state.screenHeight = getHeight(); + state.aspectRatio = getFeatureState(OSystem::kFeatureAspectRatioCorrection); + state.fullscreen = getFeatureState(OSystem::kFeatureFullscreenMode); + state.cursorPalette = getFeatureState(OSystem::kFeatureCursorPalette); +#ifdef USE_RGB_COLOR + state.pixelFormat = getScreenFormat(); +#endif + return state; +} + +bool SdlGraphicsManager::setState(const State &state) { + beginGFXTransaction(); +#ifdef USE_RGB_COLOR + initSize(state.screenWidth, state.screenHeight, &state.pixelFormat); +#else + initSize(state.screenWidth, state.screenHeight, 0); +#endif + setFeatureState(OSystem::kFeatureAspectRatioCorrection, state.aspectRatio); + setFeatureState(OSystem::kFeatureFullscreenMode, state.fullscreen); + setFeatureState(OSystem::kFeatureCursorPalette, state.cursorPalette); + + if (endGFXTransaction() != OSystem::kTransactionSuccess) { + return false; + } else { + return true; + } +} + diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h index 3ef540708a..7f8790a9b4 100644 --- a/backends/graphics/sdl/sdl-graphics.h +++ b/backends/graphics/sdl/sdl-graphics.h @@ -24,6 +24,7 @@ #define BACKENDS_GRAPHICS_SDL_SDLGRAPHICS_H #include "backends/graphics/graphics.h" +#include "backends/platform/sdl/sdl-window.h" #include "common/rect.h" @@ -36,7 +37,7 @@ class SdlEventSource; */ class SdlGraphicsManager : virtual public GraphicsManager { public: - SdlGraphicsManager(SdlEventSource *source); + SdlGraphicsManager(SdlEventSource *source, SdlWindow *window); virtual ~SdlGraphicsManager(); /** @@ -91,8 +92,39 @@ public: */ virtual void notifyMousePos(Common::Point mouse) = 0; + /** + * A (subset) of the graphic manager's state. This is used when switching + * between different SDL graphic managers on runtime. + */ + struct State { + int screenWidth, screenHeight; + bool aspectRatio; + bool fullscreen; + bool cursorPalette; + +#ifdef USE_RGB_COLOR + Graphics::PixelFormat pixelFormat; +#endif + }; + + /** + * Queries the current state of the graphic manager. + */ + State getState(); + + /** + * Setup a basic state of the graphic manager. + */ + bool setState(const State &state); + + /** + * Queries the SDL window. + */ + SdlWindow *getWindow() const { return _window; } + protected: SdlEventSource *_eventSource; + SdlWindow *_window; }; #endif diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 7f3c99fcea..9cb14525ee 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -116,13 +116,19 @@ static AspectRatio getDesiredAspectRatio() { } #endif -SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource) +SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window) : - SdlGraphicsManager(sdlEventSource), + SdlGraphicsManager(sdlEventSource, window), #ifdef USE_OSD _osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0), #endif - _hwscreen(0), _screen(0), _tmpscreen(0), + _hwscreen(0), +#if SDL_VERSION_ATLEAST(2, 0, 0) + _renderer(nullptr), _screenTexture(nullptr), +#else + _originalBitsPerPixel(0), +#endif + _screen(0), _tmpscreen(0), #ifdef USE_RGB_COLOR _screenFormat(Graphics::PixelFormat::createFormatCLUT8()), _cursorFormat(Graphics::PixelFormat::createFormatCLUT8()), @@ -235,7 +241,7 @@ void SurfaceSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) break; case OSystem::kFeatureIconifyWindow: if (enable) - SDL_WM_IconifyWindow(); + _window->iconifyWindow(); break; default: break; @@ -681,12 +687,22 @@ static void fixupResolutionForAspectRatio(AspectRatio desiredAspectRatio, int &w const int w = width; const int h = height; + int bestW = 0, bestH = 0; + uint bestMetric = (uint)-1; // Metric is wasted space + +#if SDL_VERSION_ATLEAST(2, 0, 0) + const int numModes = SDL_GetNumDisplayModes(0); + SDL_DisplayMode modeData, *mode = &modeData; + for (int i = 0; i < numModes; ++i) { + if (SDL_GetDisplayMode(0, i, &modeData)) { + continue; + } +#else SDL_Rect const* const*availableModes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_SWSURFACE); //TODO : Maybe specify a pixel format assert(availableModes); - const SDL_Rect *bestMode = NULL; - uint bestMetric = (uint)-1; // Metric is wasted space while (const SDL_Rect *mode = *availableModes++) { +#endif if (mode->w < w) continue; if (mode->h < h) @@ -699,15 +715,23 @@ static void fixupResolutionForAspectRatio(AspectRatio desiredAspectRatio, int &w continue; bestMetric = metric; - bestMode = mode; + bestW = mode->w; + bestH = mode->h; + + // Make editors a bit more happy by having the same amount of closing as + // opening curley braces. +#if SDL_VERSION_ATLEAST(2, 0, 0) } +#else + } +#endif - if (!bestMode) { + if (!bestW || !bestH) { warning("Unable to enforce the desired aspect ratio"); return; } - width = bestMode->w; - height = bestMode->h; + width = bestW; + height = bestH; } bool SurfaceSdlGraphicsManager::loadGFXMode() { @@ -774,7 +798,15 @@ bool SurfaceSdlGraphicsManager::loadGFXMode() { _hwscreen = g_eventRec.getSurface(_videoMode.hardwareWidth, _videoMode.hardwareHeight); } else #endif - { + { + // Save the original bpp to be able to restore the video mode on unload +#if !SDL_VERSION_ATLEAST(2, 0, 0) + if (_originalBitsPerPixel == 0) { + const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); + _originalBitsPerPixel = videoInfo->vfmt->BitsPerPixel; + } +#endif + _hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 16, _videoMode.fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE ); @@ -876,6 +908,10 @@ void SurfaceSdlGraphicsManager::unloadGFXMode() { _screen = NULL; } +#if SDL_VERSION_ATLEAST(2, 0, 0) + deinitializeRenderer(); +#endif + if (_hwscreen) { SDL_FreeSurface(_hwscreen); _hwscreen = NULL; @@ -903,6 +939,13 @@ void SurfaceSdlGraphicsManager::unloadGFXMode() { } #endif DestroyScalers(); + +#if !SDL_VERSION_ATLEAST(2, 0, 0) + // Reset video mode to original + // This will ensure that any new graphic manager will use the initial BPP when listing available modes + if (_originalBitsPerPixel != 0) + SDL_SetVideoMode(_videoMode.screenWidth, _videoMode.screenHeight, _originalBitsPerPixel, _videoMode.fullscreen ? (SDL_FULLSCREEN | SDL_SWSURFACE) : SDL_SWSURFACE); +#endif } bool SurfaceSdlGraphicsManager::hotswapGFXMode() { @@ -1443,6 +1486,9 @@ void SurfaceSdlGraphicsManager::setPalette(const byte *colors, uint start, uint base[i].r = b[0]; base[i].g = b[1]; base[i].b = b[2]; +#if SDL_VERSION_ATLEAST(2, 0, 0) + base[i].a = 255; +#endif } if (start < _paletteDirtyStart) @@ -1481,6 +1527,9 @@ void SurfaceSdlGraphicsManager::setCursorPalette(const byte *colors, uint start, base[i].r = b[0]; base[i].g = b[1]; base[i].b = b[2]; +#if SDL_VERSION_ATLEAST(2, 0, 0) + base[i].a = 255; +#endif } _cursorPaletteDisabled = false; @@ -1710,7 +1759,7 @@ void SurfaceSdlGraphicsManager::warpMouse(int x, int y) { int y1 = y; // Don't change actual mouse position, when mouse is outside of our window (in case of windowed mode) - if (!(SDL_GetAppState( ) & SDL_APPMOUSEFOCUS)) { + if (!_window->hasMouseFocus()) { setMousePos(x, y); // but change game cursor position return; } @@ -1720,9 +1769,9 @@ void SurfaceSdlGraphicsManager::warpMouse(int x, int y) { if (_mouseCurState.x != x || _mouseCurState.y != y) { if (!_overlayVisible) - SDL_WarpMouse(x * _videoMode.scaleFactor, y1 * _videoMode.scaleFactor); + _window->warpMouseInWindow(x * _videoMode.scaleFactor, y1 * _videoMode.scaleFactor); else - SDL_WarpMouse(x, y1); + _window->warpMouseInWindow(x, y1); // SDL_WarpMouse() generates a mouse movement event, so // setMousePos() would be called eventually. However, the @@ -2317,4 +2366,52 @@ void SurfaceSdlGraphicsManager::notifyMousePos(Common::Point mouse) { setMousePos(mouse.x, mouse.y); } +#if SDL_VERSION_ATLEAST(2, 0, 0) +void SurfaceSdlGraphicsManager::deinitializeRenderer() { + SDL_DestroyTexture(_screenTexture); + _screenTexture = nullptr; + + SDL_DestroyRenderer(_renderer); + _renderer = nullptr; + + _window->destroyWindow(); +} + +SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) { + deinitializeRenderer(); + + if (!_window->createWindow(width, height, (flags & SDL_FULLSCREEN) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)) { + return nullptr; + } + + _renderer = SDL_CreateRenderer(_window->getSDLWindow(), -1, 0); + if (!_renderer) { + deinitializeRenderer(); + return nullptr; + } + + _screenTexture = SDL_CreateTexture(_renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, width, height); + if (!_screenTexture) { + deinitializeRenderer(); + return nullptr; + } + + SDL_Surface *screen = SDL_CreateRGBSurface(0, width, height, 16, 0xF800, 0x7E0, 0x1F, 0); + if (!screen) { + deinitializeRenderer(); + return nullptr; + } else { + return screen; + } +} + +void SurfaceSdlGraphicsManager::SDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects) { + SDL_UpdateTexture(_screenTexture, nullptr, screen->pixels, screen->pitch); + + SDL_RenderClear(_renderer); + SDL_RenderCopy(_renderer, _screenTexture, NULL, NULL); + SDL_RenderPresent(_renderer); +} +#endif // SDL_VERSION_ATLEAST(2, 0, 0) + #endif diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h index 49bd66b3e5..2431ce8664 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.h +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h @@ -77,7 +77,7 @@ public: */ class SurfaceSdlGraphicsManager : public SdlGraphicsManager, public Common::EventObserver { public: - SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource); + SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window); virtual ~SurfaceSdlGraphicsManager(); virtual void activateManager(); @@ -166,6 +166,17 @@ protected: /** Hardware screen */ SDL_Surface *_hwscreen; +#if SDL_VERSION_ATLEAST(2, 0, 0) + /* SDL2 features a different API for 2D graphics. We create a wrapper + * around this API to keep the code paths as close as possible. */ + SDL_Renderer *_renderer; + SDL_Texture *_screenTexture; + void deinitializeRenderer(); + + SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags); + void SDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects); +#endif + /** Unseen game screen */ SDL_Surface *_screen; #ifdef USE_RGB_COLOR @@ -225,6 +236,9 @@ protected: }; VideoState _videoMode, _oldVideoMode; + // Original BPP to restore the video mode on unload + uint8 _originalBitsPerPixel; + /** Force full redraw on next updateScreen */ bool _forceFull; diff --git a/backends/graphics/symbiansdl/symbiansdl-graphics.cpp b/backends/graphics/symbiansdl/symbiansdl-graphics.cpp index e339fecd1c..c17cfd5efa 100644 --- a/backends/graphics/symbiansdl/symbiansdl-graphics.cpp +++ b/backends/graphics/symbiansdl/symbiansdl-graphics.cpp @@ -27,8 +27,8 @@ #include "backends/graphics/symbiansdl/symbiansdl-graphics.h" #include "backends/platform/symbian/src/SymbianActions.h" -SymbianSdlGraphicsManager::SymbianSdlGraphicsManager(SdlEventSource *sdlEventSource) - : SurfaceSdlGraphicsManager(sdlEventSource) { +SymbianSdlGraphicsManager::SymbianSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window) + : SurfaceSdlGraphicsManager(sdlEventSource, window) { } int SymbianSdlGraphicsManager::getDefaultGraphicsMode() const { diff --git a/backends/graphics/symbiansdl/symbiansdl-graphics.h b/backends/graphics/symbiansdl/symbiansdl-graphics.h index f514db286c..fb9a49a834 100644 --- a/backends/graphics/symbiansdl/symbiansdl-graphics.h +++ b/backends/graphics/symbiansdl/symbiansdl-graphics.h @@ -27,7 +27,7 @@ class SymbianSdlGraphicsManager : public SurfaceSdlGraphicsManager { public: - SymbianSdlGraphicsManager(SdlEventSource *sdlEventSource); + SymbianSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window); public: virtual bool hasFeature(OSystem::Feature f); diff --git a/backends/graphics/wincesdl/wincesdl-graphics.cpp b/backends/graphics/wincesdl/wincesdl-graphics.cpp index 8e4685dbd8..07f7d47262 100644 --- a/backends/graphics/wincesdl/wincesdl-graphics.cpp +++ b/backends/graphics/wincesdl/wincesdl-graphics.cpp @@ -42,8 +42,8 @@ #include "backends/platform/wince/CEScaler.h" #include "backends/platform/wince/CEgui/ItemAction.h" -WINCESdlGraphicsManager::WINCESdlGraphicsManager(SdlEventSource *sdlEventSource) - : SurfaceSdlGraphicsManager(sdlEventSource), +WINCESdlGraphicsManager::WINCESdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window) + : SurfaceSdlGraphicsManager(sdlEventSource, window), _panelInitialized(false), _noDoubleTapRMB(false), _noDoubleTapPT(false), _toolbarHighDrawn(false), _newOrientation(0), _orientationLandscape(0), _panelVisible(true), _saveActiveToolbar(NAME_MAIN_PANEL), _panelStateForced(false), diff --git a/backends/graphics/wincesdl/wincesdl-graphics.h b/backends/graphics/wincesdl/wincesdl-graphics.h index 50b422c10d..9316c69e44 100644 --- a/backends/graphics/wincesdl/wincesdl-graphics.h +++ b/backends/graphics/wincesdl/wincesdl-graphics.h @@ -41,7 +41,7 @@ extern bool _hasSmartphoneResolution; class WINCESdlGraphicsManager : public SurfaceSdlGraphicsManager { public: - WINCESdlGraphicsManager(SdlEventSource *sdlEventSource); + WINCESdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window); const OSystem::GraphicsMode *getSupportedGraphicsModes() const; void initSize(uint w, uint h, const Graphics::PixelFormat *format = NULL); |