From 3a2db0135d93b5f12fd42f04db3b6ad9d40834d3 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 24 Jan 2015 23:42:12 +0100 Subject: SDL: Refactor WM specific functionality into SdlGraphicsManager. --- backends/graphics/openglsdl/openglsdl-graphics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/graphics/openglsdl/openglsdl-graphics.cpp') diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index b028cd5b1a..fc2956755d 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -108,7 +108,7 @@ void OpenGLSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) case OSystem::kFeatureIconifyWindow: if (enable) { - SDL_WM_IconifyWindow(); + iconifyWindow(); } break; @@ -229,7 +229,7 @@ void OpenGLSdlGraphicsManager::notifyMousePos(Common::Point mouse) { } void OpenGLSdlGraphicsManager::setInternalMousePosition(int x, int y) { - SDL_WarpMouse(x, y); + warpMouseInWindow(x, y); } bool OpenGLSdlGraphicsManager::loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) { -- cgit v1.2.3 From 8530997fff7b5b9d558f7dd6a0d07c236e4de16f Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 25 Jan 2015 01:34:57 +0100 Subject: SDL: Add experimental support for SDL2. This is based upon skristiansson's change set to make ScummVM work with SDL2. --- backends/graphics/openglsdl/openglsdl-graphics.cpp | 134 ++++++++++++++++++--- 1 file changed, 118 insertions(+), 16 deletions(-) (limited to 'backends/graphics/openglsdl/openglsdl-graphics.cpp') diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index fc2956755d..2710b66ecd 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -29,7 +29,12 @@ #endif OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource) - : SdlGraphicsManager(eventSource), _lastVideoModeLoad(0), _hwScreen(nullptr), _lastRequestedWidth(0), _lastRequestedHeight(0), + : SdlGraphicsManager(eventSource), _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,6 +45,17 @@ 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) { for (;*availableModes; ++availableModes) { @@ -47,9 +63,19 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt _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. @@ -120,11 +146,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) & 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 +235,20 @@ void OpenGLSdlGraphicsManager::updateScreen() { OpenGLGraphicsManager::updateScreen(); // Swap OpenGL buffers +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_GL_SwapWindow(_window); +#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 +259,7 @@ void OpenGLSdlGraphicsManager::notifyResize(const uint width, const uint height) g_system->quit(); } } +#endif } void OpenGLSdlGraphicsManager::transformMouseCoordinates(Common::Point &point) { @@ -300,6 +342,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; + } + + destroyWindow(); + + uint32 flags = SDL_WINDOW_OPENGL; + if (_wantsFullScreen) { + flags |= SDL_WINDOW_FULLSCREEN; + } else { + flags |= SDL_WINDOW_RESIZABLE; + } + + if (!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) { + createWindow(width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); + } + + if (!_window) { + return false; + } + } + + _glContext = SDL_GL_CreateContext(_window); + if (!_glContext) { + return false; + } + + notifyContextCreate(rgba8888, rgba8888); + int actualWidth, actualHeight; + SDL_GetWindowSize(_window, &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 +435,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 +446,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, width, height); +#else + if (width) { + *width = _hwScreen->w; + } + + if (height) { + *height = _hwScreen->h; + } +#endif } bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) { @@ -456,7 +554,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(_hwScreen->w / _lastRequestedWidth, _hwScreen->h / _lastRequestedHeight); + int windowWidth = 0, windowHeight = 0; + getWindowDimensions(&windowWidth, &windowHeight); + _graphicsScale = MAX(windowWidth / _lastRequestedWidth, windowHeight / _lastRequestedHeight); _graphicsScale = MAX(_graphicsScale + direction, 1); // Since we overwrite a user resize here we reset its @@ -472,7 +572,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 -- cgit v1.2.3 From 627d766325e1d435816648f85dbf9c007269b3f2 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 16 Feb 2015 00:49:42 +0100 Subject: SDL: Add basic abstraction class for the SDL window. --- backends/graphics/openglsdl/openglsdl-graphics.cpp | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'backends/graphics/openglsdl/openglsdl-graphics.cpp') diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index 2710b66ecd..c71b9c9219 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -28,8 +28,8 @@ #include "common/translation.h" #endif -OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource) - : SdlGraphicsManager(eventSource), _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 @@ -134,7 +134,7 @@ void OpenGLSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) case OSystem::kFeatureIconifyWindow: if (enable) { - iconifyWindow(); + _window->iconifyWindow(); } break; @@ -148,7 +148,7 @@ bool OpenGLSdlGraphicsManager::getFeatureState(OSystem::Feature f) { case OSystem::kFeatureFullscreenMode: #if SDL_VERSION_ATLEAST(2, 0, 0) if (_window) { - return (SDL_GetWindowFlags(_window) & SDL_WINDOW_FULLSCREEN) != 0; + return (SDL_GetWindowFlags(_window->getSDLWindow()) & SDL_WINDOW_FULLSCREEN) != 0; } else { return _wantsFullScreen; } @@ -236,7 +236,7 @@ void OpenGLSdlGraphicsManager::updateScreen() { // Swap OpenGL buffers #if SDL_VERSION_ATLEAST(2, 0, 0) - SDL_GL_SwapWindow(_window); + SDL_GL_SwapWindow(_window->getSDLWindow()); #else SDL_GL_SwapBuffers(); #endif @@ -271,7 +271,7 @@ void OpenGLSdlGraphicsManager::notifyMousePos(Common::Point mouse) { } void OpenGLSdlGraphicsManager::setInternalMousePosition(int x, int y) { - warpMouseInWindow(x, y); + _window->warpMouseInWindow(x, y); } bool OpenGLSdlGraphicsManager::loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) { @@ -362,7 +362,7 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) { _glContext = nullptr; } - destroyWindow(); + _window->destroyWindow(); uint32 flags = SDL_WINDOW_OPENGL; if (_wantsFullScreen) { @@ -371,26 +371,26 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) { flags |= SDL_WINDOW_RESIZABLE; } - if (!createWindow(width, height, flags)) { + 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) { - createWindow(width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); + _window->createWindow(width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); } - if (!_window) { + if (!_window->getSDLWindow()) { return false; } } - _glContext = SDL_GL_CreateContext(_window); + _glContext = SDL_GL_CreateContext(_window->getSDLWindow()); if (!_glContext) { return false; } notifyContextCreate(rgba8888, rgba8888); int actualWidth, actualHeight; - SDL_GetWindowSize(_window, &actualWidth, &actualHeight); + getWindowDimensions(&actualWidth, &actualHeight); setActualScreenSize(actualWidth, actualHeight); return true; #else @@ -451,7 +451,7 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) { void OpenGLSdlGraphicsManager::getWindowDimensions(int *width, int *height) { #if SDL_VERSION_ATLEAST(2, 0, 0) - SDL_GetWindowSize(_window, width, height); + SDL_GetWindowSize(_window->getSDLWindow(), width, height); #else if (width) { *width = _hwScreen->w; -- cgit v1.2.3 From ed3a32a91ab9d1d1880034e1e09de3d16c17ed4a Mon Sep 17 00:00:00 2001 From: Littleboy Date: Fri, 15 May 2015 23:30:02 -0400 Subject: SDL: Check for NULL when listing available modes via SDL_ListModes It can be returned when there are no dimensions available for the currently selected pixel format --- backends/graphics/openglsdl/openglsdl-graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/graphics/openglsdl/openglsdl-graphics.cpp') diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index c71b9c9219..53868b86d8 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -57,7 +57,7 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt } #else const SDL_Rect *const *availableModes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN); - if (availableModes != (void *)-1) { + if (availableModes != NULL && availableModes != (void *)-1) { for (;*availableModes; ++availableModes) { const SDL_Rect *mode = *availableModes; -- cgit v1.2.3 From c30094433591a6f1ac5980875876f5c51f452ebf Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 16 May 2015 16:57:44 +0200 Subject: SDL: Add TODO about fullscreen modes to OpenGL SDL code. --- backends/graphics/openglsdl/openglsdl-graphics.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'backends/graphics/openglsdl/openglsdl-graphics.cpp') diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index 53868b86d8..a2b172f14a 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -57,6 +57,9 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt } #else const SDL_Rect *const *availableModes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN); + // 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; -- cgit v1.2.3