Index: source/lib/sysdep/gfx.h =================================================================== --- source/lib/sysdep/gfx.h +++ source/lib/sysdep/gfx.h @@ -41,16 +41,6 @@ **/ LIB_API std::wstring DriverInfo(); -/** - * (useful for choosing a new video mode) - * - * @param xres, yres (optional out) resolution [pixels] - * @param bpp (optional out) bits per pixel - * @param freq (optional out) vertical refresh rate [Hz] - * @return Status (if negative, outputs were left unchanged) - **/ -LIB_API Status GetVideoMode(int* xres, int* yres, int* bpp, int* freq); - } // namespace gfx #endif // #ifndef INCLUDED_GFX Index: source/lib/sysdep/os/android/android.cpp =================================================================== --- source/lib/sysdep/os/android/android.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (C) 2020 Wildfire Games. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include "precompiled.h" - -#include "lib/sysdep/sysdep.h" - -#include "lib/external_libraries/libsdl.h" - -namespace gfx { - -Status GetVideoMode(int* xres, int* yres, int* bpp, int* freq) -{ -#warning TODO: implement gfx::GetVideoMode properly for Android - - if(xres) - *xres = 800; - - if(yres) - *yres = 480; - - if(bpp) - *bpp = 32; - - if(freq) - *freq = 0; - - return INFO::OK; -} - -} Index: source/lib/sysdep/os/osx/osx.cpp =================================================================== --- source/lib/sysdep/os/osx/osx.cpp +++ source/lib/sysdep/os/osx/osx.cpp @@ -37,75 +37,6 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" -namespace gfx { - -Status GetVideoMode(int* xres, int* yres, int* bpp, int* freq) -{ - if(xres) - *xres = (int)CGDisplayPixelsWide(kCGDirectMainDisplay); - - if(yres) - *yres = (int)CGDisplayPixelsHigh(kCGDirectMainDisplay); - - if(bpp) - { -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 - // CGDisplayBitsPerPixel was deprecated in OS X 10.6 - if (CGDisplayCopyDisplayMode != NULL) - { - CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay); - CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(currentMode); - if (CFStringCompare(pixelEncoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) - *bpp = 32; - else if (CFStringCompare(pixelEncoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) - *bpp = 16; - else if (CFStringCompare(pixelEncoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) - *bpp = 8; - else // error - *bpp = 0; - - // We're responsible for this - CFRelease(pixelEncoding); - CGDisplayModeRelease(currentMode); - } - else - { -#endif // fallback to 10.5 API - CFDictionaryRef currentMode = CGDisplayCurrentMode(kCGDirectMainDisplay); - CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(currentMode, kCGDisplayBitsPerPixel); - CFNumberGetValue(num, kCFNumberIntType, bpp); -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 - } -#endif - } - - if(freq) - { -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 - if (CGDisplayCopyDisplayMode != NULL) - { - CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay); - *freq = (int)CGDisplayModeGetRefreshRate(currentMode); - - // We're responsible for this - CGDisplayModeRelease(currentMode); - } - else - { -#endif // fallback to 10.5 API - CFDictionaryRef currentMode = CGDisplayCurrentMode(kCGDirectMainDisplay); - CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(currentMode, kCGDisplayRefreshRate); - CFNumberGetValue(num, kCFNumberIntType, freq); -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 - } -#endif - } - - return INFO::OK; -} - -} // namespace gfx - OsPath sys_ExecutablePathname() { OsPath path; Index: source/lib/sysdep/os/unix/x/x.cpp =================================================================== --- source/lib/sysdep/os/unix/x/x.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* Copyright (C) 2020 Wildfire Games. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -// X Window System-specific code - -#include "precompiled.h" - -#if OS_LINUX || OS_BSD -# define HAVE_X 1 -#else -# define HAVE_X 0 -#endif - -#if HAVE_X - -#include "lib/debug.h" -#include "lib/utf8.h" -#include "lib/sysdep/gfx.h" - -#include "ps/VideoMode.h" - -#include -#include -#include - -#include "SDL.h" -#include "SDL_syswm.h" - -#include -#undef Status - -static Display *g_SDL_Display; -static Window g_SDL_Window; -static wchar_t *selection_data=NULL; -static size_t selection_size=0; - -namespace gfx { - -Status GetVideoMode(int* xres, int* yres, int* bpp, int* freq) -{ - Display* disp = XOpenDisplay(0); - if(!disp) - WARN_RETURN(ERR::FAIL); - - int screen = XDefaultScreen(disp); - - /* 2004-07-13 - NOTE: The XDisplayWidth/Height functions don't actually return the current - display mode - they return the size of the root window. This means that - users with "Virtual Desktops" bigger than what their monitors/graphics - card can handle will have to set their 0AD screen resolution manually. - - There's supposed to be an X extension that can give you the actual display - mode, probably including refresh rate info etc, but it's not worth - researching and implementing that at this stage. - */ - - if(xres) - *xres = XDisplayWidth(disp, screen); - if(yres) - *yres = XDisplayHeight(disp, screen); - if(bpp) - *bpp = XDefaultDepth(disp, screen); - if(freq) - *freq = 0; - XCloseDisplay(disp); - return INFO::OK; -} - -} // namespace gfx - - -static bool get_wminfo(SDL_SysWMinfo& wminfo) -{ - SDL_VERSION(&wminfo.version); - - const int ret = SDL_GetWindowWMInfo(g_VideoMode.GetWindow(), &wminfo); - - if(ret == 1) - return true; - - if(ret == -1) - { - debug_printf("SDL_GetWMInfo failed\n"); - return false; - } - if(ret == 0) - { - debug_printf("SDL_GetWMInfo is not implemented on this platform\n"); - return false; - } - - debug_printf("SDL_GetWMInfo returned an unknown value: %d\n", ret); - return false; -} - -#endif // #if HAVE_X Index: source/lib/sysdep/os/win/wgfx.cpp =================================================================== --- source/lib/sysdep/os/win/wgfx.cpp +++ source/lib/sysdep/os/win/wgfx.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -143,34 +143,3 @@ AppendDriverVersionsFromKnownFiles(versionList); return versionList; } - - -//----------------------------------------------------------------------------- -// direct implementations of some gfx functions - -namespace gfx { - -Status GetVideoMode(int* xres, int* yres, int* bpp, int* freq) -{ - DEVMODE dm = { sizeof(dm) }; - - if(!EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &dm)) - WARN_RETURN(ERR::FAIL); - - // EnumDisplaySettings is documented to set the values of the following: - const DWORD expectedFlags = DM_PELSWIDTH|DM_PELSHEIGHT|DM_BITSPERPEL|DM_DISPLAYFREQUENCY|DM_DISPLAYFLAGS; - ENSURE((dm.dmFields & expectedFlags) == expectedFlags); - - if(xres) - *xres = (int)dm.dmPelsWidth; - if(yres) - *yres = (int)dm.dmPelsHeight; - if(bpp) - *bpp = (int)dm.dmBitsPerPel; - if(freq) - *freq = (int)dm.dmDisplayFrequency; - - return INFO::OK; -} - -} // namespace gfx Index: source/ps/VideoMode.h =================================================================== --- source/ps/VideoMode.h +++ source/ps/VideoMode.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -102,7 +102,8 @@ SDL_Window* m_Window; - // Initial desktop settings + // Initial desktop settings. + // Frequency is in Hz, and BPP actually means bits per pixels (not bytes per pixels) int m_PreferredW; int m_PreferredH; int m_PreferredBPP; Index: source/ps/VideoMode.cpp =================================================================== --- source/ps/VideoMode.cpp +++ source/ps/VideoMode.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -173,7 +173,15 @@ // preferred video mode = current desktop settings // (command line params may override these) - gfx::GetVideoMode(&m_PreferredW, &m_PreferredH, &m_PreferredBPP, &m_PreferredFreq); + // TODO: handle multi-screen properly + SDL_DisplayMode mode; + if (SDL_GetDesktopDisplayMode(0, &mode) == 0) + { + m_PreferredW = mode.w; + m_PreferredH = mode.h; + m_PreferredBPP = SDL_BITSPERPIXEL(mode.format); + m_PreferredFreq = mode.refresh_rate; + } int w = m_ConfigW; int h = m_ConfigH;