Blame SOURCES/0012-xwayland-eglstream-Add-more-error-checking.patch

b6a310
From e8f7568016249822bb95c87447ded6abb724c13b Mon Sep 17 00:00:00 2001
b6a310
From: Olivier Fourdan <ofourdan@redhat.com>
b6a310
Date: Thu, 1 Apr 2021 08:46:52 +0200
b6a310
Subject: [PATCH xserver 12/27] xwayland/eglstream: Add more error checking
b6a310
MIME-Version: 1.0
b6a310
Content-Type: text/plain; charset=UTF-8
b6a310
Content-Transfer-Encoding: 8bit
b6a310
b6a310
eglCreateStreamKHR() can fail and return EGL_NO_STREAM_KHR, in which
b6a310
case there is no point in trying to create a buffer from it.
b6a310
b6a310
Similarly, eglCreateStreamProducerSurfaceKHR() also fail and return
b6a310
EGL_NO_SURFACE, which in turn will be used in eglMakeCurrent() as
b6a310
draw/read surface, and therefore would mean no draw/read buffer.
b6a310
b6a310
In those cases, log the error, and bail out early. That won't solve the
b6a310
issue but will help with investigating the root cause of issues with
b6a310
EGLStream backend.
b6a310
b6a310
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
b6a310
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
b6a310
https://gitlab.freedesktop.org/xorg/xserver/-/issues/1156
b6a310
(cherry picked from commit cc596bcfb273eeab82ac3d59867668af8bad2abf)
b6a310
---
b6a310
 hw/xwayland/xwayland-glamor-eglstream.c | 93 +++++++++++++++++++++++++
b6a310
 1 file changed, 93 insertions(+)
b6a310
b6a310
diff --git a/hw/xwayland/xwayland-glamor-eglstream.c b/hw/xwayland/xwayland-glamor-eglstream.c
b6a310
index 9abb7b779..77b24a4b4 100644
b6a310
--- a/hw/xwayland/xwayland-glamor-eglstream.c
b6a310
+++ b/hw/xwayland/xwayland-glamor-eglstream.c
b6a310
@@ -387,6 +387,84 @@ xwl_eglstream_set_window_pixmap(WindowPtr window, PixmapPtr pixmap)
b6a310
     xwl_screen->screen->SetWindowPixmap = xwl_eglstream_set_window_pixmap;
b6a310
 }
b6a310
 
