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

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