1use crate::{VulkanDevice, VulkanDisplay, ffi};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{SignalHandlerId, connect_raw},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 #[doc(alias = "GstVulkanWindow")]
83 pub struct VulkanWindow(Object<ffi::GstVulkanWindow, ffi::GstVulkanWindowClass>) @extends gst::Object;
84
85 match fn {
86 type_ => || ffi::gst_vulkan_window_get_type(),
87 }
88}
89
90impl VulkanWindow {
91 pub const NONE: Option<&'static VulkanWindow> = None;
92
93 #[doc(alias = "gst_vulkan_window_new")]
100 pub fn new(display: &impl IsA<VulkanDisplay>) -> VulkanWindow {
101 skip_assert_initialized!();
102 unsafe {
103 from_glib_full(ffi::gst_vulkan_window_new(
104 display.as_ref().to_glib_none().0,
105 ))
106 }
107 }
108}
109
110unsafe impl Send for VulkanWindow {}
111unsafe impl Sync for VulkanWindow {}
112
113pub trait VulkanWindowExt: IsA<VulkanWindow> + 'static {
119 #[doc(alias = "gst_vulkan_window_close")]
121 fn close(&self) {
122 unsafe {
123 ffi::gst_vulkan_window_close(self.as_ref().to_glib_none().0);
124 }
125 }
126
127 #[doc(alias = "gst_vulkan_window_get_display")]
132 #[doc(alias = "get_display")]
133 fn display(&self) -> VulkanDisplay {
134 unsafe {
135 from_glib_full(ffi::gst_vulkan_window_get_display(
136 self.as_ref().to_glib_none().0,
137 ))
138 }
139 }
140
141 #[doc(alias = "gst_vulkan_window_get_presentation_support")]
151 #[doc(alias = "get_presentation_support")]
152 fn is_presentation_support(
153 &self,
154 device: &impl IsA<VulkanDevice>,
155 queue_family_idx: u32,
156 ) -> bool {
157 unsafe {
158 from_glib(ffi::gst_vulkan_window_get_presentation_support(
159 self.as_ref().to_glib_none().0,
160 device.as_ref().to_glib_none().0,
161 queue_family_idx,
162 ))
163 }
164 }
165
166 #[doc(alias = "gst_vulkan_window_get_surface_dimensions")]
182 #[doc(alias = "get_surface_dimensions")]
183 fn surface_dimensions(&self) -> (u32, u32) {
184 unsafe {
185 let mut width = std::mem::MaybeUninit::uninit();
186 let mut height = std::mem::MaybeUninit::uninit();
187 ffi::gst_vulkan_window_get_surface_dimensions(
188 self.as_ref().to_glib_none().0,
189 width.as_mut_ptr(),
190 height.as_mut_ptr(),
191 );
192 (width.assume_init(), height.assume_init())
193 }
194 }
195
196 #[doc(alias = "gst_vulkan_window_handle_events")]
204 fn handle_events(&self, handle_events: bool) {
205 unsafe {
206 ffi::gst_vulkan_window_handle_events(
207 self.as_ref().to_glib_none().0,
208 handle_events.into_glib(),
209 );
210 }
211 }
212
213 #[doc(alias = "gst_vulkan_window_open")]
218 fn open(&self) -> Result<(), glib::Error> {
219 unsafe {
220 let mut error = std::ptr::null_mut();
221 let is_ok = ffi::gst_vulkan_window_open(self.as_ref().to_glib_none().0, &mut error);
222 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
223 if error.is_null() {
224 Ok(())
225 } else {
226 Err(from_glib_full(error))
227 }
228 }
229 }
230
231 #[doc(alias = "gst_vulkan_window_redraw")]
233 fn redraw(&self) {
234 unsafe {
235 ffi::gst_vulkan_window_redraw(self.as_ref().to_glib_none().0);
236 }
237 }
238
239 #[doc(alias = "gst_vulkan_window_resize")]
247 fn resize(&self, width: i32, height: i32) {
248 unsafe {
249 ffi::gst_vulkan_window_resize(self.as_ref().to_glib_none().0, width, height);
250 }
251 }
252
253 #[doc(alias = "gst_vulkan_window_send_key_event")]
254 fn send_key_event(&self, event_type: &str, key_str: &str) {
255 unsafe {
256 ffi::gst_vulkan_window_send_key_event(
257 self.as_ref().to_glib_none().0,
258 event_type.to_glib_none().0,
259 key_str.to_glib_none().0,
260 );
261 }
262 }
263
264 #[doc(alias = "gst_vulkan_window_send_mouse_event")]
265 fn send_mouse_event(&self, event_type: &str, button: i32, posx: f64, posy: f64) {
266 unsafe {
267 ffi::gst_vulkan_window_send_mouse_event(
268 self.as_ref().to_glib_none().0,
269 event_type.to_glib_none().0,
270 button,
271 posx,
272 posy,
273 );
274 }
275 }
276
277 #[doc(alias = "close")]
283 fn connect_close<F: Fn(&Self) -> bool + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
284 unsafe extern "C" fn close_trampoline<
285 P: IsA<VulkanWindow>,
286 F: Fn(&P) -> bool + Send + Sync + 'static,
287 >(
288 this: *mut ffi::GstVulkanWindow,
289 f: glib::ffi::gpointer,
290 ) -> glib::ffi::gboolean {
291 unsafe {
292 let f: &F = &*(f as *const F);
293 f(VulkanWindow::from_glib_borrow(this).unsafe_cast_ref()).into_glib()
294 }
295 }
296 unsafe {
297 let f: Box_<F> = Box_::new(f);
298 connect_raw(
299 self.as_ptr() as *mut _,
300 c"close".as_ptr(),
301 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
302 close_trampoline::<Self, F> as *const (),
303 )),
304 Box_::into_raw(f),
305 )
306 }
307 }
308
309 #[doc(alias = "draw")]
310 fn connect_draw<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
311 unsafe extern "C" fn draw_trampoline<
312 P: IsA<VulkanWindow>,
313 F: Fn(&P) + Send + Sync + 'static,
314 >(
315 this: *mut ffi::GstVulkanWindow,
316 f: glib::ffi::gpointer,
317 ) {
318 unsafe {
319 let f: &F = &*(f as *const F);
320 f(VulkanWindow::from_glib_borrow(this).unsafe_cast_ref())
321 }
322 }
323 unsafe {
324 let f: Box_<F> = Box_::new(f);
325 connect_raw(
326 self.as_ptr() as *mut _,
327 c"draw".as_ptr(),
328 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
329 draw_trampoline::<Self, F> as *const (),
330 )),
331 Box_::into_raw(f),
332 )
333 }
334 }
335
336 #[doc(alias = "key-event")]
342 fn connect_key_event<F: Fn(&Self, &str, &str) + Send + Sync + 'static>(
343 &self,
344 f: F,
345 ) -> SignalHandlerId {
346 unsafe extern "C" fn key_event_trampoline<
347 P: IsA<VulkanWindow>,
348 F: Fn(&P, &str, &str) + Send + Sync + 'static,
349 >(
350 this: *mut ffi::GstVulkanWindow,
351 id: *mut std::ffi::c_char,
352 key: *mut std::ffi::c_char,
353 f: glib::ffi::gpointer,
354 ) {
355 unsafe {
356 let f: &F = &*(f as *const F);
357 f(
358 VulkanWindow::from_glib_borrow(this).unsafe_cast_ref(),
359 &glib::GString::from_glib_borrow(id),
360 &glib::GString::from_glib_borrow(key),
361 )
362 }
363 }
364 unsafe {
365 let f: Box_<F> = Box_::new(f);
366 connect_raw(
367 self.as_ptr() as *mut _,
368 c"key-event".as_ptr(),
369 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
370 key_event_trampoline::<Self, F> as *const (),
371 )),
372 Box_::into_raw(f),
373 )
374 }
375 }
376
377 #[doc(alias = "mouse-event")]
387 fn connect_mouse_event<F: Fn(&Self, &str, i32, f64, f64) + Send + Sync + 'static>(
388 &self,
389 f: F,
390 ) -> SignalHandlerId {
391 unsafe extern "C" fn mouse_event_trampoline<
392 P: IsA<VulkanWindow>,
393 F: Fn(&P, &str, i32, f64, f64) + Send + Sync + 'static,
394 >(
395 this: *mut ffi::GstVulkanWindow,
396 id: *mut std::ffi::c_char,
397 button: std::ffi::c_int,
398 x: std::ffi::c_double,
399 y: std::ffi::c_double,
400 f: glib::ffi::gpointer,
401 ) {
402 unsafe {
403 let f: &F = &*(f as *const F);
404 f(
405 VulkanWindow::from_glib_borrow(this).unsafe_cast_ref(),
406 &glib::GString::from_glib_borrow(id),
407 button,
408 x,
409 y,
410 )
411 }
412 }
413 unsafe {
414 let f: Box_<F> = Box_::new(f);
415 connect_raw(
416 self.as_ptr() as *mut _,
417 c"mouse-event".as_ptr(),
418 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
419 mouse_event_trampoline::<Self, F> as *const (),
420 )),
421 Box_::into_raw(f),
422 )
423 }
424 }
425
426 #[doc(alias = "resize")]
427 fn connect_resize<F: Fn(&Self, u32, u32) + Send + Sync + 'static>(
428 &self,
429 f: F,
430 ) -> SignalHandlerId {
431 unsafe extern "C" fn resize_trampoline<
432 P: IsA<VulkanWindow>,
433 F: Fn(&P, u32, u32) + Send + Sync + 'static,
434 >(
435 this: *mut ffi::GstVulkanWindow,
436 object: std::ffi::c_uint,
437 p0: std::ffi::c_uint,
438 f: glib::ffi::gpointer,
439 ) {
440 unsafe {
441 let f: &F = &*(f as *const F);
442 f(
443 VulkanWindow::from_glib_borrow(this).unsafe_cast_ref(),
444 object,
445 p0,
446 )
447 }
448 }
449 unsafe {
450 let f: Box_<F> = Box_::new(f);
451 connect_raw(
452 self.as_ptr() as *mut _,
453 c"resize".as_ptr(),
454 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
455 resize_trampoline::<Self, F> as *const (),
456 )),
457 Box_::into_raw(f),
458 )
459 }
460 }
461
462 #[doc(alias = "display")]
463 fn connect_display_notify<F: Fn(&Self) + Send + Sync + 'static>(
464 &self,
465 f: F,
466 ) -> SignalHandlerId {
467 unsafe extern "C" fn notify_display_trampoline<
468 P: IsA<VulkanWindow>,
469 F: Fn(&P) + Send + Sync + 'static,
470 >(
471 this: *mut ffi::GstVulkanWindow,
472 _param_spec: glib::ffi::gpointer,
473 f: glib::ffi::gpointer,
474 ) {
475 unsafe {
476 let f: &F = &*(f as *const F);
477 f(VulkanWindow::from_glib_borrow(this).unsafe_cast_ref())
478 }
479 }
480 unsafe {
481 let f: Box_<F> = Box_::new(f);
482 connect_raw(
483 self.as_ptr() as *mut _,
484 c"notify::display".as_ptr(),
485 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
486 notify_display_trampoline::<Self, F> as *const (),
487 )),
488 Box_::into_raw(f),
489 )
490 }
491 }
492}
493
494impl<O: IsA<VulkanWindow>> VulkanWindowExt for O {}