diff --git a/src/backends/native/meta-backend-native-types.h b/src/backends/native/meta-backend-native-types.h index 152b57cf6..f6c87484b 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 bde08adc3..e5fe9c733 100644 --- a/src/backends/native/meta-render-device-gbm.c +++ b/src/backends/native/meta-render-device-gbm.c @@ -26,6 +26,7 @@ #include #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 f064160bc..8b917d501 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 d696f7fe0..6a0a00e1e 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 b1b71028e..48cc657c9 100644 --- a/src/backends/native/meta-render-device.h +++ b/src/backends/native/meta-render-device.h @@ -24,6 +24,7 @@ #include #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 */