[mutter] drm-buffer: Add API to export buffer file descriptor
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] drm-buffer: Add API to export buffer file descriptor
- Date: Mon, 18 Oct 2021 16:45:45 +0000 (UTC)
commit a1266e19f41b5b1ff91c64b0874189b6d27458f8
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Wed May 5 11:19:13 2021 +0200
drm-buffer: Add API to export buffer file descriptor
Practically ends up in gbm_bo_get_fd(). For dumb buffer, an
'unsupported' error is returned.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1854>
src/backends/native/meta-drm-buffer-dumb.c | 10 ++++++++++
src/backends/native/meta-drm-buffer-gbm.c | 19 +++++++++++++++++++
src/backends/native/meta-drm-buffer-import.c | 11 +++++++++++
src/backends/native/meta-drm-buffer.c | 7 +++++++
src/backends/native/meta-drm-buffer.h | 3 +++
5 files changed, 50 insertions(+)
---
diff --git a/src/backends/native/meta-drm-buffer-dumb.c b/src/backends/native/meta-drm-buffer-dumb.c
index 3e4988fcd8..b0c713decf 100644
--- a/src/backends/native/meta-drm-buffer-dumb.c
+++ b/src/backends/native/meta-drm-buffer-dumb.c
@@ -50,6 +50,15 @@ struct _MetaDrmBufferDumb
G_DEFINE_TYPE (MetaDrmBufferDumb, meta_drm_buffer_dumb, META_TYPE_DRM_BUFFER)
+static int
+meta_drm_buffer_dumb_export_fd (MetaDrmBuffer *buffer,
+ GError **error)
+{
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ "Can't export fd for dumb buffer");
+ return -1;
+}
+
static int
meta_drm_buffer_dumb_get_width (MetaDrmBuffer *buffer)
{
@@ -362,6 +371,7 @@ meta_drm_buffer_dumb_class_init (MetaDrmBufferDumbClass *klass)
object_class->finalize = meta_drm_buffer_dumb_finalize;
+ buffer_class->export_fd = meta_drm_buffer_dumb_export_fd;
buffer_class->get_width = meta_drm_buffer_dumb_get_width;
buffer_class->get_height = meta_drm_buffer_dumb_get_height;
buffer_class->get_stride = meta_drm_buffer_dumb_get_stride;
diff --git a/src/backends/native/meta-drm-buffer-gbm.c b/src/backends/native/meta-drm-buffer-gbm.c
index 9ad49be0dc..7a3abaa6bd 100644
--- a/src/backends/native/meta-drm-buffer-gbm.c
+++ b/src/backends/native/meta-drm-buffer-gbm.c
@@ -57,6 +57,24 @@ meta_drm_buffer_gbm_get_bo (MetaDrmBufferGbm *buffer_gbm)
return buffer_gbm->bo;
}
+static int
+meta_drm_buffer_gbm_export_fd (MetaDrmBuffer *buffer,
+ GError **error)
+{
+ MetaDrmBufferGbm *buffer_gbm = META_DRM_BUFFER_GBM (buffer);
+ int fd;
+
+ fd = gbm_bo_get_fd (buffer_gbm->bo);
+ if (fd == -1)
+ {
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
+ "Failed to export buffer fd: %s", g_strerror (errno));
+ return -1;
+ }
+
+ return fd;
+}
+
static int
meta_drm_buffer_gbm_get_width (MetaDrmBuffer *buffer)
{
@@ -491,6 +509,7 @@ meta_drm_buffer_gbm_class_init (MetaDrmBufferGbmClass *klass)
object_class->finalize = meta_drm_buffer_gbm_finalize;
+ buffer_class->export_fd = meta_drm_buffer_gbm_export_fd;
buffer_class->get_width = meta_drm_buffer_gbm_get_width;
buffer_class->get_height = meta_drm_buffer_gbm_get_height;
buffer_class->get_stride = meta_drm_buffer_gbm_get_stride;
diff --git a/src/backends/native/meta-drm-buffer-import.c b/src/backends/native/meta-drm-buffer-import.c
index b947bd1f92..4769e5326b 100644
--- a/src/backends/native/meta-drm-buffer-import.c
+++ b/src/backends/native/meta-drm-buffer-import.c
@@ -44,6 +44,16 @@ struct _MetaDrmBufferImport
G_DEFINE_TYPE (MetaDrmBufferImport, meta_drm_buffer_import,
META_TYPE_DRM_BUFFER)
+static int
+meta_drm_buffer_import_export_fd (MetaDrmBuffer *buffer,
+ GError **error)
+{
+ MetaDrmBufferImport *buffer_import = META_DRM_BUFFER_IMPORT (buffer);
+
+ return meta_drm_buffer_export_fd (META_DRM_BUFFER (buffer_import->importee),
+ error);
+}
+
static int
meta_drm_buffer_import_get_width (MetaDrmBuffer *buffer)
{
@@ -229,6 +239,7 @@ meta_drm_buffer_import_class_init (MetaDrmBufferImportClass *klass)
object_class->finalize = meta_drm_buffer_import_finalize;
+ buffer_class->export_fd = meta_drm_buffer_import_export_fd;
buffer_class->get_width = meta_drm_buffer_import_get_width;
buffer_class->get_height = meta_drm_buffer_import_get_height;
buffer_class->get_stride = meta_drm_buffer_import_get_stride;
diff --git a/src/backends/native/meta-drm-buffer.c b/src/backends/native/meta-drm-buffer.c
index 4ec9d820c6..09e07b61de 100644
--- a/src/backends/native/meta-drm-buffer.c
+++ b/src/backends/native/meta-drm-buffer.c
@@ -158,6 +158,13 @@ meta_drm_buffer_release_fb_id (MetaDrmBuffer *buffer)
priv->fb_id = 0;
}
+int
+meta_drm_buffer_export_fd (MetaDrmBuffer *buffer,
+ GError **error)
+{
+ return META_DRM_BUFFER_GET_CLASS (buffer)->export_fd (buffer, error);
+}
+
uint32_t
meta_drm_buffer_get_fb_id (MetaDrmBuffer *buffer)
{
diff --git a/src/backends/native/meta-drm-buffer.h b/src/backends/native/meta-drm-buffer.h
index ac4a83ef76..2a8035d8d3 100644
--- a/src/backends/native/meta-drm-buffer.h
+++ b/src/backends/native/meta-drm-buffer.h
@@ -40,6 +40,9 @@ G_DECLARE_DERIVABLE_TYPE (MetaDrmBuffer,
META, DRM_BUFFER,
GObject)
+int meta_drm_buffer_export_fd (MetaDrmBuffer *buffer,
+ GError **error);
+
uint32_t meta_drm_buffer_get_fb_id (MetaDrmBuffer *buffer);
int meta_drm_buffer_get_width (MetaDrmBuffer *buffer);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]