egl: use render node for wl_drm if available
authorSimon Ser <contact@emersion.fr>
Mon, 1 Mar 2021 11:57:54 +0000 (12:57 +0100)
committerMarge Bot <eric+marge@anholt.net>
Tue, 9 Mar 2021 15:43:51 +0000 (15:43 +0000)
This causes clients to use the render node and skip DRM
authentication if a DRM render node is available.

Signed-off-by: Simon Ser <contact@emersion.fr>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9334>

src/egl/drivers/dri2/egl_dri2.c

index 62fc7fb..0e48b96 100644 (file)
@@ -3242,11 +3242,18 @@ dri2_bind_wayland_display_wl(_EGLDisplay *disp, struct wl_display *wl_dpy)
       .is_format_supported = dri2_wl_is_format_supported
    };
    int flags = 0;
+   char *device_name;
    uint64_t cap;
 
    if (dri2_dpy->wl_server_drm)
            return EGL_FALSE;
 
+   device_name = drmGetRenderDeviceNameFromFd(dri2_dpy->fd);
+   if (!device_name)
+      device_name = strdup(dri2_dpy->device_name);
+   if (!device_name)
+      return EGL_FALSE;
+
    if (drmGetCap(dri2_dpy->fd, DRM_CAP_PRIME, &cap) == 0 &&
        cap == (DRM_PRIME_CAP_IMPORT | DRM_PRIME_CAP_EXPORT) &&
        dri2_dpy->image->base.version >= 7 &&
@@ -3254,9 +3261,11 @@ dri2_bind_wayland_display_wl(_EGLDisplay *disp, struct wl_display *wl_dpy)
       flags |= WAYLAND_DRM_PRIME;
 
    dri2_dpy->wl_server_drm =
-           wayland_drm_init(wl_dpy, dri2_dpy->device_name,
+           wayland_drm_init(wl_dpy, device_name,
                             &wl_drm_callbacks, disp, flags);
 
+   free(device_name);
+
    if (!dri2_dpy->wl_server_drm)
            return EGL_FALSE;