OpenTTD Source 20261112-master-gbcbec5e63f
VideoDriver_Win32Base Class Referenceabstract

Base class for Windows video drivers. More...

#include <win32_v.h>

Inheritance diagram for VideoDriver_Win32Base:
VideoDriver Driver VideoDriver_Win32D3D11 VideoDriver_Win32GDI

Public Member Functions

 VideoDriver_Win32Base (bool uses_hardware_acceleration=false, bool supports_animation_buffer=false)
 Create the video driver.
void Stop () override
 Stop this driver.
void MakeDirty (int left, int top, int width, int height) override
 Mark a particular area dirty.
void MainLoop () override
 Perform the actual drawing.
bool ChangeResolution (int w, int h) override
 Change the resolution of the window.
bool ToggleFullscreen (bool fullscreen) override
 Change the full screen setting.
void ClaimMousePointer () override
 Claim the exclusive rights for the mouse pointer.
void EditBoxLostFocus () override
 An edit box lost the input focus.
std::vector< int > GetListOfMonitorRefreshRates () override
 Get a list of refresh rates of each available monitor.
Public Member Functions inherited from VideoDriver
 VideoDriver (bool uses_hardware_acceleration=false, bool supports_animation_buffer=false)
 Create the video driver.
virtual void ToggleVsync (bool vsync)
 Change the vsync setting.
virtual bool AfterBlitterChange ()
 Callback invoked after the blitter was changed.
virtual bool UseSystemCursor ()
 Get whether the mouse cursor is drawn by the video driver.
virtual void PopulateSystemSprites ()
 Populate all sprites in cache.
virtual void ClearSystemSprites ()
 Clear all cached sprites.
virtual bool HasGUI () const
 Whether the driver has a graphical user interface with the end user.
virtual bool HasEfficient8Bpp () const
 Has this video driver an efficient code path for palette animated 8-bpp sprites?
constexpr bool SupportsAnimationBuffer () const
 Does this video driver support a separate animation buffer in addition to the colour buffer?
constexpr uint8_t * GetAnimBuffer () const
 Get a pointer to the animation buffer of the video back-end.
constexpr int GetAnimBufferPitch () const
 Get the animation buffer pitch in uint8_t elements per row.
virtual void EditBoxGainedFocus ()
 An edit box gained the input focus.
virtual std::string_view GetInfoString () const
 Get some information about the selected driver/backend to be shown to the user.
void QueueOnMainThread (std::function< void()> &&func)
 Queue a function to be called on the main thread with game state lock held and video buffer locked.
void GameLoopPause ()
 Pause the game-loop for a bit, releasing the game-state lock.
virtual void SetScreensaverInhibited (bool inhibited)
 Prevents the system from going to sleep.
Public Member Functions inherited from Driver
virtual std::optional< std::string_view > Start (const StringList &parm)=0
 Start this driver.
virtual ~Driver ()=default
 Ensure the destructor of the sub classes are called as well.
virtual std::string_view GetName () const =0
 Get the name of this driver.

Protected Member Functions

Dimension GetScreenSize () const override
 Get the resolution of the main screen.
void InputLoop () override
 Handle input logic, is CTRL pressed, should we fast-forward, etc.
bool LockVideoBuffer () override
 Make sure the video buffer is ready for drawing.
void UnlockVideoBuffer () override
 Unlock a previously locked video buffer.
void CheckPaletteAnim () override
 Process any pending palette animation.
bool PollEvent () override
 Process a single system event.
std::optional< std::string_view > Initialize ()
bool MakeWindow (bool full_screen, bool resize=true)
 Instantiate a new window.
void ClientSizeChanged (int w, int h, bool force=false)
 Indicate to the driver the client-size might have changed.
virtual uint8_t GetFullscreenBpp ()
 Colour depth to use for fullscreen display modes.
virtual bool AllocateBackingStore (int w, int h, bool force=false)=0
 (Re-)create the backing store.
