gdk4/auto/
texture_downloader.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::{ffi, MemoryFormat, Texture};
9use glib::{prelude::*, translate::*};
10
11glib::wrapper! {
12    /// Used to download the contents of a [`Texture`][crate::Texture].
13    ///
14    /// It is intended to be created as a short-term object for a single download,
15    /// but can be used for multiple downloads of different textures or with different
16    /// settings.
17    ///
18    /// [`TextureDownloader`][crate::TextureDownloader] can be used to convert data between different formats.
19    /// Create a [`Texture`][crate::Texture] for the existing format and then download it in a
20    /// different format.
21    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
22    pub struct TextureDownloader(Boxed<ffi::GdkTextureDownloader>);
23
24    match fn {
25        copy => |ptr| ffi::gdk_texture_downloader_copy(ptr),
26        free => |ptr| ffi::gdk_texture_downloader_free(ptr),
27        type_ => || ffi::gdk_texture_downloader_get_type(),
28    }
29}
30
31impl TextureDownloader {
32    /// Creates a new texture downloader for @texture.
33    ///
34    /// By default, the downloader will convert the data to
35    /// the default memory format, and to the sRGB color state.
36    /// ## `texture`
37    /// texture to download
38    ///
39    /// # Returns
40    ///
41    /// A new texture downloader
42    #[doc(alias = "gdk_texture_downloader_new")]
43    pub fn new(texture: &impl IsA<Texture>) -> TextureDownloader {
44        skip_assert_initialized!();
45        unsafe {
46            from_glib_full(ffi::gdk_texture_downloader_new(
47                texture.as_ref().to_glib_none().0,
48            ))
49        }
50    }
51
52    /// Downloads the given texture pixels into a `GBytes`. The rowstride will
53    /// be stored in the stride value.
54    ///
55    /// This function will abort if it tries to download a large texture and
56    /// fails to allocate memory. If you think that may happen, you should handle
57    /// memory allocation yourself and use `Gdk::TextureDownloader::download_into()`
58    /// once allocation succeeded.
59    ///
60    /// This function cannot be used with a multiplanar format. Use
61    /// `Gdk::TextureDownloader::download_bytes_with_planes()` for that purpose.
62    ///
63    /// # Returns
64    ///
65    /// The downloaded pixels
66    ///
67    /// ## `out_stride`
68    /// The stride of the resulting data in bytes
69    #[doc(alias = "gdk_texture_downloader_download_bytes")]
70    pub fn download_bytes(&self) -> (glib::Bytes, usize) {
71        unsafe {
72            let mut out_stride = std::mem::MaybeUninit::uninit();
73            let ret = from_glib_full(ffi::gdk_texture_downloader_download_bytes(
74                self.to_glib_none().0,
75                out_stride.as_mut_ptr(),
76            ));
77            (ret, out_stride.assume_init())
78        }
79    }
80
81    //#[cfg(feature = "v4_20")]
82    //#[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
83    //#[doc(alias = "gdk_texture_downloader_download_bytes_with_planes")]
84    //pub fn download_bytes_with_planes(&self, out_offsets: /*Unimplemented*/FixedArray TypeId { ns_id: 0, id: 18 }; 4, out_strides: /*Unimplemented*/FixedArray TypeId { ns_id: 0, id: 18 }; 4) -> glib::Bytes {
85    //    unsafe { TODO: call ffi:gdk_texture_downloader_download_bytes_with_planes() }
86    //}
87
88    //#[doc(alias = "gdk_texture_downloader_download_into")]
89    //pub fn download_into(&self, data: &[u8], stride: usize) {
90    //    unsafe { TODO: call ffi:gdk_texture_downloader_download_into() }
91    //}
92
93    /// Gets the color state that the data will be downloaded in.
94    ///
95    /// # Returns
96    ///
97    /// The color state of the download
98    #[cfg(feature = "v4_16")]
99    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
100    #[doc(alias = "gdk_texture_downloader_get_color_state")]
101    #[doc(alias = "get_color_state")]
102    pub fn color_state(&self) -> ColorState {
103        unsafe {
104            from_glib_full(ffi::gdk_texture_downloader_get_color_state(
105                self.to_glib_none().0,
106            ))
107        }
108    }
109
110    /// Gets the format that the data will be downloaded in.
111    ///
112    /// # Returns
113    ///
114    /// The format of the download
115    #[doc(alias = "gdk_texture_downloader_get_format")]
116    #[doc(alias = "get_format")]
117    pub fn format(&self) -> MemoryFormat {
118        unsafe {
119            from_glib(ffi::gdk_texture_downloader_get_format(
120                self.to_glib_none().0,
121            ))
122        }
123    }
124
125    /// Gets the texture that the downloader will download.
126    ///
127    /// # Returns
128    ///
129    /// The texture to download
130    #[doc(alias = "gdk_texture_downloader_get_texture")]
131    #[doc(alias = "get_texture")]
132    pub fn texture(&self) -> Texture {
133        unsafe {
134            from_glib_none(ffi::gdk_texture_downloader_get_texture(
135                self.to_glib_none().0,
136            ))
137        }
138    }
139
140    /// Sets the color state the downloader will convert the data to.
141    ///
142    /// By default, the sRGB colorstate returned by `get_srgb()`
143    /// is used.
144    /// ## `color_state`
145    /// the color state to use
146    #[cfg(feature = "v4_16")]
147    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
148    #[doc(alias = "gdk_texture_downloader_set_color_state")]
149    pub fn set_color_state(&mut self, color_state: &ColorState) {
150        unsafe {
151            ffi::gdk_texture_downloader_set_color_state(
152                self.to_glib_none_mut().0,
153                color_state.to_glib_none().0,
154            );
155        }
156    }
157
158    /// Sets the format the downloader will download.
159    ///
160    /// By default, GDK_MEMORY_DEFAULT is set.
161    /// ## `format`
162    /// the format to use
163    #[doc(alias = "gdk_texture_downloader_set_format")]
164    pub fn set_format(&mut self, format: MemoryFormat) {
165        unsafe {
166            ffi::gdk_texture_downloader_set_format(self.to_glib_none_mut().0, format.into_glib());
167        }
168    }
169
170    /// Changes the texture the downloader will download.
171    /// ## `texture`
172    /// the new texture to download
173    #[doc(alias = "gdk_texture_downloader_set_texture")]
174    pub fn set_texture(&mut self, texture: &impl IsA<Texture>) {
175        unsafe {
176            ffi::gdk_texture_downloader_set_texture(
177                self.to_glib_none_mut().0,
178                texture.as_ref().to_glib_none().0,
179            );
180        }
181    }
182}