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

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