[Scummvm-cvs-logs] scummvm master -> 092d36f39204df71038a1567c0d4d55bf854b523

lordhoto lordhoto at gmail.com
Wed Oct 23 23:02:04 CEST 2013


This automated email contains information about 11 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
6e46e9dfaf SDL: Clean up graphics manager switching slighty.
1a56b521b5 SDL: Always initialize video subsystem in initSDL.
e91300f70c SDL: Clean up graphics mode handling for OpenGL backend.
c5e2b5158c SDL: Get rid of loop in OSystem_SDL::setGraphicsMode.
4080a7a3f6 SDL: Get rid of _glModesCount.
17cb26b93c SDL: Simplify initial graphics manager selection for OpenGL.
38543f772c SDL: Make setupGraphicsModes non-virtual.
a9cb67df08 SDL: Only allow switching of SurfaceSDL <-> OpenGL when no custom manager is used.
d34c9d5bcb SDL: Do not require a static graphics mode list in OpenGL and SurfaceSDL.
c323dedf3c SDL: Fix default graphics mode for switchable case.
092d36f392 SDL: Reduce code duplication a bit.


Commit: 6e46e9dfaf141fda10af798d9770b9f2b0555575
    https://github.com/scummvm/scummvm/commit/6e46e9dfaf141fda10af798d9770b9f2b0555575
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2013-10-23T13:58:34-07:00

Commit Message:
SDL: Clean up graphics manager switching slighty.

Sadly this also requires us to extend GraphicsManager for this SDL specific
feature. However, since that's only used in the SDL backend and Tizen it
should be fine for now...

Changed paths:
    backends/graphics/graphics.h
    backends/graphics/openglsdl/openglsdl-graphics.cpp
    backends/graphics/openglsdl/openglsdl-graphics.h
    backends/graphics/sdl/sdl-graphics.cpp
    backends/graphics/sdl/sdl-graphics.h
    backends/graphics/surfacesdl/surfacesdl-graphics.cpp
    backends/graphics/surfacesdl/surfacesdl-graphics.h
    backends/platform/sdl/sdl.cpp



diff --git a/backends/graphics/graphics.h b/backends/graphics/graphics.h
index 2439722..74258b8 100644
--- a/backends/graphics/graphics.h
+++ b/backends/graphics/graphics.h
@@ -37,6 +37,27 @@ class GraphicsManager : public PaletteManager {
 public:
 	virtual ~GraphicsManager() {}
 
+	/**
+	 * Makes this graphics manager active. That means it should be ready to
+	 * process inputs now. However, even without being active it should be
+	 * able to query the supported modes and other bits.
+	 *
+	 * HACK: Actually this is specific to SdlGraphicsManager subclasses.
+	 * But sadly we cannot cast from GraphicsManager to SdlGraphicsManager
+	 * because there is no relation between these two.
+	 */
+	virtual void activateManager() {}
+
+	/**
+	 * Makes this graphics manager inactive. This should allow another
+	 * graphics manager to become active again.
+	 *
+	 * HACK: Actually this is specific to SdlGraphicsManager subclasses.
+	 * But sadly we cannot cast from GraphicsManager to SdlGraphicsManager
+	 * because there is no relation between these two.
+	 */
+	virtual void deactivateManager() {}
+
 	virtual bool hasFeature(OSystem::Feature f) = 0;
 	virtual void setFeatureState(OSystem::Feature f, bool enable) = 0;
 	virtual bool getFeatureState(OSystem::Feature f) = 0;
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index 925237b..088e97b 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -82,15 +82,24 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt
 }
 
 OpenGLSdlGraphicsManager::~OpenGLSdlGraphicsManager() {
+}
+
+void OpenGLSdlGraphicsManager::activateManager() {
+	OpenGLGraphicsManager::activateManager();
+	initEventSource();
+
+	// Register the graphics manager as a event observer
+	g_system->getEventManager()->getEventDispatcher()->registerObserver(this, 10, false);
+}
+
+void OpenGLSdlGraphicsManager::deactivateManager() {
 	// Unregister the event observer
 	if (g_system->getEventManager()->getEventDispatcher()) {
 		g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this);
 	}
-}
 
-void OpenGLSdlGraphicsManager::initEventObserver() {
-	// Register the graphics manager as a event observer
-	g_system->getEventManager()->getEventDispatcher()->registerObserver(this, 10, false);
+	deinitEventSource();
+	OpenGLGraphicsManager::deactivateManager();
 }
 
 bool OpenGLSdlGraphicsManager::hasFeature(OSystem::Feature f) {
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.h b/backends/graphics/openglsdl/openglsdl-graphics.h
index 0644f27..9934ca7 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.h
+++ b/backends/graphics/openglsdl/openglsdl-graphics.h
@@ -35,9 +35,10 @@ public:
 	OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource);
 	virtual ~OpenGLSdlGraphicsManager();
 
-	void initEventObserver();
-
 	// GraphicsManager API
+	virtual void activateManager();
+	virtual void deactivateManager();
+
 	virtual bool hasFeature(OSystem::Feature f);
 	virtual void setFeatureState(OSystem::Feature f, bool enable);
 	virtual bool getFeatureState(OSystem::Feature f);
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index 2eca4b8..417f4fa 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -26,10 +26,15 @@
 
 SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source)
 	: _eventSource(source) {
-	_eventSource->setGraphicsManager(this);
 }
 
 SdlGraphicsManager::~SdlGraphicsManager() {
-	_eventSource->setGraphicsManager(0);
 }
 
