gstreamer_gl/auto/
gl_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, GLContext, GLDisplay};
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    /// GstGLWindow represents a window that elements can render into. A window can
17    /// either be a user visible window (onscreen) or hidden (offscreen).
18    ///
19    /// This is an Abstract Base Class, you cannot instantiate it.
20    ///
21    /// ## Signals
22    ///
23    ///
24    /// #### `key-event`
25    ///  Will be emitted when a key event is received by the GstGLwindow.
26    ///
27    ///
28    ///
29    ///
30    /// #### `mouse-event`
31    ///  Will be emitted when a mouse event is received by the GstGLwindow.
32    ///
33    ///
34    ///
35    ///
36    /// #### `scroll-event`
37    ///  Will be emitted when a mouse scroll event is received by the GstGLwindow.
38    ///
39    ///
40    ///
41    ///
42    /// #### `window-handle-changed`
43    ///  Will be emitted when the window handle has been set into the native
44    /// implementation, but before the context is re-activated. By using this
45    /// signal, elements can refresh associated resource without relying on
46    /// direct handle comparision.
47    ///
48    ///
49    /// <details><summary><h4>Object</h4></summary>
50    ///
51    ///
52    /// #### `deep-notify`
53    ///  The deep notify signal is used to be notified of property changes. It is
54    /// typically attached to the toplevel bin to receive notifications from all
55    /// the elements contained in that bin.
56    ///
57    /// Detailed
58    /// </details>
59    ///
60    /// # Implements
61    ///
62    /// [`GLWindowExt`][trait@crate::prelude::GLWindowExt], [`trait@gst::prelude::ObjectExt`], [`trait@glib::ObjectExt`]
63    #[doc(alias = "GstGLWindow")]
64    pub struct GLWindow(Object<ffi::GstGLWindow, ffi::GstGLWindowClass>) @extends gst::Object;
65
66    match fn {
67        type_ => || ffi::gst_gl_window_get_type(),
68    }
69}
70
71impl GLWindow {
72    pub const NONE: Option<&'static GLWindow> = None;
73
74    /// ## `display`
75    /// a [`GLDisplay`][crate::GLDisplay]
76    ///
77    /// # Returns
78    ///
79    /// a new [`GLWindow`][crate::GLWindow] using `display`'s connection
80    #[doc(alias = "gst_gl_window_new")]
81    pub fn new(display: &impl IsA<GLDisplay>) -> GLWindow {
82        skip_assert_initialized!();
83        unsafe { from_glib_full(ffi::gst_gl_window_new(display.as_ref().to_glib_none().0)) }
84    }
85}
86
87unsafe impl Send for GLWindow {}
88unsafe impl Sync for GLWindow {}
89
90/// Trait containing all [`struct@GLWindow`] methods.
91///
92/// # Implementors
93///
94/// [`GLWindow`][struct@crate::GLWindow]
95pub trait GLWindowExt: IsA<GLWindow> + 'static {
96    /// Checks if `self` controls the GL viewport.
97    ///
98    /// # Returns
99    ///
100    /// [`true`] if `self` controls the GL viewport, otherwise [`false`]
101    #[cfg(feature = "v1_16")]
102    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
103    #[doc(alias = "gst_gl_window_controls_viewport")]
104    fn controls_viewport(&self) -> bool {
105        unsafe {
106            from_glib(ffi::gst_gl_window_controls_viewport(
107                self.as_ref().to_glib_none().0,
108            ))
109        }
110    }
111
112    /// Redraw the window contents. Implementations should invoke the draw callback.
113    #[doc(alias = "gst_gl_window_draw")]
114    fn draw(&self) {
115        unsafe {
116            ffi::gst_gl_window_draw(self.as_ref().to_glib_none().0);
117        }
118    }
119
120    ///
121    /// # Returns
122    ///
123    /// the [`GLContext`][crate::GLContext] associated with this `self`
124    #[doc(alias = "gst_gl_window_get_context")]
125    #[doc(alias = "get_context")]
126    fn context(&self) -> GLContext {
127        unsafe {
128            from_glib_full(ffi::gst_gl_window_get_context(
129                self.as_ref().to_glib_none().0,
130            ))
131        }
132    }
133
134    ///
135    /// # Returns
136    ///
137    ///
138    /// ## `width`
139    /// resulting surface width
140    ///
141    /// ## `height`
142    /// resulting surface height
143    #[doc(alias = "gst_gl_window_get_surface_dimensions")]
144    #[doc(alias = "get_surface_dimensions")]
145    fn surface_dimensions(&self) -> (u32, u32) {
146        unsafe {
147            let mut width = std::mem::MaybeUninit::uninit();
148            let mut height = std::mem::MaybeUninit::uninit();
149            ffi::gst_gl_window_get_surface_dimensions(
150                self.as_ref().to_glib_none().0,
151                width.as_mut_ptr(),
152                height.as_mut_ptr(),
153            );
154            (width.assume_init(), height.assume_init())
155        }
156    }
157
158    /// Tell a `self` that it should handle events from the window system. These
159    /// events are forwarded upstream as navigation events. In some window systems
160    /// events are not propagated in the window hierarchy if a client is listening
161    /// for them. This method allows you to disable events handling completely
162    /// from the `self`.
163    /// ## `handle_events`
164    /// a `gboolean` indicating if events should be handled or not.
165    #[doc(alias = "gst_gl_window_handle_events")]
166    fn handle_events(&self, handle_events: bool) {
167        unsafe {
168            ffi::gst_gl_window_handle_events(
169                self.as_ref().to_glib_none().0,
170                handle_events.into_glib(),
171            );
172        }
173    }
174
175    /// Query whether `self` has output surface or not
176    ///
177    /// # Returns
178    ///
179    /// [`true`] if `self` has useable output surface
180    #[cfg(feature = "v1_18")]
181    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
182    #[doc(alias = "gst_gl_window_has_output_surface")]
183    fn has_output_surface(&self) -> bool {
184        unsafe {
185            from_glib(ffi::gst_gl_window_has_output_surface(
186                self.as_ref().to_glib_none().0,
187            ))
188        }
189    }
190
191    /// Queue resizing of `self`.
192    #[doc(alias = "gst_gl_window_queue_resize")]
193    fn queue_resize(&self) {
194        unsafe {
195            ffi::gst_gl_window_queue_resize(self.as_ref().to_glib_none().0);
196        }
197    }
198
199    /// Quit the runloop's execution.
200    #[doc(alias = "gst_gl_window_quit")]
201    fn quit(&self) {
202        unsafe {
203            ffi::gst_gl_window_quit(self.as_ref().to_glib_none().0);
204        }
205    }
206
207    /// Resize `self` to the given `width` and `height`.
208    /// ## `width`
209    /// new width
210    /// ## `height`
211    /// new height
212    #[doc(alias = "gst_gl_window_resize")]
213    fn resize(&self, width: u32, height: u32) {
214        unsafe {
215            ffi::gst_gl_window_resize(self.as_ref().to_glib_none().0, width, height);
216        }
217    }
218
219    /// Start the execution of the runloop.
220    #[doc(alias = "gst_gl_window_run")]
221    fn run(&self) {
222        unsafe {
223            ffi::gst_gl_window_run(self.as_ref().to_glib_none().0);
224        }
225    }
226
227    #[doc(alias = "gst_gl_window_send_key_event")]
228    fn send_key_event(&self, event_type: &str, key_str: &str) {
229        unsafe {
230            ffi::gst_gl_window_send_key_event(
231                self.as_ref().to_glib_none().0,
232                event_type.to_glib_none().0,
233                key_str.to_glib_none().0,
234            );
235        }
236    }
237
238    #[doc(alias = "gst_gl_window_send_mouse_event")]
239    fn send_mouse_event(&self, event_type: &str, button: i32, posx: f64, posy: f64) {
240        unsafe {
241            ffi::gst_gl_window_send_mouse_event(
242                self.as_ref().to_glib_none().0,
243                event_type.to_glib_none().0,
244                button,
245                posx,
246                posy,
247            );
248        }
249    }
250
251    /// Notify a `self` about a scroll event. A scroll signal holding the event
252    /// coordinates will be emitted.
253    /// ## `posx`
254    /// x position of the mouse cursor
255    /// ## `posy`
256    /// y position of the mouse cursor
257    /// ## `delta_x`
258    /// the x offset of the scroll event
259    /// ## `delta_y`
260    /// the y offset of the scroll event
261    #[cfg(feature = "v1_18")]
262    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
263    #[doc(alias = "gst_gl_window_send_scroll_event")]
264    fn send_scroll_event(&self, posx: f64, posy: f64, delta_x: f64, delta_y: f64) {
265        unsafe {
266            ffi::gst_gl_window_send_scroll_event(
267                self.as_ref().to_glib_none().0,
268                posx,
269                posy,
270                delta_x,
271                delta_y,
272            );
273        }
274    }
275
276    /// Set the preferred width and height of the window. Implementations are free
277    /// to ignore this information.
278    /// ## `width`
279    /// new preferred width
280    /// ## `height`
281    /// new preferred height
282    #[doc(alias = "gst_gl_window_set_preferred_size")]
283    fn set_preferred_size(&self, width: i32, height: i32) {
284        unsafe {
285            ffi::gst_gl_window_set_preferred_size(self.as_ref().to_glib_none().0, width, height);
286        }
287    }
288
289    /// Tell a `self` that it should render into a specific region of the window
290    /// according to the [`gst_video::VideoOverlay`][crate::gst_video::VideoOverlay] interface.
291    /// ## `x`
292    /// x position
293    /// ## `y`
294    /// y position
295    /// ## `width`
296    /// width
297    /// ## `height`
298    /// height
299    ///
300    /// # Returns
301    ///
302    /// whether the specified region could be set
303    #[doc(alias = "gst_gl_window_set_render_rectangle")]
304    fn set_render_rectangle(
305        &self,
306        x: i32,
307        y: i32,
308        width: i32,
309        height: i32,
310    ) -> Result<(), glib::error::BoolError> {
311        unsafe {
312            glib::result_from_gboolean!(
313                ffi::gst_gl_window_set_render_rectangle(
314                    self.as_ref().to_glib_none().0,
315                    x,
316                    y,
317                    width,
318                    height
319                ),
320                "Failed to set the specified region"
321            )
322        }
323    }
324
325    /// Present the window to the screen.
326    #[doc(alias = "gst_gl_window_show")]
327    fn show(&self) {
328        unsafe {
329            ffi::gst_gl_window_show(self.as_ref().to_glib_none().0);
330        }
331    }
332
333    /// Will be emitted when a key event is received by the GstGLwindow.
334    /// ## `id`
335    /// the name of the event
336    /// ## `key`
337    /// the id of the key pressed
338    #[doc(alias = "key-event")]
339    fn connect_key_event<F: Fn(&Self, &str, &str) + Send + Sync + 'static>(
340        &self,
341        f: F,
342    ) -> SignalHandlerId {
343        unsafe extern "C" fn key_event_trampoline<
344            P: IsA<GLWindow>,
345            F: Fn(&P, &str, &str) + Send + Sync + 'static,
346        >(
347            this: *mut ffi::GstGLWindow,
348            id: *mut std::ffi::c_char,
349            key: *mut std::ffi::c_char,
350            f: glib::ffi::gpointer,
351        ) {
352            let f: &F = &*(f as *const F);
353            f(
354                GLWindow::from_glib_borrow(this).unsafe_cast_ref(),
355                &glib::GString::from_glib_borrow(id),
356                &glib::GString::from_glib_borrow(key),
357            )
358        }
359        unsafe {
360            let f: Box_<F> = Box_::new(f);
361            connect_raw(
362                self.as_ptr() as *mut _,
363                c"key-event".as_ptr() as *const _,
364                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
365                    key_event_trampoline::<Self, F> as *const (),
366                )),
367                Box_::into_raw(f),
368            )
369        }
370    }
371
372    /// Will be emitted when a mouse event is received by the GstGLwindow.
373    /// ## `id`
374    /// the name of the event
375    /// ## `button`
376    /// the id of the button
377    /// ## `x`
378    /// the x coordinate of the mouse event
379    /// ## `y`
380    /// the y coordinate of the mouse event
381    #[doc(alias = "mouse-event")]
382    fn connect_mouse_event<F: Fn(&Self, &str, i32, f64, f64) + Send + Sync + 'static>(
383        &self,
384        f: F,
385    ) -> SignalHandlerId {
386        unsafe extern "C" fn mouse_event_trampoline<
387            P: IsA<GLWindow>,
388            F: Fn(&P, &str, i32, f64, f64) + Send + Sync + 'static,
389        >(
390            this: *mut ffi::GstGLWindow,
391            id: *mut std::ffi::c_char,
392            button: std::ffi::c_int,
393            x: std::ffi::c_double,
394            y: std::ffi::c_double,
395            f: glib::ffi::gpointer,
396        ) {
397            let f: &F = &*(f as *const F);
398            f(
399                GLWindow::from_glib_borrow(this).unsafe_cast_ref(),
400                &glib::GString::from_glib_borrow(id),
401                button,
402                x,
403                y,
404            )
405        }
406        unsafe {
407            let f: Box_<F> = Box_::new(f);
408            connect_raw(
409                self.as_ptr() as *mut _,
410                c"mouse-event".as_ptr() as *const _,
411                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
412                    mouse_event_trampoline::<Self, F> as *const (),
413                )),
414                Box_::into_raw(f),
415            )
416        }
417    }
418
419    /// Will be emitted when a mouse scroll event is received by the GstGLwindow.
420    /// ## `x`
421    /// the x coordinate of the mouse event
422    /// ## `y`
423    /// the y coordinate of the mouse event
424    /// ## `delta_x`
425    /// the x offset of the scroll event
426    /// ## `delta_y`
427    /// the y offset of the scroll event
428    #[cfg(feature = "v1_18")]
429    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
430    #[doc(alias = "scroll-event")]
431    fn connect_scroll_event<F: Fn(&Self, f64, f64, f64, f64) + Send + Sync + 'static>(
432        &self,
433        f: F,
434    ) -> SignalHandlerId {
435        unsafe extern "C" fn scroll_event_trampoline<
436            P: IsA<GLWindow>,
437            F: Fn(&P, f64, f64, f64, f64) + Send + Sync + 'static,
438        >(
439            this: *mut ffi::GstGLWindow,
440            x: std::ffi::c_double,
441            y: std::ffi::c_double,
442            delta_x: std::ffi::c_double,
443            delta_y: std::ffi::c_double,
444            f: glib::ffi::gpointer,
445        ) {
446            let f: &F = &*(f as *const F);
447            f(
448                GLWindow::from_glib_borrow(this).unsafe_cast_ref(),
449                x,
450                y,
451                delta_x,
452                delta_y,
453            )
454        }
455        unsafe {
456            let f: Box_<F> = Box_::new(f);
457            connect_raw(
458                self.as_ptr() as *mut _,
459                c"scroll-event".as_ptr() as *const _,
460                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
461                    scroll_event_trampoline::<Self, F> as *const (),
462                )),
463                Box_::into_raw(f),
464            )
465        }
466    }
467
468    /// Will be emitted when the window handle has been set into the native
469    /// implementation, but before the context is re-activated. By using this
470    /// signal, elements can refresh associated resource without relying on
471    /// direct handle comparision.
472    #[cfg(feature = "v1_20")]
473    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
474    #[doc(alias = "window-handle-changed")]
475    fn connect_window_handle_changed<F: Fn(&Self) + Send + Sync + 'static>(
476        &self,
477        f: F,
478    ) -> SignalHandlerId {
479        unsafe extern "C" fn window_handle_changed_trampoline<
480            P: IsA<GLWindow>,
481            F: Fn(&P) + Send + Sync + 'static,
482        >(
483            this: *mut ffi::GstGLWindow,
484            f: glib::ffi::gpointer,
485        ) {
486            let f: &F = &*(f as *const F);
487            f(GLWindow::from_glib_borrow(this).unsafe_cast_ref())
488        }
489        unsafe {
490            let f: Box_<F> = Box_::new(f);
491            connect_raw(
492                self.as_ptr() as *mut _,
493                c"window-handle-changed".as_ptr() as *const _,
494                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
495                    window_handle_changed_trampoline::<Self, F> as *const (),
496                )),
497                Box_::into_raw(f),
498            )
499        }
500    }
501}
502
503impl<O: IsA<GLWindow>> GLWindowExt for O {}