gdk4/auto/
dmabuf_formats.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// DO NOT EDIT
4
5use crate::ffi;
6use glib::translate::*;
7
8glib::wrapper! {
9    /// The [`DmabufFormats`][crate::DmabufFormats] struct provides information about
10    /// supported DMA buffer formats.
11    ///
12    /// You can query whether a given format is supported with
13    /// [`contains()`][Self::contains()] and you can iterate
14    /// over the list of all supported formats with
15    /// [`n_formats()`][Self::n_formats()] and
16    /// [`format()`][Self::format()].
17    ///
18    /// The list of supported formats is sorted by preference,
19    /// with the best formats coming first.
20    ///
21    /// The list may contains (format, modifier) pairs where the modifier
22    /// is `DMA_FORMAT_MOD_INVALID`, indicating that **_implicit modifiers_**
23    /// may be used with this format.
24    ///
25    /// See [`DmabufTextureBuilder`][crate::DmabufTextureBuilder] for more information
26    /// about DMA buffers.
27    ///
28    /// Note that DMA buffers only exist on Linux.
29    #[derive(Debug, PartialOrd, Ord, Hash)]
30    pub struct DmabufFormats(Shared<ffi::GdkDmabufFormats>);
31
32    match fn {
33        ref => |ptr| ffi::gdk_dmabuf_formats_ref(ptr),
34        unref => |ptr| ffi::gdk_dmabuf_formats_unref(ptr),
35        type_ => || ffi::gdk_dmabuf_formats_get_type(),
36    }
37}
38
39impl DmabufFormats {
40    /// Returns whether a given format is contained in @self.
41    /// ## `fourcc`
42    /// a format code
43    /// ## `modifier`
44    /// a format modifier
45    ///
46    /// # Returns
47    ///
48    /// `TRUE` if the format specified by the arguments
49    ///   is part of @self
50    #[doc(alias = "gdk_dmabuf_formats_contains")]
51    pub fn contains(&self, fourcc: u32, modifier: u64) -> bool {
52        unsafe {
53            from_glib(ffi::gdk_dmabuf_formats_contains(
54                self.to_glib_none().0,
55                fourcc,
56                modifier,
57            ))
58        }
59    }
60
61    #[doc(alias = "gdk_dmabuf_formats_equal")]
62    fn equal(&self, formats2: &DmabufFormats) -> bool {
63        unsafe {
64            from_glib(ffi::gdk_dmabuf_formats_equal(
65                self.to_glib_none().0,
66                formats2.to_glib_none().0,
67            ))
68        }
69    }
70
71    /// Gets the fourcc code and modifier for a format
72    /// that is contained in @self.
73    /// ## `idx`
74    /// the index of the format to return
75    ///
76    /// # Returns
77    ///
78    ///
79    /// ## `fourcc`
80    /// return location for the format code
81    ///
82    /// ## `modifier`
83    /// return location for the format modifier
84    #[doc(alias = "gdk_dmabuf_formats_get_format")]
85    #[doc(alias = "get_format")]
86    pub fn format(&self, idx: usize) -> (u32, u64) {
87        unsafe {
88            let mut fourcc = std::mem::MaybeUninit::uninit();
89            let mut modifier = std::mem::MaybeUninit::uninit();
90            ffi::gdk_dmabuf_formats_get_format(
91                self.to_glib_none().0,
92                idx,
93                fourcc.as_mut_ptr(),
94                modifier.as_mut_ptr(),
95            );
96            (fourcc.assume_init(), modifier.assume_init())
97        }
98    }
99
100    /// Returns the number of formats that the @self object
101    /// contains.
102    ///
103    /// Note that DMA buffers are a Linux concept, so on other
104    /// platforms, [`n_formats()`][Self::n_formats()] will
105    /// always return zero.
106    ///
107    /// # Returns
108    ///
109    /// the number of formats
110    #[doc(alias = "gdk_dmabuf_formats_get_n_formats")]
111    #[doc(alias = "get_n_formats")]
112    pub fn n_formats(&self) -> usize {
113        unsafe { ffi::gdk_dmabuf_formats_get_n_formats(self.to_glib_none().0) }
114    }
115}
116
117impl PartialEq for DmabufFormats {
118    #[inline]
119    fn eq(&self, other: &Self) -> bool {
120        self.equal(other)
121    }
122}
123
124impl Eq for DmabufFormats {}