1use 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 #[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 #[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
90pub trait GLWindowExt: IsA<GLWindow> + 'static {
96 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 {}