Fix SDL2 2.0.12 change in SDL_GetDisplayDPI (#5024)

* Fix SDL2 2.0.12 change in SDL_GetDisplayDPI

Fixes #5019

* Remove signing requirement for DEBUG Xcode builds
This commit is contained in:
Martin Hrubý 2020-08-06 06:44:39 +02:00 committed by GitHub
parent 18c487e4ff
commit 9f854e7ce8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 106 additions and 8 deletions

View file

@ -639,6 +639,7 @@ for env in [test_env, client_env, env]:
env.Append(FRAMEWORKS = "Cocoa") # Cocoa GUI
env.Append(FRAMEWORKS = "Security") # commonCrypto (after OpenSSL replacement on Mac)
env.Append(FRAMEWORKS = "IOKit") # IOKit
env.Append(FRAMEWORKS = "CoreGraphics") # CoreGraphics
if not env['static_test']:
test_env.Append(CPPDEFINES = "BOOST_TEST_DYN_LINK")

View file

@ -91,7 +91,6 @@
46685CA4219D53E90009CFFE /* tokenizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46685C7B219D51890009CFFE /* tokenizer.cpp */; };
46685CA5219D57F60009CFFE /* battery_info.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46181DD12119F74C00908BC2 /* battery_info.cpp */; };
46685CA6219D63530009CFFE /* apple_battery_info.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46181DCE2119F73A00908BC2 /* apple_battery_info.mm */; };
46685CA7219D63960009CFFE /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 46BCC904211A1E68003BDB8C /* IOKit.framework */; };
46685CA8219D63FA0009CFFE /* preprocessor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46685C6E219D51870009CFFE /* preprocessor.cpp */; };
46685CA9219D63FE0009CFFE /* binary_or_text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46685C72219D51880009CFFE /* binary_or_text.cpp */; };
46685CAA219D64050009CFFE /* parser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46685C74219D51880009CFFE /* parser.cpp */; };
@ -120,12 +119,15 @@
469853DF24D3565100B0E93B /* tournaments.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 469853D824D3565000B0E93B /* tournaments.cpp */; };
469BDB55205C357500DBF748 /* base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 469BDB53205C357400DBF748 /* base64.cpp */; };
469BDB56205C357500DBF748 /* base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 469BDB53205C357400DBF748 /* base64.cpp */; };
46A72F3D24D6F6B30033B5A9 /* apple_video.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46A72F3C24D6F6B30033B5A9 /* apple_video.mm */; };
46A72F4424D710830033B5A9 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 46A72F4224D710720033B5A9 /* IOKit.framework */; };
46A72F4524D7108A0033B5A9 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 46A72F4324D710720033B5A9 /* CoreGraphics.framework */; };
46A72F4624D7148C0033B5A9 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 46A72F4224D710720033B5A9 /* IOKit.framework */; };
46B2A7C12028DDA2006C2323 /* libpng16.16.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = EC5C243118EF07B4001FA499 /* libpng16.16.dylib */; };
46B58F4321E097900070BB8E /* parse_network_address.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46B58F4121E097900070BB8E /* parse_network_address.cpp */; };
46B58F4421E097A80070BB8E /* parse_network_address.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46B58F4121E097900070BB8E /* parse_network_address.cpp */; };
46BAF785206672250004711F /* libboost_chrono-mt-x64.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 46BAF784206672240004711F /* libboost_chrono-mt-x64.dylib */; };
46BAF787206672300004711F /* libboost_timer-mt-x64.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 46BAF786206672300004711F /* libboost_timer-mt-x64.dylib */; };
46BCC905211A1E68003BDB8C /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 46BCC904211A1E68003BDB8C /* IOKit.framework */; };
46BDBBEA217C6F6200D2820C /* lua_terrainfilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46BDBBE6217C6F6100D2820C /* lua_terrainfilter.cpp */; };
46BDBBEB217C6F6200D2820C /* lua_terrainfilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46BDBBE6217C6F6100D2820C /* lua_terrainfilter.cpp */; };
46BDBBEC217C6F6200D2820C /* lua_terrainmap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46BDBBE8217C6F6200D2820C /* lua_terrainmap.cpp */; };
@ -1469,11 +1471,14 @@
469853DA24D3565000B0E93B /* rs_base.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rs_base.hpp; sourceTree = "<group>"; };
469853DB24D3565000B0E93B /* ban_check.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ban_check.hpp; sourceTree = "<group>"; };
469BDB53205C357400DBF748 /* base64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = base64.cpp; sourceTree = "<group>"; };
46A72F3B24D6F6B30033B5A9 /* apple_video.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = apple_video.hpp; path = ../../src/desktop/apple_video.hpp; sourceTree = "<group>"; };
46A72F3C24D6F6B30033B5A9 /* apple_video.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = apple_video.mm; path = ../../src/desktop/apple_video.mm; sourceTree = "<group>"; };
46A72F4224D710720033B5A9 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
46A72F4324D710720033B5A9 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
46B58F4121E097900070BB8E /* parse_network_address.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parse_network_address.cpp; sourceTree = "<group>"; };
46B58F4221E097900070BB8E /* parse_network_address.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = parse_network_address.hpp; sourceTree = "<group>"; };
46BAF784206672240004711F /* libboost_chrono-mt-x64.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libboost_chrono-mt-x64.dylib"; path = "lib/libboost_chrono-mt-x64.dylib"; sourceTree = "<group>"; };
46BAF786206672300004711F /* libboost_timer-mt-x64.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libboost_timer-mt-x64.dylib"; path = "lib/libboost_timer-mt-x64.dylib"; sourceTree = "<group>"; };
46BCC904211A1E68003BDB8C /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
46BDBBE6217C6F6100D2820C /* lua_terrainfilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_terrainfilter.cpp; sourceTree = "<group>"; };
46BDBBE7217C6F6100D2820C /* lua_terrainfilter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_terrainfilter.hpp; sourceTree = "<group>"; };
46BDBBE8217C6F6200D2820C /* lua_terrainmap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_terrainmap.cpp; sourceTree = "<group>"; };
@ -2735,9 +2740,9 @@
buildActionMask = 2147483647;
files = (
46406DF1230DA73E0069492E /* Security.framework in Frameworks */,
46BCC905211A1E68003BDB8C /* IOKit.framework in Frameworks */,
ECA9E7471CA20AA800A947D6 /* libreadline.8.0.dylib in Frameworks */,
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
46A72F4524D7108A0033B5A9 /* CoreGraphics.framework in Frameworks */,
F4D2A99614DAED0E00CAFF31 /* CoreFoundation.framework in Frameworks */,
91B6221D1B76C0F400B00E0F /* libboost_filesystem-mt-x64.dylib in Frameworks */,
91B6221E1B76C0F400B00E0F /* libboost_iostreams-mt-x64.dylib in Frameworks */,
@ -2750,6 +2755,7 @@
91B622231B76C0F400B00E0F /* libboost_system-mt-x64.dylib in Frameworks */,
EC5C243B18EF07B4001FA499 /* libbz2.1.0.dylib in Frameworks */,
B513B2290ED36BFB0006E551 /* libcairo.2.dylib in Frameworks */,
46A72F4424D710830033B5A9 /* IOKit.framework in Frameworks */,
EC5C243C18EF07B4001FA499 /* libexpat.1.dylib in Frameworks */,
464C036F228361B7007D2741 /* libSDL2-2.0.0.dylib in Frameworks */,
EC5C243D18EF07B4001FA499 /* libffi.7.dylib in Frameworks */,
@ -2805,7 +2811,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
46685CA7219D63960009CFFE /* IOKit.framework in Frameworks */,
B597C6F30FACDE1100CE81F5 /* Cocoa.framework in Frameworks */,
B597C51D0FACD56200CE81F5 /* libcairo.2.dylib in Frameworks */,
464C037722836961007D2741 /* libSDL2_image-2.0.0.dylib in Frameworks */,
@ -2821,6 +2826,7 @@
91A215DE1CAD99E000927AEA /* libboost_filesystem-mt-x64.dylib in Frameworks */,
464C037422836957007D2741 /* libSDL2-2.0.0.dylib in Frameworks */,
464C03752283695A007D2741 /* libSDL2_ttf-2.0.0.dylib in Frameworks */,
46A72F4624D7148C0033B5A9 /* IOKit.framework in Frameworks */,
46BAF785206672250004711F /* libboost_chrono-mt-x64.dylib in Frameworks */,
46F92F242174FF6700602C1C /* libboost_thread-mt-x64.dylib in Frameworks */,
91A215DF1CAD99E000927AEA /* libboost_iostreams-mt-x64.dylib in Frameworks */,
@ -2863,6 +2869,8 @@
F40A13BB1A3A88BA00C4D071 /* apple_notification.mm */,
46F54C28211DFB9100374A1C /* apple_version.hpp */,
46F54C26211DFB7200374A1C /* apple_version.mm */,
46A72F3B24D6F6B30033B5A9 /* apple_video.hpp */,
46A72F3C24D6F6B30033B5A9 /* apple_video.mm */,
B559986A0EC616B3008DD061 /* SDLMain.h */,
B559986B0EC616B3008DD061 /* SDLMain.mm */,
);
@ -2872,9 +2880,11 @@
1058C7A0FEA54F0111CA2CBB /* Linked System Frameworks */ = {
isa = PBXGroup;
children = (
1C58BBDF21822A930078D25A /* Security.framework */,
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
F4D2A99514DAED0E00CAFF31 /* CoreFoundation.framework */,
46A72F4324D710720033B5A9 /* CoreGraphics.framework */,
46A72F4224D710720033B5A9 /* IOKit.framework */,
1C58BBDF21822A930078D25A /* Security.framework */,
);
name = "Linked System Frameworks";
sourceTree = "<group>";
@ -3199,7 +3209,6 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
46BCC904211A1E68003BDB8C /* IOKit.framework */,
46BAF784206672240004711F /* libboost_chrono-mt-x64.dylib */,
ECF9D43F19F4026D00E6C9D9 /* libboost_filesystem-mt-x64.dylib */,
F4EF0D4B13AD4D53003C701D /* libboost_iostreams-mt-x64.dylib */,
@ -3227,6 +3236,7 @@
EC5C242B18EF07B4001FA499 /* libharfbuzz.0.dylib */,
EC5C242C18EF07B4001FA499 /* libiconv.2.dylib */,
915C68F31DF1F78600594B07 /* libintl.8.dylib */,
464C0363228361B6007D2741 /* libogg.0.dylib */,
EC5C242E18EF07B4001FA499 /* libpango-1.0.0.dylib */,
EC5C242F18EF07B4001FA499 /* libpangocairo-1.0.0.dylib */,
EC5C243018EF07B4001FA499 /* libpangoft2-1.0.0.dylib */,
@ -3234,7 +3244,6 @@
B513B2280ED36BFB0006E551 /* libpixman-1.0.dylib */,
EC5C243118EF07B4001FA499 /* libpng16.16.dylib */,
ECA9E7461CA20AA800A947D6 /* libreadline.8.0.dylib */,
464C0363228361B6007D2741 /* libogg.0.dylib */,
464C0362228361B5007D2741 /* libSDL2_image-2.0.0.dylib */,
464C0368228361B7007D2741 /* libSDL2_mixer-2.0.0.dylib */,
464C0365228361B6007D2741 /* libSDL2_net-2.0.0.dylib */,
@ -5347,6 +5356,7 @@
ECAB84581B0C1934001A3EB7 /* undo_move_action.cpp in Sources */,
46F92EDF2174FD9900602C1C /* button.cpp in Sources */,
ECAB84591B0C1934001A3EB7 /* undo_recall_action.cpp in Sources */,
46A72F3D24D6F6B30033B5A9 /* apple_video.mm in Sources */,
ECAB845A1B0C1934001A3EB7 /* undo_recruit_action.cpp in Sources */,
46F92DC32174F6A300602C1C /* depcheck_select_new.cpp in Sources */,
ECAB845B1B0C1934001A3EB7 /* undo_update_shroud_action.cpp in Sources */,

View file

@ -0,0 +1,23 @@
/*
Copyright (C) 2020 by Martin Hrubý <hrubymar10@gmail.com>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
#include <CoreGraphics/CoreGraphics.h>
namespace desktop {
namespace apple {
CGFloat get_scale_factor(int display_index);
} // end namespace apple
} // end namespace desktop

View file

@ -0,0 +1,41 @@
/*
Copyright (C) 2020 by Martin Hrubý <hrubymar10@gmail.com>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifdef __APPLE__
#include <TargetConditionals.h>
#ifdef TARGET_OS_OSX
#include "apple_video.hpp"
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
namespace desktop {
namespace apple {
CGFloat get_scale_factor(int display_index) {
CGFloat scale_factor = 1.0f;
NSArray *screens = [NSScreen screens];
if ([screens[display_index] respondsToSelector:@selector(backingScaleFactor)]) { // Mac OS X 10.7 and later
scale_factor = [screens[display_index] backingScaleFactor];
}
return scale_factor;
}
} // end namespace apple
} // end namespace desktop
#endif //end TARGET_OS_OSX
#endif //end __APPLE__

View file

@ -25,6 +25,11 @@
#include "sdl/utils.hpp"
#include "sdl/window.hpp"
#ifdef TARGET_OS_OSX
#include "desktop/apple_video.hpp"
#include "game_version.hpp"
#endif
#include <cassert>
#include <vector>
@ -404,6 +409,24 @@ std::pair<float, float> CVideo::get_dpi() const
{
float hdpi, vdpi;
if(window && SDL_GetDisplayDPI(window->get_display_index(), nullptr, &hdpi, &vdpi) == 0) {
#ifdef TARGET_OS_OSX
// SDL 2.0.12 changes SDL_GetDisplayDPI. Function now returns DPI
// multiplied by screen's scale factor. This part of code reverts
// this multiplication.
//
// For more info see issue: https://github.com/wesnoth/wesnoth/issues/5019
SDL_version sdl_version;
SDL_GetVersion(&sdl_version);
const version_info sdl_version_info(sdl_version.major, sdl_version.minor, sdl_version.patch);
const version_info version_to_compare(2, 0, 12);
if (sdl_version_info >= version_to_compare) {
float scale_factor = desktop::apple::get_scale_factor(window->get_display_index());
hdpi /= scale_factor;
vdpi /= scale_factor;
}
#endif
return { hdpi, vdpi };
}
// SDL doesn't know the screen dpi, there's a configuration issue, or we