diff --git a/include/wlr/render/timeline.h b/include/wlr/render/timeline.h index f4d07e634..dc799c8d7 100644 --- a/include/wlr/render/timeline.h +++ b/include/wlr/render/timeline.h @@ -30,6 +30,11 @@ struct wlr_render_timeline; * Create a new synchronization timeline. */ struct wlr_render_timeline *wlr_render_timeline_create(int drm_fd); +/** + * Import a timeline from a drm_syncobj FD. + */ +struct wlr_render_timeline *wlr_render_timeline_import(int drm_fd, + int drm_syncobj_fd); /** * Destroy a synchronization timeline. */ diff --git a/render/timeline.c b/render/timeline.c index a69f06d18..df98b5325 100644 --- a/render/timeline.c +++ b/render/timeline.c @@ -26,6 +26,23 @@ struct wlr_render_timeline *wlr_render_timeline_create(int drm_fd) { return timeline; } +struct wlr_render_timeline *wlr_render_timeline_import(int drm_fd, + int drm_syncobj_fd) { + struct wlr_render_timeline *timeline = calloc(1, sizeof(*timeline)); + if (timeline == NULL) { + return NULL; + } + timeline->drm_fd = drm_fd; + + if (drmSyncobjFDToHandle(drm_fd, drm_syncobj_fd, &timeline->handle) != 0) { + wlr_log_errno(WLR_ERROR, "drmSyncobjFDToHandle failed"); + free(timeline); + return NULL; + } + + return timeline; +} + void wlr_render_timeline_destroy(struct wlr_render_timeline *timeline) { drmSyncobjDestroy(timeline->drm_fd, timeline->handle); free(timeline);