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