scalerplugin: port to new plugin api

This commit is contained in:
Martin T. H. Sandsmark 2018-07-17 12:05:28 +02:00 committed by Filippos Karapetis
parent 39608f391c
commit f4f9957f85
5 changed files with 49 additions and 49 deletions

View file

@ -170,7 +170,7 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou
#endif
// HACK: just pick first scaler plugin
_normalPlugin = _scalerPlugins.front();
_normalPlugin = &_scalerPlugins.front()->get<ScalerPluginObject>();
_scalerPlugin = NULL;
_scalerIndex = 0;
_maxExtraPixels = ScalerMan.getMaxExtraPixels();
@ -260,6 +260,8 @@ bool SurfaceSdlGraphicsManager::getFeatureState(OSystem::Feature f) const {
#ifdef USE_ASPECT
case OSystem::kFeatureAspectRatioCorrection:
return _videoMode.aspectRatioCorrection;
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
case OSystem::kFeatureFilteringMode:
return _videoMode.filtering;
case OSystem::kFeatureCursorPalette:
@ -272,15 +274,16 @@ bool SurfaceSdlGraphicsManager::getFeatureState(OSystem::Feature f) const {
static void initGraphicsModes() {
s_supportedGraphicsModes = new Common::Array<OSystem::GraphicsMode>;
s_supportedGraphicsModesData = new Common::Array<GraphicsModeData>;
const ScalerPlugin::List &plugins = ScalerMan.getPlugins();
const PluginList &plugins = ScalerMan.getPlugins();
OSystem::GraphicsMode gm;
GraphicsModeData gmd;
// 0 should be the normal1x mode
s_defaultGraphicsMode = 0;
for (uint i = 0; i < plugins.size(); ++i) {
const Common::Array<uint> &factors = (*plugins[i])->getFactors();
const char *name = (*plugins[i])->getName();
const char *prettyName = (*plugins[i])->getPrettyName();
ScalerPluginObject &plugin = plugins[i]->get<ScalerPluginObject>();
const Common::Array<uint> &factors = plugin.getFactors();
const char *name = plugin.getName();
const char *prettyName = plugin.getPrettyName();
gmd.pluginName = name;
for (uint j = 0; j < factors.size(); ++j) {
Common::String n1 = Common::String::format("%s%dx", name, factors[j]);
@ -304,7 +307,7 @@ static void initGraphicsModes() {
s_supportedGraphicsModes->push_back(gm);
}
const OSystem::GraphicsMode *SurfaceSdlGraphicsManager::supportedGraphicsModes() {
const OSystem::GraphicsMode *SurfaceSdlGraphicsManager::supportedGraphicsModes() const {
if (!s_supportedGraphicsModes)
initGraphicsModes();
@ -680,7 +683,7 @@ bool SurfaceSdlGraphicsManager::setGraphicsMode(int mode, uint flags) {
// Find which plugin corresponds to the desired mode and set
// _scalerIndex accordingly. _scalerPlugin will be updated later.
while (strcmp(name, (*_scalerPlugins[_scalerIndex])->getName()) != 0) {
while (strcmp(name, _scalerPlugins[_scalerIndex]->get<ScalerPluginObject>().getName()) != 0) {
_scalerIndex++;
if (_scalerIndex >= _scalerPlugins.size()) {
_scalerIndex = 0;
@ -707,23 +710,23 @@ void SurfaceSdlGraphicsManager::setGraphicsModeIntern() {
// If the _scalerIndex has changed, change scaler plugins
if (_scalerPlugins[_scalerIndex] != _scalerPlugin || _transactionDetails.formatChanged) {
if (&_scalerPlugins[_scalerIndex]->get<ScalerPluginObject>() != _scalerPlugin || _transactionDetails.formatChanged) {
Graphics::PixelFormat format;
convertSDLPixelFormat(_hwscreen->format, &format);
if (_scalerPlugin)
(*_scalerPlugin)->deinitialize();
_scalerPlugin->deinitialize();
if (_scalerPlugins[_scalerIndex] != _normalPlugin) {
if (&_scalerPlugins[_scalerIndex]->get<ScalerPluginObject>() != _normalPlugin) {
// _normalPlugin might be needed and needs to be initialized
(*_normalPlugin)->initialize(format);
_normalPlugin->initialize(format);
}
_scalerPlugin = _scalerPlugins[_scalerIndex];
(*_scalerPlugin)->initialize(format);
_extraPixels = (*_scalerPlugin)->extraPixels();
_useOldSrc = (*_scalerPlugin)->useOldSource();
_scalerPlugin = &_scalerPlugins[_scalerIndex]->get<ScalerPluginObject>();
_scalerPlugin->initialize(format);
_extraPixels = _scalerPlugin->extraPixels();
_useOldSrc = _scalerPlugin->useOldSource();
if (_useOldSrc) {
(*_scalerPlugin)->enableSource(true);
(*_scalerPlugin)->setSource((byte *)_tmpscreen->pixels, _tmpscreen->pitch,
_scalerPlugin->enableSource(true);
_scalerPlugin->setSource((byte *)_tmpscreen->pixels, _tmpscreen->pitch,
_videoMode.screenWidth, _videoMode.screenHeight, _maxExtraPixels);
if (!_destbuffer) {
_destbuffer = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth * _videoMode.scaleFactor,
@ -739,7 +742,7 @@ void SurfaceSdlGraphicsManager::setGraphicsModeIntern() {
}
}
(*_scalerPlugin)->setFactor(_videoMode.scaleFactor);
_scalerPlugin->setFactor(_videoMode.scaleFactor);
// Blit everything to the screen
_forceRedraw = true;
@ -1021,7 +1024,7 @@ bool SurfaceSdlGraphicsManager::loadGFXMode() {
if (_useOldSrc) {
// Create surface containing previous frame's data to pass to scaler
(*_scalerPlugin)->setSource((byte *)_tmpscreen->pixels, _tmpscreen->pitch,
_scalerPlugin->setSource((byte *)_tmpscreen->pixels, _tmpscreen->pitch,
_videoMode.screenWidth, _videoMode.screenHeight, _maxExtraPixels);
// Create surface containing the raw output from the scaler
@ -1345,10 +1348,10 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() {
} else {
if (_useOldSrc) {
// scale into _destbuffer instead of _hwscreen to avoid AR problems
(*_scalerPlugin)->scale((byte *)srcSurf->pixels + (r->x + _maxExtraPixels) * 2 + (r->y + _maxExtraPixels) * srcPitch, srcPitch,
_scalerPlugin->scale((byte *)srcSurf->pixels + (r->x + _maxExtraPixels) * 2 + (r->y + _maxExtraPixels) * srcPitch, srcPitch,
(byte *)_destbuffer->pixels + rx1 * 2 + orig_dst_y * scale1 * _destbuffer->pitch, _destbuffer->pitch, r->w, dst_h, r->x, r->y);
} else
(*_scalerPlugin)->scale((byte *)srcSurf->pixels + (r->x + _maxExtraPixels) * 2 + (r->y + _maxExtraPixels) * srcPitch, srcPitch,
_scalerPlugin->scale((byte *)srcSurf->pixels + (r->x + _maxExtraPixels) * 2 + (r->y + _maxExtraPixels) * srcPitch, srcPitch,
(byte *)_hwscreen->pixels + rx1 * 2 + dst_y * dstPitch, dstPitch, r->w, dst_h, r->x, r->y);
}
}
@ -1848,13 +1851,13 @@ void SurfaceSdlGraphicsManager::clearOverlay() {
// The plugin won't write anything if _useOldSrc
if (_useOldSrc)
(*_scalerPlugin)->enableSource(false);
_scalerPlugin->enableSource(false);
(*_scalerPlugin)->scale((byte *)(_tmpscreen->pixels) + _tmpscreen->pitch + 2, _tmpscreen->pitch,
_scalerPlugin->scale((byte *)(_tmpscreen->pixels) + _tmpscreen->pitch + 2, _tmpscreen->pitch,
(byte *)_overlayscreen->pixels, _overlayscreen->pitch, _videoMode.screenWidth, _videoMode.screenHeight, 0, 0);
if (_useOldSrc)
(*_scalerPlugin)->enableSource(true);
_scalerPlugin->enableSource(true);
#ifdef USE_ASPECT
if (_videoMode.aspectRatioCorrection)
@ -2220,21 +2223,21 @@ void SurfaceSdlGraphicsManager::blitCursor() {
// otherwise use the Normal scaler
#ifdef USE_SCALERS
if (_cursorTargetScale == 1) {
if ((*_scalerPlugin)->canDrawCursor()) {
if (_scalerPlugin->canDrawCursor()) {
#endif
(*_scalerPlugin)->scale(
_scalerPlugin->scale(
(byte *)_mouseOrigSurface->pixels + _mouseOrigSurface->pitch * _maxExtraPixels + _maxExtraPixels * bytesPerPixel,
_mouseOrigSurface->pitch, (byte *)_mouseSurface->pixels, _mouseSurface->pitch,
_mouseCurState.w, _mouseCurState.h, 0, 0);
#ifdef USE_SCALERS
} else {
int tmpFactor = (*_normalPlugin)->getFactor();
(*_normalPlugin)->setFactor(_videoMode.scaleFactor);
(*_normalPlugin)->scale(
int tmpFactor = _normalPlugin->getFactor();
_normalPlugin->setFactor(_videoMode.scaleFactor);
_normalPlugin->scale(
(byte *)_mouseOrigSurface->pixels + _mouseOrigSurface->pitch * _maxExtraPixels + _maxExtraPixels * bytesPerPixel,
_mouseOrigSurface->pitch, (byte *)_mouseSurface->pixels, _mouseSurface->pitch,
_mouseCurState.w, _mouseCurState.h, 0, 0);
(*_normalPlugin)->setFactor(tmpFactor);
_normalPlugin->setFactor(tmpFactor);
}
} else {
blitSurface(
@ -2552,9 +2555,9 @@ void SurfaceSdlGraphicsManager::handleResizeImpl(const int width, const int heig
* @param factor The scale factor to match
* @return The graphics mode
*/
int findGraphicsMode(uint factor, ScalerPlugin *plugin) {
int findGraphicsMode(uint factor, ScalerPluginObject &plugin) {
for (uint i = 0; i < s_supportedGraphicsModesData->size(); ++i) {
if (strcmp((*s_supportedGraphicsModesData)[i].pluginName, (*plugin)->getName()) == 0
if (strcmp((*s_supportedGraphicsModesData)[i].pluginName, plugin.getName()) == 0
&& (*s_supportedGraphicsModesData)[i].scaleFactor == factor) {
return i;
}

View file

@ -80,6 +80,7 @@ public:
virtual void setFeatureState(OSystem::Feature f, bool enable) override;
virtual bool getFeatureState(OSystem::Feature f) const override;
const OSystem::GraphicsMode *supportedGraphicsModes() const;
virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const override;
virtual int getDefaultGraphicsMode() const override;
virtual bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags) override;
@ -330,9 +331,9 @@ protected:
// Indicates whether it is needed to free _hwSurface in destructor
bool _displayDisabled;
const ScalerPlugin::List &_scalerPlugins;
ScalerPlugin *_scalerPlugin;
ScalerPlugin *_normalPlugin;
const PluginList &_scalerPlugins;
ScalerPluginObject *_scalerPlugin;
ScalerPluginObject *_normalPlugin;
uint _scalerIndex;
uint _maxExtraPixels;
uint _extraPixels;

View file

@ -154,12 +154,11 @@ OSystem_SDL::~OSystem_SDL() {
_mutexManager = 0;
#ifdef USE_OPENGL
for (int i = 0; i < _sdlModesCount; ++i) {
for (uint i = 0; i < _graphicsModes.size(); ++i) {
// SurfaceSDL needs us to free these
free(const_cast<char *>(_graphicsModes[i].name));
free(const_cast<char *>(_graphicsModes[i].description));
}
delete[] _graphicsModes;
#endif
delete _logger;
@ -273,9 +272,10 @@ void OSystem_SDL::initBackend() {
}
}
// Look in all game domains as well
#if 0
Common::ConfigManager::DomainMap &dm = ConfMan.getGameDomains();
for (Common::ConfigManager::DomainMap::iterator domain = dm.begin(); domain != dm.end(); ++domain) {
Common::ConfigManager::Domain::iterator gm = domain->_value.find("gfx_mode");
Common::ConfigManager::Domain::const_iterator gm = domain->_value.find("gfx_mode");
if (gm != domain->_value.end()) {
for (uint i = 0; i < ARRAYSIZE(s_legacyGraphicsModes); ++i) {
if (gm->_value == s_legacyGraphicsModes[i].oldName) {
@ -285,6 +285,7 @@ void OSystem_SDL::initBackend() {
}
}
}
#endif
if (_graphicsManager == 0) {
#ifdef USE_OPENGL
@ -948,9 +949,6 @@ void OSystem_SDL::setupGraphicsModes() {
mode->id = i++;
mode++;
}
// SurfaceSDLGraphicsManager expects us to delete[] this
delete[] sdlGraphicsModes;
}
#endif

View file

@ -970,16 +970,16 @@ namespace Common {
DECLARE_SINGLETON(ScalerManager);
}
const ScalerPlugin::List &ScalerManager::getPlugins() const {
return (const ScalerPlugin::List &)PluginManager::instance().getPlugins(PLUGIN_TYPE_SCALER);
const PluginList &ScalerManager::getPlugins() const {
return PluginManager::instance().getPlugins(PLUGIN_TYPE_SCALER);
}
uint ScalerManager::getMaxExtraPixels() const {
uint maxPixels = 0;
ScalerPlugin::List plugins = getPlugins();
ScalerPlugin::List::iterator i = plugins.begin();
PluginList plugins = getPlugins();
PluginList::iterator i = plugins.begin();
for (; i != plugins.end(); ++i) {
uint n = (**i)->extraPixels();
uint n = (*i)->get<ScalerPluginObject>().extraPixels();
if (n > maxPixels) {
maxPixels = n;
}

View file

@ -168,8 +168,6 @@ private:
byte *_oldSrc;
};
typedef PluginSubclass<ScalerPluginObject> ScalerPlugin;
/**
* Singleton class to manage scaler plugins
*/
@ -178,7 +176,7 @@ private:
friend class Common::Singleton<SingletonBaseType>;
public:
const ScalerPlugin::List &getPlugins() const;
const PluginList &getPlugins() const;
/**
* Queries all scaler plugins for the maximum number of pixels they