[mutter/gbsneto/dmabuf-screencast: 2/6] renderer-native: Implement DMA buffer creation
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/gbsneto/dmabuf-screencast: 2/6] renderer-native: Implement DMA buffer creation
- Date: Fri, 28 Feb 2020 18:37:15 +0000 (UTC)
commit d366fb335de68a04c16fd54e545f9177e7e999af
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Mon Dec 9 10:05:37 2019 -0300
renderer-native: Implement DMA buffer creation
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 | 68 ++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
---
diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
index 92f5a28bb..6d9243716 100644
--- a/src/backends/native/meta-renderer-native.c
+++ b/src/backends/native/meta-renderer-native.c
@@ -2132,6 +2132,73 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
COGL_TRACE_END (MetaRendererNativePostKmsUpdate);
}
+static CoglDmaBufHandle *
+meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer,
+ int width,
+ int height,
+ GError **error)
+{
+ CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
+ MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
+ MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
+
+ switch (renderer_gpu_data->mode)
+ {
+ case META_RENDERER_NATIVE_MODE_GBM:
+ {
+ CoglFramebuffer *dmabuf_fb;
+ struct gbm_bo *new_bo;
+ int dmabuf_fd = -1;
+
+ new_bo = gbm_bo_create (renderer_gpu_data->gbm.device,
+ width, height, DRM_FORMAT_XRGB8888,
+ GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR);
+
+ if (!new_bo)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Failed to allocate buffer");
+ return NULL;
+ }
+
+ 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 buffer's DMA fd: %s",
+ g_strerror (errno));
+ return NULL;
+ }
+
+ dmabuf_fb = create_dma_buf_framebuffer (renderer_native,
+ dmabuf_fd,
+ width, height,
+ gbm_bo_get_stride (new_bo),
+ gbm_bo_get_offset (new_bo, 0),
+ DRM_FORMAT_MOD_LINEAR,
+ DRM_FORMAT_XRGB8888,
+ error);
+
+ if (!dmabuf_fb)
+ 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)
@@ -2874,6 +2941,7 @@ get_native_cogl_winsys_vtable (CoglRenderer *cogl_renderer)
vtable.renderer_connect = meta_renderer_native_connect;
vtable.renderer_disconnect = meta_renderer_native_disconnect;
+ vtable.renderer_create_dma_buf = meta_renderer_native_create_dma_buf;
vtable.onscreen_init = meta_renderer_native_init_onscreen;
vtable.onscreen_deinit = meta_renderer_native_release_onscreen;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]