diff options
author | Patric Stout <truebrain@openttd.org> | 2021-01-16 15:09:04 +0100 |
---|---|---|
committer | Patric Stout <github@truebrain.nl> | 2021-01-30 21:43:59 +0100 |
commit | 6916fc76bd3f2ababefaace061b62a7aeaa4f419 (patch) | |
tree | d8c931f3f5b7412d29329b5f4a9e701f6ff87167 /src | |
parent | a52d716c88925a6a55f91276c9b4007cdb9b6795 (diff) | |
download | openttd-6916fc76bd3f2ababefaace061b62a7aeaa4f419.tar.xz |
Codechange: [SDL2] reworked FindResolutions to be more like the rest
There was no default resolution fallback, and the code was different
from the win32 driver. It is now named the same and much more
similar.
Diffstat (limited to 'src')
-rw-r--r-- | src/video/sdl2_v.cpp | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index 919208399..f4ea0dddb 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -201,26 +201,38 @@ static void DrawSurfaceToScreenThread() } } -static void GetVideoModes() -{ - int modes = SDL_GetNumDisplayModes(0); - if (modes == 0) usererror("sdl: no modes available"); +static const Dimension default_resolutions[] = { + { 640, 480 }, + { 800, 600 }, + { 1024, 768 }, + { 1152, 864 }, + { 1280, 800 }, + { 1280, 960 }, + { 1280, 1024 }, + { 1400, 1050 }, + { 1600, 1200 }, + { 1680, 1050 }, + { 1920, 1200 } +}; +static void FindResolutions() +{ _resolutions.clear(); - SDL_DisplayMode mode; - for (int i = 0; i < modes; i++) { + for (int i = 0; i < SDL_GetNumDisplayModes(0); i++) { + SDL_DisplayMode mode; SDL_GetDisplayMode(0, i, &mode); - uint w = mode.w; - uint h = mode.h; - - if (w < 640 || h < 480) continue; // reject too small resolutions + if (mode.w < 640 || mode.h < 480) continue; + if (std::find(_resolutions.begin(), _resolutions.end(), Dimension(mode.w, mode.h)) != _resolutions.end()) continue; + _resolutions.emplace_back(mode.w, mode.h); + } - if (std::find(_resolutions.begin(), _resolutions.end(), Dimension(w, h)) != _resolutions.end()) continue; - _resolutions.emplace_back(w, h); + /* We have found no resolutions, show the default list */ + if (_resolutions.empty()) { + _resolutions.assign(std::begin(default_resolutions), std::end(default_resolutions)); } - if (_resolutions.empty()) usererror("No usable screen resolutions found!\n"); + SortResolutions(); } @@ -696,7 +708,8 @@ const char *VideoDriver_SDL::Start(const StringList &parm) this->UpdateAutoResolution(); - GetVideoModes(); + FindResolutions(); + if (!CreateMainSurface(_cur_resolution.width, _cur_resolution.height, false)) { return SDL_GetError(); } |