Blame SOURCES/0004-screen-cast-Disable-DMA-buffer-based-screen-casting-.patch

f15b50
From a239886e159e6609c3e298effbd0243af8d0e333 Mon Sep 17 00:00:00 2001
f15b50
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
f15b50
Date: Tue, 16 Jun 2020 11:30:11 +0200
f15b50
Subject: [PATCH 4/4] screen-cast: Disable DMA buffer based screen casting for
f15b50
 QXL
f15b50
f15b50
QXL doesn't support mmap():ing a DMA buffer allocated in mutter inside
f15b50
the PipeWire stream consumer process. To make screen casting work again
f15b50
on QXL, disable DMA buffer based screen casting for QXL.
f15b50
f15b50
Eventually, it should be the client that renegotiates the supported
f15b50
buffer types, but until then we need this list.
f15b50
f15b50
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1318
f15b50
---
f15b50
 src/backends/meta-screen-cast.c           | 11 ++++++
f15b50
 src/backends/meta-screen-cast.h           |  2 ++
f15b50
 src/backends/native/meta-backend-native.c | 41 +++++++++++++++++++++++
f15b50
 src/backends/native/meta-gpu-kms.c        | 26 ++++++++++++++
f15b50
 src/backends/native/meta-gpu-kms.h        |  2 ++
f15b50
 5 files changed, 82 insertions(+)
f15b50
f15b50
diff --git a/src/backends/meta-screen-cast.c b/src/backends/meta-screen-cast.c
f15b50
index 5f1ca8b5ca..268155e7b3 100644
f15b50
--- a/src/backends/meta-screen-cast.c
f15b50
+++ b/src/backends/meta-screen-cast.c
f15b50
@@ -46,6 +46,8 @@ struct _MetaScreenCast
f15b50
 
f15b50
   MetaDbusSessionWatcher *session_watcher;
f15b50
   MetaBackend *backend;
f15b50
+
f15b50
+  gboolean disable_dma_bufs;
f15b50
 };
f15b50
 
f15b50
 static void
f15b50
@@ -94,6 +96,12 @@ meta_screen_cast_get_backend (MetaScreenCast *screen_cast)
f15b50
   return screen_cast->backend;
f15b50
 }
f15b50
 
f15b50
+void
f15b50
+meta_screen_cast_disable_dma_bufs (MetaScreenCast *screen_cast)
f15b50
+{
f15b50
+  screen_cast->disable_dma_bufs = TRUE;
f15b50
+}
f15b50
+
f15b50
 CoglDmaBufHandle *
f15b50
 meta_screen_cast_create_dma_buf_handle (MetaScreenCast *screen_cast,
f15b50
                                         int             width,
f15b50
@@ -107,6 +115,9 @@ meta_screen_cast_create_dma_buf_handle (MetaScreenCast *screen_cast,
f15b50
   g_autoptr (GError) error = NULL;
f15b50
   CoglDmaBufHandle *dmabuf_handle;
f15b50
 
f15b50
+  if (screen_cast->disable_dma_bufs)
f15b50
+    return NULL;
f15b50
+
f15b50
   dmabuf_handle = cogl_renderer_create_dma_buf (cogl_renderer,
f15b50
                                                 width, height,
f15b50
                                                 &error);
f15b50
diff --git a/src/backends/meta-screen-cast.h b/src/backends/meta-screen-cast.h
f15b50
index fb5a38f34f..fa54be729f 100644
f15b50
--- a/src/backends/meta-screen-cast.h
f15b50
+++ b/src/backends/meta-screen-cast.h
f15b50
@@ -50,6 +50,8 @@ GDBusConnection * meta_screen_cast_get_connection (MetaScreenCast *screen_cast);
f15b50
 
f15b50
 MetaBackend * meta_screen_cast_get_backend (MetaScreenCast *screen_cast);
f15b50
 
f15b50
+void meta_screen_cast_disable_dma_bufs (MetaScreenCast *screen_cast);
f15b50
+
f15b50
 CoglDmaBufHandle * meta_screen_cast_create_dma_buf_handle (MetaScreenCast *screen_cast,
f15b50
                                                            int             width,
f15b50
                                                            int             height);
f15b50
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
f15b50
index c473681cb0..2bf7f5e7e2 100644
f15b50
--- a/src/backends/native/meta-backend-native.c
f15b50
+++ b/src/backends/native/meta-backend-native.c
f15b50
@@ -57,6 +57,10 @@
f15b50
 #include "core/meta-border.h"
f15b50
 #include "meta/main.h"
f15b50
 
f15b50
+#ifdef HAVE_REMOTE_DESKTOP
f15b50
+#include "backends/meta-screen-cast.h"
f15b50
+#endif
f15b50
+
f15b50
 struct _MetaBackendNative
f15b50
 {
f15b50
   MetaBackend parent;
f15b50
@@ -327,6 +331,39 @@ meta_backend_native_create_clutter_backend (MetaBackend *backend)
f15b50
   return g_object_new (META_TYPE_CLUTTER_BACKEND_NATIVE, NULL);
f15b50
 }
f15b50
 
f15b50
+#ifdef HAVE_REMOTE_DESKTOP
f15b50
+static void
f15b50
+maybe_disable_screen_cast_dma_bufs (MetaBackendNative *native)
f15b50
+{
f15b50
+  MetaBackend *backend = META_BACKEND (native);
f15b50
+  MetaRenderer *renderer = meta_backend_get_renderer (backend);
f15b50
+  MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer);
f15b50
+  MetaGpuKms *primary_gpu;
f15b50
+  const char *driver_name;
f15b50
+  int i;
f15b50
+  static const char *disable_dma_buf_drivers[] = {
f15b50
+    "qxl",
f15b50
+  };
f15b50
+
f15b50
+  primary_gpu = meta_renderer_native_get_primary_gpu (renderer_native);
f15b50
+  driver_name = meta_gpu_kms_get_driver_name (primary_gpu);
f15b50
+
f15b50
+  for (i = 0; i < G_N_ELEMENTS (disable_dma_buf_drivers); i++)
f15b50
+    {
f15b50
+      if (g_strcmp0 (driver_name, disable_dma_buf_drivers[i]) == 0)
f15b50
+        {
f15b50
+          MetaScreenCast *screen_cast = meta_backend_get_screen_cast (backend);
f15b50
+
f15b50
+          g_message ("The '%s' driver doesn't support DMA buffer screen sharing, disabling.",
f15b50
+                     driver_name);
f15b50
+
f15b50
+          meta_screen_cast_disable_dma_bufs (screen_cast);
f15b50
+          return;
f15b50
+        }
f15b50
+    }
f15b50
+}
f15b50
+#endif /* HAVE_REMOTE_DESKTOP */
f15b50
+
f15b50
 static void
f15b50
 meta_backend_native_post_init (MetaBackend *backend)
f15b50
 {
f15b50
@@ -338,6 +375,10 @@ meta_backend_native_post_init (MetaBackend *backend)
f15b50
                                                 NULL, NULL);
f15b50
   clutter_evdev_set_relative_motion_filter (manager, relative_motion_filter,
f15b50
                                             meta_backend_get_monitor_manager (backend));
f15b50
+
f15b50
+#ifdef HAVE_REMOTE_DESKTOP
f15b50
+  maybe_disable_screen_cast_dma_bufs (META_BACKEND_NATIVE (backend));
f15b50
+#endif
f15b50
 }
