[mutter] render-device: Add API to allocate DMA buffers
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] render-device: Add API to allocate DMA buffers
- Date: Mon, 18 Oct 2021 16:45:45 +0000 (UTC)
commit 802e7eb56f314237f10d417aa8accddc404ac665
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Wed May 5 15:35:59 2021 +0200
render-device: Add API to allocate DMA buffers
Only possible with the gbm implementation; aims to make it easier for
users of render devices to allocate DMA buffers.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1854>
src/backends/native/meta-backend-native-types.h | 1 +
src/backends/native/meta-render-device-gbm.c | 33 ++++++++++++++++++++++++
src/backends/native/meta-render-device-private.h | 8 ++++++
src/backends/native/meta-render-device.c | 26 +++++++++++++++++++
src/backends/native/meta-render-device.h | 8 ++++++
5 files changed, 76 insertions(+)
---
diff --git a/src/backends/native/meta-backend-native-types.h b/src/backends/native/meta-backend-native-types.h
index 152b57cf69..f6c87484be 100644
--- a/src/backends/native/meta-backend-native-types.h
+++ b/src/backends/native/meta-backend-native-types.h
@@ -31,6 +31,7 @@ typedef struct _MetaCrtcVirtual MetaCrtcVirtual;
typedef struct _MetaCrtcModeVirtual MetaCrtcModeVirtual;
typedef struct _MetaDevicePool MetaDevicePool;
typedef struct _MetaDeviceFile MetaDeviceFile;
+typedef struct _MetaDrmBuffer MetaDrmBuffer;
typedef enum _MetaSeatNativeFlag
{
diff --git a/src/backends/native/meta-render-device-gbm.c b/src/backends/native/meta-render-device-gbm.c
index bde08adc3d..e5fe9c733b 100644
--- a/src/backends/native/meta-render-device-gbm.c
+++ b/src/backends/native/meta-render-device-gbm.c
@@ -26,6 +26,7 @@
#include <gbm.h>
#include "backends/meta-backend-private.h"
+#include "backends/native/meta-drm-buffer-gbm.h"
struct _MetaRenderDeviceGbm
{
@@ -115,6 +116,36 @@ meta_render_device_gbm_create_egl_display (MetaRenderDevice *render_device,
return egl_display;
}
+static MetaDrmBuffer *
+meta_render_device_gbm_allocate_dma_buf (MetaRenderDevice *render_device,
+ int width,
+ int height,
+ uint32_t format,
+ MetaDrmBufferFlags flags,
+ GError **error)
+{
+ MetaRenderDeviceGbm *render_device_gbm =
+ META_RENDER_DEVICE_GBM (render_device);
+ MetaDeviceFile *device_file;
+ struct gbm_bo *gbm_bo;
+ MetaDrmBufferGbm *buffer_gbm;
+
+ gbm_bo = gbm_bo_create (render_device_gbm->gbm_device,
+ width, height, format,
+ GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR);
+ if (!gbm_bo)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Failed to gbm_bo: %s", g_strerror (errno));
+ return NULL;
+ }
+
+ device_file = meta_render_device_get_device_file (render_device);
+ buffer_gbm = meta_drm_buffer_gbm_new_take (device_file, gbm_bo, flags,
+ error);
+ return META_DRM_BUFFER (buffer_gbm);
+}
+
static void
meta_render_device_gbm_finalize (GObject *object)
{
@@ -135,6 +166,8 @@ meta_render_device_gbm_class_init (MetaRenderDeviceGbmClass *klass)
render_device_class->create_egl_display =
meta_render_device_gbm_create_egl_display;
+ render_device_class->allocate_dma_buf =
+ meta_render_device_gbm_allocate_dma_buf;
}
static void
diff --git a/src/backends/native/meta-render-device-private.h
b/src/backends/native/meta-render-device-private.h
index f064160bc7..8b917d501d 100644
--- a/src/backends/native/meta-render-device-private.h
+++ b/src/backends/native/meta-render-device-private.h
@@ -26,6 +26,7 @@
#include "backends/meta-egl.h"
#include "backends/native/meta-device-pool.h"
+#include "backends/native/meta-drm-buffer.h"
#include "backends/native/meta-render-device.h"
struct _MetaRenderDeviceClass
@@ -34,6 +35,13 @@ struct _MetaRenderDeviceClass
EGLDisplay (* create_egl_display) (MetaRenderDevice *render_device,
GError **error);
+
+ MetaDrmBuffer * (* allocate_dma_buf) (MetaRenderDevice *render_device,
+ int width,
+ int height,
+ uint32_t format,
+ MetaDrmBufferFlags flags,
+ GError **error);
};
#endif /* META_RENDER_DEVICE_PRIVATE_H */
diff --git a/src/backends/native/meta-render-device.c b/src/backends/native/meta-render-device.c
index d696f7fe03..6a0a00e1e9 100644
--- a/src/backends/native/meta-render-device.c
+++ b/src/backends/native/meta-render-device.c
@@ -24,6 +24,7 @@
#include "backends/meta-backend-private.h"
#include "backends/meta-egl.h"
+#include "backends/native/meta-backend-native-types.h"
enum
{
@@ -338,3 +339,28 @@ meta_render_device_get_name (MetaRenderDevice *render_device)
else
return "(device-less)";
}
+
+MetaDrmBuffer *
+meta_render_device_allocate_dma_buf (MetaRenderDevice *render_device,
+ int width,
+ int height,
+ uint32_t format,
+ MetaDrmBufferFlags flags,
+ GError **error)
+{
+ MetaRenderDeviceClass *klass = META_RENDER_DEVICE_GET_CLASS (render_device);
+
+ if (klass->allocate_dma_buf)
+ {
+ return klass->allocate_dma_buf (render_device,
+ width, height, format,
+ flags,
+ error);
+ }
+
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Render device '%s' doesn't support allocating DMA buffers",
+ meta_render_device_get_name (render_device));
+
+ return NULL;
+}
diff --git a/src/backends/native/meta-render-device.h b/src/backends/native/meta-render-device.h
index b1b71028e9..48cc657c95 100644
--- a/src/backends/native/meta-render-device.h
+++ b/src/backends/native/meta-render-device.h
@@ -24,6 +24,7 @@
#include <glib-object.h>
#include "backends/meta-backend-types.h"
+#include "backends/native/meta-backend-native-types.h"
#define META_TYPE_RENDER_DEVICE (meta_render_device_get_type ())
G_DECLARE_DERIVABLE_TYPE (MetaRenderDevice, meta_render_device,
@@ -40,4 +41,11 @@ gboolean meta_render_device_is_hardware_accelerated (MetaRenderDevice *render_de
MetaDeviceFile * meta_render_device_get_device_file (MetaRenderDevice *render_device);
+MetaDrmBuffer * meta_render_device_allocate_dma_buf (MetaRenderDevice *render_device,
+ int width,
+ int height,
+ uint32_t format,
+ MetaDrmBufferFlags flags,
+ GError **error);
+
#endif /* META_RENDER_DEVICE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]