GCC Code Coverage Report


Directory: ./
File: submodules/raylib/src/external/glfw/src/platform.c
Date: 2023-09-29 04:53:15
Exec Total Coverage
Lines: 0 26 0.0%
Branches: 0 20 0.0%

Line Branch Exec Source
1 //========================================================================
2 // GLFW 3.4 - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2002-2006 Marcus Geelnard
5 // Copyright (c) 2006-2018 Camilla Löwy <elmindreda@glfw.org>
6 //
7 // This software is provided 'as-is', without any express or implied
8 // warranty. In no event will the authors be held liable for any damages
9 // arising from the use of this software.
10 //
11 // Permission is granted to anyone to use this software for any purpose,
12 // including commercial applications, and to alter it and redistribute it
13 // freely, subject to the following restrictions:
14 //
15 // 1. The origin of this software must not be misrepresented; you must not
16 // claim that you wrote the original software. If you use this software
17 // in a product, an acknowledgment in the product documentation would
18 // be appreciated but is not required.
19 //
20 // 2. Altered source versions must be plainly marked as such, and must not
21 // be misrepresented as being the original software.
22 //
23 // 3. This notice may not be removed or altered from any source
24 // distribution.
25 //
26 //========================================================================
27 // Please use C89 style variable declarations in this file because VS 2010
28 //========================================================================
29
30 #include "internal.h"
31
32 //////////////////////////////////////////////////////////////////////////
33 ////// GLFW internal API //////
34 //////////////////////////////////////////////////////////////////////////
35
36 static const struct
37 {
38 int ID;
39 GLFWbool (*connect)(int,_GLFWplatform*);
40 } supportedPlatforms[] =
41 {
42 #if defined(_GLFW_WIN32)
43 { GLFW_PLATFORM_WIN32, _glfwConnectWin32 },
44 #endif
45 #if defined(_GLFW_COCOA)
46 { GLFW_PLATFORM_COCOA, _glfwConnectCocoa },
47 #endif
48 #if defined(_GLFW_X11)
49 { GLFW_PLATFORM_X11, _glfwConnectX11 },
50 #endif
51 #if defined(_GLFW_WAYLAND)
52 { GLFW_PLATFORM_WAYLAND, _glfwConnectWayland },
53 #endif
54 };
55
56 GLFWbool _glfwSelectPlatform(int desiredID, _GLFWplatform* platform)
57 {
58 const size_t count = sizeof(supportedPlatforms) / sizeof(supportedPlatforms[0]);
59 size_t i;
60
61 if (desiredID != GLFW_ANY_PLATFORM &&
62 desiredID != GLFW_PLATFORM_WIN32 &&
63 desiredID != GLFW_PLATFORM_COCOA &&
64 desiredID != GLFW_PLATFORM_WAYLAND &&
65 desiredID != GLFW_PLATFORM_X11 &&
66 desiredID != GLFW_PLATFORM_NULL)
67 {
68 _glfwInputError(GLFW_INVALID_ENUM, "Invalid platform ID 0x%08X", desiredID);
69 return GLFW_FALSE;
70 }
71
72 // Only allow the Null platform if specifically requested
73 if (desiredID == GLFW_PLATFORM_NULL)
74 return GLFW_FALSE; //_glfwConnectNull(desiredID, platform); // @raysan5
75 else if (count == 0)
76 {
77 _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "This binary only supports the Null platform");
78 return GLFW_FALSE;
79 }
80
81 if (desiredID == GLFW_ANY_PLATFORM)
82 {
83 // If there is exactly one platform available for auto-selection, let it emit the
84 // error on failure as the platform-specific error description may be more helpful
85 if (count == 1)
86 return supportedPlatforms[0].connect(supportedPlatforms[0].ID, platform);
87
88 for (i = 0; i < count; i++)
89 {
90 if (supportedPlatforms[i].connect(desiredID, platform))
91 return GLFW_TRUE;
92 }
93
94 _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "Failed to detect any supported platform");
95 }
96 else
97 {
98 for (i = 0; i < count; i++)
99 {
100 if (supportedPlatforms[i].ID == desiredID)
101 return supportedPlatforms[i].connect(desiredID, platform);
102 }
103
104 _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "The requested platform is not supported");
105 }
106
107 return GLFW_FALSE;
108 }
109
110 //////////////////////////////////////////////////////////////////////////
111 ////// GLFW public API //////
112 //////////////////////////////////////////////////////////////////////////
113
114 GLFWAPI int glfwGetPlatform(void)
115 {
116 _GLFW_REQUIRE_INIT_OR_RETURN(0);
117 return _glfw.platform.platformID;
118 }
119
120 GLFWAPI int glfwPlatformSupported(int platformID)
121 {
122 const size_t count = sizeof(supportedPlatforms) / sizeof(supportedPlatforms[0]);
123 size_t i;
124
125 if (platformID != GLFW_PLATFORM_WIN32 &&
126 platformID != GLFW_PLATFORM_COCOA &&
127 platformID != GLFW_PLATFORM_WAYLAND &&
128 platformID != GLFW_PLATFORM_X11 &&
129 platformID != GLFW_PLATFORM_NULL)
130 {
131 _glfwInputError(GLFW_INVALID_ENUM, "Invalid platform ID 0x%08X", platformID);
132 return GLFW_FALSE;
133 }
134
135 if (platformID == GLFW_PLATFORM_NULL)
136 return GLFW_TRUE;
137
138 for (i = 0; i < count; i++)
139 {
140 if (platformID == supportedPlatforms[i].ID)
141 return GLFW_TRUE;
142 }
143
144 return GLFW_FALSE;
145 }
146
147 GLFWAPI const char* glfwGetVersionString(void)
148 {
149 return _GLFW_VERSION_NUMBER
150 #if defined(_GLFW_WIN32)
151 " Win32 WGL"
152 #endif
153 #if defined(_GLFW_COCOA)
154 " Cocoa NSGL"
155 #endif
156 #if defined(_GLFW_WAYLAND)
157 " Wayland"
158 #endif
159 #if defined(_GLFW_X11)
160 " X11 GLX"
161 #endif
162 " Null"
163 " EGL"
164 " OSMesa"
165 #if defined(__MINGW64_VERSION_MAJOR)
166 " MinGW-w64"
167 #elif defined(__MINGW32__)
168 " MinGW"
169 #elif defined(_MSC_VER)
170 " VisualC"
171 #endif
172 #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG)
173 " hybrid-GPU"
174 #endif
175 #if defined(_POSIX_MONOTONIC_CLOCK)
176 " monotonic"
177 #endif
178 #if defined(_GLFW_BUILD_DLL)
179 #if defined(_WIN32)
180 " DLL"
181 #elif defined(__APPLE__)
182 " dynamic"
183 #else
184 " shared"
185 #endif
186 #endif
187 ;
188 }
189
190