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::{VulkanFence, VulkanInstance, VulkanPhysicalDevice, VulkanQueue, ffi};
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
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 unsafe {
223 let device = from_glib_borrow(device);
224 let queue = from_glib_borrow(queue);
225 let callback = user_data as *mut P;
226 (*callback)(&device, &queue).into_glib()
227 }
228 }
229 let func = Some(func_func::<P> as _);
230 let super_callback0: &mut P = &mut func_data;
231 unsafe {
232 ffi::gst_vulkan_device_foreach_queue(
233 self.as_ref().to_glib_none().0,
234 func,
235 super_callback0 as *mut _ as *mut _,
236 );
237 }
238 }
239
240 ///
241 /// # Returns
242 ///
243 /// the [`VulkanInstance`][crate::VulkanInstance] used to create this `self`
244 #[doc(alias = "gst_vulkan_device_get_instance")]
245 #[doc(alias = "get_instance")]
246 fn instance(&self) -> Option<VulkanInstance> {
247 unsafe {
248 from_glib_full(ffi::gst_vulkan_device_get_instance(
249 self.as_ref().to_glib_none().0,
250 ))
251 }
252 }
253
254 //#[doc(alias = "gst_vulkan_device_get_physical_device")]
255 //#[doc(alias = "get_physical_device")]
256 //#[doc(alias = "physical-device")]
257 //fn physical_device(&self) -> /*Ignored*/vulkan::PhysicalDevice {
258 // unsafe { TODO: call ffi:gst_vulkan_device_get_physical_device() }
259 //}
260
261 //#[doc(alias = "gst_vulkan_device_get_proc_address")]
262 //#[doc(alias = "get_proc_address")]
263 //fn proc_address(&self, name: &str) -> /*Unimplemented*/Option<Basic: Pointer> {
264 // unsafe { TODO: call ffi:gst_vulkan_device_get_proc_address() }
265 //}
266
267 /// ## `queue_family`
268 /// a queue family to retrieve
269 /// ## `queue_i`
270 /// index of the family to retrieve
271 ///
272 /// # Returns
273 ///
274 /// a new [`VulkanQueue`][crate::VulkanQueue]
275 #[doc(alias = "gst_vulkan_device_get_queue")]
276 #[doc(alias = "get_queue")]
277 fn queue(&self, queue_family: u32, queue_i: u32) -> VulkanQueue {
278 unsafe {
279 from_glib_full(ffi::gst_vulkan_device_get_queue(
280 self.as_ref().to_glib_none().0,
281 queue_family,
282 queue_i,
283 ))
284 }
285 }
286
287 /// ## `name`
288 /// extension name
289 ///
290 /// # Returns
291 ///
292 /// whether extension `name` is enabled
293 #[doc(alias = "gst_vulkan_device_is_extension_enabled")]
294 fn is_extension_enabled(&self, name: &str) -> bool {
295 unsafe {
296 from_glib(ffi::gst_vulkan_device_is_extension_enabled(
297 self.as_ref().to_glib_none().0,
298 name.to_glib_none().0,
299 ))
300 }
301 }
302
303 /// ## `name`
304 /// layer name
305 ///
306 /// # Returns
307 ///
308 /// whether layer `name` is enabled
309 #[doc(alias = "gst_vulkan_device_is_layer_enabled")]
310 fn is_layer_enabled(&self, name: &str) -> bool {
311 unsafe {
312 from_glib(ffi::gst_vulkan_device_is_layer_enabled(
313 self.as_ref().to_glib_none().0,
314 name.to_glib_none().0,
315 ))
316 }
317 }
318
319 /// Attempts to create the internal `VkDevice` object.
320 ///
321 /// # Returns
322 ///
323 /// whether a vulkan device could be created
324 #[doc(alias = "gst_vulkan_device_open")]
325 fn open(&self) -> Result<(), glib::Error> {
326 unsafe {
327 let mut error = std::ptr::null_mut();
328 let is_ok = ffi::gst_vulkan_device_open(self.as_ref().to_glib_none().0, &mut error);
329 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
330 if error.is_null() {
331 Ok(())
332 } else {
333 Err(from_glib_full(error))
334 }
335 }
336 }
337
338 //#[cfg(feature = "v1_24")]
339 //#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
340 //#[doc(alias = "gst_vulkan_device_queue_family_indices")]
341 //fn queue_family_indices(&self) -> /*Unknown conversion*//*Unimplemented*/Array TypeId { ns_id: 0, id: 7 } {
342 // unsafe { TODO: call ffi:gst_vulkan_device_queue_family_indices() }
343 //}
344
345 //#[cfg(feature = "v1_24")]
346 //#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
347 //#[doc(alias = "gst_vulkan_device_select_queue")]
348 //fn select_queue(&self, expected_flags: /*Ignored*/&vulkan::QueueFlagBits) -> Option<VulkanQueue> {
349 // unsafe { TODO: call ffi:gst_vulkan_device_select_queue() }
350 //}
351
352 #[doc(alias = "instance")]
353 fn connect_instance_notify<F: Fn(&Self) + Send + Sync + 'static>(
354 &self,
355 f: F,
356 ) -> SignalHandlerId {
357 unsafe extern "C" fn notify_instance_trampoline<
358 P: IsA<VulkanDevice>,
359 F: Fn(&P) + Send + Sync + 'static,
360 >(
361 this: *mut ffi::GstVulkanDevice,
362 _param_spec: glib::ffi::gpointer,
363 f: glib::ffi::gpointer,
364 ) {
365 unsafe {
366 let f: &F = &*(f as *const F);
367 f(VulkanDevice::from_glib_borrow(this).unsafe_cast_ref())
368 }
369 }
370 unsafe {
371 let f: Box_<F> = Box_::new(f);
372 connect_raw(
373 self.as_ptr() as *mut _,
374 c"notify::instance".as_ptr(),
375 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
376 notify_instance_trampoline::<Self, F> as *const (),
377 )),
378 Box_::into_raw(f),
379 )
380 }
381 }
382}
383
384impl<O: IsA<VulkanDevice>> VulkanDeviceExt for O {}