egl: reorder code in _eglQueryDevicesEXT, add *swrast variable

This is a preparation for the next commit. No change in behavior.

Reviewed-by: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
(cherry picked from commit 5952715064)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28885>
This commit is contained in:
Marek Olšák 2023-03-20 12:55:48 -04:00 committed by Matt Turner
parent 775d126791
commit f62e842e31

View file

@ -322,7 +322,7 @@ _eglQueryDevicesEXT(EGLint max_devices,
_EGLDevice **devices, _EGLDevice **devices,
EGLint *num_devices) EGLint *num_devices)
{ {
_EGLDevice *dev, *devs; _EGLDevice *dev, *devs, *swrast;
int i = 0, num_devs; int i = 0, num_devs;
if ((devices && max_devices <= 0) || !num_devices) if ((devices && max_devices <= 0) || !num_devices)
@ -332,6 +332,10 @@ _eglQueryDevicesEXT(EGLint max_devices,
num_devs = _eglRefreshDeviceList(); num_devs = _eglRefreshDeviceList();
devs = _eglGlobal.DeviceList; devs = _eglGlobal.DeviceList;
swrast = devs;
/* The first device is swrast. Start with the non-swrast device. */
devs = devs->Next;
/* bail early if we only care about the count */ /* bail early if we only care about the count */
if (!devices) { if (!devices) {
@ -339,23 +343,22 @@ _eglQueryDevicesEXT(EGLint max_devices,
goto out; goto out;
} }
/* Push the first device (the software one) to the end of the list. *num_devices = MIN2(num_devs, max_devices);
* Sending it to the user only if they've requested the full list.
/* Add non-swrast devices first and add swrast last.
* *
* By default, the user is likely to pick the first device so having the * By default, the user is likely to pick the first device so having the
* software (aka least performant) one is not a good idea. * software (aka least performant) one is not a good idea.
*/ */
*num_devices = MIN2(num_devs, max_devices); for (i = 0, dev = devs; dev && i < max_devices; i++) {
for (i = 0, dev = devs->Next; dev && i < max_devices; i++) {
devices[i] = dev; devices[i] = dev;
dev = dev->Next; dev = dev->Next;
} }
/* User requested the full device list, add the sofware device. */ /* User requested the full device list, add the sofware device. */
if (max_devices >= num_devs) { if (max_devices >= num_devs) {
assert(_eglDeviceSupports(devs, _EGL_DEVICE_SOFTWARE)); assert(_eglDeviceSupports(swrast, _EGL_DEVICE_SOFTWARE));
devices[num_devs - 1] = devs; devices[num_devs - 1] = swrast;
} }
out: out: