• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2014 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 // platform.h: Operating system specific includes and defines.
8 
9 #ifndef COMMON_PLATFORM_H_
10 #define COMMON_PLATFORM_H_
11 
12 #if defined(_WIN32)
13 #    define ANGLE_PLATFORM_WINDOWS 1
14 #elif defined(__Fuchsia__)
15 #    define ANGLE_PLATFORM_FUCHSIA 1
16 #    define ANGLE_PLATFORM_POSIX 1
17 #elif defined(__APPLE__)
18 #    define ANGLE_PLATFORM_APPLE 1
19 #    define ANGLE_PLATFORM_POSIX 1
20 #elif defined(ANDROID)
21 #    define ANGLE_PLATFORM_ANDROID 1
22 #    define ANGLE_PLATFORM_POSIX 1
23 #elif defined(__ggp__)
24 #    define ANGLE_PLATFORM_GGP 1
25 #    define ANGLE_PLATFORM_POSIX 1
26 #elif defined(__linux__) || defined(EMSCRIPTEN)
27 #    define ANGLE_PLATFORM_LINUX 1
28 #    define ANGLE_PLATFORM_POSIX 1
29 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) ||              \
30     defined(__DragonFly__) || defined(__sun) || defined(__GLIBC__) || defined(__GNU__) || \
31     defined(__QNX__) || defined(__Fuchsia__) || defined(__HAIKU__)
32 #    define ANGLE_PLATFORM_POSIX 1
33 #else
34 #    error Unsupported platform.
35 #endif
36 
37 #ifdef ANGLE_PLATFORM_WINDOWS
38 #    ifndef STRICT
39 #        define STRICT 1
40 #    endif
41 #    ifndef WIN32_LEAN_AND_MEAN
42 #        define WIN32_LEAN_AND_MEAN 1
43 #    endif
44 #    ifndef NOMINMAX
45 #        define NOMINMAX 1
46 #    endif
47 
48 #    include <intrin.h>
49 
50 #    if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP)
51 #        define ANGLE_ENABLE_WINDOWS_UWP 1
52 #    endif
53 
54 #    if defined(ANGLE_ENABLE_D3D9)
55 #        include <d3d9.h>
56 #        include <d3dcompiler.h>
57 #    endif
58 
59 // Include D3D11 headers when OpenGL is enabled on Windows for interop extensions.
60 #    if defined(ANGLE_ENABLE_D3D11) || defined(ANGLE_ENABLE_OPENGL)
61 #        include <d3d10_1.h>
62 #        include <d3d11.h>
63 #        include <d3d11_3.h>
64 #        include <d3d11on12.h>
65 #        include <d3d12.h>
66 #        include <d3dcompiler.h>
67 #        include <dxgi.h>
68 #        include <dxgi1_2.h>
69 #        include <dxgi1_4.h>
70 #    endif
71 
72 #    if defined(ANGLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)
73 #        include <wrl.h>
74 #    endif
75 
76 #    if defined(ANGLE_ENABLE_WINDOWS_UWP)
77 #        include <dxgi1_3.h>
78 #        if defined(_DEBUG)
79 #            include <DXProgrammableCapture.h>
80 #            include <dxgidebug.h>
81 #        endif
82 #    endif
83 
84 // GCC < 10.4 or 11.0 - 11.3 miscodegen extern thread_local variable accesses.
85 // This affects MinGW targets only.
86 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104862
87 #    if defined(__GNUC__)
88 #        if __GNUC__ < 10 || __GNUC__ == 10 && __GNUC_MINOR__ < 4 || \
89             __GNUC__ == 11 && __GNUC_MINOR__ < 3
90 #            define ANGLE_USE_STATIC_THREAD_LOCAL_VARIABLES 1
91 #        endif
92 #    endif
93 
94 // Include <windows.h> to ensure files that refer to near/far can be compiled.
95 #    include <windows.h>
96 
97 // Macros 'near', 'far', 'NEAR' and 'FAR' are defined by 'shared/minwindef.h' in the Windows SDK.
98 // Macros 'near' and 'far' are empty. They are not used by other Windows headers and are undefined
99 // here to avoid identifier conflicts. Macros 'NEAR' and 'FAR' contain 'near' and 'far'. They are
100 // used by other Windows headers and are cleared here to avoid compilation errors.
101 #    undef near
102 #    undef far
103 #    undef NEAR
104 #    undef FAR
105 #    define NEAR
106 #    define FAR
107 #endif
108 
109 #if defined(_MSC_VER) && !defined(_M_ARM) && !defined(_M_ARM64)
110 #    include <intrin.h>
111 #    define ANGLE_USE_SSE
112 #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
113 #    include <x86intrin.h>
114 #    if __SSE__
115 #        define ANGLE_USE_SSE
116 #    endif
117 #endif
118 
119 // Mips and arm devices need to include stddef for size_t.
120 #if defined(__mips__) || defined(__arm__) || defined(__aarch64__) || defined(__riscv)
121 #    include <stddef.h>
122 #endif
123 
124 // Macro for hinting that an expression is likely to be true/false.
125 #if !defined(ANGLE_LIKELY) || !defined(ANGLE_UNLIKELY)
126 #    if defined(__GNUC__) || defined(__clang__)
127 #        define ANGLE_LIKELY(x) __builtin_expect(!!(x), 1)
128 #        define ANGLE_UNLIKELY(x) __builtin_expect(!!(x), 0)
129 #    else
130 #        define ANGLE_LIKELY(x) (x)
131 #        define ANGLE_UNLIKELY(x) (x)
132 #    endif  // defined(__GNUC__) || defined(__clang__)
133 #endif      // !defined(ANGLE_LIKELY) || !defined(ANGLE_UNLIKELY)
134 
135 #ifdef ANGLE_PLATFORM_APPLE
136 #    include <TargetConditionals.h>
137 #    if TARGET_OS_OSX
138 #        define ANGLE_PLATFORM_MACOS 1
139 #    elif TARGET_OS_IPHONE
140 #        define ANGLE_PLATFORM_IOS_FAMILY 1
141 #        if TARGET_OS_SIMULATOR
142 #            define ANGLE_PLATFORM_IOS_FAMILY_SIMULATOR 1
143 #        endif
144 #        if TARGET_OS_IOS
145 #            define ANGLE_PLATFORM_IOS 1
146 #            if TARGET_OS_MACCATALYST
147 #                define ANGLE_PLATFORM_MACCATALYST 1
148 #            endif
149 #        elif TARGET_OS_WATCH
150 #            define ANGLE_PLATFORM_WATCHOS 1
151 #        elif TARGET_OS_TV
152 #            define ANGLE_PLATFORM_APPLETV 1
153 #        endif
154 #    endif
155 #    // Identify Metal API >= what shipped on macOS Catalina.
156 #    if (ANGLE_PLATFORM_MACOS && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500) || \
157         (ANGLE_PLATFORM_IOS_FAMILY && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000)
158 #        define ANGLE_WITH_MODERN_METAL_API 1
159 #    endif
160 #endif
161 
162 // Define ANGLE_WITH_ASAN macro.
163 #if defined(__has_feature)
164 #    if __has_feature(address_sanitizer)
165 #        define ANGLE_WITH_ASAN 1
166 #    endif
167 #endif
168 
169 // Define ANGLE_WITH_MSAN macro.
170 #if defined(__has_feature)
171 #    if __has_feature(memory_sanitizer)
172 #        define ANGLE_WITH_MSAN 1
173 #    endif
174 #endif
175 
176 // Define ANGLE_WITH_TSAN macro.
177 #if defined(__has_feature)
178 #    if __has_feature(thread_sanitizer)
179 #        define ANGLE_WITH_TSAN 1
180 #    endif
181 #endif
182 
183 // Define ANGLE_WITH_UBSAN macro.
184 #if defined(__has_feature)
185 #    if __has_feature(undefined_behavior_sanitizer)
186 #        define ANGLE_WITH_UBSAN 1
187 #    endif
188 #endif
189 
190 #if defined(ANGLE_WITH_ASAN) || defined(ANGLE_WITH_TSAN) || defined(ANGLE_WITH_UBSAN)
191 #    define ANGLE_WITH_SANITIZER 1
192 #endif  // defined(ANGLE_WITH_ASAN) || defined(ANGLE_WITH_TSAN) || defined(ANGLE_WITH_UBSAN)
193 
194 #include <stdint.h>
195 #if INTPTR_MAX == INT64_MAX
196 #    define ANGLE_IS_64_BIT_CPU 1
197 #else
198 #    define ANGLE_IS_32_BIT_CPU 1
199 #endif
200 
201 #endif  // COMMON_PLATFORM_H_
202