e625aaa
From 5a1cb0989274fd745569a60c28c9a5ca729cabf6 Mon Sep 17 00:00:00 2001
e625aaa
From: =?UTF-8?q?Michel=20D=C3=A4nzer?= <michel.daenzer@amd.com>
e625aaa
Date: Thu, 1 Nov 2018 18:44:24 +0100
e625aaa
Subject: [PATCH xserver 4/7] xwayland: Replace xwl_window::present_window with
e625aaa
 ::present_flipped
e625aaa
e625aaa
There's no need to keep track of the window which last performed a
e625aaa
Present flip. This fixes crashes due to the assertion in
e625aaa
xwl_present_flips_stop failing. Fixes issue #10.
e625aaa
e625aaa
The damage generated by a flip only needs to be ignored once, then
e625aaa
xwl_window::present_flipped can be cleared. This may fix freezing in
e625aaa
the (hypothetical) scenario where Present flips are performed on a
e625aaa
window, followed by other drawing requests using the window as the
e625aaa
destination, but nothing triggering xwl_present_flips_stop. The damage
e625aaa
from the latter drawing requests would continue being ignored.
e625aaa
e625aaa
(cherry picked from commit 6b016d58d23d16eaae9908a92ed90547d1926317)
e625aaa
---
e625aaa
 hw/xwayland/xwayland-present.c | 56 ++++++++--------------------------
e625aaa
 hw/xwayland/xwayland.c         | 17 ++++++++---
e625aaa
 hw/xwayland/xwayland.h         |  4 ++-
e625aaa
 3 files changed, 27 insertions(+), 50 deletions(-)
e625aaa
e625aaa
diff --git a/hw/xwayland/xwayland-present.c b/hw/xwayland/xwayland-present.c
e625aaa
index 4f517d46b..e6dca5ed0 100644
e625aaa
--- a/hw/xwayland/xwayland-present.c
e625aaa
+++ b/hw/xwayland/xwayland-present.c
e625aaa
@@ -90,24 +90,19 @@ xwl_present_has_events(struct xwl_present_window *xwl_present_window)
e625aaa
            !xorg_list_is_empty(&xwl_present_window->release_queue);
e625aaa
 }
e625aaa
 
e625aaa
-static inline Bool
e625aaa
-xwl_present_is_flipping(WindowPtr window, struct xwl_window *xwl_window)
e625aaa
-{
e625aaa
-    return xwl_window && xwl_window->present_window == window;
e625aaa
-}
e625aaa
-
e625aaa
 static void
e625aaa
 xwl_present_reset_timer(struct xwl_present_window *xwl_present_window)
