1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use glib::translate::*;

glib::wrapper! {
    /// The [`DmabufFormats`][crate::DmabufFormats] struct provides information about
    /// supported DMA buffer formats.
    ///
    /// You can query whether a given format is supported with
    /// [`contains()`][Self::contains()] and you can iterate
    /// over the list of all supported formats with
    /// [`n_formats()`][Self::n_formats()] and
    /// [`format()`][Self::format()].
    ///
    /// The list of supported formats is sorted by preference,
    /// with the best formats coming first.
    ///
    /// The list may contains (format, modifier) pairs where the modifier
    /// is `DMA_FORMAT_MOD_INVALID`, indicating that **_implicit modifiers_**
    /// may be used with this format.
    ///
    /// See [`DmabufTextureBuilder`][crate::DmabufTextureBuilder] for more information
    /// about DMA buffers.
    ///
    /// Note that DMA buffers only exist on Linux.
    #[derive(Debug, PartialOrd, Ord, Hash)]
    pub struct DmabufFormats(Shared<ffi::GdkDmabufFormats>);

    match fn {
        ref => |ptr| ffi::gdk_dmabuf_formats_ref(ptr),
        unref => |ptr| ffi::gdk_dmabuf_formats_unref(ptr),
        type_ => || ffi::gdk_dmabuf_formats_get_type(),
    }
}

impl DmabufFormats {
    /// Returns whether a given format is contained in @self.
    /// ## `fourcc`
    /// a format code
    /// ## `modifier`
    /// a format modifier
    ///
    /// # Returns
    ///
    /// `TRUE` if the format specified by the arguments
    ///   is part of @self
    #[doc(alias = "gdk_dmabuf_formats_contains")]
    pub fn contains(&self, fourcc: u32, modifier: u64) -> bool {
        unsafe {
            from_glib(ffi::gdk_dmabuf_formats_contains(
                self.to_glib_none().0,
                fourcc,
                modifier,
            ))
        }
    }

    #[doc(alias = "gdk_dmabuf_formats_equal")]
    fn equal(&self, formats2: &DmabufFormats) -> bool {
        unsafe {
            from_glib(ffi::gdk_dmabuf_formats_equal(
                self.to_glib_none().0,
                formats2.to_glib_none().0,
            ))
        }
    }

    /// Gets the fourcc code and modifier for a format
    /// that is contained in @self.
    /// ## `idx`
    /// the index of the format to return
    ///
    /// # Returns
    ///
    ///
    /// ## `fourcc`
    /// return location for the format code
    ///
    /// ## `modifier`
    /// return location for the format modifier
    #[doc(alias = "gdk_dmabuf_formats_get_format")]
    #[doc(alias = "get_format")]
    pub fn format(&self, idx: usize) -> (u32, u64) {
        unsafe {
            let mut fourcc = std::mem::MaybeUninit::uninit();
            let mut modifier = std::mem::MaybeUninit::uninit();
            ffi::gdk_dmabuf_formats_get_format(
                self.to_glib_none().0,
                idx,
                fourcc.as_mut_ptr(),
                modifier.as_mut_ptr(),
            );
            (fourcc.assume_init(), modifier.assume_init())
        }
    }

    /// Returns the number of formats that the @self object
    /// contains.
    ///
    /// Note that DMA buffers are a Linux concept, so on other
    /// platforms, [`n_formats()`][Self::n_formats()] will
    /// always return zero.
    ///
    /// # Returns
    ///
    /// the number of formats
    #[doc(alias = "gdk_dmabuf_formats_get_n_formats")]
    #[doc(alias = "get_n_formats")]
    pub fn n_formats(&self) -> usize {
        unsafe { ffi::gdk_dmabuf_formats_get_n_formats(self.to_glib_none().0) }
    }
}

impl PartialEq for DmabufFormats {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}

impl Eq for DmabufFormats {}