From b1fe837b8ea3b42ab062ed1856d7bed53d5a2473 Mon Sep 17 00:00:00 2001 From: frosch Date: Sat, 11 Mar 2017 13:05:54 +0000 Subject: (svn r27775) -Fix [FS#6510]: Insufficient thread synchronisation when switching blitters. (JGR) --- src/video/sdl_v.cpp | 11 +++++++++-- src/video/sdl_v.h | 4 ++++ src/video/video_driver.hpp | 13 +++++++++++++ src/video/win32_v.cpp | 11 +++++++++-- src/video/win32_v.h | 4 ++++ 5 files changed, 39 insertions(+), 4 deletions(-) (limited to 'src/video') diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp index 4bb44c9d7..3668f8602 100644 --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -817,11 +817,18 @@ bool VideoDriver_SDL::ToggleFullscreen(bool fullscreen) } bool VideoDriver_SDL::AfterBlitterChange() +{ + return CreateMainSurface(_screen.width, _screen.height); +} + +void VideoDriver_SDL::AcquireBlitterLock() { if (_draw_mutex != NULL) _draw_mutex->BeginCritical(true); - bool ret = CreateMainSurface(_screen.width, _screen.height); +} + +void VideoDriver_SDL::ReleaseBlitterLock() +{ if (_draw_mutex != NULL) _draw_mutex->EndCritical(true); - return ret; } #endif /* WITH_SDL */ diff --git a/src/video/sdl_v.h b/src/video/sdl_v.h index 730f82b93..8855c3566 100644 --- a/src/video/sdl_v.h +++ b/src/video/sdl_v.h @@ -31,6 +31,10 @@ public: /* virtual */ bool AfterBlitterChange(); + /* virtual */ void AcquireBlitterLock(); + + /* virtual */ void ReleaseBlitterLock(); + /* virtual */ bool ClaimMousePointer(); /* virtual */ const char *GetName() const { return "sdl"; } diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp index 916044d35..5cb3c6cc3 100644 --- a/src/video/video_driver.hpp +++ b/src/video/video_driver.hpp @@ -49,6 +49,7 @@ public: /** * Callback invoked after the blitter was changed. + * This may only be called between AcquireBlitterLock and ReleaseBlitterLock. * @return True if no error. */ virtual bool AfterBlitterChange() @@ -56,6 +57,18 @@ public: return true; } + /** + * Acquire any lock(s) required to be held when changing blitters. + * These lock(s) may not be acquired recursively. + */ + virtual void AcquireBlitterLock() { } + + /** + * Release any lock(s) required to be held when changing blitters. + * These lock(s) may not be acquired recursively. + */ + virtual void ReleaseBlitterLock() { } + virtual bool ClaimMousePointer() { return true; diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index c37ebd7dd..e536ae8e5 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -1333,11 +1333,18 @@ bool VideoDriver_Win32::ToggleFullscreen(bool full_screen) } bool VideoDriver_Win32::AfterBlitterChange() +{ + return AllocateDibSection(_screen.width, _screen.height, true) && this->MakeWindow(_fullscreen); +} + +void VideoDriver_Win32::AcquireBlitterLock() { if (_draw_mutex != NULL) _draw_mutex->BeginCritical(true); - bool ret = AllocateDibSection(_screen.width, _screen.height, true) && this->MakeWindow(_fullscreen); +} + +void VideoDriver_Win32::ReleaseBlitterLock() +{ if (_draw_mutex != NULL) _draw_mutex->EndCritical(true); - return ret; } void VideoDriver_Win32::EditBoxLostFocus() diff --git a/src/video/win32_v.h b/src/video/win32_v.h index 21d59185b..7609d0422 100644 --- a/src/video/win32_v.h +++ b/src/video/win32_v.h @@ -31,6 +31,10 @@ public: /* virtual */ bool AfterBlitterChange(); + /* virtual */ void AcquireBlitterLock(); + + /* virtual */ void ReleaseBlitterLock(); + /* virtual */ bool ClaimMousePointer(); /* virtual */ void EditBoxLostFocus(); -- cgit v1.2.3-54-g00ecf