e625aaa
 {
e625aaa
     if (xwl_present_has_events(xwl_present_window)) {
e625aaa
-        WindowPtr present_window = xwl_present_window->window;
e625aaa
-        Bool is_flipping = xwl_present_is_flipping(present_window,
e625aaa
-                                                   xwl_window_from_window(present_window));
e625aaa
+        CARD32 timeout;
e625aaa
+
e625aaa
+        if (xwl_present_window->frame_callback)
e625aaa
+            timeout = TIMER_LEN_FLIP;
e625aaa
+        else
e625aaa
+            timeout = TIMER_LEN_COPY;
e625aaa
 
e625aaa
         xwl_present_window->frame_timer = TimerSet(xwl_present_window->frame_timer,
e625aaa
-                                                   0,
e625aaa
-                                                   is_flipping ? TIMER_LEN_FLIP :
e625aaa
-                                                                 TIMER_LEN_COPY,
e625aaa
+                                                   0, timeout,
e625aaa
                                                    &xwl_present_timer_callback,
e625aaa
                                                    xwl_present_window);
e625aaa
     } else {
e625aaa
@@ -118,16 +113,12 @@ xwl_present_reset_timer(struct xwl_present_window *xwl_present_window)
e625aaa
 void
e625aaa
 xwl_present_cleanup(WindowPtr window)
e625aaa
 {
e625aaa
-    struct xwl_window *xwl_window = xwl_window_from_window(window);
e625aaa
     struct xwl_present_window *xwl_present_window = xwl_present_window_priv(window);
e625aaa
     struct xwl_present_event *event, *tmp;
e625aaa
 
e625aaa
     if (!xwl_present_window)
e625aaa
         return;
e625aaa
 
e625aaa
-    if (xwl_window && xwl_window->present_window == window)
e625aaa
-        xwl_window->present_window = NULL;
e625aaa
-
e625aaa
     if (xwl_present_window->frame_callback) {
e625aaa
         wl_callback_destroy(xwl_present_window->frame_callback);
e625aaa
         xwl_present_window->frame_callback = NULL;
e625aaa
@@ -361,10 +352,6 @@ xwl_present_queue_vblank(WindowPtr present_window,
e625aaa
     if (!xwl_window)
e625aaa
         return BadMatch;
e625aaa
 
e625aaa
-    if (xwl_window->present_window &&
e625aaa
-            xwl_window->present_window != present_window)
e625aaa
-        return BadMatch;
e625aaa
-
e625aaa
     event = malloc(sizeof *event);
e625aaa
     if (!event)
e625aaa
         return BadAlloc;
e625aaa
@@ -433,13 +420,6 @@ xwl_present_check_flip2(RRCrtcPtr crtc,
e625aaa
     if (!xwl_window)
e625aaa
         return FALSE;
e625aaa
 
e625aaa
-    /*
e625aaa
-     * Do not flip if there is already another child window doing flips.
e625aaa
-     */
e625aaa
-    if (xwl_window->present_window &&
e625aaa
-            xwl_window->present_window != present_window)
e625aaa
-        return FALSE;
e625aaa
-
e625aaa
     /*
e625aaa
      * We currently only allow flips of windows, that have the same
e625aaa
      * dimensions as their xwl_window parent window. For the case of
e625aaa
@@ -476,8 +456,6 @@ xwl_present_flip(WindowPtr present_window,
e625aaa
     if (!event)
e625aaa
         return FALSE;
e625aaa
 
e625aaa
-    xwl_window->present_window = present_window;
e625aaa
-
e625aaa
     buffer = xwl_glamor_pixmap_get_wl_buffer(pixmap, &buffer_created);
e625aaa
 
e625aaa
     event->event_id = event_id;
e625aaa
@@ -502,13 +480,6 @@ xwl_present_flip(WindowPtr present_window,
e625aaa
     /* We can flip directly to the main surface (full screen window without clips) */
e625aaa
     wl_surface_attach(xwl_window->surface, buffer, 0, 0);
e625aaa
 
e625aaa
-    if (!xwl_present_window->frame_timer ||
e625aaa
-            xwl_present_window->frame_timer_firing) {
e625aaa
-        /* Realign timer */
e625aaa
-        xwl_present_window->frame_timer_firing = FALSE;
e625aaa
-        xwl_present_reset_timer(xwl_present_window);
e625aaa
-    }
e625aaa
-
e625aaa
     if (!xwl_present_window->frame_callback) {
e625aaa
         xwl_present_window->frame_callback = wl_surface_frame(xwl_window->surface);
e625aaa
         wl_callback_add_listener(xwl_present_window->frame_callback,
e625aaa
@@ -516,6 +487,10 @@ xwl_present_flip(WindowPtr present_window,
e625aaa
                                  xwl_present_window);
e625aaa
     }
e625aaa
 
e625aaa
+    /* Realign timer */
e625aaa
+    xwl_present_window->frame_timer_firing = FALSE;
e625aaa
+    xwl_present_reset_timer(xwl_present_window);
e625aaa
+
e625aaa
     wl_surface_damage(xwl_window->surface, 0, 0,
e625aaa
                       damage_box->x2 - damage_box->x1,
e625aaa
                       damage_box->y2 - damage_box->y1);
e625aaa
@@ -531,22 +506,15 @@ xwl_present_flip(WindowPtr present_window,
e625aaa
     }
e625aaa
 
e625aaa
     wl_display_flush(xwl_window->xwl_screen->display);
e625aaa
+    xwl_window->present_flipped = TRUE;
e625aaa
     return TRUE;
e625aaa
 }
e625aaa
 
e625aaa
 static void
e625aaa
 xwl_present_flips_stop(WindowPtr window)
e625aaa
 {
e625aaa
-    struct xwl_window *xwl_window = xwl_window_from_window(window);
e625aaa
     struct xwl_present_window   *xwl_present_window = xwl_present_window_priv(window);
e625aaa
 
e625aaa
-    if (!xwl_window)
e625aaa
-        return;
e625aaa
-
e625aaa
-    assert(xwl_window->present_window == window);
e625aaa
-
e625aaa
-    xwl_window->present_window = NULL;
e625aaa
-
e625aaa
     /* Change back to the fast refresh rate */
e625aaa
     xwl_present_reset_timer(xwl_present_window);
e625aaa
 }
e625aaa
diff --git a/hw/xwayland/xwayland.c b/hw/xwayland/xwayland.c
e625aaa
index 96b4db18c..988b8e17d 100644
e625aaa
--- a/hw/xwayland/xwayland.c
e625aaa
+++ b/hw/xwayland/xwayland.c
e625aaa
@@ -370,6 +370,18 @@ damage_report(DamagePtr pDamage, RegionPtr pRegion, void *data)
e625aaa
     struct xwl_window *xwl_window = data;
e625aaa
     struct xwl_screen *xwl_screen = xwl_window->xwl_screen;
e625aaa
 
e625aaa
+#ifdef GLAMOR_HAS_GBM
e625aaa
+    if (xwl_window->present_flipped) {
e625aaa
+        /* This damage is from a Present flip, which already committed a new
e625aaa
+         * buffer for the surface, so we don't need to do anything in response
e625aaa
+         */
e625aaa
+        RegionEmpty(DamageRegion(pDamage));
e625aaa
+        xorg_list_del(&xwl_window->link_damage);
e625aaa
+        xwl_window->present_flipped = FALSE;
e625aaa
+        return;
e625aaa
+    }
e625aaa
+#endif
e625aaa
+
e625aaa
     xorg_list_add(&xwl_window->link_damage, &xwl_screen->damage_window_list);
e625aaa
 }
e625aaa
 
e625aaa
@@ -721,11 +733,6 @@ xwl_screen_post_damage(struct xwl_screen *xwl_screen)
e625aaa
 
e625aaa
     xorg_list_for_each_entry_safe(xwl_window, next_xwl_window,
e625aaa
                                   &xwl_screen->damage_window_list, link_damage) {
e625aaa
-#ifdef GLAMOR_HAS_GBM
e625aaa
-        /* Present on the main surface. So don't commit here as well. */
e625aaa
-        if (xwl_window->present_window)
e625aaa
-            continue;
e625aaa
-#endif
e625aaa
         /* If we're waiting on a frame callback from the server,
e625aaa
          * don't attach a new buffer. */
e625aaa
         if (xwl_window->frame_callback)
e625aaa
diff --git a/hw/xwayland/xwayland.h b/hw/xwayland/xwayland.h
e625aaa
index 3f4a601fe..a79f836ad 100644
e625aaa
--- a/hw/xwayland/xwayland.h
e625aaa
+++ b/hw/xwayland/xwayland.h
e625aaa
@@ -182,7 +182,9 @@ struct xwl_window {
e625aaa
     struct xorg_list link_damage;
e625aaa
     struct wl_callback *frame_callback;
e625aaa
     Bool allow_commits;
e625aaa
-    WindowPtr present_window;
e625aaa
+#ifdef GLAMOR_HAS_GBM
e625aaa
+    Bool present_flipped;
e625aaa
+#endif
e625aaa
 };
e625aaa
 
e625aaa
 #ifdef GLAMOR_HAS_GBM
e625aaa
-- 
e625aaa
2.19.2
e625aaa