diff options
-rw-r--r-- | backends/platform/sdl/sdl.cpp | 113 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.h | 1 |
2 files changed, 50 insertions, 64 deletions
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 5aab1b7b3b..b0ebc476e1 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -551,16 +551,9 @@ int OSystem_SDL::getDefaultGraphicsMode() const { } bool OSystem_SDL::setGraphicsMode(int mode) { - const OSystem::GraphicsMode *srcMode; - int i; - - // Check if mode is from SDL or OpenGL - if (mode < _sdlModesCount) { - srcMode = SurfaceSdlGraphicsManager::supportedGraphicsModes(); - i = 0; - } else { - srcMode = OpenGLSdlGraphicsManager::supportedGraphicsModes(); - i = _sdlModesCount; + // Check whether a invalid mode is requested. + if (mode < 0 || (uint)mode >= _graphicsModeIds.size()) { + return false; } // Very hacky way to set up the old graphics manager state, in case we @@ -579,74 +572,64 @@ bool OSystem_SDL::setGraphicsMode(int mode) { bool switchedManager = false; - // Loop through modes - while (srcMode->name) { - if (i == mode) { - // If the new mode and the current mode are not from the same graphics - // manager, delete and create the new mode graphics manager - if (_graphicsMode >= _sdlModesCount && mode < _sdlModesCount) { - debug(1, "switching to plain SDL graphics"); - _graphicsManager->deactivateManager(); - delete _graphicsManager; - _graphicsManager = new SurfaceSdlGraphicsManager(_eventSource); - - switchedManager = true; - } else if (_graphicsMode < _sdlModesCount && mode >= _sdlModesCount) { - debug(1, "switching to OpenGL graphics"); - _graphicsManager->deactivateManager(); - delete _graphicsManager; - _graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource); + // If the new mode and the current mode are not from the same graphics + // manager, delete and create the new mode graphics manager + if (_graphicsMode >= _sdlModesCount && mode < _sdlModesCount) { + debug(1, "switching to plain SDL graphics"); + _graphicsManager->deactivateManager(); + delete _graphicsManager; + _graphicsManager = new SurfaceSdlGraphicsManager(_eventSource); - switchedManager = true; - } + switchedManager = true; + } else if (_graphicsMode < _sdlModesCount && mode >= _sdlModesCount) { + debug(1, "switching to OpenGL graphics"); + _graphicsManager->deactivateManager(); + delete _graphicsManager; + _graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource); + + switchedManager = true; + } - _graphicsMode = mode; + _graphicsMode = mode; - if (switchedManager) { - _graphicsManager->activateManager(); + if (switchedManager) { + _graphicsManager->activateManager(); - _graphicsManager->beginGFXTransaction(); + _graphicsManager->beginGFXTransaction(); #ifdef USE_RGB_COLOR - _graphicsManager->initSize(screenWidth, screenHeight, &pixelFormat); + _graphicsManager->initSize(screenWidth, screenHeight, &pixelFormat); #else - _graphicsManager->initSize(screenWidth, screenHeight, 0); + _graphicsManager->initSize(screenWidth, screenHeight, 0); #endif - _graphicsManager->setFeatureState(kFeatureAspectRatioCorrection, arState); - _graphicsManager->setFeatureState(kFeatureFullscreenMode, fullscreen); - _graphicsManager->setFeatureState(kFeatureCursorPalette, cursorPalette); + _graphicsManager->setFeatureState(kFeatureAspectRatioCorrection, arState); + _graphicsManager->setFeatureState(kFeatureFullscreenMode, fullscreen); + _graphicsManager->setFeatureState(kFeatureCursorPalette, cursorPalette); - // Worst part about this right now, tell the cursor manager to - // resetup the cursor + cursor palette if necessarily + // Worst part about this right now, tell the cursor manager to + // resetup the cursor + cursor palette if necessarily - // First we need to try to setup the old state on the new manager... - if (_graphicsManager->endGFXTransaction() != kTransactionSuccess) { - // Oh my god if this failed the client code might just explode. - return false; - } - - // Next setup the cursor again - CursorMan.pushCursor(0, 0, 0, 0, 0, 0); - CursorMan.popCursor(); + // First we need to try to setup the old state on the new manager... + if (_graphicsManager->endGFXTransaction() != kTransactionSuccess) { + // Oh my god if this failed the client code might just explode. + return false; + } - // Next setup cursor palette if needed - if (cursorPalette) { - CursorMan.pushCursorPalette(0, 0, 0); - CursorMan.popCursorPalette(); - } + // Next setup the cursor again + CursorMan.pushCursor(0, 0, 0, 0, 0, 0); + CursorMan.popCursor(); - _graphicsManager->beginGFXTransaction(); - // Oh my god if this failed the client code might just explode. - return _graphicsManager->setGraphicsMode(srcMode->id); - } else { - return _graphicsManager->setGraphicsMode(srcMode->id); - } + // Next setup cursor palette if needed + if (cursorPalette) { + CursorMan.pushCursorPalette(0, 0, 0); + CursorMan.popCursorPalette(); } - i++; - srcMode++; + _graphicsManager->beginGFXTransaction(); + // Oh my god if this failed the client code might just explode. + return _graphicsManager->setGraphicsMode(_graphicsModeIds[mode]); + } else { + return _graphicsManager->setGraphicsMode(_graphicsModeIds[mode]); } - - return false; } int OSystem_SDL::getGraphicsMode() const { @@ -655,6 +638,7 @@ int OSystem_SDL::getGraphicsMode() const { void OSystem_SDL::setupGraphicsModes() { _graphicsModes.clear(); + _graphicsModeIds.clear(); const OSystem::GraphicsMode *sdlGraphicsModes = SurfaceSdlGraphicsManager::supportedGraphicsModes(); const OSystem::GraphicsMode *openglGraphicsModes = OpenGLSdlGraphicsManager::supportedGraphicsModes(); @@ -684,6 +668,7 @@ void OSystem_SDL::setupGraphicsModes() { int i = 0; OSystem::GraphicsMode *mode = _graphicsModes.begin(); while (mode->name) { + _graphicsModeIds.push_back(mode->id); mode->id = i++; mode++; } diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 6348519681..983b7a8237 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -112,6 +112,7 @@ protected: typedef Common::Array<GraphicsMode> GraphicsModeArray; GraphicsModeArray _graphicsModes; + Common::Array<int> _graphicsModeIds; int _graphicsMode; int _sdlModesCount; int _glModesCount; |