f15b50
 
f15b50
 static MetaMonitorManager *
f15b50
diff --git a/src/backends/native/meta-gpu-kms.c b/src/backends/native/meta-gpu-kms.c
f15b50
index c569b948ef..93e509def5 100644
f15b50
--- a/src/backends/native/meta-gpu-kms.c
f15b50
+++ b/src/backends/native/meta-gpu-kms.c
f15b50
@@ -66,6 +66,8 @@ struct _MetaGpuKms
f15b50
   char *file_path;
f15b50
   GSource *source;
f15b50
 
f15b50
+  char *driver_name;
f15b50
+
f15b50
   clockid_t clock_id;
f15b50
 
f15b50
   drmModeConnector **connectors;
f15b50
@@ -790,6 +792,27 @@ init_outputs (MetaGpuKms       *gpu_kms,
f15b50
   setup_output_clones (gpu);
f15b50
 }
f15b50
 
f15b50
+static void
f15b50
+init_info (MetaGpuKms *gpu_kms)
f15b50
+{
f15b50
+  drmVersion *drm_version;
f15b50
+
f15b50
+  drm_version = drmGetVersion (gpu_kms->fd);
f15b50
+  if (!drm_version)
f15b50
+    return;
f15b50
+
f15b50
+  gpu_kms->driver_name = g_strndup (drm_version->name,
f15b50
+                                    drm_version->name_len);
f15b50
+
f15b50
+  drmFreeVersion (drm_version);
f15b50
+}
f15b50
+
f15b50
+const char *
f15b50
+meta_gpu_kms_get_driver_name (MetaGpuKms *gpu_kms)
f15b50
+{
f15b50
+  return gpu_kms->driver_name;
f15b50
+}
f15b50
+
f15b50
 static gboolean
f15b50
 meta_kms_resources_init (MetaKmsResources  *resources,
f15b50
                          int                fd,
f15b50
@@ -865,6 +888,7 @@ meta_gpu_kms_read_current (MetaGpu  *gpu,
f15b50
   init_crtcs (gpu_kms, &resources);
f15b50
   init_outputs (gpu_kms, &resources);
f15b50
   init_frame_clock (gpu_kms);
f15b50
+  init_info (gpu_kms);
f15b50
 
f15b50
   meta_kms_resources_release (&resources);
f15b50
 
f15b50
@@ -940,6 +964,8 @@ meta_gpu_kms_finalize (GObject *object)
f15b50
 
f15b50
   free_resources (gpu_kms);
f15b50
 
f15b50
+  g_free (gpu_kms->driver_name);
f15b50
+
f15b50
   G_OBJECT_CLASS (meta_gpu_kms_parent_class)->finalize (object);
f15b50
 }
f15b50
 
f15b50
diff --git a/src/backends/native/meta-gpu-kms.h b/src/backends/native/meta-gpu-kms.h
f15b50
index 1f7a939e27..6096e58341 100644
f15b50
--- a/src/backends/native/meta-gpu-kms.h
f15b50
+++ b/src/backends/native/meta-gpu-kms.h
f15b50
@@ -108,4 +108,6 @@ MetaGpuKmsFlipClosureContainer * meta_gpu_kms_wrap_flip_closure (MetaGpuKms *gpu
f15b50
 
f15b50
 void meta_gpu_kms_flip_closure_container_free (MetaGpuKmsFlipClosureContainer *closure_container);
f15b50
 
f15b50
+const char * meta_gpu_kms_get_driver_name (MetaGpuKms *gpu_kms);
f15b50
+
f15b50
 #endif /* META_GPU_KMS_H */
f15b50
-- 
f15b50
2.26.2
f15b50