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
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::translate::*;

#[cfg(feature = "v4_12")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
use crate::builders::GLTextureBuilder;
use crate::{GLContext, GLTexture};

impl GLTexture {
    /// Creates a new texture for an existing GL texture.
    ///
    /// Note that the GL texture must not be modified until @destroy is called,
    /// which will happen when the GdkTexture object is finalized, or due to
    /// an explicit call of [`release()`][Self::release()].
    ///
    /// # Deprecated since 4.12
    ///
    /// [`GLTextureBuilder`][crate::GLTextureBuilder] supersedes this function
    ///   and provides extended functionality for creating GL textures.
    /// ## `context`
    /// a [`GLContext`][crate::GLContext]
    /// ## `id`
    /// the ID of a texture that was created with @context
    /// ## `width`
    /// the nominal width of the texture
    /// ## `height`
    /// the nominal height of the texture
    ///
    /// # Returns
    ///
    /// A newly-created
    ///   [`Texture`][crate::Texture]
    #[doc(alias = "gdk_gl_texture_new")]
    #[allow(clippy::missing_safety_doc)]
    pub unsafe fn new(context: &GLContext, id: u32, width: i32, height: i32) -> Self {
        from_glib_full(ffi::gdk_gl_texture_new(
            context.to_glib_none().0,
            id,
            width,
            height,
            None,
            std::ptr::null_mut(),
        ))
    }

    #[doc(alias = "gdk_gl_texture_new")]
    #[allow(clippy::missing_safety_doc)]
    pub unsafe fn with_release_func<F: FnOnce() + 'static>(
        context: &GLContext,
        id: u32,
        width: i32,
        height: i32,
        release_func: F,
    ) -> Self {
        unsafe extern "C" fn destroy_closure<F: FnOnce() + 'static>(func: glib::ffi::gpointer) {
            let released_func = Box::<F>::from_raw(func as *mut _);
            released_func();
        }
        let released_func = Box::new(release_func);
        from_glib_full(ffi::gdk_gl_texture_new(
            context.to_glib_none().0,
            id,
            width,
            height,
            Some(destroy_closure::<F>),
            Box::into_raw(released_func) as glib::ffi::gpointer,
        ))
    }

    #[cfg(feature = "v4_12")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`GLTexture`]
    /// objects.
    ///
    /// This method returns an instance of
    /// [`GLTextureBuilder`](crate::builders::GLTextureBuilder) which can be
    /// used to create [`GLTexture`] objects.
    pub fn builder() -> GLTextureBuilder {
        GLTextureBuilder::new()
    }
}