+void SdlGraphicsManager::initEventSource() {
+	_eventSource->setGraphicsManager(this);
+}
+
+void SdlGraphicsManager::deinitEventSource() {
+	_eventSource->setGraphicsManager(0);
+}
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index ea9149f..4d4338a 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -80,6 +80,9 @@ public:
 	virtual void notifyMousePos(Common::Point mouse) = 0;
 
 protected:
+	void initEventSource();
+	void deinitEventSource();
+
 	SdlEventSource *_eventSource;
 };
 
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index 871c6c4..ba8807a 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -193,10 +193,6 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou
 }
 
 SurfaceSdlGraphicsManager::~SurfaceSdlGraphicsManager() {
-	// Unregister the event observer
-	if (g_system->getEventManager()->getEventDispatcher() != NULL)
-		g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this);
-
 	unloadGFXMode();
 	if (_mouseSurface)
 		SDL_FreeSurface(_mouseSurface);
@@ -211,11 +207,24 @@ SurfaceSdlGraphicsManager::~SurfaceSdlGraphicsManager() {
 	free(_mouseData);
 }
 
-void SurfaceSdlGraphicsManager::initEventObserver() {
+void SurfaceSdlGraphicsManager::activateManager() {
+	GraphicsManager::activateManager();
+	initEventSource();
+
 	// Register the graphics manager as a event observer
 	g_system->getEventManager()->getEventDispatcher()->registerObserver(this, 10, false);
 }
 
+void SurfaceSdlGraphicsManager::deactivateManager() {
+	// Unregister the event observer
+	if (g_system->getEventManager()->getEventDispatcher()) {
+		g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this);
+	}
+
+	deinitEventSource();
+	GraphicsManager::deactivateManager();
+}
+
 bool SurfaceSdlGraphicsManager::hasFeature(OSystem::Feature f) {
 	return
 		(f == OSystem::kFeatureFullscreenMode) ||
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h
index 97de0f9..0bee70b 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.h
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h
@@ -80,7 +80,8 @@ public:
 	SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource);
 	virtual ~SurfaceSdlGraphicsManager();
 
