diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-05-01 19:39:03 +0200 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-05-02 17:57:24 +0200 |
commit | 91b8ce073f54dff48cd61186c32d0a720a2abb4d (patch) | |
tree | fc9c162bc66bb3d374a3f2543483163350e03d51 /src/gfxinit.cpp | |
parent | 2cf5df2a50e9f28ef4ba93a765bfcf79afcbb20c (diff) | |
download | openttd-91b8ce073f54dff48cd61186c32d0a720a2abb4d.tar.xz |
Codechange: Generalise the delayed blitter change to a generic video driver command queue.
Diffstat (limited to 'src/gfxinit.cpp')
-rw-r--r-- | src/gfxinit.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index b744eaa5e..c0ba4c4d4 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -244,6 +244,28 @@ static void LoadSpriteTables() } +static void RealChangeBlitter(const char *repl_blitter) +{ + const char *cur_blitter = BlitterFactory::GetCurrentBlitter()->GetName(); + if (strcmp(cur_blitter, repl_blitter) == 0) return; + + DEBUG(driver, 1, "Switching blitter from '%s' to '%s'... ", cur_blitter, repl_blitter); + Blitter *new_blitter = BlitterFactory::SelectBlitter(repl_blitter); + if (new_blitter == nullptr) NOT_REACHED(); + DEBUG(driver, 1, "Successfully switched to %s.", repl_blitter); + + if (!VideoDriver::GetInstance()->AfterBlitterChange()) { + /* Failed to switch blitter, let's hope we can return to the old one. */ + if (BlitterFactory::SelectBlitter(cur_blitter) == nullptr || !VideoDriver::GetInstance()->AfterBlitterChange()) usererror("Failed to reinitialize video driver. Specify a fixed blitter in the config"); + } + + /* Clear caches that might have sprites for another blitter. */ + VideoDriver::GetInstance()->ClearSystemSprites(); + ClearFontCache(); + GfxClearSpriteCache(); + ReInitAllWindows(false); +} + /** * Check blitter needed by NewGRF config and switch if needed. * @return False when nothing changed, true otherwise. @@ -309,7 +331,7 @@ static bool SwitchNewGRFBlitter() if (BlitterFactory::GetBlitterFactory(repl_blitter) == nullptr) continue; /* Inform the video driver we want to switch blitter as soon as possible. */ - VideoDriver::GetInstance()->ChangeBlitter(repl_blitter); + VideoDriver::GetInstance()->QueueOnMainThread(std::bind(&RealChangeBlitter, repl_blitter)); break; } |