diff options
author | Thierry Crozat | 2016-10-16 18:42:40 +0100 |
---|---|---|
committer | GitHub | 2016-10-16 18:42:40 +0100 |
commit | 5151bd99dd8bc342a1367c558892d5486826941c (patch) | |
tree | 290e6458cbfc728f5415cff213dc813913f17bc9 /backends/graphics/surfacesdl | |
parent | abc4656cc00f11091210213058a883718442b7b7 (diff) | |
parent | aa39a6ce4b2285d1308eb4607bdd53d317304661 (diff) | |
download | scummvm-rg350-5151bd99dd8bc342a1367c558892d5486826941c.tar.gz scummvm-rg350-5151bd99dd8bc342a1367c558892d5486826941c.tar.bz2 scummvm-rg350-5151bd99dd8bc342a1367c558892d5486826941c.zip |
Merge pull request #847 from criezy/sdl-filtering
Add graphics linear filtering feature
Diffstat (limited to 'backends/graphics/surfacesdl')
-rw-r--r-- | backends/graphics/surfacesdl/surfacesdl-graphics.cpp | 87 | ||||
-rw-r--r-- | backends/graphics/surfacesdl/surfacesdl-graphics.h | 11 |
2 files changed, 98 insertions, 0 deletions
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 46e243c945..90d079d151 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -190,6 +190,10 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou #else _videoMode.fullscreen = true; #endif + +#if SDL_VERSION_ATLEAST(2, 0, 0) + _videoMode.filtering = ConfMan.getBool("filtering"); +#endif } SurfaceSdlGraphicsManager::~SurfaceSdlGraphicsManager() { @@ -227,6 +231,9 @@ bool SurfaceSdlGraphicsManager::hasFeature(OSystem::Feature f) { return (f == OSystem::kFeatureFullscreenMode) || (f == OSystem::kFeatureAspectRatioCorrection) || +#if SDL_VERSION_ATLEAST(2, 0, 0) + (f == OSystem::kFeatureFilteringMode) || +#endif (f == OSystem::kFeatureCursorPalette) || (f == OSystem::kFeatureIconifyWindow); } @@ -239,6 +246,11 @@ void SurfaceSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) case OSystem::kFeatureAspectRatioCorrection: setAspectRatioCorrection(enable); break; +#if SDL_VERSION_ATLEAST(2, 0, 0) + case OSystem::kFeatureFilteringMode: + setFilteringMode(enable); + break; +#endif case OSystem::kFeatureCursorPalette: _cursorPaletteDisabled = !enable; blitCursor(); @@ -263,6 +275,10 @@ bool SurfaceSdlGraphicsManager::getFeatureState(OSystem::Feature f) { return _videoMode.fullscreen; case OSystem::kFeatureAspectRatioCorrection: return _videoMode.aspectRatioCorrection; +#if SDL_VERSION_ATLEAST(2, 0, 0) + case OSystem::kFeatureFilteringMode: + return _videoMode.filtering; +#endif case OSystem::kFeatureCursorPalette: return !_cursorPaletteDisabled; default: @@ -297,6 +313,9 @@ void SurfaceSdlGraphicsManager::beginGFXTransaction() { _transactionDetails.needUpdatescreen = false; _transactionDetails.normal1xScaler = false; +#if SDL_VERSION_ATLEAST(2, 0, 0) + _transactionDetails.needTextureUpdate = false; +#endif #ifdef USE_RGB_COLOR _transactionDetails.formatChanged = false; #endif @@ -323,6 +342,12 @@ OSystem::TransactionError SurfaceSdlGraphicsManager::endGFXTransaction() { _videoMode.mode = _oldVideoMode.mode; _videoMode.scaleFactor = _oldVideoMode.scaleFactor; +#if SDL_VERSION_ATLEAST(2, 0, 0) + } else if (_videoMode.filtering != _oldVideoMode.filtering) { + errors |= OSystem::kTransactionFilteringFailed; + + _videoMode.filtering = _oldVideoMode.filtering; +#endif #ifdef USE_RGB_COLOR } else if (_videoMode.format != _oldVideoMode.format) { errors |= OSystem::kTransactionFormatNotSupported; @@ -342,6 +367,9 @@ OSystem::TransactionError SurfaceSdlGraphicsManager::endGFXTransaction() { if (_videoMode.fullscreen == _oldVideoMode.fullscreen && _videoMode.aspectRatioCorrection == _oldVideoMode.aspectRatioCorrection && _videoMode.mode == _oldVideoMode.mode && +#if SDL_VERSION_ATLEAST(2, 0, 0) + _videoMode.filtering == _oldVideoMode.filtering && +#endif _videoMode.screenWidth == _oldVideoMode.screenWidth && _videoMode.screenHeight == _oldVideoMode.screenHeight) { @@ -395,6 +423,12 @@ OSystem::TransactionError SurfaceSdlGraphicsManager::endGFXTransaction() { if (_transactionDetails.needUpdatescreen) internUpdateScreen(); } +#if SDL_VERSION_ATLEAST(2, 0, 0) + } else if (_transactionDetails.needTextureUpdate) { + setGraphicsModeIntern(); + recreateScreenTexture(); + internUpdateScreen(); +#endif } else if (_transactionDetails.needUpdatescreen) { setGraphicsModeIntern(); internUpdateScreen(); @@ -1267,6 +1301,20 @@ void SurfaceSdlGraphicsManager::setAspectRatioCorrection(bool enable) { } } +#if SDL_VERSION_ATLEAST(2, 0, 0) +void SurfaceSdlGraphicsManager::setFilteringMode(bool enable) { + Common::StackLock lock(_graphicsMutex); + + if (_oldVideoMode.setup && _oldVideoMode.filtering == enable) + return; + + if (_transactionMode == kTransactionActive) { + _videoMode.filtering = enable; + _transactionDetails.needTextureUpdate = true; + } +} +#endif + void SurfaceSdlGraphicsManager::copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) { assert(_transactionMode == kTransactionNone); assert(buf); @@ -2302,6 +2350,25 @@ bool SurfaceSdlGraphicsManager::handleScalerHotkeys(Common::KeyCode key) { internUpdateScreen(); return true; } + +#if SDL_VERSION_ATLEAST(2, 0, 0) + // Ctrl-Alt-f toggles filtering + if (key == 'f') { + beginGFXTransaction(); + setFeatureState(OSystem::kFeatureFilteringMode, !_videoMode.filtering); + endGFXTransaction(); +#ifdef USE_OSD + if (getFeatureState(OSystem::kFeatureFilteringMode)) { + displayMessageOnOSD(_("Filtering enabled")); + } else { + displayMessageOnOSD(_("Filtering disabled")); + } +#endif + _forceFull = true; + internUpdateScreen(); + return true; + } +#endif int newMode = -1; int factor = _videoMode.scaleFactor - 1; @@ -2375,6 +2442,10 @@ bool SurfaceSdlGraphicsManager::isScalerHotkey(const Common::Event &event) { if (keyValue >= ARRAYSIZE(s_gfxModeSwitchTable)) return false; } +#if SDL_VERSION_ATLEAST(2, 0, 0) + if (event.kbd.keycode == 'f') + return true; +#endif return (isScaleKey || event.kbd.keycode == 'a'); } return false; @@ -2519,6 +2590,20 @@ void SurfaceSdlGraphicsManager::setWindowResolution(int width, int height) { _forceFull = true; } +void SurfaceSdlGraphicsManager::recreateScreenTexture() { + if (!_renderer) + return; + + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, _videoMode.filtering ? "linear" : "nearest"); + + SDL_Texture *oldTexture = _screenTexture; + _screenTexture = SDL_CreateTexture(_renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, _videoMode.hardwareWidth, _videoMode.hardwareHeight); + if (_screenTexture) + SDL_DestroyTexture(oldTexture); + else + _screenTexture = oldTexture; +} + SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) { deinitializeRenderer(); @@ -2542,6 +2627,8 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, SDL_GetWindowSize(_window->getSDLWindow(), &_windowWidth, &_windowHeight); setWindowResolution(_windowWidth, _windowHeight); + + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, _videoMode.filtering ? "linear" : "nearest"); _screenTexture = SDL_CreateTexture(_renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, width, height); if (!_screenTexture) { diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h index 82f4a33d8e..975cbfe27b 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.h +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h @@ -198,6 +198,7 @@ protected: int _windowWidth, _windowHeight; void deinitializeRenderer(); void setWindowResolution(int width, int height); + void recreateScreenTexture(); SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags); void SDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects); @@ -237,6 +238,9 @@ protected: bool needHotswap; bool needUpdatescreen; bool normal1xScaler; +#if SDL_VERSION_ATLEAST(2, 0, 0) + bool needTextureUpdate; +#endif #ifdef USE_RGB_COLOR bool formatChanged; #endif @@ -250,6 +254,10 @@ protected: bool aspectRatioCorrection; AspectRatio desiredAspectRatio; +#if SDL_VERSION_ATLEAST(2, 0, 0) + bool filtering; +#endif + int mode; int scaleFactor; @@ -383,6 +391,9 @@ protected: virtual void setFullscreenMode(bool enable); virtual void setAspectRatioCorrection(bool enable); +#if SDL_VERSION_ATLEAST(2, 0, 0) + virtual void setFilteringMode(bool enable); +#endif virtual int effectiveScreenHeight() const; |