[xserver,1/2] present: implement `present_event_abandon()`

Submitted by Olivier Fourdan on Oct. 8, 2018, 2:46 p.m.

Details

Message ID 20181008144633.29160-2-ofourdan@redhat.com
State New
Headers show
Series "RFC: implement and use `present_event_abandon()`" ( rev: 1 ) in X.org

Not browsing as part of any series.

Commit Message

Olivier Fourdan Oct. 8, 2018, 2:46 p.m.
The function `present_event_abandon()` is marked as exported in the
present.h header but it's nowhere to be found.

Such a function might prove handy for the DDX such as Xwayland who
creates and destroys CRTCs as new outputs are added or removed.

`present_event_abandon()` checks all vblank for all windows for the
given  CRTC and abort those who match, so that we don't leave events
behind referring to a `RRCtrcPtr` pointing to freed memory.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Bugzilla: https://bugs.freedesktop.org/108249
---
 present/present_screen.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

Patch hide | download patch | download mbox

diff --git a/present/present_screen.c b/present/present_screen.c
index c7e37c5fd..35a106ada 100644
--- a/present/present_screen.c
+++ b/present/present_screen.c
@@ -167,6 +167,38 @@  present_destroy_window(WindowPtr window)
     return ret;
 }
 
+static int
+check_vblank_crtc(WindowPtr window, void *value)
+{
+    ScreenPtr screen = window->drawable.pScreen;
+    present_window_priv_ptr window_priv = present_window_priv(window);
+    present_screen_priv_ptr screen_priv = present_screen_priv(screen);
+    present_vblank_ptr vblank, tmp;
+    RRCrtcPtr target_crtc = value;
+
+    if (!window_priv)
+        return WT_WALKCHILDREN;
+
+    xorg_list_for_each_entry_safe(vblank, tmp, &window_priv->vblank, window_list) {
+        if (target_crtc == vblank->crtc) {
+            screen_priv->abort_vblank(window->drawable.pScreen,
+                                      window, vblank->crtc,
+                                      vblank->event_id, vblank->target_msc);
+            present_vblank_destroy(vblank);
+        }
+    }
+
+    return WT_WALKCHILDREN;
+}
+
+void
+present_event_abandon(RRCrtcPtr crtc)
+{
+    ScreenPtr               pScreen = crtc->pScreen;
+
+    WalkTree(pScreen, check_vblank_crtc, (void *) crtc);
+}
+
 /*
  * Hook the config notify screen function to deliver present config notify events
  */