@@ -7,7 +7,10 @@ use drm_sys::*;
77
88use std:: {
99 io,
10- os:: unix:: io:: { AsRawFd , BorrowedFd } ,
10+ os:: {
11+ fd:: { FromRawFd , OwnedFd } ,
12+ unix:: io:: { AsRawFd , BorrowedFd } ,
13+ } ,
1114} ;
1215
1316/// Creates a syncobj.
@@ -39,54 +42,91 @@ pub fn destroy(fd: BorrowedFd<'_>, handle: u32) -> io::Result<drm_syncobj_destro
3942 Ok ( args)
4043}
4144
42- /// Exports a syncobj as an inter-process file descriptor or as a poll()-able sync file.
43- pub fn handle_to_fd (
45+ /// Exports a syncobj as an inter-process file descriptor.
46+ pub fn handle_to_fd ( fd : BorrowedFd < ' _ > , handle : u32 ) -> io:: Result < OwnedFd > {
47+ let mut args = drm_syncobj_handle {
48+ handle,
49+ flags : 0 ,
50+ fd : 0 ,
51+ pad : 0 ,
52+ point : 0 ,
53+ } ;
54+
55+ unsafe {
56+ ioctl:: syncobj:: handle_to_fd ( fd, & mut args) ?;
57+ }
58+
59+ Ok ( unsafe { OwnedFd :: from_raw_fd ( args. fd ) } )
60+ }
61+
62+ /// Exports a syncobj as a poll-able sync file optionally for a specified timeline point.
63+ pub fn handle_to_sync_file (
4464 fd : BorrowedFd < ' _ > ,
4565 handle : u32 ,
46- export_sync_file : bool ,
47- ) -> io:: Result < drm_syncobj_handle > {
66+ timeline_point : Option < u64 > ,
67+ ) -> io:: Result < OwnedFd > {
4868 let mut args = drm_syncobj_handle {
4969 handle,
50- flags : if export_sync_file {
51- DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE
52- } else {
53- 0
54- } ,
70+ flags : DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE
71+ | if timeline_point. is_some ( ) {
72+ DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_TIMELINE
73+ } else {
74+ 0
75+ } ,
5576 fd : 0 ,
5677 pad : 0 ,
57- point : 0 , // TODO: Add support for TIMELINE sync files
78+ point : timeline_point . unwrap_or ( 0 ) ,
5879 } ;
5980
6081 unsafe {
6182 ioctl:: syncobj:: handle_to_fd ( fd, & mut args) ?;
6283 }
6384
64- Ok ( args)
85+ Ok ( unsafe { OwnedFd :: from_raw_fd ( args. fd ) } )
6586}
6687
6788/// Imports a file descriptor exported by [`handle_to_fd`] back into a process-local handle.
68- pub fn fd_to_handle (
89+ pub fn fd_to_handle ( fd : BorrowedFd < ' _ > , opaque_fd : BorrowedFd < ' _ > ) -> io:: Result < u32 > {
90+ let mut args = drm_syncobj_handle {
91+ handle : 0 ,
92+ flags : 0 ,
93+ fd : opaque_fd. as_raw_fd ( ) ,
94+ pad : 0 ,
95+ point : 0 ,
96+ } ;
97+
98+ unsafe {
99+ ioctl:: syncobj:: fd_to_handle ( fd, & mut args) ?;
100+ }
101+
102+ Ok ( args. handle )
103+ }
104+
105+ /// Imports a sync file exported by [`handle_to_sync_file`] into an existing process-local handle optionally for a specified timeline point.
106+ pub fn sync_file_into_handle (
69107 fd : BorrowedFd < ' _ > ,
70108 syncobj_fd : BorrowedFd < ' _ > ,
71- import_sync_file : bool ,
72- ) -> io:: Result < drm_syncobj_handle > {
109+ handle : u32 ,
110+ timeline_point : Option < u64 > ,
111+ ) -> io:: Result < ( ) > {
73112 let mut args = drm_syncobj_handle {
74- handle : 0 ,
75- flags : if import_sync_file {
76- DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE
77- } else {
78- 0
79- } ,
113+ handle,
114+ flags : DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE
115+ | if timeline_point. is_some ( ) {
116+ DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_TIMELINE
117+ } else {
118+ 0
119+ } ,
80120 fd : syncobj_fd. as_raw_fd ( ) ,
81121 pad : 0 ,
82- point : 0 , // TODO: Add support for TIMELINE sync files
122+ point : timeline_point . unwrap_or ( 0 ) ,
83123 } ;
84124
85125 unsafe {
86126 ioctl:: syncobj:: fd_to_handle ( fd, & mut args) ?;
87127 }
88128
89- Ok ( args )
129+ Ok ( ( ) )
90130}
91131
92132/// Waits for one or more syncobjs to become signalled.
0 commit comments