diff options
author | sean <43609023+spnda@users.noreply.github.com> | 2021-03-09 10:22:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-09 10:22:52 +0100 |
commit | 0464a50ab8f5f6c7028da80cb0d579cdfc84717a (patch) | |
tree | 2bacc79fb89d9140f7edcca56a5cf82a943f3524 /src/video | |
parent | 64a8c38d2f08de5aee6315e5746cbe5ec73da9e3 (diff) | |
download | openttd-0464a50ab8f5f6c7028da80cb0d579cdfc84717a.tar.xz |
Add: Display refresh rate game option (#8813)
Diffstat (limited to 'src/video')
-rw-r--r-- | src/video/allegro_v.cpp | 10 | ||||
-rw-r--r-- | src/video/allegro_v.h | 2 | ||||
-rw-r--r-- | src/video/cocoa/cocoa_v.h | 2 | ||||
-rw-r--r-- | src/video/cocoa/cocoa_v.mm | 25 | ||||
-rw-r--r-- | src/video/sdl2_v.cpp | 11 | ||||
-rw-r--r-- | src/video/sdl2_v.h | 2 | ||||
-rw-r--r-- | src/video/video_driver.hpp | 9 | ||||
-rw-r--r-- | src/video/win32_v.cpp | 21 | ||||
-rw-r--r-- | src/video/win32_v.h | 2 |
9 files changed, 84 insertions, 0 deletions
diff --git a/src/video/allegro_v.cpp b/src/video/allegro_v.cpp index 0c064873b..3d8ca65aa 100644 --- a/src/video/allegro_v.cpp +++ b/src/video/allegro_v.cpp @@ -236,6 +236,16 @@ bool VideoDriver_Allegro::ClaimMousePointer() return true; } +std::vector<int> VideoDriver_Allegro::GetListOfMonitorRefreshRates() +{ + std::vector<int> rates = {}; + + int refresh_rate = get_refresh_rate(); + if (refresh_rate != 0) rates.push_back(refresh_rate); + + return rates; +} + struct AllegroVkMapping { uint16 vk_from; byte vk_count; diff --git a/src/video/allegro_v.h b/src/video/allegro_v.h index d67778b7f..d1576fea9 100644 --- a/src/video/allegro_v.h +++ b/src/video/allegro_v.h @@ -31,6 +31,8 @@ public: bool ClaimMousePointer() override; + std::vector<int> GetListOfMonitorRefreshRates() override; + const char *GetName() const override { return "allegro"; } protected: diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h index 371e4b5bc..3d3db5454 100644 --- a/src/video/cocoa/cocoa_v.h +++ b/src/video/cocoa/cocoa_v.h @@ -47,6 +47,8 @@ public: void EditBoxLostFocus() override; + std::vector<int> GetListOfMonitorRefreshRates() override; + /* --- The following methods should be private, but can't be due to Obj-C limitations. --- */ void MainLoopReal(); diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm index 8d1fd4447..9fb74cd04 100644 --- a/src/video/cocoa/cocoa_v.mm +++ b/src/video/cocoa/cocoa_v.mm @@ -43,6 +43,7 @@ #import <sys/param.h> /* for MAXPATHLEN */ #import <sys/time.h> /* gettimeofday */ +#include <array> /** * Important notice regarding all modifications!!!!!!! @@ -229,6 +230,30 @@ void VideoDriver_Cocoa::EditBoxLostFocus() } /** + * Get refresh rates of all connected monitors. + */ +std::vector<int> VideoDriver_Cocoa::GetListOfMonitorRefreshRates() +{ + std::vector<int> rates{}; + + if (MacOSVersionIsAtLeast(10, 6, 0)) { + std::array<CGDirectDisplayID, 16> displays; + + uint32_t count = 0; + CGGetActiveDisplayList(displays.size(), displays.data(), &count); + + for (uint32_t i = 0; i < count; i++) { + CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displays[i]); + int rate = (int)CGDisplayModeGetRefreshRate(mode); + if (rate > 0) rates.push_back(rate); + CGDisplayModeRelease(mode); + } + } + + return rates; +} + +/** * Get the resolution of the main screen. */ Dimension VideoDriver_Cocoa::GetScreenSize() const diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index 62675280c..2d8558534 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -237,6 +237,17 @@ void VideoDriver_SDL_Base::EditBoxLostFocus() } } +std::vector<int> VideoDriver_SDL_Base::GetListOfMonitorRefreshRates() +{ + std::vector<int> rates = {}; + for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) { + SDL_DisplayMode mode = {}; + if (SDL_GetDisplayMode(i, 0, &mode) != 0) continue; + if (mode.refresh_rate != 0) rates.push_back(mode.refresh_rate); + } + return rates; +} + struct SDLVkMapping { SDL_Keycode vk_from; diff --git a/src/video/sdl2_v.h b/src/video/sdl2_v.h index b1a64dd9c..bd43f71f8 100644 --- a/src/video/sdl2_v.h +++ b/src/video/sdl2_v.h @@ -39,6 +39,8 @@ public: void EditBoxLostFocus() override; + std::vector<int> GetListOfMonitorRefreshRates() override; + const char *GetName() const override { return "sdl"; } protected: diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp index 4b2de253a..8c2b9d437 100644 --- a/src/video/video_driver.hpp +++ b/src/video/video_driver.hpp @@ -150,6 +150,15 @@ public: virtual void EditBoxGainedFocus() {} /** + * Get a list of refresh rates of each available monitor. + * @return A vector of the refresh rates of all available monitors. + */ + virtual std::vector<int> GetListOfMonitorRefreshRates() + { + return {}; + } + + /** * Get a suggested default GUI zoom taking screen DPI into account. */ virtual ZoomLevel GetSuggestedUIZoom() diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index 8030380ce..a802cdafa 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -916,6 +916,27 @@ void VideoDriver_Win32Base::EditBoxLostFocus() SetCandidatePos(this->main_wnd); } +std::vector<int> VideoDriver_Win32Base::GetListOfMonitorRefreshRates() +{ + std::vector<int> rates = {}; + EnumDisplayMonitors(nullptr, nullptr, [](HMONITOR hMonitor, HDC hDC, LPRECT rc, LPARAM data) -> BOOL { + auto &list = *reinterpret_cast<std::vector<int>*>(data); + + MONITORINFOEX monitorInfo = {}; + monitorInfo.cbSize = sizeof(MONITORINFOEX); + GetMonitorInfo(hMonitor, &monitorInfo); + + DEVMODE devMode = {}; + devMode.dmSize = sizeof(DEVMODE); + devMode.dmDriverExtra = 0; + EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode); + + if (devMode.dmDisplayFrequency != 0) list.push_back(devMode.dmDisplayFrequency); + return true; + }, reinterpret_cast<LPARAM>(&rates)); + return rates; +} + Dimension VideoDriver_Win32Base::GetScreenSize() const { return { static_cast<uint>(GetSystemMetrics(SM_CXSCREEN)), static_cast<uint>(GetSystemMetrics(SM_CYSCREEN)) }; diff --git a/src/video/win32_v.h b/src/video/win32_v.h index 93ebdd83e..f6ca291f1 100644 --- a/src/video/win32_v.h +++ b/src/video/win32_v.h @@ -33,6 +33,8 @@ public: void EditBoxLostFocus() override; + std::vector<int> GetListOfMonitorRefreshRates() override; + protected: HWND main_wnd; ///< Handle to system window. bool fullscreen; ///< Whether to use (true) fullscreen mode. |