1 /**************************************************************************
3 * Copyright 2015, 2018 Collabora
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "util/macros.h"
30 #include "eglcurrent.h"
31 #include "egldevice.h"
32 #include "eglglobals.h"
33 #include "egltypedefs.h"
39 const char *extensions
;
45 _EGLDevice
*dev_list
, *dev
;
47 /* atexit function is called with global mutex locked */
49 dev_list
= _eglGlobal
.DeviceList
;
53 dev_list
= dev_list
->Next
;
58 _eglGlobal
.DeviceList
= NULL
;
62 _eglCheckDeviceHandle(EGLDeviceEXT device
)
66 mtx_lock(_eglGlobal
.Mutex
);
67 cur
= _eglGlobal
.DeviceList
;
69 if (cur
== (_EGLDevice
*) device
)
73 mtx_unlock(_eglGlobal
.Mutex
);
77 /* Adds a device in DeviceList, if needed for the given fd.
79 * If a software device, the fd is ignored.
82 _eglAddDevice(int fd
, bool software
)
86 mtx_lock(_eglGlobal
.Mutex
);
91 mtx_unlock(_eglGlobal
.Mutex
);
96 _eglDeviceSupports(_EGLDevice
*dev
, _EGLDeviceExtension ext
)
106 _eglQueryDeviceAttribEXT(_EGLDevice
*dev
, EGLint attribute
,
111 _eglError(EGL_BAD_ATTRIBUTE
, "eglQueryDeviceStringEXT");
117 _eglQueryDeviceStringEXT(_EGLDevice
*dev
, EGLint name
)
121 return dev
->extensions
;
123 _eglError(EGL_BAD_PARAMETER
, "eglQueryDeviceStringEXT");
128 /* Do a fresh lookup for devices.
130 * Walks through the DeviceList, discarding no longer available ones
131 * and adding new ones as applicable.
133 * Must be called with the global lock held.
136 _eglRefreshDeviceList(void)
138 MAYBE_UNUSED _EGLDevice
*dev
;
141 dev
= _eglGlobal
.DeviceList
;
147 _eglQueryDevicesEXT(EGLint max_devices
,
148 _EGLDevice
**devices
,
151 _EGLDevice
*dev
, *devs
;
154 if ((devices
&& max_devices
<= 0) || !num_devices
)
155 return _eglError(EGL_BAD_PARAMETER
, "eglQueryDevicesEXT");
157 mtx_lock(_eglGlobal
.Mutex
);
159 num_devs
= _eglRefreshDeviceList();
160 devs
= _eglGlobal
.DeviceList
;
162 /* bail early if we only care about the count */
164 *num_devices
= num_devs
;
168 *num_devices
= MIN2(num_devs
, max_devices
);
170 for (i
= 0, dev
= devs
; i
< *num_devices
; i
++) {
176 mtx_unlock(_eglGlobal
.Mutex
);