Blame SOURCES/0011-xwayland-eglstream-Small-refactoring.patch

b6a310
From 9966356963803db35997f26330fb1245777012a1 Mon Sep 17 00:00:00 2001
b6a310
From: Olivier Fourdan <ofourdan@redhat.com>
b6a310
Date: Thu, 15 Apr 2021 10:59:36 +0200
b6a310
Subject: [PATCH xserver 11/27] xwayland/eglstream: Small refactoring
b6a310
MIME-Version: 1.0
b6a310
Content-Type: text/plain; charset=UTF-8
b6a310
Content-Transfer-Encoding: 8bit
b6a310
b6a310
Some functions are called "callback" whereas they are not longer
b6a310
callback functions or "unref" while they no longer deal with a reference
b6a310
counter anymore, which is quite confusing. Rename those functions to be
b6a310
more explicit.
b6a310
b6a310
Also, the pending streams can be destroyed in different places, move the
b6a310
common code to separate function to avoid duplicating code and help with
b6a310
readability of the code.
b6a310
b6a310
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
b6a310
Acked-by: Michel Dänzer <mdaenzer@redhat.com>
b6a310
(cherry picked from commit 823f3254fabd16e5e721da57cd260beac9b8f8bd)
b6a310
---
b6a310
 hw/xwayland/xwayland-glamor-eglstream.c | 42 ++++++++++++++-----------
b6a310
 1 file changed, 24 insertions(+), 18 deletions(-)
b6a310
b6a310
diff --git a/hw/xwayland/xwayland-glamor-eglstream.c b/hw/xwayland/xwayland-glamor-eglstream.c
b6a310
index 64fe93b7c..9abb7b779 100644
b6a310
--- a/hw/xwayland/xwayland-glamor-eglstream.c
b6a310
+++ b/hw/xwayland/xwayland-glamor-eglstream.c
b6a310
@@ -287,7 +287,7 @@ xwl_glamor_egl_device_has_egl_extensions(void *device,
b6a310
 }
b6a310
 
b6a310
 static void
b6a310
-xwl_eglstream_unref_pixmap_stream(struct xwl_pixmap *xwl_pixmap)
b6a310
+xwl_eglstream_destroy_pixmap_stream(struct xwl_pixmap *xwl_pixmap)
b6a310
 {
b6a310
     struct xwl_screen *xwl_screen = xwl_pixmap->xwl_screen;
b6a310
 
b6a310
@@ -319,7 +319,17 @@ xwl_eglstream_unref_pixmap_stream(struct xwl_pixmap *xwl_pixmap)
b6a310
 }
b6a310
 
b6a310
 static void
b6a310
-xwl_glamor_eglstream_del_pending_stream_cb(struct xwl_pixmap *xwl_pixmap)
b6a310
+xwl_glamor_eglstream_destroy_pending_stream(struct xwl_eglstream_pending_stream *pending)
b6a310
+{
b6a310
+    if (pending->cb)
b6a310
+        wl_callback_destroy(pending->cb);
b6a310
+    xwl_eglstream_window_set_pending(pending->window, NULL);
b6a310
+    xorg_list_del(&pending->link);
b6a310
+    free(pending);
b6a310
+}
b6a310
+
b6a310
+static void
b6a310
+xwl_glamor_eglstream_remove_pending_stream(struct xwl_pixmap *xwl_pixmap)
b6a310
 {
b6a310
     struct xwl_eglstream_private *xwl_eglstream =
b6a310
         xwl_eglstream_get(xwl_pixmap->xwl_screen);
b6a310
@@ -328,10 +338,7 @@ xwl_glamor_eglstream_del_pending_stream_cb(struct xwl_pixmap *xwl_pixmap)
b6a310
     xorg_list_for_each_entry(pending,
b6a310
                              &xwl_eglstream->pending_streams, link) {
b6a310
         if (pending->xwl_pixmap == xwl_pixmap) {
b6a310
-            wl_callback_destroy(pending->cb);
b6a310
-            xwl_eglstream_window_set_pending(pending->window, NULL);
b6a310
-            xorg_list_del(&pending->link);
b6a310
-            free(pending);
b6a310
+            xwl_glamor_eglstream_destroy_pending_stream(pending);
b6a310
             break;
b6a310
         }
b6a310
     }
b6a310
@@ -343,9 +350,9 @@ xwl_glamor_eglstream_destroy_pixmap(PixmapPtr pixmap)
b6a310
     struct xwl_pixmap *xwl_pixmap = xwl_pixmap_get(pixmap);
b6a310
 
b6a310
     if (xwl_pixmap && pixmap->refcnt == 1) {
b6a310
-        xwl_glamor_eglstream_del_pending_stream_cb(xwl_pixmap);
b6a310
+        xwl_glamor_eglstream_remove_pending_stream(xwl_pixmap);
b6a310
+        xwl_eglstream_destroy_pixmap_stream(xwl_pixmap);
b6a310
         xwl_pixmap_del_buffer_release_cb(pixmap);
b6a310
-        xwl_eglstream_unref_pixmap_stream(xwl_pixmap);
b6a310
     }
b6a310
     return glamor_destroy_pixmap(pixmap);
b6a310
 }
