[mutter] kms-impl-simple: Add helper to process update entries



commit 6c1e9b51f9215d449690238db80f43de1682ce50
Author: Jonas Ådahl <jadahl gmail com>
Date:   Fri Nov 8 11:30:18 2019 +0100

    kms-impl-simple: Add helper to process update entries
    
    This avoids some loop iteration boiler plate.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/930

 src/backends/native/meta-kms-impl-simple.c | 106 +++++++++++++++++------------
 1 file changed, 64 insertions(+), 42 deletions(-)
---
diff --git a/src/backends/native/meta-kms-impl-simple.c b/src/backends/native/meta-kms-impl-simple.c
index fc8d2929e..319ad7454 100644
--- a/src/backends/native/meta-kms-impl-simple.c
+++ b/src/backends/native/meta-kms-impl-simple.c
@@ -73,11 +73,12 @@ meta_kms_impl_simple_new (MetaKms  *kms,
 }
 
 static gboolean
-process_connector_property (MetaKmsImpl               *impl,
-                            MetaKmsUpdate             *update,
-                            MetaKmsConnectorProperty  *connector_property,
-                            GError                   **error)
+process_connector_property (MetaKmsImpl    *impl,
+                            MetaKmsUpdate  *update,
+                            gpointer        update_entry,
+                            GError        **error)
 {
+  MetaKmsConnectorProperty *connector_property = update_entry;
   MetaKmsConnector *connector = connector_property->connector;
   MetaKmsDevice *device = meta_kms_connector_get_device (connector);
   MetaKmsImplDevice *impl_device = meta_kms_device_get_impl_device (device);
@@ -180,9 +181,10 @@ fill_connector_ids_array (GList     *connectors,
 static gboolean
 process_mode_set (MetaKmsImpl     *impl,
                   MetaKmsUpdate   *update,
-                  MetaKmsModeSet  *mode_set,
+                  gpointer         update_entry,
                   GError         **error)
 {
+  MetaKmsModeSet *mode_set = update_entry;
   MetaKmsImplSimple *impl_simple = META_KMS_IMPL_SIMPLE (impl);
   MetaKmsCrtc *crtc = mode_set->crtc;
   MetaKmsDevice *device = meta_kms_crtc_get_device (crtc);
@@ -270,10 +272,12 @@ process_mode_set (MetaKmsImpl     *impl,
 }
 
 static gboolean
-process_crtc_gamma (MetaKmsImpl       *impl,
-                    MetaKmsCrtcGamma  *gamma,
-                    GError           **error)
+process_crtc_gamma (MetaKmsImpl    *impl,
+                    MetaKmsUpdate  *update,
+                    gpointer        update_entry,
+                    GError        **error)
 {
+  MetaKmsCrtcGamma *gamma = update_entry;
   MetaKmsCrtc *crtc = gamma->crtc;
   MetaKmsDevice *device = meta_kms_crtc_get_device (crtc);
   MetaKmsImplDevice *impl_device = meta_kms_device_get_impl_device (device);
@@ -608,11 +612,12 @@ mode_set_fallback (MetaKmsImplSimple       *impl_simple,
 }
 
 static gboolean
-process_page_flip (MetaKmsImpl      *impl,
-                   MetaKmsUpdate    *update,
-                   MetaKmsPageFlip  *page_flip,
-                   GError          **error)
+process_page_flip (MetaKmsImpl    *impl,
+                   MetaKmsUpdate  *update,
+                   gpointer        update_entry,
+                   GError        **error)
 {
+  MetaKmsPageFlip *page_flip = update_entry;
   MetaKmsImplSimple *impl_simple = META_KMS_IMPL_SIMPLE (impl);
   MetaKmsCrtc *crtc;
   MetaKmsDevice *device;
@@ -722,45 +727,62 @@ discard_page_flip (MetaKmsImpl     *impl,
 }
 
 static gboolean
-meta_kms_impl_simple_process_update (MetaKmsImpl    *impl,
-                                     MetaKmsUpdate  *update,
-                                     GError        **error)
+process_entries (MetaKmsImpl     *impl,
+                 MetaKmsUpdate   *update,
+                 GList           *entries,
+                 gboolean      (* func) (MetaKmsImpl    *impl,
+                                         MetaKmsUpdate  *update,
+                                         gpointer        entry_data,
+                                         GError        **error),
+                 GError         **error)
 {
   GList *l;
 
-  meta_assert_in_kms_impl (meta_kms_impl_get_kms (impl));
-
-  for (l = meta_kms_update_get_connector_properties (update); l; l = l->next)
+  for (l = entries; l; l = l->next)
     {
-      MetaKmsConnectorProperty *connector_property = l->data;
-
-      if (!process_connector_property (impl, update, connector_property, error))
-        goto discard_page_flips;
+      if (!func (impl, update, l->data, error))
+        return FALSE;
     }
 
-  for (l = meta_kms_update_get_mode_sets (update); l; l = l->next)
-    {
-      MetaKmsModeSet *mode_set = l->data;
-
-      if (!process_mode_set (impl, update, mode_set, error))
-        goto discard_page_flips;
-    }
-
-  for (l = meta_kms_update_get_crtc_gammas (update); l; l = l->next)
-    {
-      MetaKmsCrtcGamma *gamma = l->data;
+  return TRUE;
+}
 
-      if (!process_crtc_gamma (impl, gamma, error))
-        goto discard_page_flips;
-    }
+static gboolean
+meta_kms_impl_simple_process_update (MetaKmsImpl    *impl,
+                                     MetaKmsUpdate  *update,
+                                     GError        **error)
+{
+  GList *l;
 
-  for (l = meta_kms_update_get_page_flips (update); l; l = l->next)
-    {
-      MetaKmsPageFlip *page_flip = l->data;
+  meta_assert_in_kms_impl (meta_kms_impl_get_kms (impl));
 
-      if (!process_page_flip (impl, update, page_flip, error))
-        goto discard_page_flips;
-    }
+  if (!process_entries (impl,
+                        update,
+                        meta_kms_update_get_connector_properties (update),
+                        process_connector_property,
+                        error))
+    goto discard_page_flips;
+
+  if (!process_entries (impl,
+                        update,
+                        meta_kms_update_get_mode_sets (update),
+                        process_mode_set,
+                        error))
+    goto discard_page_flips;
+
+  if (!process_entries (impl,
+                        update,
+                        meta_kms_update_get_crtc_gammas (update),
+                        process_crtc_gamma,
+                        error))
+    goto discard_page_flips;
+
+  if (!process_entries (impl,
+                        update,
+                        meta_kms_update_get_page_flips (update),
+                        process_page_flip,
+                        error))
+    goto discard_page_flips;
 
   return TRUE;
 


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