[go: up one dir, main page]

gdk4/
texture.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{ffi, prelude::*, Texture};
6
7// rustdoc-stripper-ignore-next
8/// Trait containing manually implemented methods of
9/// [`Texture`](crate::Texture).
10pub trait TextureExtManual: IsA<Texture> + 'static {
11    #[doc(alias = "gdk_texture_download")]
12    fn download(&self, data: &mut [u8], stride: usize) {
13        unsafe {
14            assert!(
15                stride >= 4,
16                "Stride for a CAIRO_FORMAT_ARGB32 should be >= 4"
17            );
18            assert!(
19                stride as i32 >= self.as_ref().width() * 4,
20                "The stride must be >= 4*width"
21            );
22            assert!(
23                data.len() as i32 >= stride as i32 * self.as_ref().height(),
24                "The data is not big enough to download the texture"
25            );
26            ffi::gdk_texture_download(self.as_ref().to_glib_none().0, data.as_mut_ptr(), stride);
27        }
28    }
29}
30
31impl<O: IsA<Texture>> TextureExtManual for O {}