Blame SOURCES/0003-screen-cast-Move-DMA-buffer-allocation-to-MetaScreen.patch

f15b50
From 914fd2bec65c2e9928b03d5bc94930bc0151f998 Mon Sep 17 00:00:00 2001
f15b50
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
f15b50
Date: Wed, 17 Jun 2020 17:48:05 +0200
f15b50
Subject: [PATCH 3/4] screen-cast: Move DMA buffer allocation to MetaScreenCast
f15b50
f15b50
The aim with centralizing it is to be able to apply global policy to DMA
f15b50
buffer allocations, e.g. disabling due to various hueristics.
f15b50
f15b50
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1318
f15b50
---
f15b50
 src/backends/meta-screen-cast-stream-src.c | 18 ++++++--------
f15b50
 src/backends/meta-screen-cast.c            | 28 ++++++++++++++++++++++
f15b50
 src/backends/meta-screen-cast.h            |  4 ++++
f15b50
 3 files changed, 39 insertions(+), 11 deletions(-)
f15b50
f15b50
diff --git a/src/backends/meta-screen-cast-stream-src.c b/src/backends/meta-screen-cast-stream-src.c
f15b50
index ff4af440c1..b77186415f 100644
f15b50
--- a/src/backends/meta-screen-cast-stream-src.c
f15b50
+++ b/src/backends/meta-screen-cast-stream-src.c
f15b50
@@ -649,10 +649,10 @@ on_stream_add_buffer (void             *data,
f15b50
   MetaScreenCastStreamSrc *src = data;
f15b50
   MetaScreenCastStreamSrcPrivate *priv =
f15b50
     meta_screen_cast_stream_src_get_instance_private (src);
f15b50
-  CoglContext *context =
f15b50
-    clutter_backend_get_cogl_context (clutter_get_default_backend ());
f15b50
-  CoglRenderer *renderer = cogl_context_get_renderer (context);
f15b50
-  g_autoptr (GError) error = NULL;
f15b50
+  MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
f15b50
+  MetaScreenCastSession *session = meta_screen_cast_stream_get_session (stream);
f15b50
+  MetaScreenCast *screen_cast =
f15b50
+    meta_screen_cast_session_get_screen_cast (session);
f15b50
   CoglDmaBufHandle *dmabuf_handle;
f15b50
   struct spa_buffer *spa_buffer = buffer->buffer;
f15b50
   struct spa_data *spa_data = spa_buffer->datas;
f15b50
@@ -664,13 +664,9 @@ on_stream_add_buffer (void             *data,
f15b50
   spa_data[0].mapoffset = 0;
f15b50
   spa_data[0].maxsize = stride * priv->video_format.size.height;
f15b50
 
f15b50
-  dmabuf_handle = cogl_renderer_create_dma_buf (renderer,
f15b50
-                                                priv->stream_width,
f15b50
-                                                priv->stream_height,
f15b50
-                                                &error);
f15b50
-
f15b50
-  if (error)
f15b50
-    g_debug ("Error exporting DMA buffer handle: %s", error->message);
f15b50
+  dmabuf_handle = meta_screen_cast_create_dma_buf_handle (screen_cast,
f15b50
+                                                          priv->stream_width,
f15b50
+                                                          priv->stream_height);
f15b50
 
f15b50
   if (dmabuf_handle)
f15b50
     {
f15b50
diff --git a/src/backends/meta-screen-cast.c b/src/backends/meta-screen-cast.c
f15b50
index 46bc268389..5f1ca8b5ca 100644
f15b50
--- a/src/backends/meta-screen-cast.c
f15b50
+++ b/src/backends/meta-screen-cast.c
f15b50
@@ -94,6 +94,34 @@ meta_screen_cast_get_backend (MetaScreenCast *screen_cast)
f15b50
   return screen_cast->backend;
f15b50
 }
f15b50
 
f15b50
+CoglDmaBufHandle *
f15b50
+meta_screen_cast_create_dma_buf_handle (MetaScreenCast *screen_cast,
f15b50
+                                        int             width,
f15b50
+                                        int             height)
f15b50
+{
f15b50
+  ClutterBackend *clutter_backend =
f15b50
+    meta_backend_get_clutter_backend (screen_cast->backend);
f15b50
+  CoglContext *cogl_context =
f15b50
+    clutter_backend_get_cogl_context (clutter_backend);
f15b50
+  CoglRenderer *cogl_renderer = cogl_context_get_renderer (cogl_context);
f15b50
+  g_autoptr (GError) error = NULL;
f15b50
+  CoglDmaBufHandle *dmabuf_handle;
f15b50
+
f15b50
+  dmabuf_handle = cogl_renderer_create_dma_buf (cogl_renderer,
f15b50
+                                                width, height,
f15b50
+                                                &error);
f15b50
+  if (!dmabuf_handle)
f15b50
+    {
f15b50
+      g_warning ("Failed to allocate DMA buffer, "
f15b50
+                 "disabling DMA buffer based screen casting: %s",
f15b50
+                 error->message);
f15b50
+      screen_cast->disable_dma_bufs = TRUE;
f15b50
+      return NULL;
f15b50
+    }
f15b50
+
f15b50
+  return dmabuf_handle;
f15b50
+}
f15b50
+
f15b50
 static gboolean
f15b50
 register_remote_desktop_screen_cast_session (MetaScreenCastSession  *session,
f15b50
                                              const char             *remote_desktop_session_id,
f15b50
diff --git a/src/backends/meta-screen-cast.h b/src/backends/meta-screen-cast.h
f15b50
index a3b650cd80..fb5a38f34f 100644
f15b50
--- a/src/backends/meta-screen-cast.h
f15b50
+++ b/src/backends/meta-screen-cast.h
f15b50
@@ -50,6 +50,10 @@ GDBusConnection * meta_screen_cast_get_connection (MetaScreenCast *screen_cast);
f15b50
 
f15b50
 MetaBackend * meta_screen_cast_get_backend (MetaScreenCast *screen_cast);
f15b50
 
f15b50
+CoglDmaBufHandle * meta_screen_cast_create_dma_buf_handle (MetaScreenCast *screen_cast,
f15b50
+                                                           int             width,
f15b50
+                                                           int             height);
f15b50
+
f15b50
 MetaScreenCast * meta_screen_cast_new (MetaBackend            *backend,
f15b50
                                        MetaDbusSessionWatcher *session_watcher);
f15b50
 
f15b50
-- 
f15b50
2.26.2
f15b50