diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-01-16 16:43:11 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-02-22 22:16:07 +0100 |
commit | d6b67758881ba24d532d42e211a5fddcc1cdd309 (patch) | |
tree | 7fe12be86517d23cd4dbc6d4f9def52186e30d0c /src/video/win32_v.h | |
parent | 73ed748deb65f14f280b8cefebb0a6beff16a4a5 (diff) | |
download | openttd-d6b67758881ba24d532d42e211a5fddcc1cdd309.tar.xz |
Change: Lock the video buffer when drawing inside the game loop to properly account for threaded drawing.
Diffstat (limited to 'src/video/win32_v.h')
-rw-r--r-- | src/video/win32_v.h | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/video/win32_v.h b/src/video/win32_v.h index 6b62ea0ee..72736ec84 100644 --- a/src/video/win32_v.h +++ b/src/video/win32_v.h @@ -11,11 +11,13 @@ #define VIDEO_WIN32_H #include "video_driver.hpp" +#include <mutex> +#include <condition_variable> /** Base class for Windows video drivers. */ class VideoDriver_Win32Base : public VideoDriver { public: - VideoDriver_Win32Base() : main_wnd(nullptr), fullscreen(false) {} + VideoDriver_Win32Base() : main_wnd(nullptr), fullscreen(false), draw_mutex(nullptr), draw_signal(nullptr) {} void Stop() override; @@ -36,9 +38,16 @@ public: void EditBoxLostFocus() override; protected: - HWND main_wnd; ///< Handle to system window. - bool fullscreen; ///< Whether to use (true) fullscreen mode. - Rect dirty_rect; ///< Region of the screen that needs redrawing. + HWND main_wnd; ///< Handle to system window. + bool fullscreen; ///< Whether to use (true) fullscreen mode. + Rect dirty_rect; ///< Region of the screen that needs redrawing. + + bool draw_threaded; ///< Whether the drawing is/may be done in a separate thread. + bool buffer_locked; ///< Video buffer was locked by the main thread. + volatile bool draw_continue; ///< Should we keep continue drawing? + + std::recursive_mutex *draw_mutex; ///< Mutex to keep the access to the shared memory controlled. + std::condition_variable_any *draw_signal; ///< Signal to draw the next frame. Dimension GetScreenSize() const override; float GetDPIScale() override; |