diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/video/allegro_v.cpp | 4 | ||||
-rw-r--r-- | src/video/allegro_v.h | 1 | ||||
-rw-r--r-- | src/video/cocoa/cocoa_v.h | 2 | ||||
-rw-r--r-- | src/video/cocoa/cocoa_v.mm | 9 | ||||
-rw-r--r-- | src/video/sdl2_v.cpp | 15 | ||||
-rw-r--r-- | src/video/sdl2_v.h | 4 | ||||
-rw-r--r-- | src/video/sdl_v.cpp | 15 | ||||
-rw-r--r-- | src/video/sdl_v.h | 4 | ||||
-rw-r--r-- | src/video/video_driver.hpp | 10 | ||||
-rw-r--r-- | src/video/win32_v.cpp | 15 | ||||
-rw-r--r-- | src/video/win32_v.h | 2 |
11 files changed, 58 insertions, 23 deletions
diff --git a/src/video/allegro_v.cpp b/src/video/allegro_v.cpp index 5ddc8b808..9b5b2e1d9 100644 --- a/src/video/allegro_v.cpp +++ b/src/video/allegro_v.cpp @@ -56,7 +56,7 @@ void VideoDriver_Allegro::MakeDirty(int left, int top, int width, int height) _num_dirty_rects++; } -static void DrawSurfaceToScreen() +void VideoDriver_Allegro::Paint() { PerformanceMeasurer framerate(PFE_VIDEO); @@ -524,7 +524,7 @@ void VideoDriver_Allegro::MainLoop() UpdateWindows(); CheckPaletteAnim(); - DrawSurfaceToScreen(); + this->Paint(); } /* If we are not in fast-forward, create some time between calls to ease up CPU usage. */ diff --git a/src/video/allegro_v.h b/src/video/allegro_v.h index 1c3a05af7..3c55a6691 100644 --- a/src/video/allegro_v.h +++ b/src/video/allegro_v.h @@ -35,6 +35,7 @@ public: protected: void InputLoop() override; + void Paint() override; }; /** Factory for the allegro video driver. */ diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h index f42d57dfe..09668ed8b 100644 --- a/src/video/cocoa/cocoa_v.h +++ b/src/video/cocoa/cocoa_v.h @@ -75,6 +75,7 @@ protected: Dimension GetScreenSize() const override; float GetDPIScale() override; void InputLoop() override; + void Paint() override; private: bool PollEvent(); @@ -89,7 +90,6 @@ private: void UpdatePalette(uint first_color, uint num_colors); void CheckPaletteAnim(); - void Draw(bool force_update = false); void BlitIndexedToView32(int left, int top, int right, int bottom); }; diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm index 5e8c82b2a..1847d53fc 100644 --- a/src/video/cocoa/cocoa_v.mm +++ b/src/video/cocoa/cocoa_v.mm @@ -465,10 +465,10 @@ void VideoDriver_Cocoa::BlitIndexedToView32(int left, int top, int right, int bo } /** - * Draw window. + * Paint window. * @param force_update Whether to redraw unconditionally */ -void VideoDriver_Cocoa::Draw(bool force_update) +void VideoDriver_Cocoa::Paint() { PerformanceMeasurer framerate(PFE_VIDEO); @@ -502,9 +502,8 @@ void VideoDriver_Cocoa::Draw(bool force_update) dirtyrect.size.height = this->dirty_rects[i].bottom - this->dirty_rects[i].top; /* Normally drawRect will be automatically called by Mac OS X during next update cycle, - * and then blitting will occur. If force_update is true, it will be done right now. */ + * and then blitting will occur. */ [ this->cocoaview setNeedsDisplayInRect:[ this->cocoaview getVirtualRect:dirtyrect ] ]; - if (force_update) [ this->cocoaview displayIfNeeded ]; } this->num_dirty_rects = 0; @@ -708,7 +707,7 @@ void VideoDriver_Cocoa::GameLoop() UpdateWindows(); this->CheckPaletteAnim(); - this->Draw(); + this->Paint(); } /* If we are not in fast-forward, create some time between calls to ease up CPU usage. */ diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index 8bee575e2..1cc6c5598 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -124,7 +124,7 @@ void VideoDriver_SDL::CheckPaletteAnim() this->MakeDirty(0, 0, _screen.width, _screen.height); } -static void Paint() +void VideoDriver_SDL::Paint() { PerformanceMeasurer framerate(PFE_VIDEO); @@ -161,7 +161,7 @@ static void Paint() MemSetT(&_dirty_rect, 0); } -static void PaintThread() +void VideoDriver_SDL::PaintThread() { /* First tell the main thread we're started */ std::unique_lock<std::recursive_mutex> lock(*_draw_mutex); @@ -172,11 +172,16 @@ static void PaintThread() while (_draw_continue) { /* Then just draw and wait till we stop */ - Paint(); + this->Paint(); _draw_signal->wait(lock); } } +/* static */ void VideoDriver_SDL::PaintThreadThunk(VideoDriver_SDL *drv) +{ + drv->PaintThread(); +} + static const Dimension default_resolutions[] = { { 640, 480 }, { 800, 600 }, @@ -820,7 +825,7 @@ void VideoDriver_SDL::LoopOnce() if (_draw_mutex != nullptr && !HasModalProgress()) { _draw_signal->notify_one(); } else { - Paint(); + this->Paint(); } } @@ -861,7 +866,7 @@ void VideoDriver_SDL::MainLoop() _draw_signal = new std::condition_variable_any(); _draw_continue = true; - _draw_threaded = StartNewThread(&draw_thread, "ottd:draw-sdl", &PaintThread); + _draw_threaded = StartNewThread(&draw_thread, "ottd:draw-sdl", &VideoDriver_SDL::PaintThreadThunk, this); /* Free the mutex if we won't be able to use it. */ if (!_draw_threaded) { diff --git a/src/video/sdl2_v.h b/src/video/sdl2_v.h index 116cef51f..91f4b2c7f 100644 --- a/src/video/sdl2_v.h +++ b/src/video/sdl2_v.h @@ -46,6 +46,8 @@ protected: void InputLoop() override; bool LockVideoBuffer() override; void UnlockVideoBuffer() override; + void Paint() override; + void PaintThread() override; private: int PollEvent(); @@ -73,6 +75,8 @@ private: int startup_display; std::thread draw_thread; std::unique_lock<std::recursive_mutex> draw_lock; + + static void PaintThreadThunk(VideoDriver_SDL *drv); }; /** Factory for the SDL video driver. */ diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp index 8190dc4d6..0aa216df2 100644 --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -147,7 +147,7 @@ static void CheckPaletteAnim() } } -static void DrawSurfaceToScreen() +void VideoDriver_SDL::Paint() { PerformanceMeasurer framerate(PFE_VIDEO); @@ -173,7 +173,7 @@ static void DrawSurfaceToScreen() } } -static void DrawSurfaceToScreenThread() +void VideoDriver_SDL::PaintThread() { /* First tell the main thread we're started */ std::unique_lock<std::recursive_mutex> lock(*_draw_mutex); @@ -185,11 +185,16 @@ static void DrawSurfaceToScreenThread() while (_draw_continue) { CheckPaletteAnim(); /* Then just draw and wait till we stop */ - DrawSurfaceToScreen(); + this->Paint(); _draw_signal->wait(lock); } } +/* static */ void VideoDriver_SDL::PaintThreadThunk(VideoDriver_SDL *drv) +{ + drv->PaintThread(); +} + static const Dimension _default_resolutions[] = { { 640, 480}, { 800, 600}, @@ -717,7 +722,7 @@ void VideoDriver_SDL::MainLoop() _draw_signal = new std::condition_variable_any(); _draw_continue = true; - _draw_threaded = StartNewThread(&draw_thread, "ottd:draw-sdl", &DrawSurfaceToScreenThread); + _draw_threaded = StartNewThread(&draw_thread, "ottd:draw-sdl", &VideoDriver_SDL::PaintThreadThunk, this); /* Free the mutex if we won't be able to use it. */ if (!_draw_threaded) { @@ -782,7 +787,7 @@ void VideoDriver_SDL::MainLoop() _draw_signal->notify_one(); } else { CheckPaletteAnim(); - DrawSurfaceToScreen(); + this->Paint(); } } diff --git a/src/video/sdl_v.h b/src/video/sdl_v.h index 896a6f5b8..a51062d85 100644 --- a/src/video/sdl_v.h +++ b/src/video/sdl_v.h @@ -41,6 +41,8 @@ protected: void InputLoop() override; bool LockVideoBuffer() override; void UnlockVideoBuffer() override; + void Paint() override; + void PaintThread() override; private: std::unique_lock<std::recursive_mutex> draw_lock; @@ -48,6 +50,8 @@ private: int PollEvent(); bool CreateMainSurface(uint w, uint h); void SetupKeyboard(); + + static void PaintThreadThunk(VideoDriver_SDL *drv); }; /** Factory for the SDL video driver. */ diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp index 875125ebc..b8acb2bb8 100644 --- a/src/video/video_driver.hpp +++ b/src/video/video_driver.hpp @@ -174,6 +174,16 @@ protected: */ virtual void UnlockVideoBuffer() {} + /** + * Paint the window. + */ + virtual void Paint() {} + + /** + * Thread function for threaded drawing. + */ + virtual void PaintThread() {} + std::chrono::steady_clock::duration GetGameInterval() { return std::chrono::milliseconds(MILLISECONDS_PER_TICK); diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index cca12c40c..8e887f0aa 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -332,7 +332,7 @@ bool VideoDriver_Win32::MakeWindow(bool full_screen) } /** Do palette animation and blit to the window. */ -static void PaintWindow() +void VideoDriver_Win32::Paint() { PerformanceMeasurer framerate(PFE_VIDEO); @@ -385,7 +385,7 @@ static void PaintWindow() MemSetT(&_dirty_rect, 0); } -static void PaintWindowThread() +void VideoDriver_Win32::PaintThread() { /* First tell the main thread we're started */ std::unique_lock<std::recursive_mutex> lock(*_draw_mutex); @@ -395,7 +395,7 @@ static void PaintWindowThread() _draw_signal->wait(*_draw_mutex); while (_draw_continue) { - PaintWindow(); + this->Paint(); /* Flush GDI buffer to ensure drawing here doesn't conflict with any GDI usage in the main WndProc. */ GdiFlush(); @@ -404,6 +404,11 @@ static void PaintWindowThread() } } +/* static */ void VideoDriver_Win32::PaintThreadThunk(VideoDriver_Win32 *drv) +{ + drv->PaintThread(); +} + /** Forward key presses to the window system. */ static LRESULT HandleCharMsg(uint keycode, WChar charcode) { @@ -1176,7 +1181,7 @@ void VideoDriver_Win32::MainLoop() this->draw_lock = std::unique_lock<std::recursive_mutex>(*_draw_mutex); _draw_continue = true; - _draw_threaded = StartNewThread(&draw_thread, "ottd:draw-win32", &PaintWindowThread); + _draw_threaded = StartNewThread(&draw_thread, "ottd:draw-win32", &VideoDriver_Win32::PaintThreadThunk, this); /* Free the mutex if we won't be able to use it. */ if (!_draw_threaded) { @@ -1254,7 +1259,7 @@ void VideoDriver_Win32::MainLoop() if (_draw_mutex != nullptr && !HasModalProgress()) { _draw_signal->notify_one(); } else { - PaintWindow(); + this->Paint(); } } diff --git a/src/video/win32_v.h b/src/video/win32_v.h index 0a80afc4d..d51594418 100644 --- a/src/video/win32_v.h +++ b/src/video/win32_v.h @@ -47,6 +47,8 @@ protected: void InputLoop() override; bool LockVideoBuffer() override; void UnlockVideoBuffer() override; + void Paint() override; + void PaintThread() override; private: std::unique_lock<std::recursive_mutex> draw_lock; |