Skip to main content

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::{GLContext, GLDisplay, 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    /// 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    /// whether an visible output surface has been requested
138    #[cfg(feature = "v1_28")]
139    #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
140    #[doc(alias = "gst_gl_window_get_request_output_surface")]
141    #[doc(alias = "get_request_output_surface")]
142    fn is_request_output_surface(&self) -> bool {
143        unsafe {
144            from_glib(ffi::gst_gl_window_get_request_output_surface(
145                self.as_ref().to_glib_none().0,
146            ))
147        }
148    }
149
150    ///
151    /// # Returns
152    ///
153    ///
154    /// ## `width`
155    /// resulting surface width
156    ///
157    /// ## `height`
158    /// resulting surface height
159    #[doc(alias = "gst_gl_window_get_surface_dimensions")]
160    #[doc(alias = "get_surface_dimensions")]
161    fn surface_dimensions(&self) -> (u32, u32) {
162        unsafe {
163            let mut width = std::mem::MaybeUninit::uninit();
164            let mut height = std::mem::MaybeUninit::uninit();
165            ffi::gst_gl_window_get_surface_dimensions(
166                self.as_ref().to_glib_none().0,
167                width.as_mut_ptr(),
168                height.as_mut_ptr(),
169            );
170            (width.assume_init(), height.assume_init())
171        }
172    }
173
174    /// Tell a `self` that it should handle events from the window system. These
175    /// events are forwarded upstream as navigation events. In some window systems
176    /// events are not propagated in the window hierarchy if a client is listening
177    /// for them. This method allows you to disable events handling completely
178    /// from the `self`.
179    /// ## `handle_events`
180    /// a `gboolean` indicating if events should be handled or not.
181    #[doc(alias = "gst_gl_window_handle_events")]
182    fn handle_events(&self, handle_events: bool) {
183        unsafe {
184            ffi::gst_gl_window_handle_events(
185                self.as_ref().to_glib_none().0,
186                handle_events.into_glib(),
187            );
188        }
189    }
190
191    /// Query whether `self` has output surface or not
192    ///
193    /// # Returns
194    ///
195    /// [`true`] if `self` has useable output surface
196    #[cfg(feature = "v1_18")]
197    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
198    #[doc(alias = "gst_gl_window_has_output_surface")]
199    fn has_output_surface(&self) -> bool {
200        unsafe {
201            from_glib(ffi::gst_gl_window_has_output_surface(
202                self.as_ref().to_glib_none().0,
203            ))
204        }
205    }
206
207    /// Queue resizing of `self`.
208    #[doc(alias = "gst_gl_window_queue_resize")]
209    fn queue_resize(&self) {
210        unsafe {
211            ffi::gst_gl_window_queue_resize(self.as_ref().to_glib_none().0);
212        }
213    }
214
215    /// Quit the runloop's execution.
216    #[doc(alias = "gst_gl_window_quit")]
217    fn quit(&self) {
218        unsafe {
219            ffi::gst_gl_window_quit(self.as_ref().to_glib_none().0);
220        }
221    }
222
223    /// Resize `self` to the given `width` and `height`.
224    /// ## `width`
225    /// new width
226    /// ## `height`
227    /// new height
228    #[doc(alias = "gst_gl_window_resize")]
229    fn resize(&self, width: u32, height: u32) {
230        unsafe {
231            ffi::gst_gl_window_resize(self.as_ref().to_glib_none().0, width, height);
232        }
233    }
234
235    /// Start the execution of the runloop.
236    #[doc(alias = "gst_gl_window_run")]
237    fn run(&self) {
238        unsafe {
239            ffi::gst_gl_window_run(self.as_ref().to_glib_none().0);
240        }
241    }
242
243    #[doc(alias = "gst_gl_window_send_key_event")]
244    fn send_key_event(&self, event_type: &str, key_str: &str) {
245        unsafe {
246            ffi::gst_gl_window_send_key_event(
247                self.as_ref().to_glib_none().0,
248                event_type.to_glib_none().0,
249                key_str.to_glib_none().0,
250            );
251        }
252    }
253
254    #[doc(alias = "gst_gl_window_send_mouse_event")]
255    fn send_mouse_event(&self, event_type: &str, button: i32, posx: f64, posy: f64) {
256        unsafe {
257            ffi::gst_gl_window_send_mouse_event(
258                self.as_ref().to_glib_none().0,
259                event_type.to_glib_none().0,
260                button,
261                posx,
262                posy,
263            );
264        }
265    }
266
267    /// Notify a `self` about a scroll event. A scroll signal holding the event
268    /// coordinates will be emitted.
269    /// ## `posx`
270    /// x position of the mouse cursor
271    /// ## `posy`
272    /// y position of the mouse cursor
273    /// ## `delta_x`
274    /// the x offset of the scroll event
275    /// ## `delta_y`
276    /// the y offset of the scroll event
277    #[cfg(feature = "v1_18")]
278    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
279    #[doc(alias = "gst_gl_window_send_scroll_event")]
280    fn send_scroll_event(&self, posx: f64, posy: f64, delta_x: f64, delta_y: f64) {
281        unsafe {
282            ffi::gst_gl_window_send_scroll_event(
283                self.as_ref().to_glib_none().0,
284                posx,
285                posy,
286                delta_x,
287                delta_y,
288            );
289        }
290    }
291
292    /// Set the preferred width and height of the window. Implementations are free
293    /// to ignore this information.
294    /// ## `width`
295    /// new preferred width
296    /// ## `height`
297    /// new preferred height
298    #[doc(alias = "gst_gl_window_set_preferred_size")]
299    fn set_preferred_size(&self, width: i32, height: i32) {
300        unsafe {
301            ffi::gst_gl_window_set_preferred_size(self.as_ref().to_glib_none().0, width, height);
302        }
303    }
304
305    /// Tell a `self` that it should render into a specific region of the window
306    /// according to the [`gst_video::VideoOverlay`][crate::gst_video::VideoOverlay] interface.
307    /// ## `x`
308    /// x position
309    /// ## `y`
310    /// y position
311    /// ## `width`
312    /// width
313    /// ## `height`
314    /// height
315    ///
316    /// # Returns
317    ///
318    /// whether the specified region could be set
319    #[doc(alias = "gst_gl_window_set_render_rectangle")]
320    fn set_render_rectangle(
321        &self,
322        x: i32,
323        y: i32,
324        width: i32,
325        height: i32,
326    ) -> Result<(), glib::error::BoolError> {
327        unsafe {
328            glib::result_from_gboolean!(
329                ffi::gst_gl_window_set_render_rectangle(
330                    self.as_ref().to_glib_none().0,
331                    x,
332                    y,
333                    width,
334                    height
335                ),
336                "Failed to set the specified region"
337            )
338        }
339    }
340
341    /// Configure whether a visible output surface is requested.
342    /// ## `output_surface`
343    /// whether to request an output surface.
344    #[cfg(feature = "v1_28")]
345    #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
346    #[doc(alias = "gst_gl_window_set_request_output_surface")]
347    fn set_request_output_surface(&self, output_surface: bool) {
348        unsafe {
349            ffi::gst_gl_window_set_request_output_surface(
350                self.as_ref().to_glib_none().0,
351                output_surface.into_glib(),
352            );
353        }
354    }
355
356    /// Present the window to the screen.
357    #[doc(alias = "gst_gl_window_show")]
358    fn show(&self) {
359        unsafe {
360            ffi::gst_gl_window_show(self.as_ref().to_glib_none().0);
361        }
362    }
363
364    /// Will be emitted when a key event is received by the GstGLwindow.
365    /// ## `id`
366    /// the name of the event
367    /// ## `key`
368    /// the id of the key pressed
369    #[doc(alias = "key-event")]
370    fn connect_key_event<F: Fn(&Self, &str, &str) + Send + Sync + 'static>(
371        &self,
372        f: F,
373    ) -> SignalHandlerId {
374        unsafe extern "C" fn key_event_trampoline<
375            P: IsA<GLWindow>,
376            F: Fn(&P, &str, &str) + Send + Sync + 'static,
377        >(
378            this: *mut ffi::GstGLWindow,
379            id: *mut std::ffi::c_char,
380            key: *mut std::ffi::c_char,
381            f: glib::ffi::gpointer,
382        ) {
383            unsafe {
384                let f: &F = &*(f as *const F);
385                f(
386                    GLWindow::from_glib_borrow(this).unsafe_cast_ref(),
387                    &glib::GString::from_glib_borrow(id),
388                    &glib::GString::from_glib_borrow(key),
389                )
390            }
391        }
392        unsafe {
393            let f: Box_<F> = Box_::new(f);
394            connect_raw(
395                self.as_ptr() as *mut _,
396                c"key-event".as_ptr(),
397                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
398                    key_event_trampoline::<Self, F> as *const (),
399                )),
400                Box_::into_raw(f),
401            )
402        }
403    }
404
405    /// Will be emitted when a mouse event is received by the GstGLwindow.
406    /// ## `id`
407    /// the name of the event
408    /// ## `button`
409    /// the id of the button
410    /// ## `x`
411    /// the x coordinate of the mouse event
412    /// ## `y`
413    /// the y coordinate of the mouse event
414    #[doc(alias = "mouse-event")]
415    fn connect_mouse_event<F: Fn(&Self, &str, i32, f64, f64) + Send + Sync + 'static>(
416        &self,
417        f: F,
418    ) -> SignalHandlerId {
419        unsafe extern "C" fn mouse_event_trampoline<
420            P: IsA<GLWindow>,
421            F: Fn(&P, &str, i32, f64, f64) + Send + Sync + 'static,
422        >(
423            this: *mut ffi::GstGLWindow,
424            id: *mut std::ffi::c_char,
425            button: std::ffi::c_int,
426            x: std::ffi::c_double,
427            y: std::ffi::c_double,
428            f: glib::ffi::gpointer,
429        ) {
430            unsafe {
431                let f: &F = &*(f as *const F);
432                f(
433                    GLWindow::from_glib_borrow(this).unsafe_cast_ref(),
434                    &glib::GString::from_glib_borrow(id),
435                    button,
436                    x,
437                    y,
438                )
439            }
440        }
441        unsafe {
442            let f: Box_<F> = Box_::new(f);
443            connect_raw(
444                self.as_ptr() as *mut _,
445                c"mouse-event".as_ptr(),
446                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
447                    mouse_event_trampoline::<Self, F> as *const (),
448                )),
449                Box_::into_raw(f),
450            )
451        }
452    }
453
454    /// Will be emitted when a mouse scroll event is received by the GstGLwindow.
455    /// ## `x`
456    /// the x coordinate of the mouse event
457    /// ## `y`
458    /// the y coordinate of the mouse event
459    /// ## `delta_x`
460    /// the x offset of the scroll event
461    /// ## `delta_y`
462    /// the y offset of the scroll event
463    #[cfg(feature = "v1_18")]
464    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
465    #[doc(alias = "scroll-event")]
466    fn connect_scroll_event<F: Fn(&Self, f64, f64, f64, f64) + Send + Sync + 'static>(
467        &self,
468        f: F,
469    ) -> SignalHandlerId {
470        unsafe extern "C" fn scroll_event_trampoline<
471            P: IsA<GLWindow>,
472            F: Fn(&P, f64, f64, f64, f64) + Send + Sync + 'static,
473        >(
474            this: *mut ffi::GstGLWindow,
475            x: std::ffi::c_double,
476            y: std::ffi::c_double,
477            delta_x: std::ffi::c_double,
478            delta_y: std::ffi::c_double,
479            f: glib::ffi::gpointer,
480        ) {
481            unsafe {
482                let f: &F = &*(f as *const F);
483                f(
484                    GLWindow::from_glib_borrow(this).unsafe_cast_ref(),
485                    x,
486                    y,
487                    delta_x,
488                    delta_y,
489                )
490            }
491        }
492        unsafe {
493            let f: Box_<F> = Box_::new(f);
494            connect_raw(
495                self.as_ptr() as *mut _,
496                c"scroll-event".as_ptr(),
497                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
498                    scroll_event_trampoline::<Self, F> as *const (),
499                )),
500                Box_::into_raw(f),
501            )
502        }
503    }
504
505    /// Will be emitted when the window handle has been set into the native
506    /// implementation, but before the context is re-activated. By using this
507    /// signal, elements can refresh associated resource without relying on
508    /// direct handle comparision.
509    #[cfg(feature = "v1_20")]
510    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
511    #[doc(alias = "window-handle-changed")]
512    fn connect_window_handle_changed<F: Fn(&Self) + Send + Sync + 'static>(
513        &self,
514        f: F,
515    ) -> SignalHandlerId {
516        unsafe extern "C" fn window_handle_changed_trampoline<
517            P: IsA<GLWindow>,
518            F: Fn(&P) + Send + Sync + 'static,
519        >(
520            this: *mut ffi::GstGLWindow,
521            f: glib::ffi::gpointer,
522        ) {
523            unsafe {
524                let f: &F = &*(f as *const F);
525                f(GLWindow::from_glib_borrow(this).unsafe_cast_ref())
526            }
527        }
528        unsafe {
529            let f: Box_<F> = Box_::new(f);
530            connect_raw(
531                self.as_ptr() as *mut _,
532                c"window-handle-changed".as_ptr(),
533                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
534                    window_handle_changed_trampoline::<Self, F> as *const (),
535                )),
536                Box_::into_raw(f),
537            )
538        }
539    }
540}
541
542impl<O: IsA<GLWindow>> GLWindowExt for O {}