From da5d773924285bccf342d76a47cc43bc64bb24eb Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Wed, 6 Jan 2021 23:02:19 +0000 Subject: [PATCH] BACKENDS: Add getDefaultScaler and getDefaultScaleFactor to OSystem --- backends/base-backend.cpp | 3 +++ backends/graphics/graphics.h | 2 ++ .../surfacesdl/surfacesdl-graphics.cpp | 24 +++++++++++++------ .../graphics/surfacesdl/surfacesdl-graphics.h | 2 ++ backends/modular-backend.cpp | 8 +++++++ backends/modular-backend.h | 2 ++ base/plugins.cpp | 14 +++++++++++ common/system.h | 22 +++++++++++++++++ graphics/scalerplugin.h | 5 ++++ 9 files changed, 75 insertions(+), 7 deletions(-) diff --git a/backends/base-backend.cpp b/backends/base-backend.cpp index 4d434bf8d85..560510e068f 100644 --- a/backends/base-backend.cpp +++ b/backends/base-backend.cpp @@ -40,6 +40,9 @@ bool BaseBackend::setScaler(const char *name, int factor) { if (!name) return false; + if (!scumm_stricmp(name, "default")) + return setScaler(getDefaultScaler(), factor); + const PluginList &scalerPlugins = ScalerMan.getPlugins(); for (uint scalerIndex = 0; scalerIndex < scalerPlugins.size(); scalerIndex++) { diff --git a/backends/graphics/graphics.h b/backends/graphics/graphics.h index 1385038aa6a..f6f297571c1 100644 --- a/backends/graphics/graphics.h +++ b/backends/graphics/graphics.h @@ -63,6 +63,8 @@ public: virtual int getDefaultStretchMode() const { return 0; } virtual bool setStretchMode(int mode) { return false; } virtual int getStretchMode() const { return 0; } + virtual uint getDefaultScaler() const { return 0; } + virtual int getDefaultScaleFactor() const { return 1; } virtual bool setScaler(uint mode, int factor) { return false; } virtual uint getScaler() const { return 0; } diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index ef37850899d..008e2999f33 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -160,12 +160,8 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou _videoMode.stretchMode = STRETCH_FIT; #endif - _videoMode.scalerIndex = 0; -#ifdef USE_SCALERS - _videoMode.scaleFactor = 2; -#else - _videoMode.scaleFactor = 1; -#endif + _videoMode.scalerIndex = getDefaultScaler(); + _videoMode.scaleFactor = getDefaultScaleFactor(); } SurfaceSdlGraphicsManager::~SurfaceSdlGraphicsManager() { @@ -557,6 +553,18 @@ int SurfaceSdlGraphicsManager::getGraphicsModeScale(int mode) const { return _videoMode.scaleFactor; } +uint SurfaceSdlGraphicsManager::getDefaultScaler() const { + return ScalerMan.findScalerPluginIndex("normal"); +} + +int SurfaceSdlGraphicsManager::getDefaultScaleFactor() const { +#ifdef USE_SCALERS + return 2; +#else + return 1; +#endif +} + bool SurfaceSdlGraphicsManager::setScaler(uint mode, int factor) { Common::StackLock lock(_graphicsMutex); @@ -566,7 +574,9 @@ bool SurfaceSdlGraphicsManager::setScaler(uint mode, int factor) { return true; int newFactor; - if (_scalerPlugins[mode]->get().hasFactor(factor)) + if (factor == -1) + newFactor = getDefaultScaleFactor(); + else if (_scalerPlugins[mode]->get().hasFactor(factor)) newFactor = factor; else if (_scalerPlugins[mode]->get().hasFactor(_oldVideoMode.scaleFactor)) newFactor = _oldVideoMode.scaleFactor; diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h index 30c41b2ef71..061a87f3317 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.h +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h @@ -73,6 +73,8 @@ public: virtual int getDefaultGraphicsMode() const override; virtual bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags) override; virtual int getGraphicsMode() const override; + virtual uint getDefaultScaler() const override; + virtual int getDefaultScaleFactor() const override; virtual bool setScaler(uint mode, int factor) override; virtual uint getScaler() const override; #ifdef USE_RGB_COLOR diff --git a/backends/modular-backend.cpp b/backends/modular-backend.cpp index c548284bfb0..e0ac0ffe04d 100644 --- a/backends/modular-backend.cpp +++ b/backends/modular-backend.cpp @@ -108,6 +108,14 @@ int ModularGraphicsBackend::getStretchMode() const { return _graphicsManager->getStretchMode(); } +uint ModularGraphicsBackend::getDefaultScaler() const { + return _graphicsManager->getDefaultScaler(); +} + +int ModularGraphicsBackend::getDefaultScaleFactor() const { + return _graphicsManager->getDefaultScaleFactor(); +} + bool ModularGraphicsBackend::setScaler(uint mode, int factor) { return _graphicsManager->setScaler(mode, factor); } diff --git a/backends/modular-backend.h b/backends/modular-backend.h index 97b231ad6e8..db22cfe29a5 100644 --- a/backends/modular-backend.h +++ b/backends/modular-backend.h @@ -76,6 +76,8 @@ public: virtual int getDefaultStretchMode() const override final; virtual bool setStretchMode(int mode) override final; virtual int getStretchMode() const override final; + virtual uint getDefaultScaler() const override final; + virtual int getDefaultScaleFactor() const override final; virtual bool setScaler(uint mode, int factor) override final; virtual uint getScaler() const override final; #ifdef USE_RGB_COLOR diff --git a/base/plugins.cpp b/base/plugins.cpp index af804a8e592..04baf89243d 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -1023,3 +1023,17 @@ Plugin *ScalerManager::findScalerPlugin(const char *name) const { return 0; } + +uint ScalerManager::findScalerPluginIndex(const char *name) const { + const PluginList &plugins = getPlugins(); + uint index = 0; + + for (PluginList::const_iterator i = plugins.begin(); i != plugins.end(); ++i) { + if (!strcmp((*i)->get().getName(), name)) { + return index; + } + index++; + } + + return 0; +} diff --git a/common/system.h b/common/system.h index af59539a204..99445b1dc65 100644 --- a/common/system.h +++ b/common/system.h @@ -866,6 +866,28 @@ public: */ virtual int getStretchMode() const { return 0; } + /** + * Return the ID of the 'default' scaler. + * + * This mode is set by the client code when no user overrides + * are present (i.e. if no custom scaler is selected using the + * command line or a config file). + * + * @return ID of the 'default' scaler. + */ + virtual uint getDefaultScaler() const { return 0; } + + /** + * Return the 'default' scale factor. + * + * This mode is set by the client code when no user overrides + * are present (i.e. if no custom shader mode is selected using + * the command line or a config file). + * + * @return The 'default' scale factor. + */ + virtual int getDefaultScaleFactor() const { return 1; } + /** * Switch to the specified scaler. * diff --git a/graphics/scalerplugin.h b/graphics/scalerplugin.h index 996e68db0ec..4a3d6cf8ec8 100644 --- a/graphics/scalerplugin.h +++ b/graphics/scalerplugin.h @@ -225,6 +225,11 @@ public: * Search the scaler plugins for a special plugin based on its name. */ Plugin *findScalerPlugin(const char *name) const; + + /** + * Search the scaler plugins for a special plugin based on its name. + */ + uint findScalerPluginIndex(const char *name) const; }; /** Convenience shortcut for accessing singleton */