[Scummvm-git-logs] scummvm master -> d33487f641bcd6e9e4d31a0bf91f7abf2f92c2e0

sev- sev at scummvm.org
Sat Apr 17 18:32:29 UTC 2021


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

Summary:
d33487f641 SDL: Refactor OpenGLSdlGraphics3dManager to inherit from SdlGraphicsManager


Commit: d33487f641bcd6e9e4d31a0bf91f7abf2f92c2e0
    https://github.com/scummvm/scummvm/commit/d33487f641bcd6e9e4d31a0bf91f7abf2f92c2e0
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2021-04-17T20:32:27+02:00

Commit Message:
SDL: Refactor OpenGLSdlGraphics3dManager to inherit from SdlGraphicsManager

Changed paths:
  R backends/graphics3d/graphics3d.h
  R backends/graphics3d/sdl/sdl-graphics3d.cpp
  R backends/graphics3d/sdl/sdl-graphics3d.h
    backends/events/sdl/sdl-events.cpp
    backends/events/sdl/sdl-events.h
    backends/events/switchsdl/switchsdl-events.cpp
    backends/graphics/sdl/sdl-graphics.cpp
    backends/graphics/sdl/sdl-graphics.h
    backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
    backends/graphics3d/openglsdl/openglsdl-graphics3d.h
    backends/modular-backend.cpp
    backends/module.mk
    backends/platform/android3d/graphics.h
    backends/platform/sdl/sdl.cpp


diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index e89d411011..9cf043ee37 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -27,7 +27,6 @@
 #include "backends/events/sdl/sdl-events.h"
 #include "backends/platform/sdl/sdl.h"
 #include "backends/graphics/graphics.h"
-#include "backends/graphics3d/sdl/sdl-graphics3d.h"
 #include "common/config-manager.h"
 #include "common/textconsole.h"
 #include "common/fs.h"
@@ -179,11 +178,7 @@ bool SdlEventSource::processMouseEvent(Common::Event &event, int x, int y, int r
 	event.relMouse.y = rely;
 
 	if (_graphicsManager) {
-		if (dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)) {
-			return dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->notifyMousePosition(event.mouse);
-		} else if (dynamic_cast<SdlGraphicsManager *>(_graphicsManager)) {
-			return dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->notifyMousePosition(event.mouse);
-		}
+		return _graphicsManager->notifyMousePosition(event.mouse);
 	}
 
 	return true;
@@ -504,12 +499,7 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
 	case SDL_WINDOWEVENT:
 		// We're only interested in events from the current display window
 		if (_graphicsManager) {
-			uint32 windowID = 0;
-			if (dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)) {
-				windowID = SDL_GetWindowID(dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->getWindow()->getSDLWindow());
-			} else if (dynamic_cast<SdlGraphicsManager *>(_graphicsManager)) {
-				windowID = SDL_GetWindowID(dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->getWindow()->getSDLWindow());
-			}
+			uint32 windowID = SDL_GetWindowID(_graphicsManager->getWindow()->getSDLWindow());
 			if (windowID != ev.window.windowID) {
 				return false;
 			}
@@ -518,11 +508,7 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
 		switch (ev.window.event) {
 		case SDL_WINDOWEVENT_EXPOSED:
 			if (_graphicsManager) {
-				if (dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)) {
-					dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->notifyVideoExpose();
-				} else if (dynamic_cast<SdlGraphicsManager *>(_graphicsManager)) {
-					dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->notifyVideoExpose();
-				}
+				_graphicsManager->notifyVideoExpose();
 			}
 			return false;
 
@@ -581,11 +567,7 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
 #else
 	case SDL_VIDEOEXPOSE:
 		if (_graphicsManager) {
-			if (dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)) {
-				dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->notifyVideoExpose();
-			} else if (dynamic_cast<SdlGraphicsManager *>(_graphicsManager)) {
-				dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->notifyVideoExpose();
-			}
+			_graphicsManager->notifyVideoExpose();
 		}
 		return false;
 
