gstreamer_vulkan/auto/vulkan_instance.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};
7#[cfg(feature = "v1_26")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
9use glib::object::ObjectType as _;
10use glib::{
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 ///
19 ///
20 /// ## Properties
21 ///
22 ///
23 /// #### `requested-api-major`
24 /// Readable | Writeable
25 ///
26 ///
27 /// #### `requested-api-minor`
28 /// Readable | Writeable
29 /// <details><summary><h4>Object</h4></summary>
30 ///
31 ///
32 /// #### `name`
33 /// Readable | Writeable | Construct
34 ///
35 ///
36 /// #### `parent`
37 /// The parent of the object. Please note, that when changing the 'parent'
38 /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::gst::Object#deep-notify]
39 /// signals due to locking issues. In some cases one can use
40 /// `GstBin::element-added` or `GstBin::element-removed` signals on the parent to
41 /// achieve a similar effect.
42 ///
43 /// Readable | Writeable
44 /// </details>
45 ///
46 /// ## Signals
47 ///
48 ///
49 /// #### `create-device`
50 /// Overrides the [`VulkanDevice`][crate::VulkanDevice] creation mechanism.
51 /// It can be called from any thread.
52 ///
53 ///
54 /// <details><summary><h4>Object</h4></summary>
55 ///
56 ///
57 /// #### `deep-notify`
58 /// The deep notify signal is used to be notified of property changes. It is
59 /// typically attached to the toplevel bin to receive notifications from all
60 /// the elements contained in that bin.
61 ///
62 /// Detailed
63 /// </details>
64 ///
65 /// # Implements
66 ///
67 /// [`VulkanInstanceExt`][trait@crate::prelude::VulkanInstanceExt], [`trait@gst::prelude::ObjectExt`], [`trait@glib::ObjectExt`]
68 #[doc(alias = "GstVulkanInstance")]
69 pub struct VulkanInstance(Object<ffi::GstVulkanInstance, ffi::GstVulkanInstanceClass>) @extends gst::Object;
70
71 match fn {
72 type_ => || ffi::gst_vulkan_instance_get_type(),
73 }
74}
75
76impl VulkanInstance {
77 pub const NONE: Option<&'static VulkanInstance> = None;
78
79 ///
80 /// # Returns
81 ///
82 /// a new uninitialized [`VulkanInstance`][crate::VulkanInstance]
83 #[doc(alias = "gst_vulkan_instance_new")]
84 pub fn new() -> VulkanInstance {
85 assert_initialized_main_thread!();
86 unsafe { from_glib_full(ffi::gst_vulkan_instance_new()) }
87 }
88
89 /// If a [`VulkanInstance`][crate::VulkanInstance] is requested in `query`, sets `instance` as the reply.
90 ///
91 /// Intended for use with element query handlers to respond to `GST_QUERY_CONTEXT`
92 /// for a [`VulkanInstance`][crate::VulkanInstance].
93 /// ## `element`
94 /// a [`gst::Element`][crate::gst::Element]
95 /// ## `query`
96 /// a [`gst::Query`][crate::gst::Query] of type `GST_QUERY_CONTEXT`
97 /// ## `instance`
98 /// the [`VulkanInstance`][crate::VulkanInstance]
99 ///
100 /// # Returns
101 ///
102 /// whether `query` was responded to with `instance`
103 #[doc(alias = "gst_vulkan_instance_handle_context_query")]
104 pub fn handle_context_query(
105 element: &impl IsA<gst::Element>,
106 query: &gst::Query,
107 instance: Option<&impl IsA<VulkanInstance>>,
108 ) -> bool {
109 assert_initialized_main_thread!();
110 unsafe {
111 from_glib(ffi::gst_vulkan_instance_handle_context_query(
112 element.as_ref().to_glib_none().0,
113 query.to_glib_none().0,
114 instance.map(|p| p.as_ref()).to_glib_none().0,
115 ))
116 }
117 }
118
119 //#[doc(alias = "gst_vulkan_instance_run_context_query")]
120 //pub fn run_context_query(element: &impl IsA<gst::Element>, instance: impl IsA<VulkanInstance>) -> bool {
121 // unsafe { TODO: call ffi:gst_vulkan_instance_run_context_query() }
122 //}
123}
124
125impl Default for VulkanInstance {
126 fn default() -> Self {
127 Self::new()
128 }
129}
130
131unsafe impl Send for VulkanInstance {}
132unsafe impl Sync for VulkanInstance {}
133
134/// Trait containing all [`struct@VulkanInstance`] methods.
135///
136/// # Implementors
137///
138/// [`VulkanInstance`][struct@crate::VulkanInstance]
139pub trait VulkanInstanceExt: IsA<VulkanInstance> + 'static {
140 /// ## `major`
141 /// the API major version to check
142 /// ## `minor`
143 /// the API minor version to check
144 /// ## `patch`
145 /// the API patch version to check
146 ///
147 /// # Returns
148 ///
149 /// whether the [`VulkanInstance`][crate::VulkanInstance] supports the version specified
150 /// by `major`, `minor` and `patch`.
151 #[cfg(feature = "v1_26")]
152 #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
153 #[doc(alias = "gst_vulkan_instance_check_api_version")]
154 fn check_api_version(&self, major: u32, minor: u32, patch: u32) -> bool {
155 unsafe {
156 from_glib(ffi::gst_vulkan_instance_check_api_version(
157 self.as_ref().to_glib_none().0,
158 major,
159 minor,
160 patch,
161 ))
162 }
163 }
164
165 /// Check if the configured vulkan instance supports the specified version.
166 /// Will not work prior to opening the instance with [`open()`][Self::open()].
167 /// If a specific version is requested, the `patch` level is ignored.
168 /// ## `major`
169 /// major version
170 /// ## `minor`
171 /// minor version
172 /// ## `patch`
173 /// patch version
174 ///
175 /// # Returns
176 ///
177 /// whether `self` is at least the requested version.
178 #[doc(alias = "gst_vulkan_instance_check_version")]
179 fn check_version(&self, major: u32, minor: u32, patch: u32) -> bool {
180 unsafe {
181 from_glib(ffi::gst_vulkan_instance_check_version(
182 self.as_ref().to_glib_none().0,
183 major,
184 minor,
185 patch,
186 ))
187 }
188 }
189
190 ///
191 /// # Returns
192 ///
193 /// a new [`VulkanDevice`][crate::VulkanDevice]
194 #[doc(alias = "gst_vulkan_instance_create_device")]
195 fn create_device(&self) -> Result<VulkanDevice, glib::Error> {
196 unsafe {
197 let mut error = std::ptr::null_mut();
198 let ret =
199 ffi::gst_vulkan_instance_create_device(self.as_ref().to_glib_none().0, &mut error);
200 if error.is_null() {
201 Ok(from_glib_full(ret))
202 } else {
203 Err(from_glib_full(error))
204 }
205 }
206 }
207
208 /// ## `device_index`
209 /// the device index to create the new [`VulkanDevice`][crate::VulkanDevice] from
210 ///
211 /// # Returns
212 ///
213 /// a new [`VulkanDevice`][crate::VulkanDevice]
214 #[cfg(feature = "v1_26")]
215 #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
216 #[doc(alias = "gst_vulkan_instance_create_device_with_index")]
217 fn create_device_with_index(&self, device_index: u32) -> Result<VulkanDevice, glib::Error> {
218 unsafe {
219 let mut error = std::ptr::null_mut();
220 let ret = ffi::gst_vulkan_instance_create_device_with_index(
221 self.as_ref().to_glib_none().0,
222 device_index,
223 &mut error,
224 );
225 if error.is_null() {
226 Ok(from_glib_full(ret))
227 } else {
228 Err(from_glib_full(error))
229 }
230 }
231 }
232
233 /// Disable an Vulkan extension by `name`. Disabling an extension will only have
234 /// an effect before the call to [`open()`][Self::open()].
235 /// ## `name`
236 /// extension name to enable
237 ///
238 /// # Returns
239 ///
240 /// whether the Vulkan extension could be disabled.
241 #[doc(alias = "gst_vulkan_instance_disable_extension")]
242 fn disable_extension(&self, name: &str) -> bool {
243 unsafe {
244 from_glib(ffi::gst_vulkan_instance_disable_extension(
245 self.as_ref().to_glib_none().0,
246 name.to_glib_none().0,
247 ))
248 }
249 }
250
251 /// Enable an Vulkan extension by `name`. Extensions cannot be enabled until
252 /// [`fill_info()`][Self::fill_info()] has been called. Enabling an extension will
253 /// only have an effect before the call to [`open()`][Self::open()].
254 /// ## `name`
255 /// extension name to enable
256 ///
257 /// # Returns
258 ///
259 /// whether the Vulkan extension could be enabled.
260 #[doc(alias = "gst_vulkan_instance_enable_extension")]
261 fn enable_extension(&self, name: &str) -> bool {
262 unsafe {
263 from_glib(ffi::gst_vulkan_instance_enable_extension(
264 self.as_ref().to_glib_none().0,
265 name.to_glib_none().0,
266 ))
267 }
268 }
269
270 /// Enable an Vulkan layer by `name`. Layer cannot be enabled until
271 /// [`fill_info()`][Self::fill_info()] has been called. Enabling a layer will
272 /// only have an effect before the call to [`open()`][Self::open()].
273 /// ## `name`
274 /// layer name to enable
275 ///
276 /// # Returns
277 ///
278 /// whether the Vulkan layer could be enabled.
279 #[doc(alias = "gst_vulkan_instance_enable_layer")]
280 fn enable_layer(&self, name: &str) -> bool {
281 unsafe {
282 from_glib(ffi::gst_vulkan_instance_enable_layer(
283 self.as_ref().to_glib_none().0,
284 name.to_glib_none().0,
285 ))
286 }
287 }
288
289 /// Retrieve as much information about the available Vulkan instance without
290 /// actually creating an Vulkan instance. Will not do anything while `self`
291 /// is open.
292 ///
293 /// # Returns
294 ///
295 /// whether the instance information could be retrieved
296 #[doc(alias = "gst_vulkan_instance_fill_info")]
297 fn fill_info(&self) -> Result<(), glib::Error> {
298 unsafe {
299 let mut error = std::ptr::null_mut();
300 let is_ok =
301 ffi::gst_vulkan_instance_fill_info(self.as_ref().to_glib_none().0, &mut error);
302 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
303 if error.is_null() {
304 Ok(())
305 } else {
306 Err(from_glib_full(error))
307 }
308 }
309 }
310
311 /// Returns the vulkan API version configured when constructing the
312 /// [`VulkanInstance`][crate::VulkanInstance]. This value can be any valid Vulkan API version and may
313 /// not match [`version()`][Self::version()] in any way. This version is the
314 /// maximum allowed vulkan API to be used in any capacity.
315 ///
316 /// This will not return valid values until [`open()`][Self::open()] has been
317 /// called.
318 ///
319 /// # Returns
320 ///
321 ///
322 /// ## `major`
323 /// major version
324 ///
325 /// ## `minor`
326 /// minor version
327 ///
328 /// ## `patch`
329 /// patch version
330 #[cfg(feature = "v1_26")]
331 #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
332 #[doc(alias = "gst_vulkan_instance_get_api_version")]
333 #[doc(alias = "get_api_version")]
334 fn api_version(&self) -> (u32, u32, u32) {
335 unsafe {
336 let mut major = std::mem::MaybeUninit::uninit();
337 let mut minor = std::mem::MaybeUninit::uninit();
338 let mut patch = std::mem::MaybeUninit::uninit();
339 ffi::gst_vulkan_instance_get_api_version(
340 self.as_ref().to_glib_none().0,
341 major.as_mut_ptr(),
342 minor.as_mut_ptr(),
343 patch.as_mut_ptr(),
344 );
345 (
346 major.assume_init(),
347 minor.assume_init(),
348 patch.assume_init(),
349 )
350 }
351 }
352
353 /// Retrieves information about an extension.
354 ///
355 /// Will not find any extensions before [`fill_info()`][Self::fill_info()] has been
356 /// called.
357 /// ## `name`
358 /// the layer name to look for
359 ///
360 /// # Returns
361 ///
362 /// whether extension `name` is available
363 ///
364 /// ## `spec_version`
365 /// return value for the layer specification version
366 #[doc(alias = "gst_vulkan_instance_get_extension_info")]
367 #[doc(alias = "get_extension_info")]
368 fn extension_info(&self, name: &str) -> Option<u32> {
369 unsafe {
370 let mut spec_version = std::mem::MaybeUninit::uninit();
371 let ret = from_glib(ffi::gst_vulkan_instance_get_extension_info(
372 self.as_ref().to_glib_none().0,
373 name.to_glib_none().0,
374 spec_version.as_mut_ptr(),
375 ));
376 if ret {
377 Some(spec_version.assume_init())
378 } else {
379 None
380 }
381 }
382 }
383
384 /// Retrieves information about a layer.
385 ///
386 /// Will not find any layers before [`fill_info()`][Self::fill_info()] has been
387 /// called.
388 /// ## `name`
389 /// the layer name to look for
390 ///
391 /// # Returns
392 ///
393 /// whether layer `name` is available
394 ///
395 /// ## `description`
396 /// return value for the layer description or [`None`]
397 ///
398 /// ## `spec_version`
399 /// return value for the layer specification version
400 ///
401 /// ## `implementation_version`
402 /// return value for the layer implementation version
403 #[doc(alias = "gst_vulkan_instance_get_layer_info")]
404 #[doc(alias = "get_layer_info")]
405 fn layer_info(&self, name: &str) -> Option<(Option<glib::GString>, u32, u32)> {
406 unsafe {
407 let mut description = std::ptr::null_mut();
408 let mut spec_version = std::mem::MaybeUninit::uninit();
409 let mut implementation_version = std::mem::MaybeUninit::uninit();
410 let ret = from_glib(ffi::gst_vulkan_instance_get_layer_info(
411 self.as_ref().to_glib_none().0,
412 name.to_glib_none().0,
413 &mut description,
414 spec_version.as_mut_ptr(),
415 implementation_version.as_mut_ptr(),
416 ));
417 if ret {
418 Some((
419 from_glib_full(description),
420 spec_version.assume_init(),
421 implementation_version.assume_init(),
422 ))
423 } else {
424 None
425 }
426 }
427 }
428
429 //#[doc(alias = "gst_vulkan_instance_get_proc_address")]
430 //#[doc(alias = "get_proc_address")]
431 //fn proc_address(&self, name: &str) -> /*Unimplemented*/Option<Basic: Pointer> {
432 // unsafe { TODO: call ffi:gst_vulkan_instance_get_proc_address() }
433 //}
434
435 /// Retrieve the vulkan instance supported version. Only returns the supported
436 /// API version by the instance without taking into account the requested API
437 /// version. This means [`check_version()`][Self::check_version()] will return
438 /// different values if a specific version has been requested (which is the
439 /// default) than a version check that is performed manually by retrieving the
440 /// version with this function.
441 ///
442 /// # Returns
443 ///
444 ///
445 /// ## `major`
446 /// major version
447 ///
448 /// ## `minor`
449 /// minor version
450 ///
451 /// ## `patch`
452 /// patch version
453 #[doc(alias = "gst_vulkan_instance_get_version")]
454 #[doc(alias = "get_version")]
455 fn version(&self) -> (u32, u32, u32) {
456 unsafe {
457 let mut major = std::mem::MaybeUninit::uninit();
458 let mut minor = std::mem::MaybeUninit::uninit();
459 let mut patch = std::mem::MaybeUninit::uninit();
460 ffi::gst_vulkan_instance_get_version(
461 self.as_ref().to_glib_none().0,
462 major.as_mut_ptr(),
463 minor.as_mut_ptr(),
464 patch.as_mut_ptr(),
465 );
466 (
467 major.assume_init(),
468 minor.assume_init(),
469 patch.assume_init(),
470 )
471 }
472 }
473
474 /// ## `name`
475 /// extension name
476 ///
477 /// # Returns
478 ///
479 /// whether extension `name` is enabled
480 #[doc(alias = "gst_vulkan_instance_is_extension_enabled")]
481 fn is_extension_enabled(&self, name: &str) -> bool {
482 unsafe {
483 from_glib(ffi::gst_vulkan_instance_is_extension_enabled(
484 self.as_ref().to_glib_none().0,
485 name.to_glib_none().0,
486 ))
487 }
488 }
489
490 /// ## `name`
491 /// layer name
492 ///
493 /// # Returns
494 ///
495 /// whether layer `name` is enabled
496 #[doc(alias = "gst_vulkan_instance_is_layer_enabled")]
497 fn is_layer_enabled(&self, name: &str) -> bool {
498 unsafe {
499 from_glib(ffi::gst_vulkan_instance_is_layer_enabled(
500 self.as_ref().to_glib_none().0,
501 name.to_glib_none().0,
502 ))
503 }
504 }
505
506 ///
507 /// # Returns
508 ///
509 /// whether the instance could be created
510 #[doc(alias = "gst_vulkan_instance_open")]
511 fn open(&self) -> Result<(), glib::Error> {
512 unsafe {
513 let mut error = std::ptr::null_mut();
514 let is_ok = ffi::gst_vulkan_instance_open(self.as_ref().to_glib_none().0, &mut error);
515 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
516 if error.is_null() {
517 Ok(())
518 } else {
519 Err(from_glib_full(error))
520 }
521 }
522 }
523
524 #[doc(alias = "requested-api-major")]
525 fn requested_api_major(&self) -> u32 {
526 ObjectExt::property(self.as_ref(), "requested-api-major")
527 }
528
529 #[doc(alias = "requested-api-major")]
530 fn set_requested_api_major(&self, requested_api_major: u32) {
531 ObjectExt::set_property(self.as_ref(), "requested-api-major", requested_api_major)
532 }
533
534 #[doc(alias = "requested-api-minor")]
535 fn requested_api_minor(&self) -> u32 {
536 ObjectExt::property(self.as_ref(), "requested-api-minor")
537 }
538
539 #[doc(alias = "requested-api-minor")]
540 fn set_requested_api_minor(&self, requested_api_minor: u32) {
541 ObjectExt::set_property(self.as_ref(), "requested-api-minor", requested_api_minor)
542 }
543
544 /// Overrides the [`VulkanDevice`][crate::VulkanDevice] creation mechanism.
545 /// It can be called from any thread.
546 /// ## `device_index`
547 /// the index of the device
548 ///
549 /// # Returns
550 ///
551 /// the newly created [`VulkanDevice`][crate::VulkanDevice].
552 #[cfg(feature = "v1_26")]
553 #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
554 #[doc(alias = "create-device")]
555 fn connect_create_device<F: Fn(&Self, u32) -> VulkanDevice + Send + Sync + 'static>(
556 &self,
557 f: F,
558 ) -> SignalHandlerId {
559 unsafe extern "C" fn create_device_trampoline<
560 P: IsA<VulkanInstance>,
561 F: Fn(&P, u32) -> VulkanDevice + Send + Sync + 'static,
562 >(
563 this: *mut ffi::GstVulkanInstance,
564 device_index: std::ffi::c_uint,
565 f: glib::ffi::gpointer,
566 ) -> *mut ffi::GstVulkanDevice {
567 let f: &F = &*(f as *const F);
568 f(
569 VulkanInstance::from_glib_borrow(this).unsafe_cast_ref(),
570 device_index,
571 )
572 .to_glib_full()
573 }
574 unsafe {
575 let f: Box_<F> = Box_::new(f);
576 connect_raw(
577 self.as_ptr() as *mut _,
578 c"create-device".as_ptr() as *const _,
579 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
580 create_device_trampoline::<Self, F> as *const (),
581 )),
582 Box_::into_raw(f),
583 )
584 }
585 }
586
587 #[doc(alias = "requested-api-major")]
588 fn connect_requested_api_major_notify<F: Fn(&Self) + Send + Sync + 'static>(
589 &self,
590 f: F,
591 ) -> SignalHandlerId {
592 unsafe extern "C" fn notify_requested_api_major_trampoline<
593 P: IsA<VulkanInstance>,
594 F: Fn(&P) + Send + Sync + 'static,
595 >(
596 this: *mut ffi::GstVulkanInstance,
597 _param_spec: glib::ffi::gpointer,
598 f: glib::ffi::gpointer,
599 ) {
600 let f: &F = &*(f as *const F);
601 f(VulkanInstance::from_glib_borrow(this).unsafe_cast_ref())
602 }
603 unsafe {
604 let f: Box_<F> = Box_::new(f);
605 connect_raw(
606 self.as_ptr() as *mut _,
607 c"notify::requested-api-major".as_ptr() as *const _,
608 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
609 notify_requested_api_major_trampoline::<Self, F> as *const (),
610 )),
611 Box_::into_raw(f),
612 )
613 }
614 }
615
616 #[doc(alias = "requested-api-minor")]
617 fn connect_requested_api_minor_notify<F: Fn(&Self) + Send + Sync + 'static>(
618 &self,
619 f: F,
620 ) -> SignalHandlerId {
621 unsafe extern "C" fn notify_requested_api_minor_trampoline<
622 P: IsA<VulkanInstance>,
623 F: Fn(&P) + Send + Sync + 'static,
624 >(
625 this: *mut ffi::GstVulkanInstance,
626 _param_spec: glib::ffi::gpointer,
627 f: glib::ffi::gpointer,
628 ) {
629 let f: &F = &*(f as *const F);
630 f(VulkanInstance::from_glib_borrow(this).unsafe_cast_ref())
631 }
632 unsafe {
633 let f: Box_<F> = Box_::new(f);
634 connect_raw(
635 self.as_ptr() as *mut _,
636 c"notify::requested-api-minor".as_ptr() as *const _,
637 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
638 notify_requested_api_minor_trampoline::<Self, F> as *const (),
639 )),
640 Box_::into_raw(f),
641 )
642 }
643 }
644}
645
646impl<O: IsA<VulkanInstance>> VulkanInstanceExt for O {}