[mutter/gbsneto/dmabuf-screencast: 8/13] renderer-native: Implement DMA buffer exporting



commit 53a6fd6e0ab56af63f8a9546d5e436bff70633a3
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Dec 9 10:05:37 2019 -0300

    renderer-native: Implement DMA buffer exporting
    
    Create a new gbm_bo using the same given geometry, and export the new
    bo's DMA buffer fd. The new bo lives as long as necessary to be used,
    and reused, by PipeWire.
    
    Unfortunately, PipeWire doesn't support modifiers properly, so use the
    linear format for now. For now, a hardcoded format of DRM_FORMAT_XRGB8888
    is set, so we don't need to negotiate the format with PipeWire early.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/1086

 src/backends/native/meta-renderer-native.c | 62 ++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
---
diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
index d1b064ead..d3e6cdba0 100644
--- a/src/backends/native/meta-renderer-native.c
+++ b/src/backends/native/meta-renderer-native.c
@@ -2132,6 +2132,66 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
   COGL_TRACE_END (MetaRendererNativePostKmsUpdate);
 }
 
+static CoglDmaBufHandle *
+meta_onscreen_native_capture_dma_buf (CoglContext  *context,
+                                      int           width,
+                                      int           height,
+                                      GError      **error)
+{
+  CoglRenderer *cogl_renderer = context->display->renderer;
+  CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
+  MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
+  MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
+  int dmabuf_fd = -1;
+
+  switch (renderer_gpu_data->mode)
+    {
+    case META_RENDERER_NATIVE_MODE_GBM:
+      {
+        CoglFramebuffer *dmabuf_fb;
+        struct gbm_bo *new_bo;
+
+        new_bo = gbm_bo_create (renderer_gpu_data->gbm.device,
+                                width, height, DRM_FORMAT_XRGB8888,
+                                GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR);
+        dmabuf_fd = gbm_bo_get_fd (new_bo);
+
+        if (dmabuf_fd == -1)
+          {
+            g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
+                         "Failed to export dma-buf fd: %s",
+                         g_strerror (errno));
+            return NULL;
+          }
+
+        dmabuf_fb = create_dmabuf_image (renderer_native,
+                                         dmabuf_fd,
+                                         width, height,
+                                         gbm_bo_get_stride (new_bo),
+                                         0,
+                                         DRM_FORMAT_MOD_LINEAR,
+                                         DRM_FORMAT_XRGB8888,
+                                         error);
+
+        if (*error)
+          return NULL;
+
+        return cogl_dma_buf_handle_new (dmabuf_fb, dmabuf_fd, new_bo,
+                                        (GDestroyNotify) gbm_bo_destroy);
+      }
+      break;
+#ifdef HAVE_EGL_DEVICE
+    case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
+      break;
+#endif
+    }
+
+  g_set_error (error, G_IO_ERROR, G_IO_ERROR_UNKNOWN,
+               "Current mode does not support exporting DMA buffers");
+
+  return NULL;
+}
+
 static gboolean
 meta_renderer_native_init_egl_context (CoglContext *cogl_context,
                                        GError     **error)
@@ -2872,6 +2932,8 @@ get_native_cogl_winsys_vtable (CoglRenderer *cogl_renderer)
       vtable.id = COGL_WINSYS_ID_CUSTOM;
       vtable.name = "EGL_KMS";
 
+      vtable.context_capture_dma_buf = meta_onscreen_native_capture_dma_buf;
+
       vtable.renderer_connect = meta_renderer_native_connect;
       vtable.renderer_disconnect = meta_renderer_native_disconnect;
 


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