[mutter/wip/carlosg/frames-client: 4/12] x11: Decouple sync alarms from window XIDs




commit e1553636e00a240d1a4c4ca522c4c26d858167a7
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Sep 9 12:45:52 2022 +0200

    x11: Decouple sync alarms from window XIDs
    
    Store the alarms in a different hashtable, and look up the MetaSyncCounter
    right away. It so far avoids the MetaWindow middle man, but will also be
    simpler when each window can possibly have more than one active alarms.

 src/x11/events.c                   | 10 ++++++----
 src/x11/meta-sync-counter.c        |  2 +-
 src/x11/meta-x11-display-private.h | 14 +++++++++-----
 src/x11/meta-x11-display.c         | 28 +++++++++++++---------------
 src/x11/window-x11.c               | 10 ----------
 src/x11/window-x11.h               |  2 --
 6 files changed, 29 insertions(+), 37 deletions(-)
---
diff --git a/src/x11/events.c b/src/x11/events.c
index d4f274a445..f5bfa0a83d 100644
--- a/src/x11/events.c
+++ b/src/x11/events.c
@@ -1314,15 +1314,17 @@ handle_other_xevent (MetaX11Display *x11_display,
   if (META_X11_DISPLAY_HAS_XSYNC (x11_display) &&
       event->type == (x11_display->xsync_event_base + XSyncAlarmNotify))
     {
-      MetaWindow *alarm_window = meta_x11_display_lookup_sync_alarm (x11_display,
-                                                                     ((XSyncAlarmNotifyEvent*)event)->alarm);
+      MetaSyncCounter *sync_counter;
 
-      if (alarm_window != NULL)
+      sync_counter = meta_x11_display_lookup_sync_alarm (x11_display,
+                                                         ((XSyncAlarmNotifyEvent*)event)->alarm);
+
+      if (sync_counter != NULL)
         {
           XSyncValue value = ((XSyncAlarmNotifyEvent*)event)->counter_value;
           gint64 new_counter_value;
           new_counter_value = XSyncValueLow32 (value) + ((gint64)XSyncValueHigh32 (value) << 32);
-          meta_window_x11_update_sync_request_counter (alarm_window, new_counter_value);
+          meta_sync_counter_update (sync_counter, new_counter_value);
           bypass_gtk = TRUE; /* GTK doesn't want to see this really */
         }
       else
diff --git a/src/x11/meta-sync-counter.c b/src/x11/meta-sync-counter.c
index 346ac49b49..2c7ae76246 100644
--- a/src/x11/meta-sync-counter.c
+++ b/src/x11/meta-sync-counter.c
@@ -152,7 +152,7 @@ meta_sync_counter_create_sync_alarm (MetaSyncCounter *sync_counter)
     {
       meta_x11_display_register_sync_alarm (x11_display,
                                             &sync_counter->sync_request_alarm,
-                                            window);
+                                            sync_counter);
     }
   else
     {
diff --git a/src/x11/meta-x11-display-private.h b/src/x11/meta-x11-display-private.h
index 9158387d69..1d5822b7e8 100644
--- a/src/x11/meta-x11-display-private.h
+++ b/src/x11/meta-x11-display-private.h
@@ -37,6 +37,7 @@
 #include "meta-startup-notification-x11.h"
 #include "meta-x11-stack-private.h"
 #include "ui/ui.h"
+#include "x11/meta-sync-counter.h"
 
 typedef struct _MetaGroupPropHooks  MetaGroupPropHooks;
 typedef struct _MetaWindowPropHooks MetaWindowPropHooks;
@@ -103,6 +104,7 @@ struct _MetaX11Display
   Window composite_overlay_window;
 
   GHashTable *xids;
+  GHashTable *alarms;
 
   gboolean has_xinerama_indices;
 
@@ -203,11 +205,13 @@ void        meta_x11_display_register_x_window   (MetaX11Display *x11_display,
 void        meta_x11_display_unregister_x_window (MetaX11Display *x11_display,
                                                   Window          xwindow);
 
-MetaWindow *meta_x11_display_lookup_sync_alarm     (MetaX11Display *x11_display,
-                                                    XSyncAlarm      alarm);
-void        meta_x11_display_register_sync_alarm   (MetaX11Display *x11_display,
-                                                    XSyncAlarm     *alarmp,
-                                                    MetaWindow     *window);
+MetaSyncCounter * meta_x11_display_lookup_sync_alarm (MetaX11Display *x11_display,
+                                                      XSyncAlarm      alarm);
+
+void        meta_x11_display_register_sync_alarm (MetaX11Display  *x11_display,
+                                                  XSyncAlarm      *alarmp,
+                                                  MetaSyncCounter *sync_counter);
+
 void        meta_x11_display_unregister_sync_alarm (MetaX11Display *x11_display,
                                                     XSyncAlarm      alarm);
 
diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c
index f353712bc5..35d9f53d05 100644
--- a/src/x11/meta-x11-display.c
+++ b/src/x11/meta-x11-display.c
@@ -203,6 +203,8 @@ meta_x11_display_dispose (GObject *object)
       x11_display->xids = NULL;
     }
 
+  g_clear_pointer (&x11_display->alarms, g_hash_table_unref);
+
   if (x11_display->xroot != None)
     {
       unset_wm_check_hint (x11_display);
@@ -1247,6 +1249,8 @@ meta_x11_display_new (MetaDisplay *display, GError **error)
 
   x11_display->xids = g_hash_table_new (meta_unsigned_long_hash,
                                         meta_unsigned_long_equal);
+  x11_display->alarms = g_hash_table_new (meta_unsigned_long_hash,
+                                          meta_unsigned_long_equal);
 
   x11_display->groups_by_leader = NULL;
   x11_display->composite_overlay_window = None;
@@ -1636,36 +1640,30 @@ meta_x11_display_unregister_x_window (MetaX11Display *x11_display,
   g_hash_table_remove (x11_display->xids, &xwindow);
 }
 
-
-/* We store sync alarms in the window ID hash table, because they are
- * just more types of XIDs in the same global space, but we have
- * typesafe functions to register/unregister for readability.
- */
-
-MetaWindow *
+MetaSyncCounter *
 meta_x11_display_lookup_sync_alarm (MetaX11Display *x11_display,
                                     XSyncAlarm      alarm)
 {
-  return g_hash_table_lookup (x11_display->xids, &alarm);
+  return g_hash_table_lookup (x11_display->alarms, &alarm);
 }
 
 void
-meta_x11_display_register_sync_alarm (MetaX11Display *x11_display,
-                                      XSyncAlarm     *alarmp,
-                                      MetaWindow     *window)
+meta_x11_display_register_sync_alarm (MetaX11Display  *x11_display,
+                                      XSyncAlarm      *alarmp,
+                                      MetaSyncCounter *sync_counter)
 {
-  g_return_if_fail (g_hash_table_lookup (x11_display->xids, alarmp) == NULL);
+  g_return_if_fail (g_hash_table_lookup (x11_display->alarms, alarmp) == NULL);
 
-  g_hash_table_insert (x11_display->xids, alarmp, window);
+  g_hash_table_insert (x11_display->alarms, alarmp, sync_counter);
 }
 
 void
 meta_x11_display_unregister_sync_alarm (MetaX11Display *x11_display,
                                         XSyncAlarm      alarm)
 {
-  g_return_if_fail (g_hash_table_lookup (x11_display->xids, &alarm) != NULL);
+  g_return_if_fail (g_hash_table_lookup (x11_display->alarms, &alarm) != NULL);
 
-  g_hash_table_remove (x11_display->xids, &alarm);
+  g_hash_table_remove (x11_display->alarms, &alarm);
 }
 
 void
diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c
index ca794c439c..30c8688e96 100644
--- a/src/x11/window-x11.c
+++ b/src/x11/window-x11.c
@@ -3980,16 +3980,6 @@ meta_window_x11_destroy_sync_request_alarm (MetaWindow *window)
   meta_sync_counter_destroy_sync_alarm (&priv->sync_counter);
 }
 
-void
-meta_window_x11_update_sync_request_counter (MetaWindow *window,
-                                             gint64      new_counter_value)
-{
-  MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
-  MetaWindowX11Private *priv = meta_window_x11_get_instance_private (window_x11);
-
-  meta_sync_counter_update (&priv->sync_counter, new_counter_value);
-}
-
 Window
 meta_window_x11_get_toplevel_xwindow (MetaWindow *window)
 {
diff --git a/src/x11/window-x11.h b/src/x11/window-x11.h
index 8193fea3a7..5581747ff4 100644
--- a/src/x11/window-x11.h
+++ b/src/x11/window-x11.h
@@ -62,8 +62,6 @@ void meta_window_x11_set_allowed_actions_hint    (MetaWindow *window);
 
 void meta_window_x11_create_sync_request_alarm   (MetaWindow *window);
 void meta_window_x11_destroy_sync_request_alarm  (MetaWindow *window);
-void meta_window_x11_update_sync_request_counter (MetaWindow *window,
-                                                  gint64      new_counter_value);
 
 void meta_window_x11_update_input_region         (MetaWindow *window);
 void meta_window_x11_update_shape_region         (MetaWindow *window);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]