From ea75aa30657eacaec827ab6844ba77d328ab5155 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 21 Oct 2021 15:02:09 +0200 Subject: [PATCH] render/drm_syncobj: add wlr_drm_syncobj_timeline_import() --- include/wlr/render/drm_syncobj.h | 5 +++++ render/drm_syncobj.c | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/wlr/render/drm_syncobj.h b/include/wlr/render/drm_syncobj.h index f879b5929..8b3609eeb 100644 --- a/include/wlr/render/drm_syncobj.h +++ b/include/wlr/render/drm_syncobj.h @@ -37,6 +37,11 @@ struct wlr_drm_syncobj_timeline { * Create a new synchronization timeline. */ struct wlr_drm_syncobj_timeline *wlr_drm_syncobj_timeline_create(int drm_fd); +/** + * Import a timeline from a drm_syncobj FD. + */ +struct wlr_drm_syncobj_timeline *wlr_drm_syncobj_timeline_import(int drm_fd, + int drm_syncobj_fd); /** * Reference a synchronization timeline. */ diff --git a/render/drm_syncobj.c b/render/drm_syncobj.c index 974b1b40d..f4b1c249a 100644 --- a/render/drm_syncobj.c +++ b/render/drm_syncobj.c @@ -21,6 +21,24 @@ struct wlr_drm_syncobj_timeline *wlr_drm_syncobj_timeline_create(int drm_fd) { return timeline; } +struct wlr_drm_syncobj_timeline *wlr_drm_syncobj_timeline_import(int drm_fd, + int drm_syncobj_fd) { + struct wlr_drm_syncobj_timeline *timeline = calloc(1, sizeof(*timeline)); + if (timeline == NULL) { + return NULL; + } + timeline->drm_fd = drm_fd; + timeline->n_refs = 1; + + if (drmSyncobjFDToHandle(drm_fd, drm_syncobj_fd, &timeline->handle) != 0) { + wlr_log_errno(WLR_ERROR, "drmSyncobjFDToHandle failed"); + free(timeline); + return NULL; + } + + return timeline; +} + struct wlr_drm_syncobj_timeline *wlr_drm_syncobj_timeline_ref(struct wlr_drm_syncobj_timeline *timeline) { timeline->n_refs++; return timeline;