virtual void * GetVideoPointer ()=0
 Get a pointer to the video buffer.
virtual void ReleaseVideoPointer ()
 Hand video buffer back to the painting backend.
virtual void PaletteChanged (HWND hWnd)=0
 Palette of the window has changed.
virtual bool MinimiseRestoreWithToggleFullscreen () const
 Whether minimising and restoring fullscreen windows uses ToggleFullscreen.
Protected Member Functions inherited from VideoDriver
void UpdateAutoResolution ()
 Apply resolution auto-detection and clamp to sensible defaults.
virtual void Paint ()
 Paint the window.
void StartGameThread ()
 Start the loop for game-tick.
void StopGameThread ()
 Stop the loop for the game-tick.
void Tick ()
 Give the video-driver a tick.
void SleepTillNextTick ()
 Sleep till the next tick is about to happen.
std::chrono::steady_clock::duration GetGameInterval ()
std::chrono::steady_clock::duration GetDrawInterval ()
void DrainCommandQueue ()
 Execute all queued commands.

Protected Attributes

HWND main_wnd = nullptr
 Handle to system window.
bool fullscreen = false
 Whether to use (true) fullscreen mode.
bool has_focus = false
 Does our window have system focus?
Rect dirty_rect
 Region of the screen that needs redrawing.
int width = 0
 Width in pixels of our display surface.
int height = 0
 Height in pixels of our display surface.
int width_org = 0
 Original monitor resolution width, before we changed it.
int height_org = 0
 Original monitor resolution height, before we changed it.
bool buffer_locked = false
 Video buffer was locked by the main thread.
Palette local_palette
 Current palette to use for drawing.
Protected Attributes inherited from VideoDriver
const uint ALLOWED_DRIFT = 5
 How many times videodriver can miss deadlines without it being overly compensated.
std::chrono::steady_clock::time_point next_game_tick
std::chrono::steady_clock::time_point next_draw_tick
std::thread game_thread
std::mutex game_state_mutex
std::mutex game_thread_wait_mutex
uint8_t * anim_buffer = nullptr
 The animation buffer if supported/used.
int anim_pitch = 0
 Pitch of the animation buffer if supported/used.
const bool uses_hardware_acceleration
 Whether hardware acceleration is used or not.
const bool supports_animation_buffer
 Whether this driver supports hardware accelerated animation.
bool fast_forward_key_pressed = false
 The fast-forward key is being pressed.
bool fast_forward_via_key = false
 The fast-forward was enabled by key press.
bool is_game_threaded = true
 Whether the game is allowed to use threads; cleared in the driver implementation constructors if required.

Friends

LRESULT WndProcGdi (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)

Additional Inherited Members

Public Types inherited from Driver
enum class  Type : uint8_t {
  Begin = 0 , Music = 0 , Sound , Video ,
  End
}
 The type of driver. More...
Static Public Member Functions inherited from VideoDriver
static VideoDriver * GetInstance ()
 Get the currently active instance of the video driver.
static std::string GetCaption ()
 Get the caption to use for the game's title bar.
Static Protected Member Functions inherited from VideoDriver
static void GameThreadThunk (VideoDriver *drv)

Detailed Description

Base class for Windows video drivers.

Definition at line 17 of file win32_v.h.

Constructor & Destructor Documentation

◆ VideoDriver_Win32Base()

VideoDriver_Win32Base::VideoDriver_Win32Base ( bool uses_hardware_acceleration = false,
bool supports_animation_buffer = false )
inline

Create the video driver.

Parameters
uses_hardware_accelerationWhether hardware acceleration is used by this driver.
supports_animation_bufferWhether this driver supports a hardware accelerated animation buffer.

Definition at line 24 of file win32_v.h.

References VideoDriver::supports_animation_buffer, VideoDriver::uses_hardware_acceleration, and VideoDriver::VideoDriver().

Referenced by VideoDriver_Win32D3D11::VideoDriver_Win32D3D11().

Member Function Documentation

