egl: keep the software device at the end of the list
authorEmil Velikov <emil.velikov@collabora.com>
Thu, 16 May 2019 17:01:39 +0000 (18:01 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 5 Jun 2019 17:35:21 +0000 (13:35 -0400)
By default, the user is likely to pick the first device so it should
not be the least performant (aka software) one.

v2: Drop odd comment (Marek)

Suggested-by: Marek Olšák <maraeo@gmail.com>
Reviewed-by: Mathias Fröhlich <Mathias.Froehlich@web.de> (v1)
Reviewed-by: Marek Olšák <marek.olsak@amd.com> (v1)
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Marek Olšák <marek.olsak@amd.com>
src/egl/main/egldevice.c

index c5c9a21273a505847e153de7940a9c569a070f29..82af1f47fedbdc459c4d4aa0975fcf6a1960f7a0 100644 (file)
@@ -293,13 +293,25 @@ _eglQueryDevicesEXT(EGLint max_devices,
       goto out;
    }
 
+   /* Push the first device (the software one) to the end of the list.
+    * Sending it to the user only if they've requested the full list.
+    *
+    * By default, the user is likely to pick the first device so having the
+    * software (aka least performant) one is not a good idea.
+    */
    *num_devices = MIN2(num_devs, max_devices);
 
-   for (i = 0, dev = devs; i < *num_devices; i++) {
+   for (i = 0, dev = devs->Next; dev && i < max_devices; i++) {
       devices[i] = dev;
       dev = dev->Next;
    }
 
+   /* User requested the full device list, add the sofware device. */
+   if (max_devices >= num_devs) {
+      assert(_eglDeviceSupports(devs, _EGL_DEVICE_SOFTWARE));
+      devices[num_devs - 1] = devs;
+   }
+
 out:
    mtx_unlock(_eglGlobal.Mutex);