# HG changeset patch # User Patric Stout # Date 2024-02-12 21:39:23 # Node ID 2657250b24e9b7d9aec433df36e87a62b13e30e9 # Parent 62e6a2924a0b46c1eed5517a7324b78881811862 Fix #10079: don't render at 1000fps if HW acceleration + vsync is requested but not active (#12067) diff --git a/src/video/cocoa/cocoa_ogl.h b/src/video/cocoa/cocoa_ogl.h --- a/src/video/cocoa/cocoa_ogl.h +++ b/src/video/cocoa/cocoa_ogl.h @@ -23,7 +23,7 @@ class VideoDriver_CocoaOpenGL : public V const char *AllocateContext(bool allow_software); public: - VideoDriver_CocoaOpenGL() : gl_context(nullptr), anim_buffer(nullptr), driver_info(this->GetName()) {} + VideoDriver_CocoaOpenGL() : VideoDriver_Cocoa(true), gl_context(nullptr), anim_buffer(nullptr), driver_info(this->GetName()) {} const char *Start(const StringList ¶m) override; void Stop() override; diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h --- a/src/video/cocoa/cocoa_v.h +++ b/src/video/cocoa/cocoa_v.h @@ -35,7 +35,7 @@ public: OTTD_CocoaWindowDelegate *delegate; //!< Window delegate object public: - VideoDriver_Cocoa(); + VideoDriver_Cocoa(bool uses_hardware_acceleration = false); void Stop() override; void MainLoop() override; diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm --- a/src/video/cocoa/cocoa_v.mm +++ b/src/video/cocoa/cocoa_v.mm @@ -87,7 +87,8 @@ static const Dimension _default_resoluti }; -VideoDriver_Cocoa::VideoDriver_Cocoa() +VideoDriver_Cocoa::VideoDriver_Cocoa(bool uses_hardware_acceleration) + : VideoDriver(uses_hardware_acceleration) { this->setup = false; this->buffer_locked = false; diff --git a/src/video/sdl2_opengl_v.h b/src/video/sdl2_opengl_v.h --- a/src/video/sdl2_opengl_v.h +++ b/src/video/sdl2_opengl_v.h @@ -12,7 +12,7 @@ /** The OpenGL video driver for windows. */ class VideoDriver_SDL_OpenGL : public VideoDriver_SDL_Base { public: - VideoDriver_SDL_OpenGL() : gl_context(nullptr), anim_buffer(nullptr) {} + VideoDriver_SDL_OpenGL() : VideoDriver_SDL_Base(true), gl_context(nullptr), anim_buffer(nullptr) {} const char *Start(const StringList ¶m) override; diff --git a/src/video/sdl2_v.h b/src/video/sdl2_v.h --- a/src/video/sdl2_v.h +++ b/src/video/sdl2_v.h @@ -17,7 +17,7 @@ /** The SDL video driver. */ class VideoDriver_SDL_Base : public VideoDriver { public: - VideoDriver_SDL_Base() : sdl_window(nullptr), buffer_locked(false) {} + VideoDriver_SDL_Base(bool uses_hardware_acceleration = false) : VideoDriver(uses_hardware_acceleration), sdl_window(nullptr), buffer_locked(false) {} const char *Start(const StringList ¶m) override; diff --git a/src/video/video_driver.cpp b/src/video/video_driver.cpp --- a/src/video/video_driver.cpp +++ b/src/video/video_driver.cpp @@ -22,8 +22,8 @@ #include "../window_func.h" #include "video_driver.hpp" -bool _video_hw_accel; ///< Whether to consider hardware accelerated video drivers. -bool _video_vsync; ///< Whether we should use vsync (only if _video_hw_accel is enabled). +bool _video_hw_accel; ///< Whether to consider hardware accelerated video drivers on startup. +bool _video_vsync; ///< Whether we should use vsync (only if active video driver supports HW acceleration). void VideoDriver::GameLoop() { diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp --- a/src/video/video_driver.hpp +++ b/src/video/video_driver.hpp @@ -35,7 +35,7 @@ class VideoDriver : public Driver { const uint DEFAULT_WINDOW_HEIGHT = 480u; ///< Default window height. public: - VideoDriver() : fast_forward_key_pressed(false), fast_forward_via_key(false), is_game_threaded(true) {} + VideoDriver(bool uses_hardware_acceleration = false) : fast_forward_key_pressed(false), fast_forward_via_key(false), is_game_threaded(true), uses_hardware_acceleration(uses_hardware_acceleration) {} /** * Mark a particular area dirty. @@ -322,7 +322,7 @@ protected: std::chrono::steady_clock::duration GetDrawInterval() { /* If vsync, draw interval is decided by the display driver */ - if (_video_vsync && _video_hw_accel) return std::chrono::microseconds(0); + if (_video_vsync && this->uses_hardware_acceleration) return std::chrono::microseconds(0); return std::chrono::microseconds(1000000 / _settings_client.gui.refresh_rate); } @@ -355,6 +355,8 @@ protected: std::mutex game_state_mutex; std::mutex game_thread_wait_mutex; + bool uses_hardware_acceleration; + static void GameThreadThunk(VideoDriver *drv); private: diff --git a/src/video/win32_v.h b/src/video/win32_v.h --- a/src/video/win32_v.h +++ b/src/video/win32_v.h @@ -18,7 +18,7 @@ /** Base class for Windows video drivers. */ class VideoDriver_Win32Base : public VideoDriver { public: - VideoDriver_Win32Base() : main_wnd(nullptr), fullscreen(false), buffer_locked(false) {} + VideoDriver_Win32Base(bool uses_hardware_acceleration = false) : VideoDriver(uses_hardware_acceleration), main_wnd(nullptr), fullscreen(false), buffer_locked(false) {} void Stop() override; @@ -118,7 +118,7 @@ public: /** The OpenGL video driver for windows. */ class VideoDriver_Win32OpenGL : public VideoDriver_Win32Base { public: - VideoDriver_Win32OpenGL() : dc(nullptr), gl_rc(nullptr), anim_buffer(nullptr), driver_info(this->GetName()) {} + VideoDriver_Win32OpenGL() : VideoDriver_Win32Base(true), dc(nullptr), gl_rc(nullptr), anim_buffer(nullptr), driver_info(this->GetName()) {} const char *Start(const StringList ¶m) override;