diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c index 7a22f824b..910d5edc4 100644 --- a/src/wayland/meta-wayland-buffer.c +++ b/src/wayland/meta-wayland-buffer.c @@ -184,6 +184,8 @@ meta_wayland_buffer_realize (MetaWaylandBuffer *buffer) NULL)) { buffer->type = META_WAYLAND_BUFFER_TYPE_EGL_IMAGE; + buffer->dma_buf.dma_buf = + meta_wayland_dma_buf_fds_for_wayland_buffer (buffer); return TRUE; } } diff --git a/src/wayland/meta-wayland-dma-buf.c b/src/wayland/meta-wayland-dma-buf.c index 350be1618..cc74afad5 100644 --- a/src/wayland/meta-wayland-dma-buf.c +++ b/src/wayland/meta-wayland-dma-buf.c @@ -689,6 +689,56 @@ static const struct wl_buffer_interface dma_buf_buffer_impl = buffer_destroy, }; +/** + * meta_wayland_dma_buf_fds_for_wayland_buffer: + * @buffer: A #MetaWaylandBuffer object + * + * Creates an associated #MetaWaylandDmaBufBuffer for the wayland buffer, which + * contains just the dma-buf file descriptors. + * + * Returns: The new #MetaWaylandDmaBufBuffer (or + * %NULL if it couldn't be created) + */ +MetaWaylandDmaBufBuffer * +meta_wayland_dma_buf_fds_for_wayland_buffer (MetaWaylandBuffer *buffer) +{ +#ifdef HAVE_NATIVE_BACKEND + MetaBackend *backend = meta_get_backend (); + MetaRenderer *renderer = meta_backend_get_renderer (backend); + MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer); + MetaGpuKms *gpu_kms; + struct gbm_device *gbm_device; + struct gbm_bo *gbm_bo; + MetaWaylandDmaBufBuffer *dma_buf; + uint32_t i, n_planes; + + gpu_kms = meta_renderer_native_get_primary_gpu (renderer_native); + if (!gpu_kms) + return NULL; + + gbm_device = meta_gbm_device_from_gpu (gpu_kms); + + gbm_bo = gbm_bo_import (gbm_device, + GBM_BO_IMPORT_WL_BUFFER, buffer->resource, + GBM_BO_USE_RENDERING); + if (!gbm_bo) + return NULL; + + dma_buf = g_object_new (META_TYPE_WAYLAND_DMA_BUF_BUFFER, NULL); + + n_planes = gbm_bo_get_plane_count (gbm_bo); + for (i = 0; i < n_planes; i++) + dma_buf->fds[i] = gbm_bo_get_fd_for_plane (gbm_bo, i); + while (i < META_WAYLAND_DMA_BUF_MAX_FDS) + dma_buf->fds[i++] = -1; + + gbm_bo_destroy (gbm_bo); + return dma_buf; +#else + return NULL; +#endif +} + /** * meta_wayland_dma_buf_from_buffer: * @buffer: A #MetaWaylandBuffer object @@ -710,7 +760,7 @@ meta_wayland_dma_buf_from_buffer (MetaWaylandBuffer *buffer) &dma_buf_buffer_impl)) return wl_resource_get_user_data (buffer->resource); - return NULL; + return buffer->dma_buf.dma_buf; } static void diff --git a/src/wayland/meta-wayland-dma-buf.h b/src/wayland/meta-wayland-dma-buf.h index dc1231560..57b1ef68e 100644 --- a/src/wayland/meta-wayland-dma-buf.h +++ b/src/wayland/meta-wayland-dma-buf.h @@ -51,6 +51,9 @@ meta_wayland_dma_buf_buffer_attach (MetaWaylandBuffer *buffer, CoglTexture **texture, GError **error); +MetaWaylandDmaBufBuffer * +meta_wayland_dma_buf_fds_for_wayland_buffer (MetaWaylandBuffer *buffer); + MetaWaylandDmaBufBuffer * meta_wayland_dma_buf_from_buffer (MetaWaylandBuffer *buffer);