From 7a661e4c38b3628fab39202903be12baab21b8b4 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 20 Oct 2021 19:01:40 +0200 Subject: [PATCH] render/timeline: add wlr_render_timeline_import_dmabuf Same as wlr_render_timeline_import_sync_file, but takes a DMA-BUF as argument. Depends on [1]. [1]: https://lore.kernel.org/dri-devel/20210610210925.642582-5-jason@jlekstrand.net/ --- include/wlr/render/timeline.h | 11 +++++++++++ render/timeline.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/include/wlr/render/timeline.h b/include/wlr/render/timeline.h index 80705cb56..f4d07e634 100644 --- a/include/wlr/render/timeline.h +++ b/include/wlr/render/timeline.h @@ -56,5 +56,16 @@ int wlr_render_timeline_export_sync_file(struct wlr_render_timeline *timeline, */ bool wlr_render_timeline_import_sync_file(struct wlr_render_timeline *timeline, uint64_t dst_point, int sync_file_fd); +/** + * Import a timeline point from a DMA-BUF's implicit fence. + * + * The provided timeline point will be signalled when the DMA-BUF's producer + * has finished their write operations. + * + * This allows inter-operation with other APIs which don't support drm_syncobj + * nor sync_file yet. + */ +bool wlr_render_timeline_import_dmabuf(struct wlr_render_timeline *timeline, + uint64_t dst_point, int dmabuf_fd); #endif diff --git a/render/timeline.c b/render/timeline.c index 6acf3e8ee..a69f06d18 100644 --- a/render/timeline.c +++ b/render/timeline.c @@ -1,5 +1,7 @@ -#include +#include #include +#include +#include #include #include @@ -84,3 +86,31 @@ out: drmSyncobjDestroy(timeline->drm_fd, syncobj_handle); return ok; } + +#ifndef DMA_BUF_IOCTL_EXPORT_SYNC_FILE + +struct dma_buf_export_sync_file { + __u32 flags; + __s32 fd; +}; + +#define DMA_BUF_IOCTL_EXPORT_SYNC_FILE _IOWR(DMA_BUF_BASE, 2, struct dma_buf_export_sync_file) + +#endif + +bool wlr_render_timeline_import_dmabuf(struct wlr_render_timeline *timeline, + uint64_t dst_point, int dmabuf_fd) { + struct dma_buf_export_sync_file ioctl_data = { + .flags = DMA_BUF_SYNC_READ, + }; + if (drmIoctl(dmabuf_fd, DMA_BUF_IOCTL_EXPORT_SYNC_FILE, + &ioctl_data) != 0) { + wlr_log_errno(WLR_ERROR, "drmIoctl(EXPORT_SYNC_FILE) failed"); + return false; + } + + bool ok = wlr_render_timeline_import_sync_file(timeline, + ioctl_data.fd, dst_point); + close(ioctl_data.fd); + return ok; +}