Blame SOURCES/582b2d345abaa0e313cf16c902e602084ea59551.patch

204100
From 582b2d345abaa0e313cf16c902e602084ea59551 Mon Sep 17 00:00:00 2001
204100
From: Erik Kurzinger <ekurzinger@nvidia.com>
204100
Date: Tue, 23 Nov 2021 14:15:14 -0500
204100
Subject: [PATCH] egl-wayland: retrieve DRM device name before acquiring API
204100
 lock
204100
204100
wlEglBindDisplaysHook acquires the external API lock before calling
204100
wl_eglstream_display_bind, which in turn calls wl_drm_display_bind. That
204100
function calls back into EGL to query the DRM device associated with the
204100
given EGLDisplay.
204100
204100
Normally this is not a problem since the EGLDisplay passed to
204100
eglBindWaylandDisplayWL will be an internal EGL_PLATFORM_DEVICE handle.
204100
However, some applications, notably anything WebKit-based, will instead
204100
pass in an external EGL_PLATFORM_WAYLAND handle. This means that the
204100
eglQueryDisplayAttrib call by wl_drm_display_bind will require EGL to
204100
call back into the egl-wayland library to look up the internal handle.
204100
This is done by wlEglGetInternalHandleExport, which will attempt to
204100
acquire the external API lock a second time, which will fail.
204100
204100
To avoid this, add a new function to wayland-drm.c which will retrieve
204100
the DRM device name for the given EGLDisplay. wlEglBindDisplaysHook will
204100
call this *before* acquiring the external API lock, and then pass it to
204100
wl_drm_display_bind via wl_eglstream_display_bind so it can be saved in
204100
the wl_eglstream_display struct.
204100
---
204100
 include/wayland-drm.h              |  7 ++++++-
204100
 include/wayland-eglstream-server.h |  3 ++-
204100
 src/wayland-drm.c                  | 33 +++++++++++++++---------------
204100
 src/wayland-egldisplay.c           |  8 +++++---
204100
 src/wayland-eglstream-server.c     |  5 +++--
204100
 5 files changed, 32 insertions(+), 24 deletions(-)
204100
204100
diff --git a/include/wayland-drm.h b/include/wayland-drm.h
204100
index be363c6..84d0f11 100644
204100
--- a/include/wayland-drm.h
204100
+++ b/include/wayland-drm.h
204100
@@ -23,9 +23,14 @@
204100
 #ifndef WAYLAND_DRM_H
204100
 #define WAYLAND_DRM_H
204100
 
204100
+extern const char *
204100
+wl_drm_get_dev_name(const WlEglPlatformData *data,
204100
+                    EGLDisplay dpy);
204100
+
204100
 extern EGLBoolean
204100
 wl_drm_display_bind(struct wl_display *display,
204100
-                    struct wl_eglstream_display *wlStreamDpy);
204100
+                    struct wl_eglstream_display *wlStreamDpy,
204100
+                    const char *dev_name);
204100
 extern void
204100
 wl_drm_display_unbind(struct wl_eglstream_display *wlStreamDpy);
204100
 
204100
diff --git a/include/wayland-eglstream-server.h b/include/wayland-eglstream-server.h
204100
index 76e772c..0f7d477 100644
204100
--- a/include/wayland-eglstream-server.h
204100
+++ b/include/wayland-eglstream-server.h
204100
@@ -49,7 +49,8 @@ EGLBoolean
204100
 wl_eglstream_display_bind(WlEglPlatformData *data,
204100
                           struct wl_display *wlDisplay,
204100
                           EGLDisplay eglDisplay,
204100
-                          const char *exts);
204100
+                          const char *exts,
204100
+                          const char *dev_name);
204100
 
