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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::GLBaseFilter;
use crate::GLMemory;
use crate::GLShader;
use glib::object::IsA;
use glib::translate::*;

glib::wrapper! {
    /// [`crate::GLFilter`] helps to implement simple OpenGL filter elements taking a
    /// single input and producing a single output with a [`crate::GLFramebuffer`]
    ///
    /// # Implements
    ///
    /// [`trait@crate::prelude::GLFilterExt`], [`trait@crate::prelude::GLBaseFilterExt`], [`trait@gst_base::prelude::BaseTransformExt`], [`trait@gst::prelude::ElementExt`], [`trait@gst::prelude::ObjectExt`], [`trait@glib::object::ObjectExt`]
    pub struct GLFilter(Object<ffi::GstGLFilter, ffi::GstGLFilterClass>) @extends GLBaseFilter, gst_base::BaseTransform, gst::Element, gst::Object;

    match fn {
        type_ => || ffi::gst_gl_filter_get_type(),
    }
}

unsafe impl Send for GLFilter {}
unsafe impl Sync for GLFilter {}

pub const NONE_GL_FILTER: Option<&GLFilter> = None;

/// Trait containing all `GLFilter` methods.
///
/// # Implementors
///
/// [`struct@crate::GLFilter`]
pub trait GLFilterExt: 'static {
    /// Render a fullscreen quad using the current GL state. The only GL state this
    /// modifies is the necessary vertex/index buffers and, if necessary, a
    /// Vertex Array Object for drawing a fullscreen quad. Framebuffer state,
    /// any shaders, viewport state, etc must be setup by the caller.
    #[doc(alias = "gst_gl_filter_draw_fullscreen_quad")]
    fn draw_fullscreen_quad(&self);

    /// Calls filter_texture vfunc with correctly mapped `GstGLMemorys`
    /// ## `input`
    /// an input buffer
    /// ## `output`
    /// an output buffer
    ///
    /// # Returns
    ///
    /// whether the transformation succeeded
    #[doc(alias = "gst_gl_filter_filter_texture")]
    fn filter_texture(
        &self,
        input: &gst::Buffer,
        output: &gst::Buffer,
    ) -> Result<(), glib::error::BoolError>;

    /// Transforms `input` into `output` using `func` on through FBO.
    /// ## `input`
    /// the input texture
    /// ## `output`
    /// the output texture
    /// ## `func`
    /// the function to transform `input` into `output`. called with `data`
    /// ## `data`
    /// the data associated with `func`
    ///
    /// # Returns
    ///
    /// the return value of `func`
    #[doc(alias = "gst_gl_filter_render_to_target")]
    fn render_to_target<P: FnMut(&GLFilter, &GLMemory) -> bool>(
        &self,
        input: &GLMemory,
        output: &GLMemory,
        func: P,
    ) -> Result<(), glib::error::BoolError>;

    /// Transforms `input` into `output` using `shader` with a FBO.
    ///
    /// See also: [`Self::render_to_target()`]
    /// ## `input`
    /// the input texture
    /// ## `output`
    /// the output texture
    /// ## `shader`
    /// the shader to use.
    #[doc(alias = "gst_gl_filter_render_to_target_with_shader")]
    fn render_to_target_with_shader(&self, input: &GLMemory, output: &GLMemory, shader: &GLShader);
}

impl<O: IsA<GLFilter>> GLFilterExt for O {
    fn draw_fullscreen_quad(&self) {
        unsafe {
            ffi::gst_gl_filter_draw_fullscreen_quad(self.as_ref().to_glib_none().0);
        }
    }

    fn filter_texture(
        &self,
        input: &gst::Buffer,
        output: &gst::Buffer,
    ) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_gl_filter_filter_texture(
                    self.as_ref().to_glib_none().0,
                    input.to_glib_none().0,
                    output.to_glib_none().0
                ),
                "Failed to transform texture"
            )
        }
    }

    fn render_to_target<P: FnMut(&GLFilter, &GLMemory) -> bool>(
        &self,
        input: &GLMemory,
        output: &GLMemory,
        func: P,
    ) -> Result<(), glib::error::BoolError> {
        let func_data: P = func;
        unsafe extern "C" fn func_func<P: FnMut(&GLFilter, &GLMemory) -> bool>(
            filter: *mut ffi::GstGLFilter,
            in_tex: *mut ffi::GstGLMemory,
            user_data: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let filter = from_glib_borrow(filter);
            let in_tex = from_glib_borrow(in_tex);
            let callback: *mut P = user_data as *const _ as usize as *mut P;
            let res = (*callback)(&filter, &in_tex);
            res.into_glib()
        }
        let func = Some(func_func::<P> as _);
        let super_callback0: &P = &func_data;
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_gl_filter_render_to_target(
                    self.as_ref().to_glib_none().0,
                    mut_override(input.to_glib_none().0),
                    mut_override(output.to_glib_none().0),
                    func,
                    super_callback0 as *const _ as usize as *mut _
                ),
                "`func` returned `false`"
            )
        }
    }

    fn render_to_target_with_shader(&self, input: &GLMemory, output: &GLMemory, shader: &GLShader) {
        unsafe {
            ffi::gst_gl_filter_render_to_target_with_shader(
                self.as_ref().to_glib_none().0,
                mut_override(input.to_glib_none().0),
                mut_override(output.to_glib_none().0),
                shader.to_glib_none().0,
            );
        }
    }
}