Skip to content

Commit 31f3a3e

Browse files
sdroegebilelmoussaoui
authored andcommitted
gdk: Use RawFd for DmabufTextureBuilder fd setter and mark function unsafe
The fd must be valid for as long as the texture stays around, which can't be statically guaranteed and is job of the user, e.g. by using the release function. And use Borrowed fd for getter.
1 parent 4e32f64 commit 31f3a3e

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

gdk4/Gir.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ status = "generate"
453453
# Take by value and return self
454454
manual = true
455455
[[object.function]]
456+
pattern = "get_fd"
457+
# Use BorrowedFd
458+
manual = true
459+
[[object.function]]
456460
name = "build"
457461
manual = true # Can't be auto-generated
458462
[[object.property]]

gdk4/src/auto/dmabuf_texture_builder.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ impl DmabufTextureBuilder {
4747
}
4848
}
4949

50-
#[doc(alias = "gdk_dmabuf_texture_builder_get_fd")]
51-
#[doc(alias = "get_fd")]
52-
pub fn fd(&self, plane: u32) -> i32 {
53-
unsafe { ffi::gdk_dmabuf_texture_builder_get_fd(self.to_glib_none().0, plane) }
54-
}
55-
5650
#[doc(alias = "gdk_dmabuf_texture_builder_get_fourcc")]
5751
#[doc(alias = "get_fourcc")]
5852
pub fn fourcc(&self) -> u32 {

gdk4/src/dmabuf_texture_builder.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,34 @@ impl DmabufTextureBuilder {
3535
self
3636
}
3737

38+
// rustdoc-stripper-ignore-next
39+
/// # Safety
40+
///
41+
/// The caller must ensure that `fd` says valid for at least as long as the texture, e.g. by
42+
/// using `build_with_release_func()` to get notified when `fd` is not used anymore.
3843
#[doc(alias = "gdk_dmabuf_texture_builder_set_fd")]
39-
pub fn set_fd(self, plane: u32, fd: i32) -> Self {
44+
pub unsafe fn set_fd(self, plane: u32, fd: std::os::fd::RawFd) -> Self {
4045
unsafe {
4146
ffi::gdk_dmabuf_texture_builder_set_fd(self.to_glib_none().0, plane, fd);
4247
}
4348

4449
self
4550
}
4651

52+
#[doc(alias = "gdk_dmabuf_texture_builder_get_fd")]
53+
#[doc(alias = "get_fd")]
54+
pub fn fd(&self, plane: u32) -> Option<std::os::fd::BorrowedFd<'_>> {
55+
unsafe {
56+
let fd = ffi::gdk_dmabuf_texture_builder_get_fd(self.to_glib_none().0, plane);
57+
58+
if fd == -1 {
59+
None
60+
} else {
61+
Some(std::os::fd::BorrowedFd::borrow_raw(fd))
62+
}
63+
}
64+
}
65+
4766
#[doc(alias = "gdk_dmabuf_texture_builder_set_fourcc")]
4867
#[doc(alias = "fourcc")]
4968
pub fn set_fourcc(self, fourcc: u32) -> Self {

0 commit comments

Comments
 (0)