wayland/dma-buf: Add meta_wayland_dma_buf_fds_for_wayland_buffer

And call it from meta_wayland_buffer_realize. This makes dma-buf fds
available for EGL image type buffers as well.

v2:
* Move buffer->dma_buf.dma_buf assignment value to next line.
  (Jonas Ådahl)

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
This commit is contained in:
Michel Dänzer 2021-05-22 18:32:44 +02:00 committed by Michel Dänzer
parent f0fd013262
commit 416285d1b7
3 changed files with 56 additions and 1 deletions

View File

@ -184,6 +184,8 @@ meta_wayland_buffer_realize (MetaWaylandBuffer *buffer)
NULL)) NULL))
{ {
buffer->type = META_WAYLAND_BUFFER_TYPE_EGL_IMAGE; buffer->type = META_WAYLAND_BUFFER_TYPE_EGL_IMAGE;
buffer->dma_buf.dma_buf =
meta_wayland_dma_buf_fds_for_wayland_buffer (buffer);
return TRUE; return TRUE;
} }
} }

View File

@ -689,6 +689,56 @@ static const struct wl_buffer_interface dma_buf_buffer_impl =
buffer_destroy, 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: * meta_wayland_dma_buf_from_buffer:
* @buffer: A #MetaWaylandBuffer object * @buffer: A #MetaWaylandBuffer object
@ -710,7 +760,7 @@ meta_wayland_dma_buf_from_buffer (MetaWaylandBuffer *buffer)
&dma_buf_buffer_impl)) &dma_buf_buffer_impl))
return wl_resource_get_user_data (buffer->resource); return wl_resource_get_user_data (buffer->resource);
return NULL; return buffer->dma_buf.dma_buf;
} }
static void static void

View File

@ -51,6 +51,9 @@ meta_wayland_dma_buf_buffer_attach (MetaWaylandBuffer *buffer,
CoglTexture **texture, CoglTexture **texture,
GError **error); GError **error);
MetaWaylandDmaBufBuffer *
meta_wayland_dma_buf_fds_for_wayland_buffer (MetaWaylandBuffer *buffer);
MetaWaylandDmaBufBuffer * MetaWaylandDmaBufBuffer *
meta_wayland_dma_buf_from_buffer (MetaWaylandBuffer *buffer); meta_wayland_dma_buf_from_buffer (MetaWaylandBuffer *buffer);