b6a310
+static const char *
b6a310
+xwl_eglstream_get_error_str(EGLint error)
b6a310
+{
b6a310
+    switch (error) {
b6a310
+    case EGL_BAD_PARAMETER:
b6a310
+        return "EGL_BAD_PARAMETER";
b6a310
+    case EGL_BAD_ATTRIBUTE:
b6a310
+        return "EGL_BAD_ATTRIBUTE";
b6a310
+    case EGL_BAD_MATCH:
b6a310
+        return "EGL_BAD_MATCH";
b6a310
+    case EGL_BAD_ACCESS:
b6a310
+        return "EGL_BAD_ACCESS";
b6a310
+    case EGL_BAD_STATE_KHR:
b6a310
+        return "EGL_BAD_STATE_KHR";
b6a310
+    case EGL_BAD_STREAM_KHR:
b6a310
+        return "EGL_BAD_STREAM_KHR";
b6a310
+    case EGL_BAD_DISPLAY:
b6a310
+        return "EGL_BAD_DISPLAY";
b6a310
+    case EGL_NOT_INITIALIZED:
b6a310
+        return "EGL_NOT_INITIALIZED";
b6a310
+    default:
b6a310
+        return "Unknown error";
b6a310
+    }
b6a310
+}
b6a310
+
b6a310
+static const char *
b6a310
+xwl_eglstream_get_stream_state_str(EGLint state)
b6a310
+{
b6a310
+    switch (state) {
b6a310
+    case EGL_STREAM_STATE_CREATED_KHR:
b6a310
+        return "EGL_STREAM_STATE_CREATED_KHR";
b6a310
+    case EGL_STREAM_STATE_CONNECTING_KHR:
b6a310
+        return "EGL_STREAM_STATE_CONNECTING_KHR";
b6a310
+    case EGL_STREAM_STATE_EMPTY_KHR:
b6a310
+        return "EGL_STREAM_STATE_EMPTY_KHR";
b6a310
+    case EGL_STREAM_STATE_NEW_FRAME_AVAILABLE_KHR:
b6a310
+        return "EGL_STREAM_STATE_NEW_FRAME_AVAILABLE_KHR";
b6a310
+    case EGL_STREAM_STATE_OLD_FRAME_AVAILABLE_KHR:
b6a310
+        return "EGL_STREAM_STATE_OLD_FRAME_AVAILABLE_KHR";
b6a310
+    case EGL_STREAM_STATE_DISCONNECTED_KHR:
b6a310
+        return "EGL_STREAM_STATE_DISCONNECTED_KHR";
b6a310
+    default:
b6a310
+        return "Unknown state";
b6a310
+    }
b6a310
+}
b6a310
+
b6a310
+static EGLint
b6a310
+xwl_eglstream_get_state(EGLDisplay egl_display, EGLStreamKHR egl_stream)
b6a310
+{
b6a310
+    EGLint state;
b6a310
+
b6a310
+    eglQueryStreamKHR(egl_display, egl_stream, EGL_STREAM_STATE_KHR, &state);
b6a310
+    if (!eglQueryStreamKHR(egl_display, egl_stream,
b6a310
+                           EGL_STREAM_STATE_KHR, &state)) {
b6a310
+        EGLint state_error = eglGetError();
b6a310
+        ErrorF("eglstream: Failed to query state - error 0x%X: %s\n",
b6a310
+               state_error, xwl_eglstream_get_error_str(state_error));
b6a310
+        return EGL_FALSE;
b6a310
+    }
b6a310
+
b6a310
+    return state;
b6a310
+}
b6a310
+
b6a310
+
b6a310
+static void
b6a310
+xwl_eglstream_print_error(EGLDisplay egl_display,
b6a310
+                          EGLStreamKHR egl_stream, EGLint error)
b6a310
+{
b6a310
+    ErrorF("eglstream: error 0x%X: %s\n", error,
b6a310
+           xwl_eglstream_get_error_str(error));
b6a310
+
b6a310
+    if (error == EGL_BAD_STATE_KHR) {
b6a310
+        EGLint state = xwl_eglstream_get_state(egl_display, egl_stream);
b6a310
+        ErrorF("eglstream: stream state 0x%X: %s\n", state,
b6a310
+               xwl_eglstream_get_stream_state_str(state));
b6a310
+    }
b6a310
+}
b6a310
+
b6a310
 /* Because we run asynchronously with our wayland compositor, it's possible
b6a310
  * that an X client event could cause us to begin creating a stream for a
b6a310
  * pixmap/window combo before the stream for the pixmap this window
b6a310
@@ -466,6 +544,13 @@ xwl_eglstream_consumer_ready_callback(void *data,
b6a310
             EGL_NONE
b6a310
         });
b6a310
 
b6a310
+    if (xwl_pixmap->surface == EGL_NO_SURFACE) {
b6a310
+        ErrorF("eglstream: Failed to create EGLSurface for pixmap\n");
b6a310
+        xwl_eglstream_print_error(xwl_screen->egl_display,
b6a310
+                                  xwl_pixmap->stream, eglGetError());
b6a310
+        goto out;
b6a310
+    }
b6a310
+
b6a310
     DebugF("eglstream: win %d completes eglstream for pixmap %p, congrats!\n",
b6a310
            pending->window->drawable.id, pending->pixmap);
b6a310
 
b6a310
@@ -543,8 +628,16 @@ xwl_eglstream_create_pixmap_and_stream(struct xwl_screen *xwl_screen,
b6a310
     xwl_pixmap->xwl_screen = xwl_screen;
b6a310
     xwl_pixmap->surface = EGL_NO_SURFACE;
b6a310
     xwl_pixmap->stream = eglCreateStreamKHR(xwl_screen->egl_display, NULL);
b6a310
+    if (xwl_pixmap->stream == EGL_NO_STREAM_KHR) {
b6a310
+        ErrorF("eglstream: Couldn't create EGL stream.\n");
b6a310
+        goto fail;
b6a310
+    }
b6a310
     stream_fd = eglGetStreamFileDescriptorKHR(xwl_screen->egl_display,
b6a310
                                               xwl_pixmap->stream);
b6a310
+    if (stream_fd == EGL_NO_FILE_DESCRIPTOR_KHR) {
b6a310
+        ErrorF("eglstream: Couldn't get EGL stream file descriptor.\n");
b6a310
+        goto fail;
b6a310
+    }
b6a310
 
b6a310
     wl_array_init(&stream_attribs);
b6a310
     xwl_pixmap->buffer =
b6a310
-- 
b6a310
2.31.1
b6a310