◆ AllocateBackingStore()

virtual bool VideoDriver_Win32Base::AllocateBackingStore ( int w,
int h,
bool force = false )
protectedpure virtual

(Re-)create the backing store.

Parameters
wThe width of the window.
hThe height of the window.
forceWhether to force full reallocation, instead of not reallocating when size did not change.
Returns
Whether the backing store was (re-)created.

Implemented in VideoDriver_Win32D3D11, and VideoDriver_Win32GDI.

Referenced by ClientSizeChanged().

◆ ChangeResolution()

bool VideoDriver_Win32Base::ChangeResolution ( int w,
int h )
overridevirtual

Change the resolution of the window.

Parameters
wThe new width.
hThe new height.
Returns
True if the change succeeded.

Implements VideoDriver.

Reimplemented in VideoDriver_Win32D3D11.

Definition at line 1115 of file win32_v.cpp.

References _window_maximize, height, height_org, main_wnd, MakeWindow(), width, and width_org.

Referenced by MakeWindow().

◆ CheckPaletteAnim()

void VideoDriver_Win32Base::CheckPaletteAnim ( )
overrideprotectedvirtual

Process any pending palette animation.

Reimplemented from VideoDriver.

Definition at line 1040 of file win32_v.cpp.

References CopyPalette(), local_palette, and MakeDirty().

◆ ClaimMousePointer()

void VideoDriver_Win32Base::ClaimMousePointer ( )
overridevirtual

Claim the exclusive rights for the mouse pointer.

Reimplemented from VideoDriver.

Definition at line 62 of file win32_v.cpp.

◆ ClientSizeChanged()

void VideoDriver_Win32Base::ClientSizeChanged ( int w,
int h,
bool force = false )
protected

Indicate to the driver the client-size might have changed.

Parameters
wThe new width of the window.
hThe new height of the window.
forceWhether to force full reallocation, instead of not reallocating when size did not change.

Definition at line 1103 of file win32_v.cpp.

References AllocateBackingStore(), CopyPalette(), GameSizeChanged(), BlitterFactory::GetCurrentBlitter(), local_palette, and Blitter::PostResize().

Referenced by VideoDriver_Win32D3D11::AfterBlitterChange(), and VideoDriver_Win32D3D11::Start().

◆ EditBoxLostFocus()

void VideoDriver_Win32Base::EditBoxLostFocus ( )
overridevirtual

An edit box lost the input focus.

Abort character compositing if necessary.

Reimplemented from VideoDriver.

Definition at line 1133 of file win32_v.cpp.

References CancelIMEComposition(), main_wnd, SetCandidatePos(), and SetCompositionPos().

◆ GetFullscreenBpp()

uint8_t VideoDriver_Win32Base::GetFullscreenBpp ( )
protectedvirtual

Colour depth to use for fullscreen display modes.

Returns
The colour depth in bits per pixel.

Reimplemented in VideoDriver_Win32D3D11.

Definition at line 138 of file win32_v.cpp.

References _support8bpp, BlitterFactory::GetCurrentBlitter(), Blitter::GetScreenDepth(), and Hardware.

Referenced by MakeWindow().

◆ GetListOfMonitorRefreshRates()

std::vector< int > VideoDriver_Win32Base::GetListOfMonitorRefreshRates ( )
overridevirtual

Get a list of refresh rates of each available monitor.

Returns
A vector of the refresh rates of all available monitors.

Reimplemented from VideoDriver.

Definition at line 1157 of file win32_v.cpp.

◆ GetScreenSize()

Dimension VideoDriver_Win32Base::GetScreenSize ( ) const
overrideprotectedvirtual

Get the resolution of the main screen.

Returns
The dimension of the screen in pixels.

Reimplemented from VideoDriver.

Definition at line 1164 of file win32_v.cpp.

◆ GetVideoPointer()

virtual void * VideoDriver_Win32Base::GetVideoPointer ( )
protectedpure virtual

Get a pointer to the video buffer.

