From aa39a6ce4b2285d1308eb4607bdd53d317304661 Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Thu, 13 Oct 2016 00:19:15 +0100 Subject: SURFACESDL: Improve toggling filtering on/off We don't need to recreate the window when turning filtering on or off. Only the texture needs to be recreated. --- .../graphics/surfacesdl/surfacesdl-graphics.cpp | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'backends/graphics/surfacesdl/surfacesdl-graphics.cpp') diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 2b62cc2c6e..90d079d151 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -313,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 @@ -420,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(); @@ -1301,7 +1310,7 @@ void SurfaceSdlGraphicsManager::setFilteringMode(bool enable) { if (_transactionMode == kTransactionActive) { _videoMode.filtering = enable; - _transactionDetails.needHotswap = true; + _transactionDetails.needTextureUpdate = true; } } #endif @@ -2355,6 +2364,7 @@ bool SurfaceSdlGraphicsManager::handleScalerHotkeys(Common::KeyCode key) { displayMessageOnOSD(_("Filtering disabled")); } #endif + _forceFull = true; internUpdateScreen(); return true; } @@ -2580,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(); -- cgit v1.2.3