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 +++++++++++++++++++++- backends/graphics/surfacesdl/surfacesdl-graphics.h | 4 ++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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(); diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h index bc2edc964c..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 -- cgit v1.2.3