@@ -979,11 +961,8 @@ void SdlEventSource::setEngineRunning(const bool value) {
 
 bool SdlEventSource::handleResizeEvent(Common::Event &event, int w, int h) {
 	if (_graphicsManager) {
-		if (dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)) {
-			dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->notifyResize(w, h);
-		} else if (dynamic_cast<SdlGraphicsManager *>(_graphicsManager)) {
-			dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->notifyResize(w, h);
-		}
+		_graphicsManager->notifyResize(w, h);
+
 		// If the screen changed, send an Common::EVENT_SCREEN_CHANGED
 		int screenID = g_system->getScreenChangeID();
 		if (screenID != _lastScreenID) {
diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h
index 958ce70f8c..a6c91e5923 100644
--- a/backends/events/sdl/sdl-events.h
+++ b/backends/events/sdl/sdl-events.h
@@ -43,7 +43,7 @@ public:
 	SdlEventSource();
 	virtual ~SdlEventSource();
 
-	void setGraphicsManager(GraphicsManager *gMan) { _graphicsManager = gMan; }
+	void setGraphicsManager(SdlGraphicsManager *gMan) { _graphicsManager = gMan; }
 
 	/**
 	 * Gets and processes SDL events.
@@ -85,7 +85,7 @@ protected:
 	/**
 	 * The associated graphics manager.
 	 */
-	GraphicsManager *_graphicsManager;
+	SdlGraphicsManager *_graphicsManager;
 
 	/**
 	 * Search for a game controller db file and load it.
diff --git a/backends/events/switchsdl/switchsdl-events.cpp b/backends/events/switchsdl/switchsdl-events.cpp
index f1bf30436e..05238d4b1a 100644
--- a/backends/events/switchsdl/switchsdl-events.cpp
+++ b/backends/events/switchsdl/switchsdl-events.cpp
@@ -28,7 +28,6 @@
 
 #include "backends/platform/sdl/switch/switch.h"
 #include "backends/events/switchsdl/switchsdl-events.h"
-#include "backends/graphics3d/sdl/sdl-graphics3d.h"
 #include "backends/timer/sdl/sdl-timer.h"
 #include "backends/platform/sdl/sdl.h"
 #include "engines/engine.h"
@@ -221,15 +220,8 @@ void SwitchEventSource::preprocessFingerMotion(SDL_Event *event) {
 	if (numFingersDown >= 1) {
 		int x = _mouseX;
 		int y = _mouseY;
-		int xMax;
-		int yMax;
-		if (dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)) {
-			xMax = dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->getOverlayWidth() - 1;
-			yMax = dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->getOverlayHeight() - 1;
-		} else {
-			xMax = dynamic_cast<WindowedGraphicsManager *>(_graphicsManager)->getWindowWidth() - 1;
-			yMax = dynamic_cast<WindowedGraphicsManager *>(_graphicsManager)->getWindowHeight() - 1;
-		}
+		int xMax = _graphicsManager->getWindowWidth() - 1;
+		int yMax = _graphicsManager->getWindowHeight() - 1;
 
 		if (port == 0 && !ConfMan.getBool("touchpad_mouse_mode")) {
 			convertTouchXYToGameXY(event->tfinger.x, event->tfinger.y, &x, &y);
@@ -361,15 +353,8 @@ void SwitchEventSource::preprocessFingerMotion(SDL_Event *event) {
 }
 
 void SwitchEventSource::convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY) {
-	int screenH, screenW;
-
-	if (dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)) {
-		screenH = dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->getOverlayHeight();
-		screenW = dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->getOverlayWidth();
-	} else {
-		screenH = dynamic_cast<WindowedGraphicsManager *>(_graphicsManager)->getWindowHeight();
-		screenW = dynamic_cast<WindowedGraphicsManager *>(_graphicsManager)->getWindowWidth();
-	}
+	int screenH = _graphicsManager->getWindowHeight();
+	int screenW = _graphicsManager->getWindowWidth();
 
 	const int dispW = TOUCHSCREEN_WIDTH;
 	const int dispH = TOUCHSCREEN_HEIGHT;
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index 88733acc70..1a7be89ff8 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -41,6 +41,8 @@ SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source, SdlWindow *window
 	, _allowWindowSizeReset(false), _hintedWidth(0), _hintedHeight(0), _lastFlags(0)
 #endif
 {
+	ConfMan.registerDefault("fullscreen_res", "desktop");
+
 	SDL_GetMouseState(&_cursorX, &_cursorY);
 }
 
@@ -100,6 +102,23 @@ bool SdlGraphicsManager::setState(const State &state) {
 	}
 }
 
+Common::Rect SdlGraphicsManager::getPreferredFullscreenResolution() {
+	// Default to the desktop resolution, unless the user has set a
+	// resolution in the configuration file
+	const Common::String &fsres = ConfMan.get("fullscreen_res");
+	if (fsres != "desktop") {
+		uint newW, newH;
+		int converted = sscanf(fsres.c_str(), "%ux%u", &newW, &newH);
+		if (converted == 2) {
+			return Common::Rect(newW, newH);
+		} else {
+			warning("Could not parse 'fullscreen_res' option: expected WWWxHHH, got %s", fsres.c_str());
+		}
+	}
+
+	return _window->getDesktopResolution();
+}
+
 bool SdlGraphicsManager::defaultGraphicsModeConfig() const {
 	const Common::ConfigManager::Domain *transientDomain = ConfMan.getDomain(Common::ConfigManager::kTransientDomain);
 	if (transientDomain && transientDomain->contains("gfx_mode")) {
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index 760473cde8..256e8bec79 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -151,6 +151,9 @@ protected:
 		kActionPreviousScaleFilter
 	};
 
+	/** Obtain the user configured fullscreen resolution, or default to the desktop resolution */
+	Common::Rect getPreferredFullscreenResolution();
+
 	virtual int getGraphicsModeScale(int mode) const = 0;
 
 	bool defaultGraphicsModeConfig() const;
diff --git a/backends/graphics3d/graphics3d.h b/backends/graphics3d/graphics3d.h
deleted file mode 100644
index 3c7506df8f..0000000000
--- a/backends/graphics3d/graphics3d.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/* ResidualVM - Graphic Adventure Engine
- *
- * ResidulVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef BACKENDS_GRAPHICS3D_ABSTRACT_H
-#define BACKENDS_GRAPHICS3D_ABSTRACT_H
-
-#include "common/system.h"
-#include "common/noncopyable.h"
-#include "common/keyboard.h"
-#include "common/config-manager.h"
-
-#include "graphics/mode.h"
-#include "graphics/palette.h"
-
-#include "backends/graphics/graphics.h"
-
-/**
- * Abstract class for graphics manager. Subclasses
- * implement the real functionality.
- */
-class Graphics3dManager : public GraphicsManager {
-public:
-	// Following methods are not used by 3D graphics managers
-#ifdef USE_RGB_COLOR
-	virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const {
-		Common::List<Graphics::PixelFormat> supportedFormats;
-		return supportedFormats;
-	}
-#endif
-	virtual void setPalette(const byte *colors, uint start, uint num) {}
-	virtual void grabPalette(byte *colors, uint start, uint num) const {}
-	virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) {}
-	virtual Graphics::Surface *lockScreen() { return nullptr; }
-	virtual void unlockScreen() {}
-	virtual void fillScreen(uint32 col) {}
-	virtual void setShakePos(int shakeXOffset, int shakeYOffset) {};
-	virtual void setFocusRectangle(const Common::Rect& rect) {}
-	virtual void clearFocusRectangle() {}
-	virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL) {}
-	virtual void setCursorPalette(const byte *colors, uint start, uint num) {}
-
-	// Stubs for windowed gfx manager calls
-	int getWindowWidth() const { return 0; }
-	int getWindowHeight() const { return 0; }
-	virtual void unlockWindowSize() {}
-};
-
-#endif
diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
index 7b69292a9a..8da6f94447 100644
--- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
+++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
@@ -45,7 +45,7 @@
 #endif
 
 OpenGLSdlGraphics3dManager::OpenGLSdlGraphics3dManager(SdlEventSource *eventSource, SdlWindow *window, bool supportsFrameBuffer)
-	: SdlGraphics3dManager(eventSource, window),
+	: SdlGraphicsManager(eventSource, window),
 #if SDL_VERSION_ATLEAST(2, 0, 0)
 	_glContext(nullptr),
 #endif
@@ -283,6 +283,8 @@ void OpenGLSdlGraphics3dManager::createOrUpdateScreen() {
 	int obtainedHeight = effectiveHeight;
 #endif
 
+	handleResize(obtainedWidth, obtainedHeight);
+
 	// Compute the rectangle where to draw the game inside the effective screen
 	_gameRect = computeGameRect(renderToFrameBuffer, _engineRequestedWidth, _engineRequestedHeight,
 	                            obtainedWidth, obtainedHeight);
@@ -671,6 +673,11 @@ int16 OpenGLSdlGraphics3dManager::getOverlayWidth() const {
 	return _overlayScreen->getWidth();
 }
 
+bool OpenGLSdlGraphics3dManager::showMouse(bool visible) {
+	SDL_ShowCursor(visible);
+	return true;
+}
+
 void OpenGLSdlGraphics3dManager::warpMouse(int x, int y) {
 	if (!_overlayVisible && _frameBuffer) {
 		// Scale from game coordinates to screen coordinates
diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.h b/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
index 608344e575..009f640cdc 100644
--- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
+++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
@@ -23,7 +23,9 @@
 #ifndef BACKENDS_GRAPHICS3D_OPENGLSDL_GRAPHICS3D_H
 #define BACKENDS_GRAPHICS3D_OPENGLSDL_GRAPHICS3D_H
 
-#include "backends/graphics3d/sdl/sdl-graphics3d.h"
+#include "backends/graphics/sdl/sdl-graphics.h"
+
+#include "math/rect2d.h"
 
 #if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) || defined(USE_GLES2)
 
@@ -39,7 +41,7 @@ namespace OpenGL {
  *
  * Used when rendering games with OpenGL
  */
-class OpenGLSdlGraphics3dManager : public SdlGraphics3dManager {
+class OpenGLSdlGraphics3dManager : public SdlGraphicsManager {
 public:
 	OpenGLSdlGraphics3dManager(SdlEventSource *eventSource, SdlWindow *window, bool supportsFrameBuffer);
 	virtual ~OpenGLSdlGraphics3dManager();
@@ -60,6 +62,10 @@ public:
 	// GraphicsManager API - Graphics mode
 #ifdef USE_RGB_COLOR
 	virtual Graphics::PixelFormat getScreenFormat() const override { return _overlayFormat; }
+	virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const override {
+		Common::List<Graphics::PixelFormat> supportedFormats;
+		return supportedFormats;
+	}
 #endif
 	virtual int getScreenChangeID() const override { return _screenChangeCount; }
 	virtual void initSize(uint w, uint h, const Graphics::PixelFormat *format) override;
@@ -68,6 +74,16 @@ public:
 
 	// GraphicsManager API - Draw methods
 	virtual void updateScreen() override;
+	// Following methods are not used by 3D graphics managers
+	virtual void setPalette(const byte *colors, uint start, uint num) override {}
+	virtual void grabPalette(byte *colors, uint start, uint num) const override {}
+	virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) override {}
+	virtual Graphics::Surface *lockScreen() override { return nullptr; }
+	virtual void unlockScreen() override {}
+	virtual void fillScreen(uint32 col) override {}
+	virtual void setShakePos(int shakeXOffset, int shakeYOffset) override {};
+	virtual void setFocusRectangle(const Common::Rect& rect) override {}
+	virtual void clearFocusRectangle() override {}
 
 	// GraphicsManager API - Overlay
 	virtual void showOverlay() override;
@@ -81,12 +97,24 @@ public:
 	virtual bool isOverlayVisible() const override { return _overlayVisible; }
 
 	// GraphicsManager API - Mouse
+	virtual bool showMouse(bool visible) override;
 	virtual void warpMouse(int x, int y) override;
+	virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL) override {}
+	virtual void setCursorPalette(const byte *colors, uint start, uint num) override {}
 
 	// SdlGraphicsManager API
-	virtual void transformMouseCoordinates(Common::Point &point) override;
+	virtual void notifyVideoExpose() override {};
+	virtual void notifyResize(const int width, const int height) override;
+
+	virtual bool gameNeedsAspectRatioCorrection() const override { return false; }
+	virtual int getGraphicsModeScale(int mode) const override { return 1; }
+
+	void transformMouseCoordinates(Common::Point &point);
+	virtual bool notifyMousePosition(Common::Point &mouse) override {
+		transformMouseCoordinates(mouse);
 
-	void notifyResize(const int width, const int height) override;
+		return true;
+	}
 
 protected:
 #if SDL_VERSION_ATLEAST(2, 0, 0)
diff --git a/backends/graphics3d/sdl/sdl-graphics3d.cpp b/backends/graphics3d/sdl/sdl-graphics3d.cpp
deleted file mode 100644
index 03d0aa14bf..0000000000
--- a/backends/graphics3d/sdl/sdl-graphics3d.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-/* ResidualVM - A 3D game interpreter
- *
- * ResidualVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "backends/graphics/sdl/sdl-graphics.h"
-#include "backends/graphics3d/sdl/sdl-graphics3d.h"
-#include "backends/events/sdl/sdl-events.h"
-#include "backends/platform/sdl/sdl-sys.h"
-#include "backends/platform/sdl/sdl.h"
-#include "backends/keymapper/action.h"
-#include "backends/keymapper/keymap.h"
-#include "common/config-manager.h"
-#include "common/fs.h"
-#include "common/textconsole.h"
-#include "common/translation.h"
-#include "common/file.h"
-
-SdlGraphics3dManager::SdlGraphics3dManager(SdlEventSource *source, SdlWindow *window) :
-		_eventSource(source), _window(window) {
-	ConfMan.registerDefault("fullscreen_res", "desktop");
-}
-
-void SdlGraphics3dManager::activateManager() {
-	_eventSource->setGraphicsManager(this);
-
-	// Register the graphics manager as a event observer
-	g_system->getEventManager()->getEventDispatcher()->registerObserver(this, 10, false);
-}
-
-void SdlGraphics3dManager::deactivateManager() {
-	// Unregister the event observer
-	if (g_system->getEventManager()->getEventDispatcher()) {
-		g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this);
-	}
-
-	_eventSource->setGraphicsManager(0);
-}
-
-void SdlGraphics3dManager::saveScreenshot() {
-	Common::String filename;
-
-	Common::String screenshotsPath;
-	OSystem_SDL *sdl_g_system = dynamic_cast<OSystem_SDL*>(g_system);
-	if (sdl_g_system)
-		screenshotsPath = sdl_g_system->getScreenshotsPath();
-
-	// Use the name of the running target as a base for screenshot file names
-	Common::String currentTarget = ConfMan.getActiveDomainName();
-
-#ifdef USE_PNG
-	const char *extension = "png";
-#else
-	const char *extension = "bmp";
-#endif
-
-	for (int n = 0;; n++) {
-		filename = Common::String::format("scummvm%s%s-%05d.%s", currentTarget.empty() ? "" : "-",
-		                                  currentTarget.c_str(), n, extension);
-
-		Common::FSNode file = Common::FSNode(screenshotsPath + filename);
-		if (!file.exists()) {
-			break;
-		}
-	}
-
-	if (saveScreenshot(screenshotsPath + filename)) {
-		if (screenshotsPath.empty())
-			debug("Saved screenshot '%s' in current directory", filename.c_str());
-		else
-			debug("Saved screenshot '%s' in directory '%s'", filename.c_str(), screenshotsPath.c_str());
-	} else {
-		if (screenshotsPath.empty())
-			warning("Could not save screenshot in current directory");
-		else
-			warning("Could not save screenshot in directory '%s'", screenshotsPath.c_str());
-	}
-}
-
-bool SdlGraphics3dManager::notifyEvent(const Common::Event &event) {
-	if (event.type != Common::EVENT_CUSTOM_BACKEND_ACTION_START) {
-		return false;
-	}
-
-	switch ((CustomEventAction) event.customType) {
-	case kActionToggleMouseCapture:
-		getWindow()->grabMouse(!getWindow()->mouseIsGrabbed());
-		return true;
-
-	case kActionToggleFullscreen:
-		toggleFullScreen();
-		return true;
-
-	case kActionSaveScreenshot:
-		saveScreenshot();
-		return true;
-
-	default:
-		return false;
-	}
-}
-
-void SdlGraphics3dManager::toggleFullScreen() {
-	if (!g_system->hasFeature(OSystem::kFeatureFullscreenMode) ||
-	   (!g_system->hasFeature(OSystem::kFeatureFullscreenToggleKeepsContext) && g_system->hasFeature(OSystem::kFeatureOpenGLForGame))) {
-		return;
-	}
-
-	setFeatureState(OSystem::kFeatureFullscreenMode, !getFeatureState(OSystem::kFeatureFullscreenMode));
-}
-
-Common::Keymap *SdlGraphics3dManager::getKeymap() {
-	using namespace Common;
-
-	Keymap *keymap = new Keymap(Keymap::kKeymapTypeGlobal, "sdl-graphics", _("Graphics"));
-	Action *act;
-
-	if (g_system->hasFeature(OSystem::kFeatureFullscreenMode)) {
-		act = new Action("FULS", _("Toggle fullscreen"));
-		act->addDefaultInputMapping("A+RETURN");
-		act->addDefaultInputMapping("A+KP_ENTER");
-		act->setCustomBackendActionEvent(kActionToggleFullscreen);
-		keymap->addAction(act);
-	}
-
-	act = new Action("CAPT", _("Toggle mouse capture"));
-	act->addDefaultInputMapping("C+m");
-	act->setCustomBackendActionEvent(kActionToggleMouseCapture);
-	keymap->addAction(act);
-
-	act = new Action("SCRS", _("Save screenshot"));
-	act->addDefaultInputMapping("A+s");
-	act->setCustomBackendActionEvent(kActionSaveScreenshot);
-	keymap->addAction(act);
-
-	if (hasFeature(OSystem::kFeatureAspectRatioCorrection)) {
-		act = new Action("ASPT", _("Toggle aspect ratio correction"));
-		act->addDefaultInputMapping("C+A+a");
-		act->setCustomBackendActionEvent(kActionToggleAspectRatioCorrection);
-		keymap->addAction(act);
-	}
-
-	return keymap;
-}
-
-Common::Rect SdlGraphics3dManager::getPreferredFullscreenResolution() {
-	// Default to the desktop resolution, unless the user has set a
-	// resolution in the configuration file
-	const Common::String &fsres = ConfMan.get("fullscreen_res");
-	if (fsres != "desktop") {
-		uint newW, newH;
-		int converted = sscanf(fsres.c_str(), "%ux%u", &newW, &newH);
-		if (converted == 2) {
-			return Common::Rect(newW, newH);
-		} else {
-			warning("Could not parse 'fullscreen_res' option: expected WWWxHHH, got %s", fsres.c_str());
-		}
-	}
-
-	return _window->getDesktopResolution();
-}
-
-#pragma mark -
-#pragma mark --- Mouse ---
-#pragma mark -
-
-bool SdlGraphics3dManager::showMouse(bool visible) {
-	SDL_ShowCursor(visible);
-	return true;
-}
-
-bool SdlGraphics3dManager::lockMouse(bool lock) {
-	return _window->lockMouse(lock);
-}
-
-bool SdlGraphics3dManager::notifyMousePosition(Common::Point &mouse) {
-	transformMouseCoordinates(mouse);
-
-	return true;
-}
diff --git a/backends/graphics3d/sdl/sdl-graphics3d.h b/backends/graphics3d/sdl/sdl-graphics3d.h
deleted file mode 100644
index 46900cb503..0000000000
--- a/backends/graphics3d/sdl/sdl-graphics3d.h
+++ /dev/null
@@ -1,148 +0,0 @@
-/* ResidualVM - A 3D game interpreter
- *
- * ResidualVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef BACKENDS_GRAPHICS3D_SDL_SDLGRAPHICS3D_H
-#define BACKENDS_GRAPHICS3D_SDL_SDLGRAPHICS3D_H
-
-#include "backends/graphics3d/graphics3d.h"
-#include "backends/platform/sdl/sdl-window.h"
-
-#include "common/events.h"
-#include "common/rect.h"
-
-#include "math/rect2d.h"
-
-class SdlEventSource;
-
-/**
- * Base class for a SDL based graphics manager.
- */
-class SdlGraphics3dManager : virtual public Graphics3dManager, public Common::EventObserver {
-public:
-	SdlGraphics3dManager(SdlEventSource *source, SdlWindow *window);
-	virtual ~SdlGraphics3dManager() {}
-
-	/**
-	 * 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.
-	 */
-	virtual void activateManager();
-
-	/**
-	 * Makes this graphics manager inactive. This should allow another
-	 * graphics manager to become active again.
-	 */
-	virtual void deactivateManager();
-
-	/**
-	 * Notify the graphics manager that the graphics needs to be redrawn, since
-	 * the application window was modified.
-	 *
-	 * This is basically called when SDL_VIDEOEXPOSE was received.
-	 */
-	virtual void notifyVideoExpose() {};
-
-	/**
-	 * Notify the graphics manager about a resize event.
-	 *
-	 * It is noteworthy that the requested width/height should actually be set
-	 * up as is and not changed by the graphics manager, since otherwise it may
-	 * lead to odd behavior for certain window managers.
-	 *
-	 * It is only required to overwrite this method in case you want a
-	 * resizable window. The default implementation just does nothing.
-	 *
-	 * @param width Requested window width.
-	 * @param height Requested window height.
-	 */
-	virtual void notifyResize(const int width, const int height) {};
-
-	/**
-	 * Transforms real screen coordinates into the current active screen
-	 * coordinates (may be either game screen or overlay).
-	 *
-	 * @param point Mouse coordinates to transform.
-	 */
-	virtual void transformMouseCoordinates(Common::Point &point) = 0;
-
-	/**
-	 * Notifies the graphics manager about a mouse position change.
-	 *
-	 * The passed point *must* be converted from window coordinates to virtual
-	 * coordinates in order for the event to be processed correctly by the game
-	 * engine. Just use `convertWindowToVirtual` for this unless you need to do
-	 * something special.
-	 *
-	 * @param mouse The mouse position in window coordinates, which must be
-	 * converted synchronously to virtual coordinates.
-	 * @returns true if the mouse was in a valid position for the game and
-	 * should cause the event to be sent to the game.
-	 */
-	virtual bool notifyMousePosition(Common::Point &mouse);
-
-	virtual bool showMouse(bool visible) override;
-	virtual bool lockMouse(bool lock) override;
-
-	virtual bool saveScreenshot(const Common::String &filename) const { return false; }
-	void saveScreenshot() override;
-
-	// Override from Common::EventObserver
-	virtual bool notifyEvent(const Common::Event &event) override;
-
-	/**
-	 * A (subset) of the graphic manager's state. This is used when switching
-	 * between different SDL graphic managers at runtime.
-	 */
-	struct State {
-		bool aspectRatio;
-		bool fullscreen;
-	};
-
-	/** Obtain the user configured fullscreen resolution, or default to the desktop resolution */
-	virtual Common::Rect getPreferredFullscreenResolution();
-
-	/**
-	 * @returns the SDL window.
-	 */
-	SdlWindow *getWindow() const { return _window; }
-
-	Common::Keymap *getKeymap();
-
-protected:
-	enum CustomEventAction {
-		kActionToggleFullscreen = 100,
-		kActionToggleMouseCapture,
-		kActionSaveScreenshot,
-		kActionToggleAspectRatioCorrection
-	};
-
-protected:
-
-	SdlEventSource *_eventSource;
-	SdlWindow *_window;
-
-private:
-	void toggleFullScreen();
-};
-
-#endif
diff --git a/backends/modular-backend.cpp b/backends/modular-backend.cpp
index c7f4355e78..6db2d7669c 100644
--- a/backends/modular-backend.cpp
+++ b/backends/modular-backend.cpp
@@ -24,7 +24,6 @@
 
 #include "backends/audiocd/audiocd.h"
 #include "backends/graphics/graphics.h"
-#include "backends/graphics3d/graphics3d.h"
 #include "backends/mixer/mixer.h"
 #include "backends/mutex/mutex.h"
 #include "gui/EventRecorder.h"
diff --git a/backends/module.mk b/backends/module.mk
index 3cb3391e0f..02082f30c7 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -143,7 +143,6 @@ MODULE_OBJS += \
 	events/sdl/sdl-events.o \
 	graphics/sdl/sdl-graphics.o \
 	graphics/surfacesdl/surfacesdl-graphics.o \
-	graphics3d/sdl/sdl-graphics3d.o \
 	graphics3d/openglsdl/openglsdl-graphics3d.o \
 	mixer/sdl/sdl-mixer.o \
 	mutex/sdl/sdl-mutex.o \
diff --git a/backends/platform/android3d/graphics.h b/backends/platform/android3d/graphics.h
index 461558b88b..a6e3f4c7d7 100644
--- a/backends/platform/android3d/graphics.h
+++ b/backends/platform/android3d/graphics.h
@@ -24,9 +24,9 @@
 #define ANDROID_GRAPHICS_H
 
 #include "common/scummsys.h"
-#include "backends/graphics3d/graphics3d.h"
+#include "backends/graphics/graphics.h"
 
-class AndroidGraphicsManager : public Graphics3dManager {
+class AndroidGraphicsManager : public GraphicsManager {
 public:
 	AndroidGraphicsManager();
 	virtual ~AndroidGraphicsManager();
@@ -77,6 +77,10 @@ public:
 	virtual void unlockScreen() override;
 	virtual void fillScreen(uint32 col);
 
+	virtual void setShakePos(int shakeXOffset, int shakeYOffset) {};
+	virtual void setFocusRectangle(const Common::Rect& rect) {}
+	virtual void clearFocusRectangle() {}
+
 	virtual void initSize(uint width, uint height,
 							const Graphics::PixelFormat *format) override;
 	virtual int getScreenChangeID() const override;
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 3710a42d2d..6389d9c0f3 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -47,7 +47,6 @@
 #include "backends/mutex/sdl/sdl-mutex.h"
 #include "backends/timer/sdl/sdl-timer.h"
 #include "backends/graphics/surfacesdl/surfacesdl-graphics.h"
-#include "backends/graphics3d/sdl/sdl-graphics3d.h"
 #ifdef USE_OPENGL
 #include "backends/graphics/openglsdl/openglsdl-graphics.h"
 #include "graphics/cursorman.h"
@@ -120,11 +119,7 @@ OSystem_SDL::~OSystem_SDL() {
 	delete _savefileManager;
 	_savefileManager = 0;
 	if (_graphicsManager) {
-		if (dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)) {
-			dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->deactivateManager();
-		} else {
-			dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->deactivateManager();
-		}
+		dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->deactivateManager();
 	}
 	delete _graphicsManager;
 	_graphicsManager = 0;
@@ -342,11 +337,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 (dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)) {
-		dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->activateManager();
-	} else {
-		dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->activateManager();
-	}
+	dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->activateManager();
 }
 
 #if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) || defined(USE_GLES2)
@@ -431,7 +422,7 @@ void OSystem_SDL::detectAntiAliasingSupport() {
 
 void OSystem_SDL::engineInit() {
 #if SDL_VERSION_ATLEAST(2, 0, 0)
-	if (dynamic_cast<SdlGraphicsManager *>(_graphicsManager)) {
+	if (_graphicsManager) {
 		dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->unlockWindowSize();
 	}
 	// Disable screen saver when engine starts
@@ -455,7 +446,7 @@ void OSystem_SDL::engineInit() {
 
 void OSystem_SDL::engineDone() {
 #if SDL_VERSION_ATLEAST(2, 0, 0)
-	if (dynamic_cast<SdlGraphicsManager *>(_graphicsManager)) {
+	if (_graphicsManager) {
 		dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->unlockWindowSize();
 	}
 	SDL_EnableScreenSaver();
@@ -539,12 +530,7 @@ void OSystem_SDL::fatalError() {
 Common::KeymapArray OSystem_SDL::getGlobalKeymaps() {
 	Common::KeymapArray globalMaps = BaseBackend::getGlobalKeymaps();
 
-	Common::Keymap *keymap;
-	if (dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)) {
-		keymap = dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->getKeymap();
-	} else {
-		keymap = dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->getKeymap();
-	}
+	Common::Keymap *keymap = dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->getKeymap();
 	globalMaps.push_back(keymap);
 
 	return globalMaps;
@@ -777,78 +763,50 @@ bool OSystem_SDL::setGraphicsMode(int mode, uint flags) {
 		return false;
 	}
 
-	bool switchedManager = false;
+	// Very hacky way to set up the old graphics manager state, in case we
+	// switch from SDL->OpenGL or OpenGL->SDL.
+	//
+	// This is a probably temporary workaround to fix bugs like #5799
+	// "SDL/OpenGL: Crash when switching renderer backend".
+	//
+	// It's also used to restore state from 3D to 2D GFX manager
 	SdlGraphicsManager *sdlGraphicsManager = dynamic_cast<SdlGraphicsManager *>(_graphicsManager);
-	SdlGraphics3dManager *sdlGraphics3dManager = dynamic_cast<SdlGraphics3dManager *>(_graphicsManager);
-	assert(sdlGraphicsManager || sdlGraphics3dManager);
-
-	if (sdlGraphicsManager) {
-		// Very hacky way to set up the old graphics manager state, in case we
-		// switch from SDL->OpenGL or OpenGL->SDL.
-		//
-		// This is a probably temporary workaround to fix bugs like #5799
-		// "SDL/OpenGL: Crash when switching renderer backend".
-		//
-		// It's also used to restore state from 3D to 2D GFX manager
-		_gfxManagerState = sdlGraphicsManager->getState();
-	}
+	_gfxManagerState = sdlGraphicsManager->getState();
+	bool supports3D = sdlGraphicsManager->hasFeature(kFeatureOpenGLForGame);
+
+	bool switchedManager = false;
 
 	// If the new mode and the current mode are not from the same graphics
 	// manager, delete and create the new mode graphics manager
-	if (!render3d) {
-		if (sdlGraphics3dManager) {
-			sdlGraphics3dManager->deactivateManager();
-			delete sdlGraphics3dManager;
-		}
-
-		if ((sdlGraphics3dManager || _graphicsMode >= _firstGLMode) && mode < _firstGLMode) {
-			debug(1, "switching to plain SDL graphics");
-			if (sdlGraphicsManager) {
-				sdlGraphicsManager->deactivateManager();
-				delete sdlGraphicsManager;
-			}
-			_graphicsManager = sdlGraphicsManager = new SurfaceSdlGraphicsManager(_eventSource, _window);
-			switchedManager = true;
-		} else if ((sdlGraphics3dManager || _graphicsMode < _firstGLMode) && mode >= _firstGLMode) {
-			debug(1, "switching to OpenGL graphics");
-			if (sdlGraphicsManager) {
-				sdlGraphicsManager->deactivateManager();
-				delete sdlGraphicsManager;
-			}
-			_graphicsManager = sdlGraphicsManager = new OpenGLSdlGraphicsManager(_eventSource, _window);
-			switchedManager = true;
-		}
-
-		if (sdlGraphics3dManager) {
-			sdlGraphics3dManager = nullptr;
-		}
-	} else {
+#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) || defined(USE_GLES2)
+	if (render3d && !supports3D) {
+		debug(1, "switching to OpenGL 3D graphics");
+		sdlGraphicsManager->deactivateManager();
+		delete sdlGraphicsManager;
+		_graphicsManager = sdlGraphicsManager = new OpenGLSdlGraphics3dManager(_eventSource, _window, _supportsFrameBuffer);
+		switchedManager = true;
+	} else
+#endif
+	if ((supports3D || _graphicsMode >= _firstGLMode) && mode < _firstGLMode) {
+		debug(1, "switching to plain SDL graphics");
 		if (sdlGraphicsManager) {
 			sdlGraphicsManager->deactivateManager();
 			delete sdlGraphicsManager;
 		}
-#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) || defined(USE_GLES2)
-		if (!dynamic_cast<OpenGLSdlGraphics3dManager *>(sdlGraphics3dManager)) {
-			if (sdlGraphics3dManager) {
-				sdlGraphics3dManager->deactivateManager();
-				delete sdlGraphics3dManager;
-			}
-			_graphicsManager = sdlGraphics3dManager = new OpenGLSdlGraphics3dManager(_eventSource, _window, _supportsFrameBuffer);
-			switchedManager = true;
-		}
-#endif
-		if (sdlGraphicsManager) {
-			sdlGraphicsManager = nullptr;
-		}
+		_graphicsManager = sdlGraphicsManager = new SurfaceSdlGraphicsManager(_eventSource, _window);
+		switchedManager = true;
+	} else if ((supports3D || _graphicsMode < _firstGLMode) && mode >= _firstGLMode) {
+		debug(1, "switching to OpenGL graphics");
+		sdlGraphicsManager->deactivateManager();
+		delete sdlGraphicsManager;
+		_graphicsManager = sdlGraphicsManager = new OpenGLSdlGraphicsManager(_eventSource, _window);
+		switchedManager = true;
 	}
 
 	_graphicsMode = mode;
 
 	if (switchedManager) {
-		if (sdlGraphicsManager)
-			sdlGraphicsManager->activateManager();
-		else if (sdlGraphics3dManager)
-			sdlGraphics3dManager->activateManager();
+		sdlGraphicsManager->activateManager();
 
 		// Setup the graphics mode and size first
 		// This is needed so that we can check the supported pixel formats when
@@ -859,11 +817,9 @@ bool OSystem_SDL::setGraphicsMode(int mode, uint flags) {
 		_graphicsManager->initSize(_gfxManagerState.screenWidth, _gfxManagerState.screenHeight);
 		_graphicsManager->endGFXTransaction();
 
-		// Restore state
-		if (sdlGraphicsManager) {
-			// This failing will probably have bad consequences...
-			if (!sdlGraphicsManager->setState(_gfxManagerState))
-				return false;
+		// This failing will probably have bad consequences...
+		if (!sdlGraphicsManager->setState(_gfxManagerState)) {
+			return false;
 		}
 
 		// Next setup the cursor again




More information about the Scummvm-git-logs mailing list