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 # include <windows.h> 50 51 # if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP) 52 # define ANGLE_ENABLE_WINDOWS_UWP 1 53 # endif 54 55 # if defined(ANGLE_ENABLE_D3D9) 56 # include <d3d9.h> 57 # include <d3dcompiler.h> 58 # endif 59 60 // Include D3D11 headers when OpenGL is enabled on Windows for interop extensions. 61 # if defined(ANGLE_ENABLE_D3D11) || defined(ANGLE_ENABLE_OPENGL) 62 # include <d3d10_1.h> 63 # include <d3d11.h> 64 # include <d3d11_3.h> 65 # include <d3d11on12.h> 66 # include <d3d12.h> 67 # include <d3dcompiler.h> 68 # include <dxgi.h> 69 # include <dxgi1_2.h> 70 # include <dxgi1_4.h> 71 # endif 72 73 # if defined(ANGLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11) 74 # include <wrl.h> 75 # endif 76 77 # if defined(ANGLE_ENABLE_WINDOWS_UWP) 78 # include <dxgi1_3.h> 79 # if defined(_DEBUG) 80 # include <DXProgrammableCapture.h> 81 # include <dxgidebug.h> 82 # endif 83 # endif 84 85 // Macros 'near', 'far', 'NEAR' and 'FAR' are defined by 'shared/minwindef.h' in the Windows SDK. 86 // Macros 'near' and 'far' are empty. They are not used by other Windows headers and are undefined 87 // here to avoid identifier conflicts. Macros 'NEAR' and 'FAR' contain 'near' and 'far'. They are 88 // used by other Windows headers and are cleared here to avoid compilation errors. 89 # undef near 90 # undef far 91 # undef NEAR 92 # undef FAR 93 # define NEAR 94 # define FAR 95 #endif 96 97 #if defined(_MSC_VER) && !defined(_M_ARM) && !defined(_M_ARM64) 98 # include <intrin.h> 99 # define ANGLE_USE_SSE 100 #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) 101 # include <x86intrin.h> 102 # define ANGLE_USE_SSE 103 #endif 104 105 // Mips and arm devices need to include stddef for size_t. 106 #if defined(__mips__) || defined(__arm__) || defined(__aarch64__) 107 # include <stddef.h> 108 #endif 109 110 // The MemoryBarrier function name collides with a macro under Windows 111 // We will undef the macro so that the function name does not get replaced 112 #undef MemoryBarrier 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 <TargetConditionals.h> 127 # if TARGET_OS_OSX 128 # define ANGLE_PLATFORM_MACOS 1 129 # elif TARGET_OS_IPHONE 130 # define ANGLE_PLATFORM_IOS 1 131 # if TARGET_OS_SIMULATOR 132 # define ANGLE_PLATFORM_IOS_SIMULATOR 1 133 # endif 134 # if TARGET_OS_MACCATALYST 135 # define ANGLE_PLATFORM_MACCATALYST 1 136 # endif 137 # endif 138 # // This might be useful globally. At the moment it is used 139 # // to differentiate MacCatalyst on Intel and Apple Silicon. 140 # if defined(__arm64__) || defined(__aarch64__) 141 # define ANGLE_CPU_ARM64 1 142 # endif 143 # // EAGL should be enabled on iOS, but not Mac Catalyst unless it is running on Apple Silicon. 144 # if (defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)) || \ 145 (defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64)) 146 # define ANGLE_ENABLE_EAGL 147 # endif 148 # // Identify Metal API >= what shipped on macOS Catalina. 149 # if (defined(ANGLE_PLATFORM_MACOS) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500) || \ 150 (defined(ANGLE_PLATFORM_IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000) 151 # define ANGLE_WITH_MODERN_METAL_API 1 152 # endif 153 #endif 154 155 // Define ANGLE_WITH_ASAN macro. 156 #if defined(__has_feature) 157 # if __has_feature(address_sanitizer) 158 # define ANGLE_WITH_ASAN 1 159 # endif 160 #endif 161 162 #include <cstdint> 163 #if INTPTR_MAX == INT64_MAX 164 # define ANGLE_IS_64_BIT_CPU 1 165 #else 166 # define ANGLE_IS_32_BIT_CPU 1 167 #endif 168 169 #endif // COMMON_PLATFORM_H_ 170