gstreamer_vulkan/auto/
vulkan_window.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ffi, VulkanDevice, VulkanDisplay};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    /// [`VulkanWindow`][crate::VulkanWindow] is an opaque struct and should only be accessed through the
17    /// provided api.
18    ///
19    /// This is an Abstract Base Class, you cannot instantiate it.
20    ///
21    /// ## Properties
22    ///
23    ///
24    /// #### `display`
25    ///  Readable
26    /// <details><summary><h4>Object</h4></summary>
27    ///
28    ///
29    /// #### `name`
30    ///  Readable | Writeable | Construct
31    ///
32    ///
33    /// #### `parent`
34    ///  The parent of the object. Please note, that when changing the 'parent'
35    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::gst::Object#deep-notify]
36    /// signals due to locking issues. In some cases one can use
37    /// `GstBin::element-added` or `GstBin::element-removed` signals on the parent to
38    /// achieve a similar effect.
39    ///
40    /// Readable | Writeable
41    /// </details>
42    ///
43    /// ## Signals
44    ///
45    ///
46    /// #### `close`
47    ///
48    ///
49    ///
50    /// #### `draw`
51    ///
52    ///
53    ///
54    /// #### `key-event`
55    ///  Will be emitted when a key event is received by the [`VulkanWindow`][crate::VulkanWindow].
56    ///
57    ///
58    ///
59    ///
60    /// #### `mouse-event`
61    ///  Will be emitted when a mouse event is received by the [`VulkanWindow`][crate::VulkanWindow].
62    ///
63    ///
64    ///
65    ///
66    /// #### `resize`
67    ///
68    /// <details><summary><h4>Object</h4></summary>
69    ///
70    ///
71    /// #### `deep-notify`
72    ///  The deep notify signal is used to be notified of property changes. It is
73    /// typically attached to the toplevel bin to receive notifications from all
74    /// the elements contained in that bin.
75    ///
76    /// Detailed
77    /// </details>
78    ///
79    /// # Implements
80    ///
81    /// [`VulkanWindowExt`][trait@crate::prelude::VulkanWindowExt], [`trait@gst::prelude::ObjectExt`], [`trait@glib::ObjectExt`]
82    #[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    /// ## `display`
94    /// a [`VulkanDisplay`][crate::VulkanDisplay]
95    ///
96    /// # Returns
97    ///
98    /// a new [`VulkanWindow`][crate::VulkanWindow] using `display`'s connection
99    #[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
113/// Trait containing all [`struct@VulkanWindow`] methods.
114///
115/// # Implementors
116///
117/// [`VulkanWindow`][struct@crate::VulkanWindow]
118pub trait VulkanWindowExt: IsA<VulkanWindow> + 'static {
119    /// Attempt to close the window.
120    #[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    ///
128    /// # Returns
129    ///
130    /// the [`VulkanDisplay`][crate::VulkanDisplay] for `self`
131    #[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    /// ## `device`
142    /// a [`VulkanDevice`][crate::VulkanDevice]
143    /// ## `queue_family_idx`
144    /// the queue family
145    ///
146    /// # Returns
147    ///
148    /// whether the given combination of `self`, `device` and
149    ///  `queue_family_idx` supports presentation
150    #[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")]
167    //#[doc(alias = "get_surface")]
168    //fn surface(&self) -> Result</*Ignored*/vulkan::SurfaceKHR, glib::Error> {
169    //    unsafe { TODO: call ffi:gst_vulkan_window_get_surface() }
170    //}
171
172    ///
173    /// # Returns
174    ///
175    ///
176    /// ## `width`
177    /// Current width of `self`
178    ///
179    /// ## `height`
180    /// Current height of `self`
181    #[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    /// Tell a `self` that it should handle events from the window system. These
197    /// events are forwarded upstream as navigation events. In some window systems
198    /// events are not propagated in the window hierarchy if a client is listening
199    /// for them. This method allows you to disable events handling completely
200    /// from the `self`.
201    /// ## `handle_events`
202    /// a `gboolean` indicating if events should be handled or not.
203    #[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    ///
214    /// # Returns
215    ///
216    /// whether `self` could be successfully opened
217    #[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    /// Ask the `self` to redraw its contents
232    #[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    /// Resize the output surface.
240    ///
241    /// Currently intended for subclasses to update internal state.
242    /// ## `width`
243    /// the new width
244    /// ## `height`
245    /// the new height
246    #[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 = "gst_vulkan_window_set_window_handle")]
278    //fn set_window_handle(&self, handle: /*Unimplemented*/Basic: UIntPtr) {
279    //    unsafe { TODO: call ffi:gst_vulkan_window_set_window_handle() }
280    //}
281
282    #[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            let f: &F = &*(f as *const F);
292            f(VulkanWindow::from_glib_borrow(this).unsafe_cast_ref()).into_glib()
293        }
294        unsafe {
295            let f: Box_<F> = Box_::new(f);
296            connect_raw(
297                self.as_ptr() as *mut _,
298                c"close".as_ptr() as *const _,
299                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
300                    close_trampoline::<Self, F> as *const (),
301                )),
302                Box_::into_raw(f),
303            )
304        }
305    }
306
307    #[doc(alias = "draw")]
308    fn connect_draw<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
309        unsafe extern "C" fn draw_trampoline<
310            P: IsA<VulkanWindow>,
311            F: Fn(&P) + Send + Sync + 'static,
312        >(
313            this: *mut ffi::GstVulkanWindow,
314            f: glib::ffi::gpointer,
315        ) {
316            let f: &F = &*(f as *const F);
317            f(VulkanWindow::from_glib_borrow(this).unsafe_cast_ref())
318        }
319        unsafe {
320            let f: Box_<F> = Box_::new(f);
321            connect_raw(
322                self.as_ptr() as *mut _,
323                c"draw".as_ptr() as *const _,
324                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
325                    draw_trampoline::<Self, F> as *const (),
326                )),
327                Box_::into_raw(f),
328            )
329        }
330    }
331
332    /// Will be emitted when a key event is received by the [`VulkanWindow`][crate::VulkanWindow].
333    /// ## `id`
334    /// the name of the event
335    /// ## `key`
336    /// the id of the key pressed
337    #[doc(alias = "key-event")]
338    fn connect_key_event<F: Fn(&Self, &str, &str) + Send + Sync + 'static>(
339        &self,
340        f: F,
341    ) -> SignalHandlerId {
342        unsafe extern "C" fn key_event_trampoline<
343            P: IsA<VulkanWindow>,
344            F: Fn(&P, &str, &str) + Send + Sync + 'static,
345        >(
346            this: *mut ffi::GstVulkanWindow,
347            id: *mut std::ffi::c_char,
348            key: *mut std::ffi::c_char,
349            f: glib::ffi::gpointer,
350        ) {
351            let f: &F = &*(f as *const F);
352            f(
353                VulkanWindow::from_glib_borrow(this).unsafe_cast_ref(),
354                &glib::GString::from_glib_borrow(id),
355                &glib::GString::from_glib_borrow(key),
356            )
357        }
358        unsafe {
359            let f: Box_<F> = Box_::new(f);
360            connect_raw(
361                self.as_ptr() as *mut _,
362                c"key-event".as_ptr() as *const _,
363                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
364                    key_event_trampoline::<Self, F> as *const (),
365                )),
366                Box_::into_raw(f),
367            )
368        }
369    }
370
371    /// Will be emitted when a mouse event is received by the [`VulkanWindow`][crate::VulkanWindow].
372    /// ## `id`
373    /// the name of the event
374    /// ## `button`
375    /// the id of the button
376    /// ## `x`
377    /// the x coordinate of the mouse event
378    /// ## `y`
379    /// the y coordinate of the mouse event
380    #[doc(alias = "mouse-event")]
381    fn connect_mouse_event<F: Fn(&Self, &str, i32, f64, f64) + Send + Sync + 'static>(
382        &self,
383        f: F,
384    ) -> SignalHandlerId {
385        unsafe extern "C" fn mouse_event_trampoline<
386            P: IsA<VulkanWindow>,
387            F: Fn(&P, &str, i32, f64, f64) + Send + Sync + 'static,
388        >(
389            this: *mut ffi::GstVulkanWindow,
390            id: *mut std::ffi::c_char,
391            button: std::ffi::c_int,
392            x: std::ffi::c_double,
393            y: std::ffi::c_double,
394            f: glib::ffi::gpointer,
395        ) {
396            let f: &F = &*(f as *const F);
397            f(
398                VulkanWindow::from_glib_borrow(this).unsafe_cast_ref(),
399                &glib::GString::from_glib_borrow(id),
400                button,
401                x,
402                y,
403            )
404        }
405        unsafe {
406            let f: Box_<F> = Box_::new(f);
407            connect_raw(
408                self.as_ptr() as *mut _,
409                c"mouse-event".as_ptr() as *const _,
410                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
411                    mouse_event_trampoline::<Self, F> as *const (),
412                )),
413                Box_::into_raw(f),
414            )
415        }
416    }
417
418    #[doc(alias = "resize")]
419    fn connect_resize<F: Fn(&Self, u32, u32) + Send + Sync + 'static>(
420        &self,
421        f: F,
422    ) -> SignalHandlerId {
423        unsafe extern "C" fn resize_trampoline<
424            P: IsA<VulkanWindow>,
425            F: Fn(&P, u32, u32) + Send + Sync + 'static,
426        >(
427            this: *mut ffi::GstVulkanWindow,
428            object: std::ffi::c_uint,
429            p0: std::ffi::c_uint,
430            f: glib::ffi::gpointer,
431        ) {
432            let f: &F = &*(f as *const F);
433            f(
434                VulkanWindow::from_glib_borrow(this).unsafe_cast_ref(),
435                object,
436                p0,
437            )
438        }
439        unsafe {
440            let f: Box_<F> = Box_::new(f);
441            connect_raw(
442                self.as_ptr() as *mut _,
443                c"resize".as_ptr() as *const _,
444                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
445                    resize_trampoline::<Self, F> as *const (),
446                )),
447                Box_::into_raw(f),
448            )
449        }
450    }
451
452    #[doc(alias = "display")]
453    fn connect_display_notify<F: Fn(&Self) + Send + Sync + 'static>(
454        &self,
455        f: F,
456    ) -> SignalHandlerId {
457        unsafe extern "C" fn notify_display_trampoline<
458            P: IsA<VulkanWindow>,
459            F: Fn(&P) + Send + Sync + 'static,
460        >(
461            this: *mut ffi::GstVulkanWindow,
462            _param_spec: glib::ffi::gpointer,
463            f: glib::ffi::gpointer,
464        ) {
465            let f: &F = &*(f as *const F);
466            f(VulkanWindow::from_glib_borrow(this).unsafe_cast_ref())
467        }
468        unsafe {
469            let f: Box_<F> = Box_::new(f);
470            connect_raw(
471                self.as_ptr() as *mut _,
472                c"notify::display".as_ptr() as *const _,
473                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
474                    notify_display_trampoline::<Self, F> as *const (),
475                )),
476                Box_::into_raw(f),
477            )
478        }
479    }
480}
481
482impl<O: IsA<VulkanWindow>> VulkanWindowExt for O {}