[mutter/gbsneto/dmabuf-screencast: 4/8] screen-cast-stream-src: Add DMA buffer related vfuncs



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

    screen-cast-stream-src: Add DMA buffer 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..fcd6f5091 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;
@@ -139,6 +141,28 @@ meta_screen_cast_stream_src_record_frame (MetaScreenCastStreamSrc *src,
   return klass->record_frame (src, data);
 }
 
+static CoglDmaBufHandle *
+meta_screen_cast_stream_src_capture_dma_buf (MetaScreenCastStreamSrc *src)
+{
+  MetaScreenCastStreamSrcClass *klass =
+    META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src);
+
+  if (klass->capture_dma_buf)
+    return klass->capture_dma_buf (src);
+
+  return NULL;
+}
+
+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 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_dma_buf_handle_free);
 }
 
 static void
diff --git a/src/backends/meta-screen-cast-stream-src.h b/src/backends/meta-screen-cast-stream-src.h
index fc0e5bc77..38573dfb4 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);
+  CoglDmaBufHandle * (* capture_dma_buf) (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]