[mutter/wip/laney/drmmodegetresources-handle-failure-2: 3/3] gpu: Add a new "can_have_outputs" vfunc and bail out if all GPUs say no



commit 015b508c8996a3fc2ef27c26fd081cb78f9ebd09
Author: Iain Lane <iainl gnome org>
Date:   Mon Aug 13 11:22:22 2018 +0100

    gpu: Add a new "can_have_outputs" vfunc and bail out if all GPUs say no
    
    We need a way for mutter to exit if no available GPUs are going to work.
    For example if gdm starts gnome-shell and we're using a DRM driver that
    doesn't work with KMS then we should exit so that GDM can try with Xorg,
    rather than operating in headless mode.
    
    Related: https://gitlab.gnome.org/GNOME/mutter/issues/223

 src/backends/meta-gpu.h             |  1 +
 src/backends/meta-monitor-manager.c | 22 ++++++++++++++++++++++
 src/backends/native/meta-gpu-kms.c  | 11 +++++++++++
 src/backends/x11/meta-gpu-xrandr.c  |  7 +++++++
 4 files changed, 41 insertions(+)
---
diff --git a/src/backends/meta-gpu.h b/src/backends/meta-gpu.h
index 4badcbd26..b66b82fb7 100644
--- a/src/backends/meta-gpu.h
+++ b/src/backends/meta-gpu.h
@@ -35,6 +35,7 @@ struct _MetaGpuClass
 
   gboolean (* read_current) (MetaGpu  *gpu,
                              GError  **error);
+  gboolean (* can_have_outputs) (MetaGpu *gpu);
 };
 
 int meta_gpu_get_kms_fd (MetaGpu *gpu);
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
index 3850dd0b9..5e9231ff7 100644
--- a/src/backends/meta-monitor-manager.c
+++ b/src/backends/meta-monitor-manager.c
@@ -686,6 +686,22 @@ experimental_features_changed (MetaSettings           *settings,
   meta_settings_update_ui_scaling_factor (settings);
 }
 
+static gboolean
+meta_monitor_manager_can_have_outputs (MetaMonitorManager *manager)
+{
+  GList *l;
+
+  for (l = manager->gpus; l; l = l->next)
+    {
+      MetaGpu *gpu = META_GPU (l->data);
+
+      if (META_GPU_GET_CLASS (gpu)->can_have_outputs (gpu))
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
 void
 meta_monitor_manager_setup (MetaMonitorManager *manager)
 {
@@ -695,6 +711,12 @@ meta_monitor_manager_setup (MetaMonitorManager *manager)
 
   meta_monitor_manager_read_current_state (manager);
 
+  if (!meta_monitor_manager_can_have_outputs (manager))
+    {
+      g_critical ("None of the present GPUs can have outputs. Cannot continue.");
+      meta_exit (META_EXIT_ERROR);
+    }
+
   meta_monitor_manager_ensure_initial_config (manager);
 
   manager->in_init = FALSE;
diff --git a/src/backends/native/meta-gpu-kms.c b/src/backends/native/meta-gpu-kms.c
index 9de9fc63e..5961f275f 100644
--- a/src/backends/native/meta-gpu-kms.c
+++ b/src/backends/native/meta-gpu-kms.c
@@ -812,6 +812,14 @@ meta_gpu_kms_read_current (MetaGpu  *gpu,
   return TRUE;
 }
 
+static gboolean
+meta_gpu_kms_can_have_outputs (MetaGpu *gpu)
+{
+  MetaGpuKms *gpu_kms = META_GPU_KMS (gpu);
+
+  return gpu_kms->n_connectors > 0;
+}
+
 MetaGpuKms *
 meta_gpu_kms_new (MetaMonitorManagerKms  *monitor_manager_kms,
                   const char             *kms_file_path,
@@ -840,6 +848,8 @@ meta_gpu_kms_new (MetaMonitorManagerKms  *monitor_manager_kms,
 
   drmSetClientCap (gpu_kms->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
 
+  meta_gpu_kms_read_current (META_GPU (gpu_kms), NULL);
+
   source = g_source_new (&kms_event_funcs, sizeof (MetaKmsSource));
   kms_source = (MetaKmsSource *) source;
   kms_source->fd_tag = g_source_add_unix_fd (source,
@@ -889,4 +899,5 @@ meta_gpu_kms_class_init (MetaGpuKmsClass *klass)
   object_class->finalize = meta_gpu_kms_finalize;
 
   gpu_class->read_current = meta_gpu_kms_read_current;
+  gpu_class->can_have_outputs = meta_gpu_kms_can_have_outputs;
 }
diff --git a/src/backends/x11/meta-gpu-xrandr.c b/src/backends/x11/meta-gpu-xrandr.c
index 14b46d530..8ff78df2b 100644
--- a/src/backends/x11/meta-gpu-xrandr.c
+++ b/src/backends/x11/meta-gpu-xrandr.c
@@ -260,6 +260,12 @@ meta_gpu_xrandr_read_current (MetaGpu  *gpu,
   return TRUE;
 }
 
+static gboolean
+meta_gpu_xrandr_can_have_outputs (MetaGpu *gpu)
+{
+  return TRUE;
+}
+
 MetaGpuXrandr *
 meta_gpu_xrandr_new (MetaMonitorManagerXrandr *monitor_manager_xrandr)
 {
@@ -293,4 +299,5 @@ meta_gpu_xrandr_class_init (MetaGpuXrandrClass *klass)
   object_class->finalize = meta_gpu_xrandr_finalize;
 
   gpu_class->read_current = meta_gpu_xrandr_read_current;
+  gpu_class->can_have_outputs = meta_gpu_xrandr_can_have_outputs;
 }


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