[mutter/gbsneto/dmabuf-screencast: 5/8] screen-cast-stream-src: Add DMABuf-related vfuncs



commit c519c07f91c3c9e243c459657f30b40c829cdb60
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Dec 9 10:07:29 2019 -0300

    screen-cast-stream-src: Add DMABuf-related vfuncs
    
    Those will be used by the add_buffer implementation to try and
    export a DMA buffer instead of copying the current framebuffer
    into a memfd, and to blit the onscreen framebuffer contents when
    drawing.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/1086

 src/backends/meta-screen-cast-stream-src.c | 32 ++++++++++++++++++++++++++++++
 src/backends/meta-screen-cast-stream-src.h |  3 +++
 2 files changed, 35 insertions(+)
---
diff --git a/src/backends/meta-screen-cast-stream-src.c b/src/backends/meta-screen-cast-stream-src.c
index ba1ce94a7..db68b5be4 100644
--- a/src/backends/meta-screen-cast-stream-src.c
+++ b/src/backends/meta-screen-cast-stream-src.c
@@ -90,6 +90,8 @@ typedef struct _MetaScreenCastStreamSrcPrivate
 
   uint64_t last_frame_timestamp_us;
 
+  GHashTable *dmabuf_handles;
+
   int stream_width;
   int stream_height;
 } MetaScreenCastStreamSrcPrivate;
@@ -129,6 +131,16 @@ meta_screen_cast_stream_src_get_videocrop (MetaScreenCastStreamSrc *src,
   return FALSE;
 }
 
+static gboolean
+meta_screen_cast_stream_src_blit_to_framebuffer (MetaScreenCastStreamSrc *src,
+                                                 CoglFramebuffer         *framebuffer)
+{
+  MetaScreenCastStreamSrcClass *klass =
+    META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src);
+
+  return klass->blit_to_framebuffer (src, framebuffer);
+}
+
 static gboolean
 meta_screen_cast_stream_src_record_frame (MetaScreenCastStreamSrc *src,
                                           uint8_t                 *data)
@@ -139,6 +151,18 @@ meta_screen_cast_stream_src_record_frame (MetaScreenCastStreamSrc *src,
   return klass->record_frame (src, data);
 }
 
+static CoglOnscreenDmabufHandle *
+meta_screen_cast_stream_src_capture_dmabuf (MetaScreenCastStreamSrc *src)
+{
+  MetaScreenCastStreamSrcClass *klass =
+    META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src);
+
+  if (klass->capture_dmabuf)
+    return klass->capture_dmabuf (src);
+
+  return NULL;
+}
+
 static void
 meta_screen_cast_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc *src,
                                                  struct spa_meta_cursor  *spa_meta_cursor)
@@ -854,6 +878,7 @@ meta_screen_cast_stream_src_finalize (GObject *object)
   if (meta_screen_cast_stream_src_is_enabled (src))
     meta_screen_cast_stream_src_disable (src);
 
+  g_clear_pointer (&priv->dmabuf_handles, g_hash_table_destroy);
   g_clear_pointer (&priv->pipewire_stream, pw_stream_destroy);
   g_clear_pointer (&priv->pipewire_core, pw_core_disconnect);
   g_clear_pointer (&priv->pipewire_context, pw_context_destroy);
@@ -905,6 +930,13 @@ meta_screen_cast_stream_src_get_property (GObject    *object,
 static void
 meta_screen_cast_stream_src_init (MetaScreenCastStreamSrc *src)
 {
+  MetaScreenCastStreamSrcPrivate *priv =
+    meta_screen_cast_stream_src_get_instance_private (src);
+
+  priv->dmabuf_handles =
+    g_hash_table_new_full (g_direct_hash, g_direct_equal,
+                           NULL,
+                           (GDestroyNotify) cogl_onscreen_dmabuf_handle_release);
 }
 
 static void
diff --git a/src/backends/meta-screen-cast-stream-src.h b/src/backends/meta-screen-cast-stream-src.h
index fc0e5bc77..7f6261729 100644
--- a/src/backends/meta-screen-cast-stream-src.h
+++ b/src/backends/meta-screen-cast-stream-src.h
@@ -55,6 +55,9 @@ struct _MetaScreenCastStreamSrcClass
   void (* disable) (MetaScreenCastStreamSrc *src);
   gboolean (* record_frame) (MetaScreenCastStreamSrc *src,
                              uint8_t                 *data);
+  CoglOnscreenDmabufHandle * (* capture_dmabuf) (MetaScreenCastStreamSrc *src);
+  gboolean (* blit_to_framebuffer) (MetaScreenCastStreamSrc *src,
+                                    CoglFramebuffer         *framebuffer);
   gboolean (* get_videocrop) (MetaScreenCastStreamSrc *src,
                               MetaRectangle           *crop_rect);
   void (* set_cursor_metadata) (MetaScreenCastStreamSrc *src,


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