xref: /aosp_15_r20/external/angle/src/common/platform.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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) && !defined(ANGLE_ANDROID_DMA_BUF)
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 // Mips and arm devices need to include stddef for size_t.
110 #if defined(__mips__) || defined(__arm__) || defined(__aarch64__) || defined(__riscv)
111 #    include <stddef.h>
112 #endif
113 
114 // Macro for hinting that an expression is likely to be true/false.
115 #if !defined(ANGLE_LIKELY) || !defined(ANGLE_UNLIKELY)
116 #    if defined(__GNUC__) || defined(__clang__)
117 #        define ANGLE_LIKELY(x) __builtin_expect(!!(x), 1)
118 #        define ANGLE_UNLIKELY(x) __builtin_expect(!!(x), 0)
119 #    else
120 #        define ANGLE_LIKELY(x) (x)
121 #        define ANGLE_UNLIKELY(x) (x)
122 #    endif  // defined(__GNUC__) || defined(__clang__)
123 #endif      // !defined(ANGLE_LIKELY) || !defined(ANGLE_UNLIKELY)
124 
125 #ifdef ANGLE_PLATFORM_APPLE
126 #    include <AvailabilityMacros.h>
127 #    include <TargetConditionals.h>
128 #    if TARGET_OS_OSX
129 #        if __MAC_OS_X_VERSION_MAX_ALLOWED < 120000
130 #            error macOS 12 SDK or newer is required.
131 #        endif
132 #        define ANGLE_PLATFORM_MACOS 1
133 #    elif TARGET_OS_IPHONE
134 #        define ANGLE_PLATFORM_IOS_FAMILY 1
135 #        if TARGET_OS_SIMULATOR
136 #            define ANGLE_PLATFORM_IOS_FAMILY_SIMULATOR 1
137 #        endif
138 #        if TARGET_OS_VISION  // Must be checked before iOS
139 #            define ANGLE_PLATFORM_VISIONOS 1
140 #        elif TARGET_OS_IOS
141 #            if __IPHONE_OS_VERSION_MAX_ALLOWED < 170000
142 #                error iOS 17 SDK or newer is required.
143 #            endif
144 #            define ANGLE_PLATFORM_IOS 1
145 #            if TARGET_OS_MACCATALYST
146 #                define ANGLE_PLATFORM_MACCATALYST 1
147 #            endif
148 #        elif TARGET_OS_WATCH
149 #            define ANGLE_PLATFORM_WATCHOS 1
150 #        elif TARGET_OS_TV
151 #            if __TV_OS_VERSION_MAX_ALLOWED < 170000
152 #                error tvOS 17 SDK or newer is required.
153 #            endif
154 #            define ANGLE_PLATFORM_APPLETV 1
155 #        endif
156 #    endif
157 #endif
158 
159 // Define ANGLE_WITH_ASAN macro.
160 #if defined(__has_feature)
161 #    if __has_feature(address_sanitizer)
162 #        define ANGLE_WITH_ASAN 1
163 #    endif
164 #endif
165 
166 // Define ANGLE_WITH_MSAN macro.
167 #if defined(__has_feature)
168 #    if __has_feature(memory_sanitizer)
169 #        define ANGLE_WITH_MSAN 1
170 #    endif
171 #endif
172 
173 // Define ANGLE_WITH_TSAN macro.
174 #if defined(__has_feature)
175 #    if __has_feature(thread_sanitizer)
176 #        define ANGLE_WITH_TSAN 1
177 #    endif
178 #endif
179 
180 // Define ANGLE_WITH_UBSAN macro.
181 #if defined(__has_feature)
182 #    if __has_feature(undefined_behavior_sanitizer)
183 #        define ANGLE_WITH_UBSAN 1
184 #    endif
185 #endif
186 
187 #if defined(ANGLE_WITH_ASAN) || defined(ANGLE_WITH_TSAN) || defined(ANGLE_WITH_UBSAN)
188 #    define ANGLE_WITH_SANITIZER 1
189 #endif  // defined(ANGLE_WITH_ASAN) || defined(ANGLE_WITH_TSAN) || defined(ANGLE_WITH_UBSAN)
190 
191 #include <stdint.h>
192 #if INTPTR_MAX == INT64_MAX
193 #    define ANGLE_IS_64_BIT_CPU 1
194 #else
195 #    define ANGLE_IS_32_BIT_CPU 1
196 #endif
197 
198 #endif  // COMMON_PLATFORM_H_
199