b6a310
@@ -432,8 +439,6 @@ xwl_eglstream_consumer_ready_callback(void *data,
b6a310
     struct xwl_eglstream_pending_stream *pending;
b6a310
     Bool found = FALSE;
b6a310
 
b6a310
-    wl_callback_destroy(callback);
b6a310
-
b6a310
     xorg_list_for_each_entry(pending, &xwl_eglstream->pending_streams, link) {
b6a310
         if (pending->cb == callback) {
b6a310
             found = TRUE;
b6a310
@@ -442,8 +447,11 @@ xwl_eglstream_consumer_ready_callback(void *data,
b6a310
     }
b6a310
     assert(found);
b6a310
 
b6a310
+    wl_callback_destroy(callback);
b6a310
+    pending->cb = NULL;
b6a310
+
b6a310
     if (!pending->is_valid) {
b6a310
-        xwl_eglstream_unref_pixmap_stream(pending->xwl_pixmap);
b6a310
+        xwl_eglstream_destroy_pixmap_stream(pending->xwl_pixmap);
b6a310
         goto out;
b6a310
     }
b6a310
 
b6a310
@@ -462,9 +470,7 @@ xwl_eglstream_consumer_ready_callback(void *data,
b6a310
            pending->window->drawable.id, pending->pixmap);
b6a310
 
b6a310
 out:
b6a310
-    xwl_eglstream_window_set_pending(pending->window, NULL);
b6a310
-    xorg_list_del(&pending->link);
b6a310
-    free(pending);
b6a310
+    xwl_glamor_eglstream_destroy_pending_stream(pending);
b6a310
 }
b6a310
 
b6a310
 static const struct wl_callback_listener consumer_ready_listener = {
b6a310
@@ -514,8 +520,8 @@ static const struct wl_buffer_listener xwl_eglstream_buffer_release_listener = {
b6a310
 };
b6a310
 
b6a310
 static void
b6a310
-xwl_eglstream_create_pending_stream(struct xwl_screen *xwl_screen,
b6a310
-                                    WindowPtr window, PixmapPtr pixmap)
b6a310
+xwl_eglstream_create_pixmap_and_stream(struct xwl_screen *xwl_screen,
b6a310
+                                       WindowPtr window, PixmapPtr pixmap)
b6a310
 {
b6a310
     struct xwl_eglstream_private *xwl_eglstream =
b6a310
         xwl_eglstream_get(xwl_screen);
b6a310
@@ -599,8 +605,8 @@ xwl_glamor_eglstream_allow_commits(struct xwl_window *xwl_window)
b6a310
     /* Glamor pixmap has no backing stream yet; begin making one and disallow
b6a310
      * commits until then
b6a310
      */
b6a310
-    xwl_eglstream_create_pending_stream(xwl_screen, xwl_window->window,
b6a310
-                                        pixmap);
b6a310
+    xwl_eglstream_create_pixmap_and_stream(xwl_screen, xwl_window->window,
b6a310
+                                           pixmap);
b6a310
 
b6a310
     return FALSE;
b6a310
 }
b6a310
-- 
b6a310
2.31.1
b6a310