Returns
The pointer.

Implemented in VideoDriver_Win32D3D11, and VideoDriver_Win32GDI.

Referenced by LockVideoBuffer().

◆ Initialize()

std::optional< std::string_view > VideoDriver_Win32Base::Initialize ( )
protected

Definition at line 1009 of file win32_v.cpp.

◆ InputLoop()

void VideoDriver_Win32Base::InputLoop ( )
overrideprotectedvirtual

Handle input logic, is CTRL pressed, should we fast-forward, etc.

Reimplemented from VideoDriver.

Definition at line 1046 of file win32_v.cpp.

References _dirkeys, _input_pressed, Ctrl, Down, VideoDriver::fast_forward_key_pressed, HandleCtrlChanged(), has_focus, IsCtrlPressed(), Left, Right, Shift, and Up.

◆ LockVideoBuffer()

bool VideoDriver_Win32Base::LockVideoBuffer ( )
overrideprotectedvirtual

Make sure the video buffer is ready for drawing.

Returns
True if the video buffer has to be unlocked.

Reimplemented from VideoDriver.

Definition at line 1169 of file win32_v.cpp.

References buffer_locked, and GetVideoPointer().

◆ MainLoop()

void VideoDriver_Win32Base::MainLoop ( )
overridevirtual

Perform the actual drawing.

Implements VideoDriver.

Definition at line 1083 of file win32_v.cpp.

References VideoDriver::SleepTillNextTick(), VideoDriver::StartGameThread(), VideoDriver::StopGameThread(), and VideoDriver::Tick().

◆ MakeDirty()

void VideoDriver_Win32Base::MakeDirty ( int left,
int top,
int width,
int height )
overridevirtual

Mark a particular area dirty.

Parameters
leftThe left most line of the dirty area.
topThe top most line of the dirty area.
widthThe width of the dirty area.
heightThe height of the dirty area.

Implements VideoDriver.

Definition at line 1034 of file win32_v.cpp.

References BoundingRect(), dirty_rect, height, and width.

Referenced by CheckPaletteAnim(), and VideoDriver_Win32GDI::PaletteChanged().

◆ MakeWindow()

bool VideoDriver_Win32Base::MakeWindow ( bool full_screen,
bool resize = true )
protected

Instantiate a new window.

Parameters
full_screenWhether to make a full screen window or not.
resizeWhether to change window size.
Returns
True if the window could be created.

Definition at line 150 of file win32_v.cpp.

References _window_maximize, ChangeResolution(), fullscreen, GameSizeChanged(), VideoDriver::GetCaption(), BlitterFactory::GetCurrentBlitter(), GetFullscreenBpp(), height, height_org, main_wnd, MakeWindow(), OTTD2FS(), Blitter::PostResize(), settings, width, and width_org.

Referenced by VideoDriver_Win32GDI::AfterBlitterChange(), ChangeResolution(), MakeWindow(), VideoDriver_Win32D3D11::Start(), VideoDriver_Win32GDI::Start(), and ToggleFullscreen().

◆ MinimiseRestoreWithToggleFullscreen()

virtual bool VideoDriver_Win32Base::MinimiseRestoreWithToggleFullscreen ( ) const
inlineprotectedvirtual

Whether minimising and restoring fullscreen windows uses ToggleFullscreen.

Returns
True if ToggleFullscreen should be used.

Reimplemented in VideoDriver_Win32D3D11.

Definition at line 97 of file win32_v.h.

Referenced by Stop().

◆ PaletteChanged()

virtual void VideoDriver_Win32Base::PaletteChanged ( HWND hWnd)
protectedpure virtual

Palette of the window has changed.

Parameters
hWndThe window handle of the changed window.

Implemented in VideoDriver_Win32D3D11, and VideoDriver_Win32GDI.

◆ PollEvent()

bool VideoDriver_Win32Base::PollEvent ( )
overrideprotectedvirtual

Process a single system event.

Returns
False if there are no more events to process.

