gstreamer_vulkan/auto/vulkan_device.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, VulkanFence, VulkanInstance, VulkanPhysicalDevice, VulkanQueue};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 ///
16 ///
17 /// ## Properties
18 ///
19 ///
20 /// #### `instance`
21 /// Readable
22 ///
23 ///
24 /// #### `physical-device`
25 /// Readable | Writeable | Construct Only
26 /// <details><summary><h4>Object</h4></summary>
27 ///
28 ///
29 /// #### `name`
30 /// Readable | Writeable | Construct
31 ///
32 ///
33 /// #### `parent`
34 /// The parent of the object. Please note, that when changing the 'parent'
35 /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::gst::Object#deep-notify]
36 /// signals due to locking issues. In some cases one can use
37 /// `GstBin::element-added` or `GstBin::element-removed` signals on the parent to
38 /// achieve a similar effect.
39 ///
40 /// Readable | Writeable
41 /// </details>
42 ///
43 /// # Implements
44 ///
45 /// [`VulkanDeviceExt`][trait@crate::prelude::VulkanDeviceExt], [`trait@gst::prelude::ObjectExt`], [`trait@glib::ObjectExt`]
46 #[doc(alias = "GstVulkanDevice")]
47 pub struct VulkanDevice(Object<ffi::GstVulkanDevice, ffi::GstVulkanDeviceClass>) @extends gst::Object;
48
49 match fn {
50 type_ => || ffi::gst_vulkan_device_get_type(),
51 }
52}
53
54impl VulkanDevice {
55 pub const NONE: Option<&'static VulkanDevice> = None;
56
57 /// ## `physical_device`
58 /// the associated [`VulkanPhysicalDevice`][crate::VulkanPhysicalDevice]
59 ///
60 /// # Returns
61 ///
62 /// a new [`VulkanDevice`][crate::VulkanDevice]
63 #[doc(alias = "gst_vulkan_device_new")]
64 pub fn new(physical_device: &impl IsA<VulkanPhysicalDevice>) -> VulkanDevice {
65 skip_assert_initialized!();
66 unsafe {
67 from_glib_full(ffi::gst_vulkan_device_new(
68 physical_device.as_ref().to_glib_none().0,
69 ))
70 }
71 }
72
73 /// ## `instance`
74 /// the associated [`VulkanInstance`][crate::VulkanInstance]
75 /// ## `device_index`
76 /// the device index to create the new [`VulkanDevice`][crate::VulkanDevice] from
77 ///
78 /// # Returns
79 ///
80 /// a new [`VulkanDevice`][crate::VulkanDevice]
81 #[doc(alias = "gst_vulkan_device_new_with_index")]
82 #[doc(alias = "new_with_index")]
83 pub fn with_index(instance: &impl IsA<VulkanInstance>, device_index: u32) -> VulkanDevice {
84 skip_assert_initialized!();
85 unsafe {
86 from_glib_full(ffi::gst_vulkan_device_new_with_index(
87 instance.as_ref().to_glib_none().0,
88 device_index,
89 ))
90 }
91 }
92
93 /// If a [`VulkanDevice`][crate::VulkanDevice] is requested in `query`, sets `device` as the reply.
94 ///
95 /// Intended for use with element query handlers to respond to `GST_QUERY_CONTEXT`
96 /// for a [`VulkanDevice`][crate::VulkanDevice].
97 /// ## `element`
98 /// a [`gst::Element`][crate::gst::Element]
99 /// ## `query`
100 /// a [`gst::Query`][crate::gst::Query] of type `GST_QUERY_CONTEXT`
101 /// ## `device`
102 /// the [`VulkanDevice`][crate::VulkanDevice]
103 ///
104 /// # Returns
105 ///
106 /// whether `query` was responded to with `device`
107 #[doc(alias = "gst_vulkan_device_handle_context_query")]
108 pub fn handle_context_query(
109 element: &impl IsA<gst::Element>,
110 query: &gst::Query,
111 device: &impl IsA<VulkanDevice>,
112 ) -> bool {
113 skip_assert_initialized!();
114 unsafe {
115 from_glib(ffi::gst_vulkan_device_handle_context_query(
116 element.as_ref().to_glib_none().0,
117 query.to_glib_none().0,
118 device.as_ref().to_glib_none().0,
119 ))
120 }
121 }
122
123 //#[doc(alias = "gst_vulkan_device_run_context_query")]
124 //pub fn run_context_query(element: &impl IsA<gst::Element>, device: impl IsA<VulkanDevice>) -> bool {
125 // unsafe { TODO: call ffi:gst_vulkan_device_run_context_query() }
126 //}
127}
128
129unsafe impl Send for VulkanDevice {}
130unsafe impl Sync for VulkanDevice {}
131
132/// Trait containing all [`struct@VulkanDevice`] methods.
133///
134/// # Implementors
135///
136/// [`VulkanDevice`][struct@crate::VulkanDevice]
137pub trait VulkanDeviceExt: IsA<VulkanDevice> + 'static {
138 ///
139 /// # Returns
140 ///
141 /// a new [`VulkanFence`][crate::VulkanFence] or [`None`]
142 #[doc(alias = "gst_vulkan_device_create_fence")]
143 fn create_fence(&self) -> Result<Option<VulkanFence>, glib::Error> {
144 unsafe {
145 let mut error = std::ptr::null_mut();
146 let ret =
147 ffi::gst_vulkan_device_create_fence(self.as_ref().to_glib_none().0, &mut error);
148 if error.is_null() {
149 Ok(from_glib_full(ret))
150 } else {
151 Err(from_glib_full(error))
152 }
153 }
154 }
155
156 /// Disable an Vulkan extension by `name`. Disabling an extension will only have
157 /// an effect before the call to [`open()`][Self::open()].
158 /// ## `name`
159 /// extension name to enable
160 ///
161 /// # Returns
162 ///
163 /// whether the Vulkan extension could be disabled.
164 #[doc(alias = "gst_vulkan_device_disable_extension")]
165 fn disable_extension(&self, name: &str) -> bool {
166 unsafe {
167 from_glib(ffi::gst_vulkan_device_disable_extension(
168 self.as_ref().to_glib_none().0,
169 name.to_glib_none().0,
170 ))
171 }
172 }
173
174 /// Enable an Vulkan extension by `name`. Enabling an extension will
175 /// only have an effect before the call to [`open()`][Self::open()].
176 /// ## `name`
177 /// extension name to enable
178 ///
179 /// # Returns
180 ///
181 /// whether the Vulkan extension could be enabled.
182 #[doc(alias = "gst_vulkan_device_enable_extension")]
183 fn enable_extension(&self, name: &str) -> bool {
184 unsafe {
185 from_glib(ffi::gst_vulkan_device_enable_extension(
186 self.as_ref().to_glib_none().0,
187 name.to_glib_none().0,
188 ))
189 }
190 }
191
192 /// Enable an Vulkan layer by `name`. Enabling a layer will
193 /// only have an effect before the call to [`open()`][Self::open()].
194 /// ## `name`
195 /// layer name to enable
196 ///
197 /// # Returns
198 ///
199 /// whether the Vulkan layer could be enabled.
200 #[doc(alias = "gst_vulkan_device_enable_layer")]
201 fn enable_layer(&self, name: &str) -> bool {
202 unsafe {
203 from_glib(ffi::gst_vulkan_device_enable_layer(
204 self.as_ref().to_glib_none().0,
205 name.to_glib_none().0,
206 ))
207 }
208 }
209
210 /// Iterate over each queue family available on [`VulkanDevice`][crate::VulkanDevice]
211 /// ## `func`
212 /// a `GstVulkanDeviceForEachQueueFunc`
213 /// to run for each [`VulkanQueue`][crate::VulkanQueue]
214 #[doc(alias = "gst_vulkan_device_foreach_queue")]
215 fn foreach_queue<P: FnMut(&VulkanDevice, &VulkanQueue) -> bool>(&self, func: P) {
216 let mut func_data: P = func;
217 unsafe extern "C" fn func_func<P: FnMut(&VulkanDevice, &VulkanQueue) -> bool>(
218 device: *mut ffi::GstVulkanDevice,
219 queue: *mut ffi::GstVulkanQueue,
220 user_data: glib::ffi::gpointer,
221 ) -> glib::ffi::gboolean {
222 let device = from_glib_borrow(device);
223 let queue = from_glib_borrow(queue);
224 let callback = user_data as *mut P;
225 (*callback)(&device, &queue).into_glib()
226 }
227 let func = Some(func_func::<P> as _);
228 let super_callback0: &mut P = &mut func_data;
229 unsafe {
230 ffi::gst_vulkan_device_foreach_queue(
231 self.as_ref().to_glib_none().0,
232 func,
233 super_callback0 as *mut _ as *mut _,
234 );
235 }
236 }
237
238 ///
239 /// # Returns
240 ///
241 /// the [`VulkanInstance`][crate::VulkanInstance] used to create this `self`
242 #[doc(alias = "gst_vulkan_device_get_instance")]
243 #[doc(alias = "get_instance")]
244 fn instance(&self) -> Option<VulkanInstance> {
245 unsafe {
246 from_glib_full(ffi::gst_vulkan_device_get_instance(
247 self.as_ref().to_glib_none().0,
248 ))
249 }
250 }
251
252 //#[doc(alias = "gst_vulkan_device_get_physical_device")]
253 //#[doc(alias = "get_physical_device")]
254 //#[doc(alias = "physical-device")]
255 //fn physical_device(&self) -> /*Ignored*/vulkan::PhysicalDevice {
256 // unsafe { TODO: call ffi:gst_vulkan_device_get_physical_device() }
257 //}
258
259 //#[doc(alias = "gst_vulkan_device_get_proc_address")]
260 //#[doc(alias = "get_proc_address")]
261 //fn proc_address(&self, name: &str) -> /*Unimplemented*/Option<Basic: Pointer> {
262 // unsafe { TODO: call ffi:gst_vulkan_device_get_proc_address() }
263 //}
264
265 /// ## `queue_family`
266 /// a queue family to retrieve
267 /// ## `queue_i`
268 /// index of the family to retrieve
269 ///
270 /// # Returns
271 ///
272 /// a new [`VulkanQueue`][crate::VulkanQueue]
273 #[doc(alias = "gst_vulkan_device_get_queue")]
274 #[doc(alias = "get_queue")]
275 fn queue(&self, queue_family: u32, queue_i: u32) -> VulkanQueue {
276 unsafe {
277 from_glib_full(ffi::gst_vulkan_device_get_queue(
278 self.as_ref().to_glib_none().0,
279 queue_family,
280 queue_i,
281 ))
282 }
283 }
284
285 /// ## `name`
286 /// extension name
287 ///
288 /// # Returns
289 ///
290 /// whether extension `name` is enabled
291 #[doc(alias = "gst_vulkan_device_is_extension_enabled")]
292 fn is_extension_enabled(&self, name: &str) -> bool {
293 unsafe {
294 from_glib(ffi::gst_vulkan_device_is_extension_enabled(
295 self.as_ref().to_glib_none().0,
296 name.to_glib_none().0,
297 ))
298 }
299 }
300
301 /// ## `name`
302 /// layer name
303 ///
304 /// # Returns
305 ///
306 /// whether layer `name` is enabled
307 #[doc(alias = "gst_vulkan_device_is_layer_enabled")]
308 fn is_layer_enabled(&self, name: &str) -> bool {
309 unsafe {
310 from_glib(ffi::gst_vulkan_device_is_layer_enabled(
311 self.as_ref().to_glib_none().0,
312 name.to_glib_none().0,
313 ))
314 }
315 }
316
317 /// Attempts to create the internal `VkDevice` object.
318 ///
319 /// # Returns
320 ///
321 /// whether a vulkan device could be created
322 #[doc(alias = "gst_vulkan_device_open")]
323 fn open(&self) -> Result<(), glib::Error> {
324 unsafe {
325 let mut error = std::ptr::null_mut();
326 let is_ok = ffi::gst_vulkan_device_open(self.as_ref().to_glib_none().0, &mut error);
327 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
328 if error.is_null() {
329 Ok(())
330 } else {
331 Err(from_glib_full(error))
332 }
333 }
334 }
335
336 //#[cfg(feature = "v1_24")]
337 //#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
338 //#[doc(alias = "gst_vulkan_device_queue_family_indices")]
339 //fn queue_family_indices(&self) -> /*Unknown conversion*//*Unimplemented*/Array TypeId { ns_id: 0, id: 7 } {
340 // unsafe { TODO: call ffi:gst_vulkan_device_queue_family_indices() }
341 //}
342
343 //#[cfg(feature = "v1_24")]
344 //#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
345 //#[doc(alias = "gst_vulkan_device_select_queue")]
346 //fn select_queue(&self, expected_flags: /*Ignored*/&vulkan::QueueFlagBits) -> Option<VulkanQueue> {
347 // unsafe { TODO: call ffi:gst_vulkan_device_select_queue() }
348 //}
349
350 #[doc(alias = "instance")]
351 fn connect_instance_notify<F: Fn(&Self) + Send + Sync + 'static>(
352 &self,
353 f: F,
354 ) -> SignalHandlerId {
355 unsafe extern "C" fn notify_instance_trampoline<
356 P: IsA<VulkanDevice>,
357 F: Fn(&P) + Send + Sync + 'static,
358 >(
359 this: *mut ffi::GstVulkanDevice,
360 _param_spec: glib::ffi::gpointer,
361 f: glib::ffi::gpointer,
362 ) {
363 let f: &F = &*(f as *const F);
364 f(VulkanDevice::from_glib_borrow(this).unsafe_cast_ref())
365 }
366 unsafe {
367 let f: Box_<F> = Box_::new(f);
368 connect_raw(
369 self.as_ptr() as *mut _,
370 c"notify::instance".as_ptr() as *const _,
371 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
372 notify_instance_trampoline::<Self, F> as *const (),
373 )),
374 Box_::into_raw(f),
375 )
376 }
377 }
378}
379
380impl<O: IsA<VulkanDevice>> VulkanDeviceExt for O {}