From 6916fc76bd3f2ababefaace061b62a7aeaa4f419 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 16 Jan 2021 15:09:04 +0100 Subject: 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. --- src/video/sdl2_v.cpp | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'src/video') 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(); } -- cgit v1.2.3-70-g09d2