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