Changeset - r28750:2657250b24e9
[Not reviewed]
master
0 8 0
Patric Stout - 3 months ago 2024-02-12 21:39:23
truebrain@openttd.org
Fix #10079: don't render at 1000fps if HW acceleration + vsync is requested but not active (#12067)
8 files changed with 14 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/video/cocoa/cocoa_ogl.h
Show inline comments
 
@@ -20,13 +20,13 @@ class VideoDriver_CocoaOpenGL : public V
 
	uint8_t *anim_buffer; ///< Animation buffer from OpenGL back-end.
 
	std::string driver_info; ///< Information string about selected driver.
 

	
 
	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 &param) override;
 
	void Stop() override;
 

	
 
	bool HasEfficient8Bpp() const override { return true; }
 

	
src/video/cocoa/cocoa_v.h
Show inline comments
 
@@ -32,13 +32,13 @@ public:
 
	OTTD_CocoaView *cocoaview;   ///< Pointer to view object
 
	CGColorSpaceRef color_space; ///< Window color space
 

	
 
	OTTD_CocoaWindowDelegate *delegate; //!< Window delegate object
 

	
 
public:
 
	VideoDriver_Cocoa();
 
	VideoDriver_Cocoa(bool uses_hardware_acceleration = false);
 

	
 
	void Stop() override;
 
	void MainLoop() override;
 

	
 
	void MakeDirty(int left, int top, int width, int height) override;
 
	bool AfterBlitterChange() override;
src/video/cocoa/cocoa_v.mm
Show inline comments
 
@@ -84,13 +84,14 @@ static const Dimension _default_resoluti
 
	{ 1680, 1050 },
 
	{ 1920, 1200 },
 
	{ 2560, 1440 }
 
};
 

	
 

	
 
VideoDriver_Cocoa::VideoDriver_Cocoa()
 
VideoDriver_Cocoa::VideoDriver_Cocoa(bool uses_hardware_acceleration)
 
	: VideoDriver(uses_hardware_acceleration)
 
{
 
	this->setup         = false;
 
	this->buffer_locked = false;
 

	
 
	this->refresh_sys_sprites = true;
 

	
src/video/sdl2_opengl_v.h
Show inline comments
 
@@ -9,13 +9,13 @@
 

	
 
#include "sdl2_v.h"
 

	
 
/** 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 &param) override;
 

	
 
	void Stop() override;
 

	
 
	bool HasEfficient8Bpp() const override { return true; }
src/video/sdl2_v.h
Show inline comments
 
@@ -14,13 +14,13 @@
 

	
 
#include "video_driver.hpp"
 

	
 
/** 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 &param) override;
 

	
 
	void Stop() override;
 

	
 
	void MakeDirty(int left, int top, int width, int height) override;
src/video/video_driver.cpp
Show inline comments
 
@@ -19,14 +19,14 @@
 
#include "../progress.h"
 
#include "../rev.h"
 
#include "../thread.h"
 
#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()
 
{
 
	this->next_game_tick += this->GetGameInterval();
 

	
 
	/* Avoid next_game_tick getting behind more and more if it cannot keep up. */
src/video/video_driver.hpp
Show inline comments
 
@@ -32,13 +32,13 @@ extern bool _video_vsync;
 
/** The base of all video drivers. */
 
class VideoDriver : public Driver {
 
	const uint DEFAULT_WINDOW_WIDTH = 640u;  ///< Default window width.
 
	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.
 
	 * @param left   The left most line of the dirty area.
 
	 * @param top    The top most line of the dirty area.
 
	 * @param width  The width of the dirty area.
 
@@ -319,13 +319,13 @@ protected:
 
		return std::chrono::microseconds(MILLISECONDS_PER_TICK * 1000 * 100 / _game_speed);
 
	}
 

	
 
	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);
 
	}
 

	
 
	/** Execute all queued commands. */
 
	void DrainCommandQueue()
 
	{
 
@@ -352,12 +352,14 @@ protected:
 

	
 
	bool is_game_threaded;
 
	std::thread game_thread;
 
	std::mutex game_state_mutex;
 
	std::mutex game_thread_wait_mutex;
 

	
 
	bool uses_hardware_acceleration;
 

	
 
	static void GameThreadThunk(VideoDriver *drv);
 

	
 
private:
 
	std::mutex cmd_queue_mutex;
 
	std::vector<std::function<void()>> cmd_queue;
 

	
src/video/win32_v.h
Show inline comments
 
@@ -15,13 +15,13 @@
 
#include <condition_variable>
 
#include <windows.h>
 

	
 
/** 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;
 

	
 
	void MakeDirty(int left, int top, int width, int height) override;
 

	
 
	void MainLoop() override;
 
@@ -115,13 +115,13 @@ public:
 

	
 
#ifdef WITH_OPENGL
 

	
 
/** 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 &param) override;
 

	
 
	void Stop() override;
 

	
 
	bool ToggleFullscreen(bool fullscreen) override;
0 comments (0 inline, 0 general)