[mutter/wip/gbsneto/kms-transactions-on-steroids: 22/30] kms: Add API to add a GSource that'll be invoked in the impl context



commit 8ba01d33730024a4e92c6ef62e7b0360fd462056
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Sun Mar 10 13:40:30 2019 +0100

    kms: Add API to add a GSource that'll be invoked in the impl context
    
    The MetaKmsImpl implementation may need to add a GSource that should be
    invoked in the right context; e.g. a idle callback, timeout etc. It
    cannot just add it itself, since it's the responsibility of MetaKms to
    determine what is the impl context and what is the main context, so add
    API to MetaKms to ensure the callback is invoked correctly.
    
    It's the responsibility of the caller to eventually remove and destroy
    the GSource.
    
    https://gitlab.gnome.org/GNOME/mutter/issues/548
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/525

 src/backends/native/meta-kms-private.h |  4 +++
 src/backends/native/meta-kms.c         | 48 ++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
---
diff --git a/src/backends/native/meta-kms-private.h b/src/backends/native/meta-kms-private.h
index 8c0ce9425..a2f2a05db 100644
--- a/src/backends/native/meta-kms-private.h
+++ b/src/backends/native/meta-kms-private.h
@@ -41,6 +41,10 @@ gboolean meta_kms_run_impl_task_sync (MetaKms              *kms,
                                       gpointer              user_data,
                                       GError              **error);
 
+GSource * meta_kms_add_source_in_impl (MetaKms     *kms,
+                                       GSourceFunc  func,
+                                       gpointer     user_data);
+
 gboolean meta_kms_in_impl_task (MetaKms *kms);
 
 #define meta_assert_in_kms_impl(kms) \
diff --git a/src/backends/native/meta-kms.c b/src/backends/native/meta-kms.c
index 408b9f5a2..27b709658 100644
--- a/src/backends/native/meta-kms.c
+++ b/src/backends/native/meta-kms.c
@@ -34,6 +34,12 @@ typedef struct _MetaKmsCallbackData
   GDestroyNotify user_data_destroy;
 } MetaKmsCallbackData;
 
+typedef struct _MetaKmsSimpleImplSource
+{
+  GSource source;
+  MetaKms *kms;
+} MetaKmsSimpleImplSource;
+
 struct _MetaKms
 {
   GObject parent;
@@ -117,6 +123,48 @@ meta_kms_run_impl_task_sync (MetaKms              *kms,
   return ret;
 }
 
+static gboolean
+simple_impl_source_dispatch (GSource     *source,
+                             GSourceFunc  callback,
+                             gpointer     user_data)
+{
+  MetaKmsSimpleImplSource *simple_impl_source =
+    (MetaKmsSimpleImplSource *) source;
+  MetaKms *kms = simple_impl_source->kms;
+  gboolean ret;
+
+  kms->in_impl_task = TRUE;
+  ret = callback (user_data);
+  kms->in_impl_task = FALSE;
+
+  return ret;
+}
+
+static GSourceFuncs simple_impl_source_funcs = {
+  .dispatch = simple_impl_source_dispatch,
+};
+
+GSource *
+meta_kms_add_source_in_impl (MetaKms     *kms,
+                             GSourceFunc  func,
+                             gpointer     user_data)
+{
+  GSource *source;
+  MetaKmsSimpleImplSource *simple_impl_source;
+
+  meta_assert_in_kms_impl (kms);
+
+  source = g_source_new (&simple_impl_source_funcs,
+                         sizeof (MetaKmsSimpleImplSource));
+  simple_impl_source = (MetaKmsSimpleImplSource *) source;
+  simple_impl_source->kms = kms;
+
+  g_source_set_callback (source, func, user_data, NULL);
+  g_source_attach (source, g_main_context_get_thread_default ());
+
+  return source;
+}
+
 gboolean
 meta_kms_in_impl_task (MetaKms *kms)
 {


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