1 //
2 // Copyright 2023 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_helpers.h: common platform detection helper functions
8
9 #ifndef COMMON_PLATFORM_HELPERS_H_
10 #define COMMON_PLATFORM_HELPERS_H_
11
12 #include "common/platform.h"
13
14 namespace angle
15 {
16
IsAndroid()17 inline constexpr bool IsAndroid()
18 {
19 #if defined(ANGLE_PLATFORM_ANDROID)
20 return true;
21 #else
22 return false;
23 #endif
24 }
25
IsApple()26 inline constexpr bool IsApple()
27 {
28 // This means any Apple-vended OS (including iOS, macOS, etc)
29 #if defined(ANGLE_PLATFORM_APPLE)
30 return true;
31 #else
32 return false;
33 #endif
34 }
35
IsChromeOS()36 inline constexpr bool IsChromeOS()
37 {
38 #if defined(ANGLE_PLATFORM_CHROMEOS)
39 return true;
40 #else
41 return false;
42 #endif
43 }
44
IsFuchsia()45 inline constexpr bool IsFuchsia()
46 {
47 #if defined(ANGLE_PLATFORM_FUCHSIA)
48 return true;
49 #else
50 return false;
51 #endif
52 }
53
IsIOS()54 inline constexpr bool IsIOS()
55 {
56 #if ANGLE_PLATFORM_IOS_FAMILY
57 return true;
58 #else
59 return false;
60 #endif
61 }
62
IsLinux()63 inline constexpr bool IsLinux()
64 {
65 #if defined(ANGLE_PLATFORM_LINUX)
66 return true;
67 #else
68 return false;
69 #endif
70 }
71
IsMac()72 inline constexpr bool IsMac()
73 {
74 #if defined(ANGLE_PLATFORM_MACOS)
75 return true;
76 #else
77 return false;
78 #endif
79 }
80
IsWindows()81 inline constexpr bool IsWindows()
82 {
83 #if defined(ANGLE_PLATFORM_WINDOWS)
84 return true;
85 #else
86 return false;
87 #endif
88 }
89
90 // Helper for version number comparisons
91 struct VersionTriple
92 {
VersionTripleVersionTriple93 constexpr VersionTriple() {}
94
VersionTripleVersionTriple95 constexpr VersionTriple(int major, int minor, int patch)
96 : majorVersion(major), minorVersion(minor), patchVersion(patch)
97 {}
98
99 int majorVersion = 0;
100 int minorVersion = 0;
101 int patchVersion = 0;
102 };
103
104 bool operator==(const VersionTriple &a, const VersionTriple &b);
105 bool operator!=(const VersionTriple &a, const VersionTriple &b);
106 bool operator<(const VersionTriple &a, const VersionTriple &b);
107 bool operator>=(const VersionTriple &a, const VersionTriple &b);
108
109 //
110 // Windows version check helpers
111 //
112
113 // Exact version checks
114 bool IsWindowsXP();
115 bool IsWindowsVista();
116 bool IsWindows7();
117 bool IsWindows8();
118 bool IsWindows10();
119 bool IsWindows11();
120
121 // Windows version or later helpers
122 bool IsWindowsXPOrLater();
123 bool IsWindowsVistaOrLater();
124 bool IsWindows7OrLater();
125 bool IsWindows8OrLater();
126 bool IsWindows10OrLater();
127 bool IsWindows11OrLater();
128
129 bool Is64Bit();
130
131 } // namespace angle
132
133 #endif // COMMON_PLATFORM_HELPERS_H_
134