Reimplemented from VideoDriver.

Definition at line 1070 of file win32_v.cpp.

References EditBoxInGlobalFocus().

◆ ReleaseVideoPointer()

virtual void VideoDriver_Win32Base::ReleaseVideoPointer ( )
inlineprotectedvirtual

Hand video buffer back to the painting backend.

Reimplemented in VideoDriver_Win32D3D11.

Definition at line 85 of file win32_v.h.

Referenced by UnlockVideoBuffer().

◆ Stop()

void VideoDriver_Win32Base::Stop ( )
overridevirtual

Stop this driver.

Implements Driver.

Reimplemented in VideoDriver_Win32D3D11, and VideoDriver_Win32GDI.

Definition at line 1027 of file win32_v.cpp.

References fullscreen, main_wnd, and MinimiseRestoreWithToggleFullscreen().

Referenced by VideoDriver_Win32D3D11::Stop(), and VideoDriver_Win32GDI::Stop().

◆ ToggleFullscreen()

bool VideoDriver_Win32Base::ToggleFullscreen ( bool fullscreen)
overridevirtual

Change the full screen setting.

Parameters
fullscreenThe new setting.
Returns
True if the change succeeded.

Implements VideoDriver.

Reimplemented in VideoDriver_Win32D3D11.

Definition at line 1125 of file win32_v.cpp.

References InvalidateWindowClassesData(), and MakeWindow().

◆ UnlockVideoBuffer()

void VideoDriver_Win32Base::UnlockVideoBuffer ( )
overrideprotectedvirtual

Unlock a previously locked video buffer.

Reimplemented from VideoDriver.

Definition at line 1180 of file win32_v.cpp.

References buffer_locked, and ReleaseVideoPointer().

◆ WndProcGdi

LRESULT WndProcGdi ( HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam )
friend

Definition at line 522 of file win32_v.cpp.

Field Documentation

◆ buffer_locked

bool VideoDriver_Win32Base::buffer_locked = false
protected

Video buffer was locked by the main thread.

Definition at line 53 of file win32_v.h.

Referenced by LockVideoBuffer(), and UnlockVideoBuffer().

◆ dirty_rect

Rect VideoDriver_Win32Base::dirty_rect
protected

Region of the screen that needs redrawing.

Definition at line 47 of file win32_v.h.

Referenced by VideoDriver_Win32D3D11::AllocateBackingStore(), MakeDirty(), VideoDriver_Win32GDI::Paint(), and VideoDriver_Win32D3D11::ReleaseVideoPointer().

◆ fullscreen

bool VideoDriver_Win32Base::fullscreen = false
protected

Whether to use (true) fullscreen mode.

Definition at line 45 of file win32_v.h.

Referenced by MakeWindow(), Stop(), and VideoDriver_Win32D3D11::ToggleFullscreen().

◆ has_focus

bool VideoDriver_Win32Base::has_focus = false
protected

Does our window have system focus?

Definition at line 46 of file win32_v.h.

Referenced by InputLoop().

◆ height

◆ height_org

int VideoDriver_Win32Base::height_org = 0
protected

Original monitor resolution height, before we changed it.

Definition at line 51 of file win32_v.h.

Referenced by ChangeResolution(), and MakeWindow().

◆ local_palette

Palette VideoDriver_Win32Base::local_palette
protected

Current palette to use for drawing.

Definition at line 54 of file win32_v.h.

Referenced by CheckPaletteAnim(), ClientSizeChanged(), VideoDriver_Win32D3D11::Paint(), and VideoDriver_Win32GDI::Paint().

◆ main_wnd

HWND VideoDriver_Win32Base::main_wnd = nullptr
protected

◆ width

◆ width_org

int VideoDriver_Win32Base::width_org = 0
protected

Original monitor resolution width, before we changed it.

Definition at line 50 of file win32_v.h.

Referenced by ChangeResolution(), and MakeWindow().


The documentation for this class was generated from the following files: