| 1 | // Take a look at the license at the top of the repository in the LICENSE file. |
| 2 | |
| 3 | use std::ptr; |
| 4 | |
| 5 | use glib::{prelude::*, translate::*}; |
| 6 | use gst::ContextRef; |
| 7 | |
| 8 | use crate::{ffi, GLDisplay}; |
| 9 | |
| 10 | pub trait ContextGLExt { |
| 11 | #[doc (alias = "get_gl_display" )] |
| 12 | #[doc (alias = "gst_context_get_gl_display" )] |
| 13 | fn gl_display(&self) -> Option<GLDisplay>; |
| 14 | #[doc (alias = "gst_context_set_gl_display" )] |
| 15 | fn set_gl_display<'a, T: IsA<GLDisplay>>(&self, display: impl Into<Option<&'a T>>); |
| 16 | } |
| 17 | |
| 18 | impl ContextGLExt for ContextRef { |
| 19 | fn gl_display(&self) -> Option<GLDisplay> { |
| 20 | unsafe { |
| 21 | let mut display: *mut GstGLDisplay = ptr::null_mut(); |
| 22 | if from_glib(val:ffi::gst_context_get_gl_display( |
| 23 | self.as_mut_ptr(), |
| 24 | &mut display, |
| 25 | )) { |
| 26 | Some(from_glib_full(ptr:display)) |
| 27 | } else { |
| 28 | None |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | fn set_gl_display<'a, T: IsA<GLDisplay>>(&self, display: impl Into<Option<&'a T>>) { |
| 34 | unsafe { |
| 35 | ffi::gst_context_set_gl_display( |
| 36 | self.as_mut_ptr(), |
| 37 | display.into().map(|d| d.as_ref()).to_glib_none().0, |
| 38 | ); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |