Browse Source

Platform: query DPI awareness on Apple and warn if not set.

I'm not really sure if the extra work and link dependencies are worth
the warning, but since I *need* to do something similar for Windows, why
not have it here as well.
pull/272/head
Vladimír Vondruš 8 years ago
parent
commit
769bc0da90
  1. 10
      modules/FindMagnum.cmake
  2. 14
      src/Magnum/Platform/CMakeLists.txt
  3. 12
      src/Magnum/Platform/Implementation/dpiScaling.hpp
  4. 40
      src/Magnum/Platform/Implementation/dpiScaling.mm
  5. 9
      src/Magnum/Platform/Sdl2Application.cpp
  6. 4
      src/Magnum/Platform/Test/CMakeLists.txt
  7. 20
      src/Magnum/Platform/Test/Sdl2ApplicationTest.plist

10
modules/FindMagnum.cmake

@ -639,8 +639,14 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
find_package(SDL2) find_package(SDL2)
set_property(TARGET Magnum::${_component} APPEND PROPERTY set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES SDL2::SDL2) INTERFACE_LINK_LIBRARIES SDL2::SDL2)
if(CORRADE_TARGET_UNIX AND NOT CORRADE_TARGET_APPLE) # Use the Foundation framework on Apple to query the DPI awareness
# Needed for opt-in DPI queries if(CORRADE_TARGET_APPLE)
find_library(_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_LIBRARY Foundation)
mark_as_advanced(_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_LIBRARY)
set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ${_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_LIBRARY})
# Needed for opt-in DPI queries
elseif(CORRADE_TARGET_UNIX)
set_property(TARGET Magnum::${_component} APPEND PROPERTY set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS}) INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS})
endif() endif()

14
src/Magnum/Platform/CMakeLists.txt

@ -205,6 +205,9 @@ if(WITH_SDL2APPLICATION)
if(TARGET_GL) if(TARGET_GL)
list(APPEND MagnumSdl2Application_SRCS ${MagnumSomeContext_OBJECTS}) list(APPEND MagnumSdl2Application_SRCS ${MagnumSomeContext_OBJECTS})
endif() endif()
if(CORRADE_TARGET_APPLE)
list(APPEND MagnumSdl2Application_SRCS Implementation/dpiScaling.mm)
endif()
add_library(MagnumSdl2Application STATIC add_library(MagnumSdl2Application STATIC
${MagnumSdl2Application_SRCS} ${MagnumSdl2Application_SRCS}
@ -222,8 +225,17 @@ if(WITH_SDL2APPLICATION)
${MagnumSomeContext_LIBRARY}) ${MagnumSomeContext_LIBRARY})
endif() endif()
# Use the Foundation framework on Apple to query the DPI awareness
if(CORRADE_TARGET_APPLE)
find_library(_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_LIBRARY Foundation)
mark_as_advanced(_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_LIBRARY)
find_path(_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_INCLUDE_DIR NAMES NSBundle.h)
mark_as_advanced(_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_INCLUDE_DIR)
target_link_libraries(MagnumSdl2Application PUBLIC ${_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_LIBRARY})
target_include_directories(MagnumSdl2Application PRIVATE ${_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_INCLUDE_DIR})
# If there is X11, ask it for DPI # If there is X11, ask it for DPI
if(CORRADE_TARGET_UNIX AND NOT CORRADE_TARGET_APPLE) elseif(CORRADE_TARGET_UNIX)
find_package(X11) find_package(X11)
if(X11_FOUND) if(X11_FOUND)
# Not linking to X11, we dlopen() instead # Not linking to X11, we dlopen() instead

12
src/Magnum/Platform/Implementation/dpiScaling.hpp

@ -40,7 +40,9 @@
#include <emscripten/html5.h> #include <emscripten/html5.h>
#endif #endif
namespace Magnum { namespace Platform { namespace Implementation { namespace { namespace Magnum { namespace Platform { namespace Implementation {
namespace {
inline Utility::Arguments windowScalingArguments() { inline Utility::Arguments windowScalingArguments() {
Utility::Arguments args{"magnum"}; Utility::Arguments args{"magnum"};
@ -126,6 +128,12 @@ inline Float emscriptenDpiScaling() {
} }
#endif #endif
}}}} }
#ifdef CORRADE_TARGET_APPLE
bool isAppleBundleHiDpiEnabled();
#endif
}}}
#endif #endif

40
src/Magnum/Platform/Implementation/dpiScaling.mm

@ -0,0 +1,40 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
Vladimír Vondruš <mosra@centrum.cz>
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.
*/
#import "NSBundle.h"
#include "dpiScaling.hpp"
namespace Magnum { namespace Platform { namespace Implementation {
/* HiDPI is available only for bundles, so if the executable is not a bundle,
return false */
bool isAppleBundleHiDpiEnabled() {
NSBundle* bundle = [NSBundle mainBundle];
if(!bundle) return false;
return bool([bundle objectForInfoDictionaryKey:@"NSHighResolutionCapable"]);
}
}}}

9
src/Magnum/Platform/Sdl2Application.cpp

@ -135,6 +135,15 @@ void Sdl2Application::create(const Configuration& configuration, const GLConfigu
Vector2 Sdl2Application::dpiScaling(const Configuration& configuration) const { Vector2 Sdl2Application::dpiScaling(const Configuration& configuration) const {
std::ostream* verbose = _verboseLog ? Debug::output() : nullptr; std::ostream* verbose = _verboseLog ? Debug::output() : nullptr;
/* Print a helpful warning in case some extra steps are needed for HiDPI
support */
#ifdef CORRADE_TARGET_APPLE
if(!Implementation::isAppleBundleHiDpiEnabled())
Warning{} << "Platform::Sdl2Application: warning: the executable is not a HiDPI-enabled app bundle";
#elif defined(CORRADE_TARGET_WINDOWS)
/** @todo */
#endif
/* Use values from the configuration only if not overriden on command line. /* Use values from the configuration only if not overriden on command line.
In any case explicit scaling has a precedence before the policy. */ In any case explicit scaling has a precedence before the policy. */
Implementation::DpiScalingPolicy dpiScalingPolicy{}; Implementation::DpiScalingPolicy dpiScalingPolicy{};

4
src/Magnum/Platform/Test/CMakeLists.txt

@ -58,8 +58,10 @@ if(WITH_SDL2APPLICATION)
../WebApplication.css ../WebApplication.css
Sdl2ApplicationTest.html Sdl2ApplicationTest.html
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
elseif(CORRADE_TARGET_IOS) elseif(CORRADE_TARGET_IOS OR CORRADE_TARGET_APPLE)
# The plist is needed in order to mark the app as DPI-aware
set_target_properties(PlatformSdl2ApplicationTest PROPERTIES set_target_properties(PlatformSdl2ApplicationTest PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Sdl2ApplicationTest.plist
MACOSX_BUNDLE ON MACOSX_BUNDLE ON
XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "YES") XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "YES")
endif() endif()

20
src/Magnum/Platform/Test/Sdl2ApplicationTest.plist

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en-US</string>
<key>CFBundleExecutable</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>cz.mosra.magnum.Sdl2ApplicationTest</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Magnum Triangle</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>
Loading…
Cancel
Save