BACKENDS: Add getDefaultScaler and getDefaultScaleFactor to OSystem

This commit is contained in:
Cameron Cawley 2021-01-06 23:02:19 +00:00 committed by Eugene Sandulenko
parent 7ed5984e2f
commit da5d773924
9 changed files with 75 additions and 7 deletions

View File

@ -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++) {

View File

@ -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; }

View File

@ -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<ScalerPluginObject>().hasFactor(factor))
if (factor == -1)
newFactor = getDefaultScaleFactor();
else if (_scalerPlugins[mode]->get<ScalerPluginObject>().hasFactor(factor))
newFactor = factor;
else if (_scalerPlugins[mode]->get<ScalerPluginObject>().hasFactor(_oldVideoMode.scaleFactor))
newFactor = _oldVideoMode.scaleFactor;

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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<ScalerPluginObject>().getName(), name)) {
return index;
}
index++;
}
return 0;
}

View File

@ -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.
*

View File

@ -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 */