mirror of
https://github.com/brl/mutter.git
synced 2024-12-26 12:52:14 +00:00
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:
parent
f0fd013262
commit
416285d1b7
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user