egl/android: use software rendering when appropriate
[mesa.git] / src / egl / drivers / dri2 / platform_android.c
index 1c508b9feb39e21a58bf4ad32264c1a830b57565..e25a6f73ed829a356fa155e26036f4034c740739 100644 (file)
@@ -1365,6 +1365,21 @@ droid_load_driver(_EGLDisplay *disp, bool swrast)
       goto error;
    }
 #else
+   if (swrast) {
+      /* Use kms swrast only with vgem / virtio_gpu.
+       * virtio-gpu fallbacks to software rendering when 3D features
+       * are unavailable since 6c5ab.
+       */
+      if (strcmp(dri2_dpy->driver_name, "vgem") == 0 ||
+          strcmp(dri2_dpy->driver_name, "virtio_gpu") == 0) {
+         free(dri2_dpy->driver_name);
+         dri2_dpy->driver_name = strdup("kms_swrast");
+      } else {
+         err = "DRI3: failed to find software capable driver";
+         goto error;
+      }
+   }
+
    dri2_dpy->loader_extensions = droid_image_loader_extensions;
    if (!dri2_load_driver_dri3(disp)) {
       err = "DRI3: failed to load driver";
@@ -1432,6 +1447,9 @@ droid_open_device(_EGLDisplay *disp, bool swrast)
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
    int fd = -1, err = -EINVAL;
 
+   if (swrast)
+      return EGL_FALSE;
+
    if (dri2_dpy->gralloc->perform)
       err = dri2_dpy->gralloc->perform(dri2_dpy->gralloc,
                                        GRALLOC_MODULE_PERFORM_GET_DRM_FD,
@@ -1527,14 +1545,11 @@ EGLBoolean
 dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp)
 {
    _EGLDevice *dev;
+   bool device_opened = false;
    struct dri2_egl_display *dri2_dpy;
    const char *err;
    int ret;
 
-   /* Not supported yet */
-   if (disp->Options.ForceSoftware)
-      return EGL_FALSE;
-
    dri2_dpy = calloc(1, sizeof(*dri2_dpy));
    if (!dri2_dpy)
       return _eglError(EGL_BAD_ALLOC, "eglInitialize");
@@ -1548,8 +1563,12 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp)
    }
 
    disp->DriverData = (void *) dri2_dpy;
+   if (!disp->Options.ForceSoftware)
+      device_opened = droid_open_device(disp, false);
+   if (!device_opened)
+      device_opened = droid_open_device(disp, true);
 
-   if (!droid_open_device(disp, false)) {
+   if (!device_opened) {
       err = "DRI2: failed to open device";
       goto cleanup;
    }