204100
 /*
204100
  * wl_eglstream_display_unbind()
204100
diff --git a/src/wayland-drm.c b/src/wayland-drm.c
204100
index aa6de23..a08d82f 100644
204100
--- a/src/wayland-drm.c
204100
+++ b/src/wayland-drm.c
204100
@@ -152,37 +152,36 @@ bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
204100
         wl_resource_post_event(resource, WL_DRM_CAPABILITIES, 0);
204100
 }
204100
 
204100
-EGLBoolean
204100
-wl_drm_display_bind(struct wl_display *display,
204100
-                    struct wl_eglstream_display *wlStreamDpy)
204100
+const char *
204100
+wl_drm_get_dev_name(const WlEglPlatformData *data,
204100
+                    EGLDisplay dpy)
204100
 {
204100
-    EGLDisplay dpy = wlStreamDpy->eglDisplay;
204100
     EGLDeviceEXT egl_dev;
204100
     const char *dev_exts;
204100
-    const char *dev_name;
204100
 
204100
-    if (!wlStreamDpy->data->egl.queryDisplayAttrib(dpy,
204100
-                                                   EGL_DEVICE_EXT,
204100
-                                                   (EGLAttribKHR*)&egl_dev)) {
204100
-        return EGL_FALSE;
204100
+    if (!data->egl.queryDisplayAttrib(dpy, EGL_DEVICE_EXT,
204100
+                                      (EGLAttribKHR*)&egl_dev)) {
204100
+        return NULL;
204100
     }
204100
 
204100
-
204100
-    dev_exts = wlStreamDpy->data->egl.queryDeviceString(egl_dev,
204100
-                                                        EGL_EXTENSIONS);
204100
+    dev_exts = data->egl.queryDeviceString(egl_dev, EGL_EXTENSIONS);
204100
 
204100
     if (!dev_exts) {
204100
-        return EGL_FALSE;
204100
+        return NULL;
204100
     }
204100
 
204100
     if (!wlEglFindExtension("EGL_EXT_device_drm_render_node", dev_exts)) {
204100
-        return EGL_FALSE;
204100
+        return NULL;
204100
     }
204100
 
204100
-    dev_name =
204100
-        wlStreamDpy->data->egl.queryDeviceString(egl_dev,
204100
-                                                 EGL_DRM_RENDER_NODE_FILE_EXT);
204100
+    return data->egl.queryDeviceString(egl_dev, EGL_DRM_RENDER_NODE_FILE_EXT);
204100
+}
204100
 
204100
+EGLBoolean
204100
+wl_drm_display_bind(struct wl_display *display,
204100
+                    struct wl_eglstream_display *wlStreamDpy,
204100
+                    const char *dev_name)
204100
+{
204100
     if (!dev_name) {
204100
         return EGL_FALSE;
204100
     }
204100
diff --git a/src/wayland-egldisplay.c b/src/wayland-egldisplay.c
204100
index 8b7394a..d285bf7 100644
204100
--- a/src/wayland-egldisplay.c
204100
+++ b/src/wayland-egldisplay.c
204100
@@ -30,6 +30,7 @@
204100
 #include "wayland-eglhandle.h"
204100
 #include "wayland-eglutils.h"
204100
 #include "wayland-drm-client-protocol.h"
204100
+#include "wayland-drm.h"
204100
 #include <string.h>
204100
 #include <stdlib.h>
204100
 #include <assert.h>
204100
@@ -70,15 +71,16 @@ EGLBoolean wlEglIsValidNativeDisplayExport(void *data, void *nativeDpy)
204100
 
204100
 EGLBoolean wlEglBindDisplaysHook(void *data, EGLDisplay dpy, void *nativeDpy)
204100
 {
204100
-    /* Retrieve extension string before taking external API lock */
204100
-    const char *exts = ((WlEglPlatformData *)data)->egl.queryString(dpy, EGL_EXTENSIONS);
204100
+    /* Retrieve extension string and device name before taking external API lock */
204100
+    const char *exts = ((WlEglPlatformData *)data)->egl.queryString(dpy, EGL_EXTENSIONS),
204100
+               *dev_name = wl_drm_get_dev_name(data, dpy);
204100
     EGLBoolean res = EGL_FALSE;
204100
 
204100
     wlExternalApiLock();
204100
 
204100
     res = wl_eglstream_display_bind((WlEglPlatformData *)data,
204100
                                     (struct wl_display *)nativeDpy,
204100
-                                    dpy, exts);
204100
+                                    dpy, exts, dev_name);
204100
 
204100
     wlExternalApiUnlock();
204100
 
204100
diff --git a/src/wayland-eglstream-server.c b/src/wayland-eglstream-server.c
204100
index b1baa08..1dfd7ce 100644
204100
--- a/src/wayland-eglstream-server.c
204100
+++ b/src/wayland-eglstream-server.c
204100
@@ -289,7 +289,8 @@ EGLBoolean
204100
 wl_eglstream_display_bind(WlEglPlatformData *data,
204100
                           struct wl_display *wlDisplay,
204100
                           EGLDisplay eglDisplay,
204100
-                          const char *exts)
204100
+                          const char *exts,
204100
+                          const char *dev_name)
204100
 {
204100
     struct wl_eglstream_display *wlStreamDpy = NULL;
204100
     char                        *env         = NULL;
204100
@@ -355,7 +356,7 @@ wl_eglstream_display_bind(WlEglPlatformData *data,
204100
                                            wl_eglstream_display_global_bind);
204100
 
204100
     /* Failure is not fatal */
204100
-    wl_drm_display_bind(wlDisplay, wlStreamDpy);
204100
+    wl_drm_display_bind(wlDisplay, wlStreamDpy, dev_name);
204100
 
204100
     wl_list_insert(&wlStreamDpyList, &wlStreamDpy->link);
204100