• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // apple_platform_utils.h: Common utilities for Apple platforms.
8 
9 #ifndef COMMON_APPLE_PLATFORM_UTILS_H_
10 #define COMMON_APPLE_PLATFORM_UTILS_H_
11 
12 #include "common/platform.h"
13 
14 #include <string>
15 
16 // These are macros for substitution of Apple specific directive @available:
17 
18 // TARGET_OS_MACCATALYST only available in MacSDK 10.15
19 
20 #if TARGET_OS_MACCATALYST
21 // ANGLE_APPLE_AVAILABLE_XCI: check if either of the 3 platforms (OSX/Catalyst/iOS) min verions is
22 // available:
23 #    define ANGLE_APPLE_AVAILABLE_XCI(macVer, macCatalystVer, iOSVer) \
24         @available(macOS macVer, macCatalyst macCatalystVer, iOS iOSVer, *)
25 // ANGLE_APPLE_AVAILABLE_XC: check if either of the 2 platforms (OSX/Catalyst) min verions is
26 // available:
27 #    define ANGLE_APPLE_AVAILABLE_XC(macVer, macCatalystVer) \
28         @available(macOS macVer, macCatalyst macCatalystVer, *)
29 // ANGLE_APPLE_AVAILABLE_CI: check if either of the 2 platforms (Catalyst/iOS) min verions is
30 // available:
31 #    define ANGLE_APPLE_AVAILABLE_CI(macCatalystVer, iOSVer) \
32         @available(macCatalyst macCatalystVer, iOS iOSVer, *)
33 #else
34 #    define ANGLE_APPLE_AVAILABLE_XCI(macVer, macCatalystVer, iOSVer) \
35         ANGLE_APPLE_AVAILABLE_XI(macVer, iOSVer)
36 
37 #    define ANGLE_APPLE_AVAILABLE_XC(macVer, macCatalystVer) @available(macOS macVer, *)
38 #    define ANGLE_APPLE_AVAILABLE_CI(macCatalystVer, iOSVer) @available(iOS iOSVer, tvOS iOSVer, *)
39 #endif
40 
41 // ANGLE_APPLE_AVAILABLE_XI: check if either of the 2 platforms (OSX/iOS) min verions is available:
42 #define ANGLE_APPLE_AVAILABLE_XI(macVer, iOSVer) \
43     @available(macOS macVer, iOS iOSVer, tvOS iOSVer, *)
44 
45 // ANGLE_APPLE_AVAILABLE_I: check if a particular iOS version is available
46 #define ANGLE_APPLE_AVAILABLE_I(iOSVer) @available(iOS iOSVer, tvOS iOSVer, *)
47 
48 #if TARGET_OS_IPHONE
49 #    if !defined(__IPHONE_11_0)
50 #        define __IPHONE_11_0 110000
51 #    endif
52 #    if !defined(ANGLE_IOS_DEPLOY_TARGET)
53 #        define ANGLE_IOS_DEPLOY_TARGET __IPHONE_11_0
54 #    endif
55 #    if !defined(__IPHONE_OS_VERSION_MAX_ALLOWED)
56 #        define __IPHONE_OS_VERSION_MAX_ALLOWED __IPHONE_11_0
57 #    endif
58 #    if !defined(__TV_OS_VERSION_MAX_ALLOWED)
59 #        define __TV_OS_VERSION_MAX_ALLOWED __IPHONE_11_0
60 #    endif
61 #endif
62 
63 #if !defined(TARGET_OS_MACCATALYST)
64 #    define TARGET_OS_MACCATALYST 0
65 #endif
66 
67 #if defined(__ARM_ARCH)
68 #    define ANGLE_APPLE_IS_ARM (__ARM_ARCH != 0)
69 #else
70 #    define ANGLE_APPLE_IS_ARM 0
71 #endif
72 
73 #define ANGLE_APPLE_OBJC_SCOPE @autoreleasepool
74 
75 #if !__has_feature(objc_arc)
76 #    define ANGLE_APPLE_AUTORELEASE autorelease
77 #    define ANGLE_APPLE_RETAIN retain
78 #    define ANGLE_APPLE_RELEASE release
79 #else
80 #    define ANGLE_APPLE_AUTORELEASE self
81 #    define ANGLE_APPLE_RETAIN self
82 #    define ANGLE_APPLE_RELEASE self
83 #endif
84 
85 #define ANGLE_APPLE_UNUSED __attribute__((unused))
86 
87 #if __has_warning("-Wdeprecated-declarations")
88 #    define ANGLE_APPLE_ALLOW_DEPRECATED_BEGIN \
89         _Pragma("GCC diagnostic push")         \
90             _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
91 #else
92 #    define ANGLE_APPLE_ALLOW_DEPRECATED_BEGIN
93 #endif
94 
95 #if __has_warning("-Wdeprecated-declarations")
96 #    define ANGLE_APPLE_ALLOW_DEPRECATED_END _Pragma("GCC diagnostic pop")
97 #else
98 #    define ANGLE_APPLE_ALLOW_DEPRECATED_END
99 #endif
100 
101 namespace angle
102 {
103 bool IsMetalRendererAvailable();
104 
105 bool GetMacosMachineModel(std::string *outMachineModel);
106 bool ParseMacMachineModel(const std::string &identifier,
107                           std::string *type,
108                           int32_t *major,
109                           int32_t *minor);
110 }  // namespace angle
111 
112 #endif
113