Skip to content

Commit b75d09b

Browse files
elmarcobilelmoussaoui
authored andcommitted
gdk: implement GLTextureBuilder (get|set)_sync
Signed-off-by: Marc-André Lureau <[email protected]>
1 parent 25efd7b commit b75d09b

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

gdk4/Gir.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ generate_builder = false
498498
pattern = "set_(context|format|has_mipmap|height|id|update_region|update_texture|width)"
499499
manual = true
500500
[[object.function]]
501+
pattern = "(set|get)_sync"
502+
manual = true
503+
[[object.function]]
501504
name = "build"
502505
manual = true
503506
[[object.property]]

gdk4/src/auto/gl_texture_builder.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ impl GLTextureBuilder {
6464
unsafe { ffi::gdk_gl_texture_builder_get_id(self.to_glib_none().0) }
6565
}
6666

67-
//#[doc(alias = "gdk_gl_texture_builder_get_sync")]
68-
//#[doc(alias = "get_sync")]
69-
//pub fn sync(&self) -> /*Unimplemented*/Option<Basic: Pointer> {
70-
// unsafe { TODO: call ffi:gdk_gl_texture_builder_get_sync() }
71-
//}
72-
7367
#[doc(alias = "gdk_gl_texture_builder_get_update_region")]
7468
#[doc(alias = "get_update_region")]
7569
pub fn update_region(&self) -> Option<cairo::Region> {
@@ -95,11 +89,6 @@ impl GLTextureBuilder {
9589
pub fn width(&self) -> i32 {
9690
unsafe { ffi::gdk_gl_texture_builder_get_width(self.to_glib_none().0) }
9791
}
98-
99-
//#[doc(alias = "gdk_gl_texture_builder_set_sync")]
100-
//pub fn set_sync(&self, sync: /*Unimplemented*/Option<Basic: Pointer>) {
101-
// unsafe { TODO: call ffi:gdk_gl_texture_builder_set_sync() }
102-
//}
10392
}
10493

10594
#[cfg(feature = "v4_12")]

gdk4/src/gl_texture_builder.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
use crate::{GLContext, GLTextureBuilder, MemoryFormat, Texture};
44
use glib::{prelude::*, translate::*};
55

6+
// TODO add a feature for a "common" GL binding instead
7+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
8+
pub struct GLSync(*mut libc::c_void);
9+
10+
impl GLSync {
11+
#[inline]
12+
pub unsafe fn from_ptr(ptr: *mut libc::c_void) -> Self {
13+
Self(ptr)
14+
}
15+
16+
#[inline]
17+
pub fn as_ptr(&self) -> *mut libc::c_void {
18+
self.0
19+
}
20+
}
21+
622
impl GLTextureBuilder {
723
#[doc(alias = "gdk_gl_texture_builder_build")]
824
#[must_use = "The builder must be built to be used"]
@@ -112,4 +128,25 @@ impl GLTextureBuilder {
112128

113129
self
114130
}
131+
132+
#[doc(alias = "gdk_gl_texture_builder_get_sync")]
133+
#[doc(alias = "get_sync")]
134+
pub fn sync(&self) -> Option<GLSync> {
135+
let ptr = unsafe { ffi::gdk_gl_texture_builder_get_sync(self.to_glib_none().0) };
136+
if ptr.is_null() {
137+
None
138+
} else {
139+
unsafe { Some(GLSync::from_ptr(ptr)) }
140+
}
141+
}
142+
143+
#[doc(alias = "gdk_gl_texture_builder_set_sync")]
144+
pub fn set_sync(self, sync: Option<GLSync>) -> Self {
145+
let ptr = sync.map(|s| s.as_ptr()).unwrap_or(std::ptr::null_mut());
146+
unsafe {
147+
ffi::gdk_gl_texture_builder_set_sync(self.to_glib_none().0, ptr);
148+
}
149+
150+
self
151+
}
115152
}

0 commit comments

Comments
 (0)