-	virtual void initEventObserver();
+	virtual void activateManager();
+	virtual void deactivateManager();
 
 	virtual bool hasFeature(OSystem::Feature f);
 	virtual void setFeatureState(OSystem::Feature f, bool enable);
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 1431e1f..84187f9 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -89,6 +89,9 @@ OSystem_SDL::~OSystem_SDL() {
 	// Hence, we perform the destruction on our own.
 	delete _savefileManager;
 	_savefileManager = 0;
+	if (_graphicsManager) {
+		_graphicsManager->deactivateManager();
+	}
 	delete _graphicsManager;
 	_graphicsManager = 0;
 	delete _eventManager;
@@ -161,8 +164,6 @@ void OSystem_SDL::initBackend() {
 	if (_eventSource == 0)
 		_eventSource = new SdlEventSource();
 
-	int graphicsManagerType = 0;
-
 #ifdef USE_OPENGL
 	// Query the desktop resolution. We simply hope nothing tried to change
 	// the resolution so far.
@@ -193,13 +194,11 @@ void OSystem_SDL::initBackend() {
 			// If the gfx_mode is from OpenGL, create the OpenGL graphics manager
 			if (use_opengl) {
 				_graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
-				graphicsManagerType = 1;
 			}
 		}
 #endif
 		if (_graphicsManager == 0) {
 			_graphicsManager = new SurfaceSdlGraphicsManager(_eventSource);
-			graphicsManagerType = 0;
 		}
 	}
 
@@ -242,13 +241,7 @@ void OSystem_SDL::initBackend() {
 	// so the virtual keyboard can be initialized, but we have to add the
 	// graphics manager as an event observer after initializing the event
 	// manager.
-	if (graphicsManagerType == 0)
-		((SurfaceSdlGraphicsManager *)_graphicsManager)->initEventObserver();
-#ifdef USE_OPENGL
-	else if (graphicsManagerType == 1)
-		((OpenGLSdlGraphicsManager *)_graphicsManager)->initEventObserver();
-#endif
-
+	_graphicsManager->activateManager();
 }
 
 #if defined(USE_TASKBAR)
@@ -595,18 +588,16 @@ bool OSystem_SDL::setGraphicsMode(int mode) {
 			// 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);
-				((SurfaceSdlGraphicsManager *)_graphicsManager)->initEventObserver();
-				_graphicsManager->beginGFXTransaction();
 
 				switchedManager = true;
 			} else if (_graphicsMode < _sdlModesCount && mode >= _sdlModesCount) {
 				debug(1, "switching to OpenGL graphics");
+				_graphicsManager->deactivateManager();
 				delete _graphicsManager;
 				_graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
-				((OpenGLSdlGraphicsManager *)_graphicsManager)->initEventObserver();
-				_graphicsManager->beginGFXTransaction();
 
 				switchedManager = true;
 			}
@@ -614,6 +605,9 @@ bool OSystem_SDL::setGraphicsMode(int mode) {
 			_graphicsMode = mode;
 
 			if (switchedManager) {
+				_graphicsManager->activateManager();
+
+				_graphicsManager->beginGFXTransaction();
 #ifdef USE_RGB_COLOR
 				_graphicsManager->initSize(screenWidth, screenHeight, &pixelFormat);
 #else


Commit: 1a56b521b598efcb1587dd8934b6564cf5799b7b
    https://github.com/scummvm/scummvm/commit/1a56b521b598efcb1587dd8934b6564cf5799b7b
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2013-10-23T13:58:38-07:00

Commit Message:
SDL: Always initialize video subsystem in initSDL.

Changed paths:
    backends/graphics/openglsdl/openglsdl-graphics.cpp
    backends/graphics/surfacesdl/surfacesdl-graphics.cpp
    backends/platform/gph/gph-backend.cpp
    backends/platform/openpandora/op-backend.cpp
    backends/platform/sdl/sdl.cpp
    backends/platform/wince/wince-sdl.cpp



diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index 088e97b..e39cd35 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -32,11 +32,6 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt
     : SdlGraphicsManager(eventSource), _lastVideoModeLoad(0), _hwScreen(nullptr), _lastRequestedWidth(0), _lastRequestedHeight(0),
       _graphicsScale(2), _ignoreLoadVideoMode(false), _gotResize(false), _wantsFullScreen(false), _ignoreResizeEvents(0),
       _desiredFullscreenWidth(0), _desiredFullscreenHeight(0) {
-	// Initialize SDL video subsystem
-	if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) {
-		error("Could not initialize SDL: %s", SDL_GetError());
-	}
-
 	// Setup OpenGL attributes for SDL
 	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
 	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
@@ -44,13 +39,6 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt
 	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
 	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
 
-	// This is also called in initSDL(), but initializing graphics
-	// may reset it.
-	SDL_EnableUNICODE(1);
-
-	// Disable OS cursor
-	SDL_ShowCursor(SDL_DISABLE);
-
 	// Retrieve a list of working fullscreen modes
 	const SDL_Rect *const *availableModes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN);
 	if (availableModes != (void *)-1) {
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index ba8807a..8ad0bcb 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -142,14 +142,6 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou
 #endif
 	_transactionMode(kTransactionNone) {
 
-	if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) {
-		error("Could not initialize SDL: %s", SDL_GetError());
-	}
-
-	// This is also called in initSDL(), but initializing graphics
-	// may reset it.
-	SDL_EnableUNICODE(1);
-
 	// allocate palette storage
 	_currentPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256);
 	_cursorPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256);
@@ -165,8 +157,6 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou
 		_enableFocusRectDebugCode = ConfMan.getBool("use_sdl_debug_focusrect");
 #endif
 
-	SDL_ShowCursor(SDL_DISABLE);
-
 	memset(&_oldVideoMode, 0, sizeof(_oldVideoMode));
 	memset(&_videoMode, 0, sizeof(_videoMode));
 	memset(&_transactionDetails, 0, sizeof(_transactionDetails));
diff --git a/backends/platform/gph/gph-backend.cpp b/backends/platform/gph/gph-backend.cpp
index 485780b..7239fdb 100644
--- a/backends/platform/gph/gph-backend.cpp
+++ b/backends/platform/gph/gph-backend.cpp
@@ -172,7 +172,7 @@ void OSystem_GPH::initSDL() {
 	// Check if SDL has not been initialized
 	if (!_initedSDL) {
 
-		uint32 sdlFlags = SDL_INIT_EVENTTHREAD;
+		uint32 sdlFlags = SDL_INIT_EVENTTHREAD | SDL_INIT_VIDEO;
 		if (ConfMan.hasKey("disable_sdl_parachute"))
 			sdlFlags |= SDL_INIT_NOPARACHUTE;
 
@@ -180,6 +180,12 @@ void OSystem_GPH::initSDL() {
 		if (SDL_Init(sdlFlags) == -1)
 			error("Could not initialize SDL: %s", SDL_GetError());
 
+		// Enable unicode support if possible
+		SDL_EnableUNICODE(1);
+
+		// Disable OS cursor
+		SDL_ShowCursor(SDL_DISABLE);
+
 		_initedSDL = true;
 	}
 }
diff --git a/backends/platform/openpandora/op-backend.cpp b/backends/platform/openpandora/op-backend.cpp
index 354aa24..4350d69 100644
--- a/backends/platform/openpandora/op-backend.cpp
+++ b/backends/platform/openpandora/op-backend.cpp
@@ -160,7 +160,7 @@ void OSystem_OP::initSDL() {
 	// Check if SDL has not been initialized
 	if (!_initedSDL) {
 
-		uint32 sdlFlags = SDL_INIT_EVENTTHREAD;
+		uint32 sdlFlags = SDL_INIT_EVENTTHREAD | SDL_INIT_VIDEO;
 		if (ConfMan.hasKey("disable_sdl_parachute"))
 			sdlFlags |= SDL_INIT_NOPARACHUTE;
 
@@ -168,6 +168,12 @@ void OSystem_OP::initSDL() {
 		if (SDL_Init(sdlFlags) == -1)
 			error("Could not initialize SDL: %s", SDL_GetError());
 
+		// Enable unicode support if possible
+		SDL_EnableUNICODE(1);
+
+		// Disable OS cursor
+		SDL_ShowCursor(SDL_DISABLE);
+
 		_initedSDL = true;
 	}
 }
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 84187f9..e8a7f7b 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -262,16 +262,15 @@ void OSystem_SDL::engineDone() {
 void OSystem_SDL::initSDL() {
 	// Check if SDL has not been initialized
 	if (!_initedSDL) {
-		uint32 sdlFlags = 0;
+		// We always initialize the video subsystem because we will need it to
+		// be initialized before the graphics managers to retrieve the desktop
+		// resolution, for example. WebOS also requires this initialization
+		// or otherwise the application won't start.
+		uint32 sdlFlags = SDL_INIT_VIDEO;
+
 		if (ConfMan.hasKey("disable_sdl_parachute"))
 			sdlFlags |= SDL_INIT_NOPARACHUTE;
 
-#if defined(WEBOS) || defined(USE_OPENGL)
-		// WebOS needs this flag or otherwise the application won't start.
-		// OpenGL SDL needs this to query the desktop resolution on startup.
-		sdlFlags |= SDL_INIT_VIDEO;
-#endif
-
 		// Initialize SDL (SDL Subsystems are initiliazed in the corresponding sdl managers)
 		if (SDL_Init(sdlFlags) == -1)
 			error("Could not initialize SDL: %s", SDL_GetError());
@@ -279,6 +278,9 @@ void OSystem_SDL::initSDL() {
 		// Enable unicode support if possible
 		SDL_EnableUNICODE(1);
 
+		// Disable OS cursor
+		SDL_ShowCursor(SDL_DISABLE);
+
 		_initedSDL = true;
 	}
 }
diff --git a/backends/platform/wince/wince-sdl.cpp b/backends/platform/wince/wince-sdl.cpp
index 3897731..ea2bc42 100644
--- a/backends/platform/wince/wince-sdl.cpp
+++ b/backends/platform/wince/wince-sdl.cpp
@@ -563,7 +563,7 @@ void OSystem_WINCE3::setGraphicsModeIntern() {
 void OSystem_WINCE3::initSDL() {
 	// Check if SDL has not been initialized
 	if (!_initedSDL) {
-		uint32 sdlFlags = SDL_INIT_EVENTTHREAD;
+		uint32 sdlFlags = SDL_INIT_EVENTTHREAD | SDL_INIT_VIDEO;
 		if (ConfMan.hasKey("disable_sdl_parachute"))
 			sdlFlags |= SDL_INIT_NOPARACHUTE;
 
@@ -579,6 +579,9 @@ void OSystem_WINCE3::initSDL() {
 		// Enable unicode support if possible
 		SDL_EnableUNICODE(1);
 
+		// Disable OS cursor
+		SDL_ShowCursor(SDL_DISABLE);
+
 		_initedSDL = true;
 	}
 }


Commit: e91300f70cb17722347b809ffe94f0bc585655de
    https://github.com/scummvm/scummvm/commit/e91300f70cb17722347b809ffe94f0bc585655de
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2013-10-23T13:58:42-07:00

Commit Message:
SDL: Clean up graphics mode handling for OpenGL backend.

Instead of custom memory management Common::Array is used now.

Changed paths:
    backends/platform/sdl/sdl.cpp
    backends/platform/sdl/sdl.h



diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index e8a7f7b..5aab1b7 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -67,7 +67,7 @@ OSystem_SDL::OSystem_SDL()
 #ifdef USE_OPENGL
 	_desktopWidth(0),
 	_desktopHeight(0),
-	_graphicsModes(0),
+	_graphicsModes(),
 	_graphicsMode(0),
 	_sdlModesCount(0),
 	_glModesCount(0),
@@ -115,10 +115,6 @@ OSystem_SDL::~OSystem_SDL() {
 	delete _mutexManager;
 	_mutexManager = 0;
 
-#ifdef USE_OPENGL
-	delete[] _graphicsModes;
-#endif
-
 	delete _logger;
 	_logger = 0;
 
@@ -543,7 +539,7 @@ Common::TimerManager *OSystem_SDL::getTimerManager() {
 #ifdef USE_OPENGL
 
 const OSystem::GraphicsMode *OSystem_SDL::getSupportedGraphicsModes() const {
-	return _graphicsModes;
+	return _graphicsModes.begin();
 }
 
 int OSystem_SDL::getDefaultGraphicsMode() const {
@@ -658,6 +654,8 @@ int OSystem_SDL::getGraphicsMode() const {
 }
 
 void OSystem_SDL::setupGraphicsModes() {
+	_graphicsModes.clear();
+
 	const OSystem::GraphicsMode *sdlGraphicsModes = SurfaceSdlGraphicsManager::supportedGraphicsModes();
 	const OSystem::GraphicsMode *openglGraphicsModes = OpenGLSdlGraphicsManager::supportedGraphicsModes();
 	_sdlModesCount = 0;
@@ -667,29 +665,24 @@ void OSystem_SDL::setupGraphicsModes() {
 	const OSystem::GraphicsMode *srcMode = sdlGraphicsModes;
 	while (srcMode->name) {
 		_sdlModesCount++;
+		_graphicsModes.push_back(*srcMode);
 		srcMode++;
 	}
 	srcMode = openglGraphicsModes;
 	while (srcMode->name) {
 		_glModesCount++;
+		_graphicsModes.push_back(*srcMode);
 		srcMode++;
 	}
 
-	// Allocate enough space for merged array of modes
-	_graphicsModes = new OSystem::GraphicsMode[_glModesCount  + _sdlModesCount + 1];
-
-	// Copy SDL graphics modes
-	memcpy((void *)_graphicsModes, sdlGraphicsModes, _sdlModesCount * sizeof(OSystem::GraphicsMode));
-
-	// Copy OpenGL graphics modes
-	memcpy((void *)(_graphicsModes + _sdlModesCount), openglGraphicsModes, _glModesCount  * sizeof(OSystem::GraphicsMode));
-
 	// Set a null mode at the end
-	memset((void *)(_graphicsModes + _sdlModesCount + _glModesCount), 0, sizeof(OSystem::GraphicsMode));
+	GraphicsMode nullMode;
+	memset(&nullMode, 0, sizeof(nullMode));
+	_graphicsModes.push_back(nullMode);
 
 	// Set new internal ids for all modes
 	int i = 0;
-	OSystem::GraphicsMode *mode = _graphicsModes;
+	OSystem::GraphicsMode *mode = _graphicsModes.begin();
 	while (mode->name) {
 		mode->id = i++;
 		mode++;
diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index 590354b..6348519 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -30,6 +30,8 @@
 #include "backends/events/sdl/sdl-events.h"
 #include "backends/log/log.h"
 
+#include "common/array.h"
+
 /**
  * Base OSystem class for all SDL ports.
  */
@@ -108,7 +110,8 @@ protected:
 #ifdef USE_OPENGL
 	int _desktopWidth, _desktopHeight;
 
-	OSystem::GraphicsMode *_graphicsModes;
+	typedef Common::Array<GraphicsMode> GraphicsModeArray;
+	GraphicsModeArray _graphicsModes;
 	int _graphicsMode;
 	int _sdlModesCount;
 	int _glModesCount;


Commit: c5e2b5158c21ec97db40d933f7edd0543e6f286c
    https://github.com/scummvm/scummvm/commit/c5e2b5158c21ec97db40d933f7edd0543e6f286c
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2013-10-23T13:58:46-07:00

Commit Message:
SDL: Get rid of loop in OSystem_SDL::setGraphicsMode.

Changed paths:
    backends/platform/sdl/sdl.cpp
    backends/platform/sdl/sdl.h



diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 5aab1b7..b0ebc47 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 6348519..983b7a8 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;


Commit: 4080a7a3f642d7f155f3e706f0c084c3280f5d40
    https://github.com/scummvm/scummvm/commit/4080a7a3f642d7f155f3e706f0c084c3280f5d40
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2013-10-23T13:58:50-07:00

Commit Message:
SDL: Get rid of _glModesCount.

Changed paths:
    backends/platform/sdl/sdl.cpp
    backends/platform/sdl/sdl.h



diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index b0ebc47..620d3c5 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -69,8 +69,7 @@ OSystem_SDL::OSystem_SDL()
 	_desktopHeight(0),
 	_graphicsModes(),
 	_graphicsMode(0),
-	_sdlModesCount(0),
-	_glModesCount(0),
+	_firstGLMode(0),
 #endif
 	_inited(false),
 	_initedSDL(false),
@@ -179,7 +178,7 @@ void OSystem_SDL::initBackend() {
 			int i = 0;
 			while (mode->name) {
 				if (scumm_stricmp(mode->name, gfxMode.c_str()) == 0) {
-					_graphicsMode = i + _sdlModesCount;
+					_graphicsMode = i + _firstGLMode;
 					use_opengl = true;
 				}
 
@@ -544,10 +543,10 @@ const OSystem::GraphicsMode *OSystem_SDL::getSupportedGraphicsModes() const {
 
 int OSystem_SDL::getDefaultGraphicsMode() const {
 	// Return the default graphics mode from the current graphics manager
-	if (_graphicsMode < _sdlModesCount)
+	if (_graphicsMode < _firstGLMode)
 		return _graphicsManager->getDefaultGraphicsMode();
 	else
-		return _graphicsManager->getDefaultGraphicsMode() + _sdlModesCount;
+		return _graphicsManager->getDefaultGraphicsMode() + _firstGLMode;
 }
 
 bool OSystem_SDL::setGraphicsMode(int mode) {
@@ -574,14 +573,14 @@ bool OSystem_SDL::setGraphicsMode(int 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) {
+	if (_graphicsMode >= _firstGLMode && mode < _firstGLMode) {
 		debug(1, "switching to plain SDL graphics");
 		_graphicsManager->deactivateManager();
 		delete _graphicsManager;
 		_graphicsManager = new SurfaceSdlGraphicsManager(_eventSource);
 
 		switchedManager = true;
-	} else if (_graphicsMode < _sdlModesCount && mode >= _sdlModesCount) {
+	} else if (_graphicsMode < _firstGLMode && mode >= _firstGLMode) {
 		debug(1, "switching to OpenGL graphics");
 		_graphicsManager->deactivateManager();
 		delete _graphicsManager;
@@ -642,19 +641,16 @@ void OSystem_SDL::setupGraphicsModes() {
 
 	const OSystem::GraphicsMode *sdlGraphicsModes = SurfaceSdlGraphicsManager::supportedGraphicsModes();
 	const OSystem::GraphicsMode *openglGraphicsModes = OpenGLSdlGraphicsManager::supportedGraphicsModes();
-	_sdlModesCount = 0;
-	_glModesCount = 0;
 
 	// Count the number of graphics modes
 	const OSystem::GraphicsMode *srcMode = sdlGraphicsModes;
 	while (srcMode->name) {
-		_sdlModesCount++;
 		_graphicsModes.push_back(*srcMode);
 		srcMode++;
 	}
+	_firstGLMode = _graphicsModes.size();
 	srcMode = openglGraphicsModes;
 	while (srcMode->name) {
-		_glModesCount++;
 		_graphicsModes.push_back(*srcMode);
 		srcMode++;
 	}
diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index 983b7a8..6389bdf 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -114,8 +114,7 @@ protected:
 	GraphicsModeArray _graphicsModes;
 	Common::Array<int> _graphicsModeIds;
 	int _graphicsMode;
-	int _sdlModesCount;
-	int _glModesCount;
+	int _firstGLMode;
 
 	/**
 	 * Creates the merged graphics modes list


Commit: 17cb26b93c5b6a00dcc9dc66d400e640fe16c097
    https://github.com/scummvm/scummvm/commit/17cb26b93c5b6a00dcc9dc66d400e640fe16c097
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2013-10-23T13:58:53-07:00

Commit Message:
SDL: Simplify initial graphics manager selection for OpenGL.

Changed paths:
    backends/platform/sdl/sdl.cpp



diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 620d3c5..113e779 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -172,26 +172,18 @@ void OSystem_SDL::initBackend() {
 	if (_graphicsManager == 0) {
 #ifdef USE_OPENGL
 		if (ConfMan.hasKey("gfx_mode")) {
+			// If the gfx_mode is from OpenGL, create the OpenGL graphics manager
 			Common::String gfxMode(ConfMan.get("gfx_mode"));
-			bool use_opengl = false;
-			const OSystem::GraphicsMode *mode = OpenGLSdlGraphicsManager::supportedGraphicsModes();
-			int i = 0;
-			while (mode->name) {
-				if (scumm_stricmp(mode->name, gfxMode.c_str()) == 0) {
-					_graphicsMode = i + _firstGLMode;
-					use_opengl = true;
+			for (uint i = _firstGLMode; i < _graphicsModeIds.size(); ++i) {
+				if (!scumm_stricmp(_graphicsModes[i].name, gfxMode.c_str())) {
+					_graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
+					_graphicsMode = i;
+					break;
 				}
-
-				mode++;
-				++i;
-			}
-
-			// If the gfx_mode is from OpenGL, create the OpenGL graphics manager
-			if (use_opengl) {
-				_graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
 			}
 		}
 #endif
+
 		if (_graphicsManager == 0) {
 			_graphicsManager = new SurfaceSdlGraphicsManager(_eventSource);
 		}


Commit: 38543f772c6b11cd1f5339cabac4c45f4d5e4db4
    https://github.com/scummvm/scummvm/commit/38543f772c6b11cd1f5339cabac4c45f4d5e4db4
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2013-10-23T13:58:57-07:00

Commit Message:
SDL: Make setupGraphicsModes non-virtual.

The logic of switching the managers is pretty much fixed at the same level
and cannot be easily overwritten.

Changed paths:
    backends/platform/sdl/sdl.h



diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index 6389bdf..6c7f371 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -119,7 +119,7 @@ protected:
 	/**
 	 * Creates the merged graphics modes list
 	 */
-	virtual void setupGraphicsModes();
+	void setupGraphicsModes();
 
 	virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const;
 	virtual int getDefaultGraphicsMode() const;


Commit: a9cb67df081cd8da44720d9c0b924ed22f7a38b7
    https://github.com/scummvm/scummvm/commit/a9cb67df081cd8da44720d9c0b924ed22f7a38b7
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2013-10-23T13:59:02-07:00

Commit Message:
SDL: Only allow switching of SurfaceSDL <-> OpenGL when no custom manager is used.

Changed paths:
    backends/platform/sdl/sdl.cpp



diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 113e779..39865c8 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -144,10 +144,6 @@ void OSystem_SDL::init() {
 		_taskbarManager = new Common::TaskbarManager();
 #endif
 
-#ifdef USE_OPENGL
-	// Setup a list with both SDL and OpenGL graphics modes
-	setupGraphicsModes();
-#endif
 }
 
 void OSystem_SDL::initBackend() {
@@ -171,6 +167,14 @@ void OSystem_SDL::initBackend() {
 
 	if (_graphicsManager == 0) {
 #ifdef USE_OPENGL
+		// Setup a list with both SDL and OpenGL graphics modes. We only do
+		// this whenever the subclass did not already set up an graphics
+		// manager yet. This is because we don't know the type of the graphics
+		// manager of the subclass, thus we cannot easily switch between the
+		// OpenGL one and the set up one. It also is to be expected that the
+		// subclass does not want any switching of graphics managers anyway.
+		setupGraphicsModes();
+
 		if (ConfMan.hasKey("gfx_mode")) {
 			// If the gfx_mode is from OpenGL, create the OpenGL graphics manager
 			Common::String gfxMode(ConfMan.get("gfx_mode"));
@@ -530,18 +534,30 @@ Common::TimerManager *OSystem_SDL::getTimerManager() {
 #ifdef USE_OPENGL
 
 const OSystem::GraphicsMode *OSystem_SDL::getSupportedGraphicsModes() const {
-	return _graphicsModes.begin();
+	if (_graphicsModes.empty()) {
+		return _graphicsManager->getSupportedGraphicsModes();
+	} else {
+		return _graphicsModes.begin();
+	}
 }
 
 int OSystem_SDL::getDefaultGraphicsMode() const {
-	// Return the default graphics mode from the current graphics manager
-	if (_graphicsMode < _firstGLMode)
+	if (_graphicsModes.empty()) {
 		return _graphicsManager->getDefaultGraphicsMode();
-	else
-		return _graphicsManager->getDefaultGraphicsMode() + _firstGLMode;
+	} else {
+		// Return the default graphics mode from the current graphics manager
+		if (_graphicsMode < _firstGLMode)
+			return _graphicsManager->getDefaultGraphicsMode();
+		else
+			return _graphicsManager->getDefaultGraphicsMode() + _firstGLMode;
+	}
 }
 
 bool OSystem_SDL::setGraphicsMode(int mode) {
+	if (_graphicsModes.empty()) {
+		return _graphicsManager->setGraphicsMode(mode);
+	}
+
 	// Check whether a invalid mode is requested.
 	if (mode < 0 || (uint)mode >= _graphicsModeIds.size()) {
 		return false;
@@ -624,7 +640,11 @@ bool OSystem_SDL::setGraphicsMode(int mode) {
 }
 
 int OSystem_SDL::getGraphicsMode() const {
-	return _graphicsMode;
+	if (_graphicsModes.empty()) {
+		return _graphicsManager->getGraphicsMode();
+	} else {
+		return _graphicsMode;
+	}
 }
 
 void OSystem_SDL::setupGraphicsModes() {


Commit: d34c9d5bcbbad9fdde59143d15d7e18bc82231c1
    https://github.com/scummvm/scummvm/commit/d34c9d5bcbbad9fdde59143d15d7e18bc82231c1
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2013-10-23T13:59:06-07:00

Commit Message:
SDL: Do not require a static graphics mode list in OpenGL and SurfaceSDL.

Changed paths:
    backends/graphics/opengl/opengl-graphics.cpp
    backends/graphics/opengl/opengl-graphics.h
    backends/graphics/surfacesdl/surfacesdl-graphics.cpp
    backends/graphics/surfacesdl/surfacesdl-graphics.h
    backends/platform/sdl/sdl.cpp



diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index 00e8dc3..9ad0e62 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -122,10 +122,6 @@ const OSystem::GraphicsMode glGraphicsModes[] = {
 
 } // End of anonymous namespace
 
-const OSystem::GraphicsMode *OpenGLGraphicsManager::supportedGraphicsModes() {
-	return glGraphicsModes;
-}
-
 const OSystem::GraphicsMode *OpenGLGraphicsManager::getSupportedGraphicsModes() const {
 	return glGraphicsModes;
 }
diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h
index ebfe38f..d2d0358 100644
--- a/backends/graphics/opengl/opengl-graphics.h
+++ b/backends/graphics/opengl/opengl-graphics.h
@@ -57,10 +57,6 @@ public:
 	virtual void setFeatureState(OSystem::Feature f, bool enable);
 	virtual bool getFeatureState(OSystem::Feature f);
 
-	// HACK: This is required for the SDL backend to switch between OpenGL SDL
-	// and Surface SDL.
-	static const OSystem::GraphicsMode *supportedGraphicsModes();
-
 	virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const;
 	virtual int getDefaultGraphicsMode() const;
 	virtual bool setGraphicsMode(int mode);
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index 8ad0bcb..c946b8e 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -262,10 +262,6 @@ bool SurfaceSdlGraphicsManager::getFeatureState(OSystem::Feature f) {
 	}
 }
 
-const OSystem::GraphicsMode *SurfaceSdlGraphicsManager::supportedGraphicsModes() {
-	return s_supportedGraphicsModes;
-}
-
 const OSystem::GraphicsMode *SurfaceSdlGraphicsManager::getSupportedGraphicsModes() const {
 	return s_supportedGraphicsModes;
 }
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h
index 0bee70b..00c05ff 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.h
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h
@@ -87,7 +87,6 @@ public:
 	virtual void setFeatureState(OSystem::Feature f, bool enable);
 	virtual bool getFeatureState(OSystem::Feature f);
 
-	static const OSystem::GraphicsMode *supportedGraphicsModes();
 	virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const;
 	virtual int getDefaultGraphicsMode() const;
 	virtual bool setGraphicsMode(int mode);
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 39865c8..327dfe2 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -651,21 +651,26 @@ void OSystem_SDL::setupGraphicsModes() {
 	_graphicsModes.clear();
 	_graphicsModeIds.clear();
 
-	const OSystem::GraphicsMode *sdlGraphicsModes = SurfaceSdlGraphicsManager::supportedGraphicsModes();
-	const OSystem::GraphicsMode *openglGraphicsModes = OpenGLSdlGraphicsManager::supportedGraphicsModes();
-
 	// Count the number of graphics modes
-	const OSystem::GraphicsMode *srcMode = sdlGraphicsModes;
+	const OSystem::GraphicsMode *srcMode;
+
+	GraphicsManager *manager = new SurfaceSdlGraphicsManager(_eventSource);
+	srcMode = manager->getSupportedGraphicsModes();
 	while (srcMode->name) {
 		_graphicsModes.push_back(*srcMode);
 		srcMode++;
 	}
+	delete manager;
+
 	_firstGLMode = _graphicsModes.size();
-	srcMode = openglGraphicsModes;
+	manager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
+	srcMode = manager->getSupportedGraphicsModes();
 	while (srcMode->name) {
 		_graphicsModes.push_back(*srcMode);
 		srcMode++;
 	}
+	delete manager;
+	manager = nullptr;
 
 	// Set a null mode at the end
 	GraphicsMode nullMode;


Commit: c323dedf3c5bc293e664d298b74be63658fc55bf
    https://github.com/scummvm/scummvm/commit/c323dedf3c5bc293e664d298b74be63658fc55bf
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2013-10-23T13:59:09-07:00

Commit Message:
SDL: Fix default graphics mode for switchable case.

The former code (incorrectly) assumed that the getDefaultGraphicsMode returns
the index in the table returned by getSupportedGraphicsModes. Now the correct
ID is searched and then used.

Changed paths:
    backends/platform/sdl/sdl.cpp
    backends/platform/sdl/sdl.h



diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 327dfe2..3272033 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -70,6 +70,8 @@ OSystem_SDL::OSystem_SDL()
 	_graphicsModes(),
 	_graphicsMode(0),
 	_firstGLMode(0),
+	_defaultSDLMode(0),
+	_defaultGLMode(0),
 #endif
 	_inited(false),
 	_initedSDL(false),
@@ -547,9 +549,9 @@ int OSystem_SDL::getDefaultGraphicsMode() const {
 	} else {
 		// Return the default graphics mode from the current graphics manager
 		if (_graphicsMode < _firstGLMode)
-			return _graphicsManager->getDefaultGraphicsMode();
+			return _defaultSDLMode;
 		else
-			return _graphicsManager->getDefaultGraphicsMode() + _firstGLMode;
+			return _defaultGLMode;
 	}
 }
 
@@ -650,27 +652,39 @@ int OSystem_SDL::getGraphicsMode() const {
 void OSystem_SDL::setupGraphicsModes() {
 	_graphicsModes.clear();
 	_graphicsModeIds.clear();
+	_defaultSDLMode = _defaultGLMode = -1;
 
 	// Count the number of graphics modes
 	const OSystem::GraphicsMode *srcMode;
+	int defaultMode;
 
 	GraphicsManager *manager = new SurfaceSdlGraphicsManager(_eventSource);
 	srcMode = manager->getSupportedGraphicsModes();
+	defaultMode = manager->getDefaultGraphicsMode();
 	while (srcMode->name) {
+		if (defaultMode == srcMode->id) {
+			_defaultSDLMode = _graphicsModes.size();
+		}
 		_graphicsModes.push_back(*srcMode);
 		srcMode++;
 	}
 	delete manager;
+	assert(_defaultSDLMode != -1);
 
 	_firstGLMode = _graphicsModes.size();
 	manager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
 	srcMode = manager->getSupportedGraphicsModes();
+	defaultMode = manager->getDefaultGraphicsMode();
 	while (srcMode->name) {
+		if (defaultMode == srcMode->id) {
+			_defaultGLMode = _graphicsModes.size();
+		}
 		_graphicsModes.push_back(*srcMode);
 		srcMode++;
 	}
 	delete manager;
 	manager = nullptr;
+	assert(_defaultGLMode != -1);
 
 	// Set a null mode at the end
 	GraphicsMode nullMode;
diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index 6c7f371..814cdd7 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -115,6 +115,8 @@ protected:
 	Common::Array<int> _graphicsModeIds;
 	int _graphicsMode;
 	int _firstGLMode;
+	int _defaultSDLMode;
+	int _defaultGLMode;
 
 	/**
 	 * Creates the merged graphics modes list


Commit: 092d36f39204df71038a1567c0d4d55bf854b523
    https://github.com/scummvm/scummvm/commit/092d36f39204df71038a1567c0d4d55bf854b523
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2013-10-23T13:59:13-07:00

Commit Message:
SDL: Reduce code duplication a bit.

Now instead of initializing this in OSystem_SDL::initSDL (and in subclasses
overwriting this) we simply initialize it in OSystem_SDL::init.

Changed paths:
    backends/platform/gph/gph-backend.cpp
    backends/platform/openpandora/op-backend.cpp
    backends/platform/sdl/sdl.cpp
    backends/platform/wince/wince-sdl.cpp



diff --git a/backends/platform/gph/gph-backend.cpp b/backends/platform/gph/gph-backend.cpp
index 7239fdb..e51d7d0 100644
--- a/backends/platform/gph/gph-backend.cpp
+++ b/backends/platform/gph/gph-backend.cpp
@@ -180,12 +180,6 @@ void OSystem_GPH::initSDL() {
 		if (SDL_Init(sdlFlags) == -1)
 			error("Could not initialize SDL: %s", SDL_GetError());
 
-		// Enable unicode support if possible
-		SDL_EnableUNICODE(1);
-
-		// Disable OS cursor
-		SDL_ShowCursor(SDL_DISABLE);
-
 		_initedSDL = true;
 	}
 }
diff --git a/backends/platform/openpandora/op-backend.cpp b/backends/platform/openpandora/op-backend.cpp
index 4350d69..60c3cc7 100644
--- a/backends/platform/openpandora/op-backend.cpp
+++ b/backends/platform/openpandora/op-backend.cpp
@@ -168,12 +168,6 @@ void OSystem_OP::initSDL() {
 		if (SDL_Init(sdlFlags) == -1)
 			error("Could not initialize SDL: %s", SDL_GetError());
 
-		// Enable unicode support if possible
-		SDL_EnableUNICODE(1);
-
-		// Disable OS cursor
-		SDL_ShowCursor(SDL_DISABLE);
-
 		_initedSDL = true;
 	}
 }
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 3272033..c240727 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -126,6 +126,12 @@ void OSystem_SDL::init() {
 	// Initialize SDL
 	initSDL();
 
+	// Enable unicode support if possible
+	SDL_EnableUNICODE(1);
+
+	// Disable OS cursor
+	SDL_ShowCursor(SDL_DISABLE);
+
 	if (!_logger)
 		_logger = new Backends::Log::Log(this);
 
@@ -268,12 +274,6 @@ void OSystem_SDL::initSDL() {
 		if (SDL_Init(sdlFlags) == -1)
 			error("Could not initialize SDL: %s", SDL_GetError());
 
-		// Enable unicode support if possible
-		SDL_EnableUNICODE(1);
-
-		// Disable OS cursor
-		SDL_ShowCursor(SDL_DISABLE);
-
 		_initedSDL = true;
 	}
 }
diff --git a/backends/platform/wince/wince-sdl.cpp b/backends/platform/wince/wince-sdl.cpp
index ea2bc42..1c5cd55 100644
--- a/backends/platform/wince/wince-sdl.cpp
+++ b/backends/platform/wince/wince-sdl.cpp
@@ -576,12 +576,6 @@ void OSystem_WINCE3::initSDL() {
 		if (SDL_Init(sdlFlags) == -1)
 			error("Could not initialize SDL: %s", SDL_GetError());
 
-		// Enable unicode support if possible
-		SDL_EnableUNICODE(1);
-
-		// Disable OS cursor
-		SDL_ShowCursor(SDL_DISABLE);
-
 		_initedSDL = true;
 	}
 }






More information about the Scummvm-git-logs mailing list