gdk4/auto/dmabuf_texture_builder.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
5#[cfg(feature = "v4_16")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
7use crate::ColorState;
8use crate::{Display, Texture, ffi};
9use glib::translate::*;
10
11glib::wrapper! {
12 /// Constructs [`Texture`][crate::Texture] objects from DMA buffers.
13 ///
14 /// DMA buffers are commonly called **_dma-bufs_**.
15 ///
16 /// DMA buffers are a feature of the Linux kernel to enable efficient buffer and
17 /// memory sharing between hardware such as codecs, GPUs, displays, cameras and the
18 /// kernel drivers controlling them. For example, a decoder may want its output to
19 /// be directly shared with the display server for rendering without a copy.
20 ///
21 /// Any device driver which participates in DMA buffer sharing, can do so as either
22 /// the exporter or importer of buffers (or both).
23 ///
24 /// The memory that is shared via DMA buffers is usually stored in non-system memory
25 /// (maybe in device's local memory or something else not directly accessible by the
26 /// CPU), and accessing this memory from the CPU may have higher-than-usual overhead.
27 ///
28 /// In particular for graphics data, it is not uncommon that data consists of multiple
29 /// separate blocks of memory, for example one block for each of the red, green and
30 /// blue channels. These blocks are called **_planes_**. DMA buffers can have up to
31 /// four planes. Even if the memory is a single block, the data can be organized in
32 /// multiple planes, by specifying offsets from the beginning of the data.
33 ///
34 /// DMA buffers are exposed to user-space as file descriptors allowing to pass them
35 /// between processes. If a DMA buffer has multiple planes, more than one file
36 /// descriptor may be present, up to the number of planes. If the number of file
37 /// descriptors is less than the number of planes, the remaining ones should be set to
38 /// -1.
39 ///
40 /// The format of the data (for graphics data, essentially its colorspace) is described
41 /// by a 32-bit integer. These format identifiers are defined in the header file `drm_fourcc.h`
42 /// and commonly referred to as **_fourcc_** values, since they are identified by 4 ASCII
43 /// characters. Additionally, each DMA buffer has a **_modifier_**, which is a 64-bit integer
44 /// that describes driver-specific details of the memory layout, such as tiling or compression.
45 ///
46 /// For historical reasons, some producers of dma-bufs don't provide an explicit modifier, but
47 /// instead return `DMA_FORMAT_MOD_INVALID` to indicate that their modifier is **_implicit_**.
48 /// GTK tries to accommodate this situation by accepting `DMA_FORMAT_MOD_INVALID` as modifier.
49 ///
50 /// The operation of [`DmabufTextureBuilder`][crate::DmabufTextureBuilder] is quite simple: Create a texture builder,
51 /// set all the necessary properties, and then call [`build()`][Self::build()]
52 /// to create the new texture.
53 ///
54 /// The required properties for a dma-buf texture are
55 ///
56 /// * The width and height in pixels
57 ///
58 /// * The `fourcc` code and `modifier` which identify the format and memory layout of the dma-buf
59 ///
60 /// * The file descriptor, offset and stride for each of the planes
61 ///
62 /// [`DmabufTextureBuilder`][crate::DmabufTextureBuilder] can be used for quick one-shot construction of
63 /// textures as well as kept around and reused to construct multiple textures.
64 ///
65 /// For further information, see
66 ///
67 /// * The Linux kernel [documentation](https://docs.kernel.org/driver-api/dma-buf.html)
68 ///
69 /// * The header file [drm_fourcc.h](https://gitlab.freedesktop.org/mesa/drm/-/blob/main/include/drm/drm_fourcc.h)
70 ///
71 /// ## Properties
72 ///
73 ///
74 /// #### `color-state`
75 /// The color state of the texture.
76 ///
77 /// Readable | Writeable
78 ///
79 ///
80 /// #### `display`
81 /// The display that this texture will be used on.
82 ///
83 /// Readable | Writeable
84 ///
85 ///
86 /// #### `fourcc`
87 /// The format of the texture, as a fourcc value.
88 ///
89 /// Readable | Writeable
90 ///
91 ///
92 /// #### `height`
93 /// The height of the texture.
94 ///
95 /// Readable | Writeable
96 ///
97 ///
98 /// #### `modifier`
99 /// The modifier.
100 ///
101 /// Readable | Writeable
102 ///
103 ///
104 /// #### `n-planes`
105 /// The number of planes of the texture.
106 ///
107 /// Note that you can set properties for other planes,
108 /// but they will be ignored when constructing the texture.
109 ///
110 /// Readable | Writeable
111 ///
112 ///
113 /// #### `premultiplied`
114 /// Whether the alpha channel is premultiplied into the others.
115 ///
116 /// Only relevant if the format has alpha.
117 ///
118 /// Readable | Writeable
119 ///
120 ///
121 /// #### `update-region`
122 /// The update region for [`update-texture`][struct@crate::DmabufTextureBuilder#update-texture].
123 ///
124 /// Readable | Writeable
125 ///
126 ///
127 /// #### `update-texture`
128 /// The texture [`update-region`][struct@crate::DmabufTextureBuilder#update-region] is an update for.
129 ///
130 /// Readable | Writeable
131 ///
132 ///
133 /// #### `width`
134 /// The width of the texture.
135 ///
136 /// Readable | Writeable
137 #[doc(alias = "GdkDmabufTextureBuilder")]
138 pub struct DmabufTextureBuilder(Object<ffi::GdkDmabufTextureBuilder, ffi::GdkDmabufTextureBuilderClass>);
139
140 match fn {
141 type_ => || ffi::gdk_dmabuf_texture_builder_get_type(),
142 }
143}
144
145impl DmabufTextureBuilder {
146 /// Creates a new texture builder.
147 ///
148 /// # Returns
149 ///
150 /// the new `GdkTextureBuilder`
151 #[doc(alias = "gdk_dmabuf_texture_builder_new")]
152 pub fn new() -> DmabufTextureBuilder {
153 assert_initialized_main_thread!();
154 unsafe { from_glib_full(ffi::gdk_dmabuf_texture_builder_new()) }
155 }
156
157 /// Gets the color state previously set via gdk_dmabuf_texture_builder_set_color_state().
158 ///
159 /// # Returns
160 ///
161 /// the color state
162 #[cfg(feature = "v4_16")]
163 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
164 #[doc(alias = "gdk_dmabuf_texture_builder_get_color_state")]
165 #[doc(alias = "get_color_state")]
166 #[doc(alias = "color-state")]
167 pub fn color_state(&self) -> Option<ColorState> {
168 unsafe {
169 from_glib_none(ffi::gdk_dmabuf_texture_builder_get_color_state(
170 self.to_glib_none().0,
171 ))
172 }
173 }
174
175 /// Returns the display that this texture builder is
176 /// associated with.
177 ///
178 /// # Returns
179 ///
180 /// the display
181 #[doc(alias = "gdk_dmabuf_texture_builder_get_display")]
182 #[doc(alias = "get_display")]
183 pub fn display(&self) -> Display {
184 unsafe {
185 from_glib_none(ffi::gdk_dmabuf_texture_builder_get_display(
186 self.to_glib_none().0,
187 ))
188 }
189 }
190
191 /// Gets the format previously set via gdk_dmabuf_texture_builder_set_fourcc()
192 /// or 0 if the format wasn't set.
193 ///
194 /// The format is specified as a fourcc code.
195 ///
196 /// # Returns
197 ///
198 /// The format
199 #[doc(alias = "gdk_dmabuf_texture_builder_get_fourcc")]
200 #[doc(alias = "get_fourcc")]
201 pub fn fourcc(&self) -> u32 {
202 unsafe { ffi::gdk_dmabuf_texture_builder_get_fourcc(self.to_glib_none().0) }
203 }
204
205 /// Gets the height previously set via gdk_dmabuf_texture_builder_set_height() or
206 /// 0 if the height wasn't set.
207 ///
208 /// # Returns
209 ///
210 /// The height
211 #[doc(alias = "gdk_dmabuf_texture_builder_get_height")]
212 #[doc(alias = "get_height")]
213 pub fn height(&self) -> u32 {
214 unsafe { ffi::gdk_dmabuf_texture_builder_get_height(self.to_glib_none().0) }
215 }
216
217 /// Gets the modifier value.
218 ///
219 /// # Returns
220 ///
221 /// the modifier
222 #[doc(alias = "gdk_dmabuf_texture_builder_get_modifier")]
223 #[doc(alias = "get_modifier")]
224 pub fn modifier(&self) -> u64 {
225 unsafe { ffi::gdk_dmabuf_texture_builder_get_modifier(self.to_glib_none().0) }
226 }
227
228 /// Gets the number of planes.
229 ///
230 /// # Returns
231 ///
232 /// The number of planes
233 #[doc(alias = "gdk_dmabuf_texture_builder_get_n_planes")]
234 #[doc(alias = "get_n_planes")]
235 #[doc(alias = "n-planes")]
236 pub fn n_planes(&self) -> u32 {
237 unsafe { ffi::gdk_dmabuf_texture_builder_get_n_planes(self.to_glib_none().0) }
238 }
239
240 /// Gets the offset value for a plane.
241 /// ## `plane`
242 /// the plane to get the offset for
243 ///
244 /// # Returns
245 ///
246 /// the offset
247 #[doc(alias = "gdk_dmabuf_texture_builder_get_offset")]
248 #[doc(alias = "get_offset")]
249 pub fn offset(&self, plane: u32) -> u32 {
250 unsafe { ffi::gdk_dmabuf_texture_builder_get_offset(self.to_glib_none().0, plane) }
251 }
252
253 /// Whether the data is premultiplied.
254 ///
255 /// # Returns
256 ///
257 /// whether the data is premultiplied
258 #[doc(alias = "gdk_dmabuf_texture_builder_get_premultiplied")]
259 #[doc(alias = "get_premultiplied")]
260 #[doc(alias = "premultiplied")]
261 pub fn is_premultiplied(&self) -> bool {
262 unsafe {
263 from_glib(ffi::gdk_dmabuf_texture_builder_get_premultiplied(
264 self.to_glib_none().0,
265 ))
266 }
267 }
268
269 /// Gets the stride value for a plane.
270 /// ## `plane`
271 /// the plane to get the stride for
272 ///
273 /// # Returns
274 ///
275 /// the stride
276 #[doc(alias = "gdk_dmabuf_texture_builder_get_stride")]
277 #[doc(alias = "get_stride")]
278 pub fn stride(&self, plane: u32) -> u32 {
279 unsafe { ffi::gdk_dmabuf_texture_builder_get_stride(self.to_glib_none().0, plane) }
280 }
281
282 /// Gets the region previously set via gdk_dmabuf_texture_builder_set_update_region() or
283 /// [`None`] if none was set.
284 ///
285 /// # Returns
286 ///
287 /// The region
288 #[doc(alias = "gdk_dmabuf_texture_builder_get_update_region")]
289 #[doc(alias = "get_update_region")]
290 #[doc(alias = "update-region")]
291 pub fn update_region(&self) -> Option<cairo::Region> {
292 unsafe {
293 from_glib_none(ffi::gdk_dmabuf_texture_builder_get_update_region(
294 self.to_glib_none().0,
295 ))
296 }
297 }
298
299 /// Gets the texture previously set via gdk_dmabuf_texture_builder_set_update_texture() or
300 /// [`None`] if none was set.
301 ///
302 /// # Returns
303 ///
304 /// The texture
305 #[doc(alias = "gdk_dmabuf_texture_builder_get_update_texture")]
306 #[doc(alias = "get_update_texture")]
307 #[doc(alias = "update-texture")]
308 pub fn update_texture(&self) -> Option<Texture> {
309 unsafe {
310 from_glib_none(ffi::gdk_dmabuf_texture_builder_get_update_texture(
311 self.to_glib_none().0,
312 ))
313 }
314 }
315
316 /// Gets the width previously set via gdk_dmabuf_texture_builder_set_width() or
317 /// 0 if the width wasn't set.
318 ///
319 /// # Returns
320 ///
321 /// The width
322 #[doc(alias = "gdk_dmabuf_texture_builder_get_width")]
323 #[doc(alias = "get_width")]
324 pub fn width(&self) -> u32 {
325 unsafe { ffi::gdk_dmabuf_texture_builder_get_width(self.to_glib_none().0) }
326 }
327}
328
329#[cfg(feature = "v4_14")]
330#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
331impl Default for DmabufTextureBuilder {
332 fn default() -> Self {
333 Self::new()
334 }
335}