From 72615a1fb981b7fb80ae3873865200cc16c7cb46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 8 May 2025 14:39:52 +0300 Subject: [PATCH 1/4] gdk: Take self by value in DmabufTextureBuilder for consistency --- gdk4/Gir.toml | 8 + gdk4/src/auto/dmabuf_texture_builder.rs | 383 +----------------------- gdk4/src/dmabuf_texture_builder.rs | 150 +++++++++- 3 files changed, 157 insertions(+), 384 deletions(-) diff --git a/gdk4/Gir.toml b/gdk4/Gir.toml index d6fbf953c62f..14a525250b7e 100644 --- a/gdk4/Gir.toml +++ b/gdk4/Gir.toml @@ -449,8 +449,15 @@ status = "generate" name = "region" const = true [[object.function]] + pattern = "set_(color_state|display|fd|fourcc|height|modifier|n_planes|offset|premultiplied|stride|update_region|update_texture|width)" + # Take by value and return self + manual = true + [[object.function]] name = "build" manual = true # Can't be auto-generated + [[object.property]] + pattern = "(color-state|display|fourcc|height|modifier|n-planes|premultiplied|update-region|update-texture|width)" + generate = [] # ignore get/set/notify [[object]] name = "Gdk.Drag" @@ -528,6 +535,7 @@ generate_builder = false const = true [[object.function]] pattern = "set_(context|format|has_mipmap|height|id|update_region|update_texture|width)" + # Take by value and return self manual = true [[object.function]] pattern = "(set|get)_sync" diff --git a/gdk4/src/auto/dmabuf_texture_builder.rs b/gdk4/src/auto/dmabuf_texture_builder.rs index b8b92c518c3a..1522e02a41f7 100644 --- a/gdk4/src/auto/dmabuf_texture_builder.rs +++ b/gdk4/src/auto/dmabuf_texture_builder.rs @@ -6,12 +6,7 @@ #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] use crate::ColorState; use crate::{ffi, Display, Texture}; -use glib::{ - prelude::*, - signal::{connect_raw, SignalHandlerId}, - translate::*, -}; -use std::boxed::Box as Box_; +use glib::translate::*; glib::wrapper! { #[doc(alias = "GdkDmabufTextureBuilder")] @@ -133,382 +128,6 @@ impl DmabufTextureBuilder { pub fn width(&self) -> u32 { unsafe { ffi::gdk_dmabuf_texture_builder_get_width(self.to_glib_none().0) } } - - #[cfg(feature = "v4_16")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] - #[doc(alias = "gdk_dmabuf_texture_builder_set_color_state")] - #[doc(alias = "color-state")] - pub fn set_color_state(&self, color_state: Option<&ColorState>) { - unsafe { - ffi::gdk_dmabuf_texture_builder_set_color_state( - self.to_glib_none().0, - color_state.to_glib_none().0, - ); - } - } - - #[doc(alias = "gdk_dmabuf_texture_builder_set_display")] - #[doc(alias = "display")] - pub fn set_display(&self, display: &impl IsA) { - unsafe { - ffi::gdk_dmabuf_texture_builder_set_display( - self.to_glib_none().0, - display.as_ref().to_glib_none().0, - ); - } - } - - #[doc(alias = "gdk_dmabuf_texture_builder_set_fd")] - pub fn set_fd(&self, plane: u32, fd: i32) { - unsafe { - ffi::gdk_dmabuf_texture_builder_set_fd(self.to_glib_none().0, plane, fd); - } - } - - #[doc(alias = "gdk_dmabuf_texture_builder_set_fourcc")] - #[doc(alias = "fourcc")] - pub fn set_fourcc(&self, fourcc: u32) { - unsafe { - ffi::gdk_dmabuf_texture_builder_set_fourcc(self.to_glib_none().0, fourcc); - } - } - - #[doc(alias = "gdk_dmabuf_texture_builder_set_height")] - #[doc(alias = "height")] - pub fn set_height(&self, height: u32) { - unsafe { - ffi::gdk_dmabuf_texture_builder_set_height(self.to_glib_none().0, height); - } - } - - #[doc(alias = "gdk_dmabuf_texture_builder_set_modifier")] - #[doc(alias = "modifier")] - pub fn set_modifier(&self, modifier: u64) { - unsafe { - ffi::gdk_dmabuf_texture_builder_set_modifier(self.to_glib_none().0, modifier); - } - } - - #[doc(alias = "gdk_dmabuf_texture_builder_set_n_planes")] - #[doc(alias = "n-planes")] - pub fn set_n_planes(&self, n_planes: u32) { - unsafe { - ffi::gdk_dmabuf_texture_builder_set_n_planes(self.to_glib_none().0, n_planes); - } - } - - #[doc(alias = "gdk_dmabuf_texture_builder_set_offset")] - pub fn set_offset(&self, plane: u32, offset: u32) { - unsafe { - ffi::gdk_dmabuf_texture_builder_set_offset(self.to_glib_none().0, plane, offset); - } - } - - #[doc(alias = "gdk_dmabuf_texture_builder_set_premultiplied")] - #[doc(alias = "premultiplied")] - pub fn set_premultiplied(&self, premultiplied: bool) { - unsafe { - ffi::gdk_dmabuf_texture_builder_set_premultiplied( - self.to_glib_none().0, - premultiplied.into_glib(), - ); - } - } - - #[doc(alias = "gdk_dmabuf_texture_builder_set_stride")] - pub fn set_stride(&self, plane: u32, stride: u32) { - unsafe { - ffi::gdk_dmabuf_texture_builder_set_stride(self.to_glib_none().0, plane, stride); - } - } - - #[doc(alias = "gdk_dmabuf_texture_builder_set_update_region")] - #[doc(alias = "update-region")] - pub fn set_update_region(&self, region: Option<&cairo::Region>) { - unsafe { - ffi::gdk_dmabuf_texture_builder_set_update_region( - self.to_glib_none().0, - mut_override(region.to_glib_none().0), - ); - } - } - - #[doc(alias = "gdk_dmabuf_texture_builder_set_update_texture")] - #[doc(alias = "update-texture")] - pub fn set_update_texture(&self, texture: Option<&impl IsA>) { - unsafe { - ffi::gdk_dmabuf_texture_builder_set_update_texture( - self.to_glib_none().0, - texture.map(|p| p.as_ref()).to_glib_none().0, - ); - } - } - - #[doc(alias = "gdk_dmabuf_texture_builder_set_width")] - #[doc(alias = "width")] - pub fn set_width(&self, width: u32) { - unsafe { - ffi::gdk_dmabuf_texture_builder_set_width(self.to_glib_none().0, width); - } - } - - #[cfg(feature = "v4_16")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] - #[doc(alias = "color-state")] - pub fn connect_color_state_notify(&self, f: F) -> SignalHandlerId { - unsafe extern "C" fn notify_color_state_trampoline< - F: Fn(&DmabufTextureBuilder) + 'static, - >( - this: *mut ffi::GdkDmabufTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::color-state".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_color_state_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_14")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))] - #[doc(alias = "display")] - pub fn connect_display_notify(&self, f: F) -> SignalHandlerId { - unsafe extern "C" fn notify_display_trampoline( - this: *mut ffi::GdkDmabufTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::display".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_display_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_14")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))] - #[doc(alias = "fourcc")] - pub fn connect_fourcc_notify(&self, f: F) -> SignalHandlerId { - unsafe extern "C" fn notify_fourcc_trampoline( - this: *mut ffi::GdkDmabufTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::fourcc".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_fourcc_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_14")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))] - #[doc(alias = "height")] - pub fn connect_height_notify(&self, f: F) -> SignalHandlerId { - unsafe extern "C" fn notify_height_trampoline( - this: *mut ffi::GdkDmabufTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::height".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_height_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_14")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))] - #[doc(alias = "modifier")] - pub fn connect_modifier_notify(&self, f: F) -> SignalHandlerId { - unsafe extern "C" fn notify_modifier_trampoline( - this: *mut ffi::GdkDmabufTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::modifier".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_modifier_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_14")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))] - #[doc(alias = "n-planes")] - pub fn connect_n_planes_notify(&self, f: F) -> SignalHandlerId { - unsafe extern "C" fn notify_n_planes_trampoline( - this: *mut ffi::GdkDmabufTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::n-planes".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_n_planes_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_14")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))] - #[doc(alias = "premultiplied")] - pub fn connect_premultiplied_notify(&self, f: F) -> SignalHandlerId { - unsafe extern "C" fn notify_premultiplied_trampoline< - F: Fn(&DmabufTextureBuilder) + 'static, - >( - this: *mut ffi::GdkDmabufTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::premultiplied".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_premultiplied_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_14")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))] - #[doc(alias = "update-region")] - pub fn connect_update_region_notify(&self, f: F) -> SignalHandlerId { - unsafe extern "C" fn notify_update_region_trampoline< - F: Fn(&DmabufTextureBuilder) + 'static, - >( - this: *mut ffi::GdkDmabufTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::update-region".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_update_region_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_14")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))] - #[doc(alias = "update-texture")] - pub fn connect_update_texture_notify(&self, f: F) -> SignalHandlerId { - unsafe extern "C" fn notify_update_texture_trampoline< - F: Fn(&DmabufTextureBuilder) + 'static, - >( - this: *mut ffi::GdkDmabufTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::update-texture".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_update_texture_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_14")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))] - #[doc(alias = "width")] - pub fn connect_width_notify(&self, f: F) -> SignalHandlerId { - unsafe extern "C" fn notify_width_trampoline( - this: *mut ffi::GdkDmabufTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::width".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_width_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } } #[cfg(feature = "v4_14")] diff --git a/gdk4/src/dmabuf_texture_builder.rs b/gdk4/src/dmabuf_texture_builder.rs index afa5cfc558a3..fcdfed029a7c 100644 --- a/gdk4/src/dmabuf_texture_builder.rs +++ b/gdk4/src/dmabuf_texture_builder.rs @@ -1,10 +1,156 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use glib::translate::*; +use glib::{prelude::*, translate::*}; -use crate::{ffi, DmabufTextureBuilder, Texture}; +#[cfg(feature = "v4_16")] +use crate::ColorState; +use crate::{ffi, Display, DmabufTextureBuilder, Texture}; impl DmabufTextureBuilder { + #[cfg(feature = "v4_16")] + #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] + #[doc(alias = "gdk_dmabuf_texture_builder_set_color_state")] + #[doc(alias = "color-state")] + pub fn set_color_state(self, color_state: Option<&ColorState>) -> Self { + unsafe { + ffi::gdk_dmabuf_texture_builder_set_color_state( + self.to_glib_none().0, + color_state.to_glib_none().0, + ); + } + + self + } + + #[doc(alias = "gdk_dmabuf_texture_builder_set_display")] + #[doc(alias = "display")] + pub fn set_display(self, display: &impl IsA) -> Self { + unsafe { + ffi::gdk_dmabuf_texture_builder_set_display( + self.to_glib_none().0, + display.as_ref().to_glib_none().0, + ); + } + + self + } + + #[doc(alias = "gdk_dmabuf_texture_builder_set_fd")] + pub fn set_fd(self, plane: u32, fd: i32) -> Self { + unsafe { + ffi::gdk_dmabuf_texture_builder_set_fd(self.to_glib_none().0, plane, fd); + } + + self + } + + #[doc(alias = "gdk_dmabuf_texture_builder_set_fourcc")] + #[doc(alias = "fourcc")] + pub fn set_fourcc(self, fourcc: u32) -> Self { + unsafe { + ffi::gdk_dmabuf_texture_builder_set_fourcc(self.to_glib_none().0, fourcc); + } + + self + } + + #[doc(alias = "gdk_dmabuf_texture_builder_set_height")] + #[doc(alias = "height")] + pub fn set_height(self, height: u32) -> Self { + unsafe { + ffi::gdk_dmabuf_texture_builder_set_height(self.to_glib_none().0, height); + } + + self + } + + #[doc(alias = "gdk_dmabuf_texture_builder_set_modifier")] + #[doc(alias = "modifier")] + pub fn set_modifier(self, modifier: u64) -> Self { + unsafe { + ffi::gdk_dmabuf_texture_builder_set_modifier(self.to_glib_none().0, modifier); + } + + self + } + + #[doc(alias = "gdk_dmabuf_texture_builder_set_n_planes")] + #[doc(alias = "n-planes")] + pub fn set_n_planes(self, n_planes: u32) -> Self { + unsafe { + ffi::gdk_dmabuf_texture_builder_set_n_planes(self.to_glib_none().0, n_planes); + } + + self + } + + #[doc(alias = "gdk_dmabuf_texture_builder_set_offset")] + pub fn set_offset(self, plane: u32, offset: u32) -> Self { + unsafe { + ffi::gdk_dmabuf_texture_builder_set_offset(self.to_glib_none().0, plane, offset); + } + + self + } + + #[doc(alias = "gdk_dmabuf_texture_builder_set_premultiplied")] + #[doc(alias = "premultiplied")] + pub fn set_premultiplied(self, premultiplied: bool) -> Self { + unsafe { + ffi::gdk_dmabuf_texture_builder_set_premultiplied( + self.to_glib_none().0, + premultiplied.into_glib(), + ); + } + + self + } + + #[doc(alias = "gdk_dmabuf_texture_builder_set_stride")] + pub fn set_stride(self, plane: u32, stride: u32) -> Self { + unsafe { + ffi::gdk_dmabuf_texture_builder_set_stride(self.to_glib_none().0, plane, stride); + } + + self + } + + #[doc(alias = "gdk_dmabuf_texture_builder_set_update_region")] + #[doc(alias = "update-region")] + pub fn set_update_region(self, region: Option<&cairo::Region>) -> Self { + unsafe { + ffi::gdk_dmabuf_texture_builder_set_update_region( + self.to_glib_none().0, + mut_override(region.to_glib_none().0), + ); + } + + self + } + + #[doc(alias = "gdk_dmabuf_texture_builder_set_update_texture")] + #[doc(alias = "update-texture")] + pub fn set_update_texture(self, texture: Option<&impl IsA>) -> Self { + unsafe { + ffi::gdk_dmabuf_texture_builder_set_update_texture( + self.to_glib_none().0, + texture.map(|p| p.as_ref()).to_glib_none().0, + ); + } + + self + } + + #[doc(alias = "gdk_dmabuf_texture_builder_set_width")] + #[doc(alias = "width")] + pub fn set_width(self, width: u32) -> Self { + unsafe { + ffi::gdk_dmabuf_texture_builder_set_width(self.to_glib_none().0, width); + } + + self + } + #[doc(alias = "gdk_dmabuf_texture_builder_build")] #[must_use = "The builder must be built to be used"] #[allow(clippy::missing_safety_doc)] From 9bd16e9860cde2f9d07094d90de51c351bfdd6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 8 May 2025 14:44:00 +0300 Subject: [PATCH 2/4] gdk: Take self by value in GLTextureBuilder for setting the color-state too --- gdk4/Gir.toml | 4 +-- gdk4/src/auto/gl_texture_builder.rs | 52 ----------------------------- gdk4/src/gl_texture_builder.rs | 17 ++++++++++ 3 files changed, 19 insertions(+), 54 deletions(-) diff --git a/gdk4/Gir.toml b/gdk4/Gir.toml index 14a525250b7e..e877434386c9 100644 --- a/gdk4/Gir.toml +++ b/gdk4/Gir.toml @@ -534,7 +534,7 @@ generate_builder = false name = "region" const = true [[object.function]] - pattern = "set_(context|format|has_mipmap|height|id|update_region|update_texture|width)" + pattern = "set_(color_state|context|format|has_mipmap|height|id|update_region|update_texture|width)" # Take by value and return self manual = true [[object.function]] @@ -544,7 +544,7 @@ generate_builder = false name = "build" manual = true [[object.property]] - pattern = "(context|format|has-mipmap|height|id|sync|update-region|update-texture|width)" + pattern = "(color-state|context|format|has-mipmap|height|id|sync|update-region|update-texture|width)" generate = [] # ignore get/set/notify [[object]] diff --git a/gdk4/src/auto/gl_texture_builder.rs b/gdk4/src/auto/gl_texture_builder.rs index 160fa999e68f..aeb8483d7e4d 100644 --- a/gdk4/src/auto/gl_texture_builder.rs +++ b/gdk4/src/auto/gl_texture_builder.rs @@ -7,15 +7,6 @@ use crate::ColorState; use crate::{ffi, GLContext, MemoryFormat, Texture}; use glib::translate::*; -#[cfg(feature = "v4_16")] -#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] -use glib::{ - prelude::*, - signal::{connect_raw, SignalHandlerId}, -}; -#[cfg(feature = "v4_16")] -#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] -use std::boxed::Box as Box_; glib::wrapper! { #[doc(alias = "GdkGLTextureBuilder")] @@ -116,49 +107,6 @@ impl GLTextureBuilder { pub fn width(&self) -> i32 { unsafe { ffi::gdk_gl_texture_builder_get_width(self.to_glib_none().0) } } - - #[cfg(feature = "v4_16")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] - #[doc(alias = "gdk_gl_texture_builder_set_color_state")] - #[doc(alias = "color-state")] - pub fn set_color_state(&self, color_state: &ColorState) { - unsafe { - ffi::gdk_gl_texture_builder_set_color_state( - self.to_glib_none().0, - color_state.to_glib_none().0, - ); - } - } - - #[cfg(feature = "v4_16")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] - #[doc(alias = "color-state")] - pub fn connect_color_state_notify( - &self, - f: F, - ) -> SignalHandlerId { - unsafe extern "C" fn notify_color_state_trampoline< - F: Fn(&GLTextureBuilder) + Send + Sync + 'static, - >( - this: *mut ffi::GdkGLTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::color-state".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_color_state_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } } #[cfg(feature = "v4_12")] diff --git a/gdk4/src/gl_texture_builder.rs b/gdk4/src/gl_texture_builder.rs index 4e27386c75ff..18377a71e914 100644 --- a/gdk4/src/gl_texture_builder.rs +++ b/gdk4/src/gl_texture_builder.rs @@ -2,6 +2,8 @@ use glib::{prelude::*, translate::*}; +#[cfg(feature = "v4_16")] +use crate::ColorState; use crate::{ffi, GLContext, GLTextureBuilder, MemoryFormat, Texture}; #[cfg(not(feature = "gl"))] @@ -43,6 +45,21 @@ impl GLTextureBuilder { )) } + #[cfg(feature = "v4_16")] + #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] + #[doc(alias = "gdk_gl_texture_builder_set_color_state")] + #[doc(alias = "color-state")] + pub fn set_color_state(self, color_state: &ColorState) -> Self { + unsafe { + ffi::gdk_gl_texture_builder_set_color_state( + self.to_glib_none().0, + color_state.to_glib_none().0, + ); + } + + self + } + #[doc(alias = "gdk_gl_texture_builder_set_context")] pub fn set_context(self, context: Option<&impl IsA>) -> Self { unsafe { From de7689ef46a53395408cfff8ea656343c046b765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 8 May 2025 14:51:26 +0300 Subject: [PATCH 3/4] gdk: Take self by value in MemoryTextureBuilder for consistency --- gdk4/Gir.toml | 7 + gdk4/src/auto/memory_texture_builder.rs | 345 +----------------------- gdk4/src/lib.rs | 3 + gdk4/src/memory_texture_builder.rs | 124 +++++++++ 4 files changed, 135 insertions(+), 344 deletions(-) create mode 100644 gdk4/src/memory_texture_builder.rs diff --git a/gdk4/Gir.toml b/gdk4/Gir.toml index e877434386c9..b339d91cd156 100644 --- a/gdk4/Gir.toml +++ b/gdk4/Gir.toml @@ -584,6 +584,13 @@ concurrency = "send+sync" [[object.function.parameter]] name = "region" const = true + [[object.function]] + pattern = "set_(bytes|color_state|format|height|offset|stride|stride_for_plane|update_region|update_texture|width)" + # Take by value and return self + manual = true + [[object.property]] + pattern = "(bytes|color-state|format|height|stride|update-region|update-texture|width)" + generate = [] # ignore get/set/notify [[object]] name = "Gdk.Monitor" diff --git a/gdk4/src/auto/memory_texture_builder.rs b/gdk4/src/auto/memory_texture_builder.rs index 4f48641428ce..dc80b97be922 100644 --- a/gdk4/src/auto/memory_texture_builder.rs +++ b/gdk4/src/auto/memory_texture_builder.rs @@ -3,12 +3,7 @@ // DO NOT EDIT use crate::{ffi, ColorState, MemoryFormat, Texture}; -use glib::{ - prelude::*, - signal::{connect_raw, SignalHandlerId}, - translate::*, -}; -use std::boxed::Box as Box_; +use glib::translate::*; glib::wrapper! { #[doc(alias = "GdkMemoryTextureBuilder")] @@ -119,344 +114,6 @@ impl MemoryTextureBuilder { pub fn width(&self) -> i32 { unsafe { ffi::gdk_memory_texture_builder_get_width(self.to_glib_none().0) } } - - #[doc(alias = "gdk_memory_texture_builder_set_bytes")] - #[doc(alias = "bytes")] - pub fn set_bytes(&self, bytes: Option<&glib::Bytes>) { - unsafe { - ffi::gdk_memory_texture_builder_set_bytes( - self.to_glib_none().0, - bytes.to_glib_none().0, - ); - } - } - - #[doc(alias = "gdk_memory_texture_builder_set_color_state")] - #[doc(alias = "color-state")] - pub fn set_color_state(&self, color_state: Option<&ColorState>) { - unsafe { - ffi::gdk_memory_texture_builder_set_color_state( - self.to_glib_none().0, - color_state.to_glib_none().0, - ); - } - } - - #[doc(alias = "gdk_memory_texture_builder_set_format")] - #[doc(alias = "format")] - pub fn set_format(&self, format: MemoryFormat) { - unsafe { - ffi::gdk_memory_texture_builder_set_format(self.to_glib_none().0, format.into_glib()); - } - } - - #[doc(alias = "gdk_memory_texture_builder_set_height")] - #[doc(alias = "height")] - pub fn set_height(&self, height: i32) { - unsafe { - ffi::gdk_memory_texture_builder_set_height(self.to_glib_none().0, height); - } - } - - #[cfg(feature = "v4_20")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))] - #[doc(alias = "gdk_memory_texture_builder_set_offset")] - pub fn set_offset(&self, plane: u32, offset: usize) { - unsafe { - ffi::gdk_memory_texture_builder_set_offset(self.to_glib_none().0, plane, offset); - } - } - - #[doc(alias = "gdk_memory_texture_builder_set_stride")] - #[doc(alias = "stride")] - pub fn set_stride(&self, stride: usize) { - unsafe { - ffi::gdk_memory_texture_builder_set_stride(self.to_glib_none().0, stride); - } - } - - #[cfg(feature = "v4_20")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))] - #[doc(alias = "gdk_memory_texture_builder_set_stride_for_plane")] - pub fn set_stride_for_plane(&self, plane: u32, stride: usize) { - unsafe { - ffi::gdk_memory_texture_builder_set_stride_for_plane( - self.to_glib_none().0, - plane, - stride, - ); - } - } - - #[doc(alias = "gdk_memory_texture_builder_set_update_region")] - #[doc(alias = "update-region")] - pub fn set_update_region(&self, region: Option<&cairo::Region>) { - unsafe { - ffi::gdk_memory_texture_builder_set_update_region( - self.to_glib_none().0, - mut_override(region.to_glib_none().0), - ); - } - } - - #[doc(alias = "gdk_memory_texture_builder_set_update_texture")] - #[doc(alias = "update-texture")] - pub fn set_update_texture(&self, texture: Option<&impl IsA>) { - unsafe { - ffi::gdk_memory_texture_builder_set_update_texture( - self.to_glib_none().0, - texture.map(|p| p.as_ref()).to_glib_none().0, - ); - } - } - - #[doc(alias = "gdk_memory_texture_builder_set_width")] - #[doc(alias = "width")] - pub fn set_width(&self, width: i32) { - unsafe { - ffi::gdk_memory_texture_builder_set_width(self.to_glib_none().0, width); - } - } - - #[cfg(feature = "v4_16")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] - #[doc(alias = "bytes")] - pub fn connect_bytes_notify( - &self, - f: F, - ) -> SignalHandlerId { - unsafe extern "C" fn notify_bytes_trampoline< - F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static, - >( - this: *mut ffi::GdkMemoryTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::bytes".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_bytes_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_16")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] - #[doc(alias = "color-state")] - pub fn connect_color_state_notify( - &self, - f: F, - ) -> SignalHandlerId { - unsafe extern "C" fn notify_color_state_trampoline< - F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static, - >( - this: *mut ffi::GdkMemoryTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::color-state".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_color_state_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_16")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] - #[doc(alias = "format")] - pub fn connect_format_notify( - &self, - f: F, - ) -> SignalHandlerId { - unsafe extern "C" fn notify_format_trampoline< - F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static, - >( - this: *mut ffi::GdkMemoryTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::format".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_format_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_16")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] - #[doc(alias = "height")] - pub fn connect_height_notify( - &self, - f: F, - ) -> SignalHandlerId { - unsafe extern "C" fn notify_height_trampoline< - F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static, - >( - this: *mut ffi::GdkMemoryTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::height".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_height_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_16")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] - #[doc(alias = "stride")] - pub fn connect_stride_notify( - &self, - f: F, - ) -> SignalHandlerId { - unsafe extern "C" fn notify_stride_trampoline< - F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static, - >( - this: *mut ffi::GdkMemoryTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::stride".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_stride_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_16")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] - #[doc(alias = "update-region")] - pub fn connect_update_region_notify( - &self, - f: F, - ) -> SignalHandlerId { - unsafe extern "C" fn notify_update_region_trampoline< - F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static, - >( - this: *mut ffi::GdkMemoryTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::update-region".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_update_region_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_16")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] - #[doc(alias = "update-texture")] - pub fn connect_update_texture_notify( - &self, - f: F, - ) -> SignalHandlerId { - unsafe extern "C" fn notify_update_texture_trampoline< - F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static, - >( - this: *mut ffi::GdkMemoryTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::update-texture".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_update_texture_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } - - #[cfg(feature = "v4_16")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] - #[doc(alias = "width")] - pub fn connect_width_notify( - &self, - f: F, - ) -> SignalHandlerId { - unsafe extern "C" fn notify_width_trampoline< - F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static, - >( - this: *mut ffi::GdkMemoryTextureBuilder, - _param_spec: glib::ffi::gpointer, - f: glib::ffi::gpointer, - ) { - let f: &F = &*(f as *const F); - f(&from_glib_borrow(this)) - } - unsafe { - let f: Box_ = Box_::new(f); - connect_raw( - self.as_ptr() as *mut _, - c"notify::width".as_ptr() as *const _, - Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( - notify_width_trampoline:: as *const (), - )), - Box_::into_raw(f), - ) - } - } } #[cfg(feature = "v4_16")] diff --git a/gdk4/src/lib.rs b/gdk4/src/lib.rs index 4ce8a188e219..908091a172ad 100644 --- a/gdk4/src/lib.rs +++ b/gdk4/src/lib.rs @@ -100,6 +100,9 @@ mod grab_broken_event; mod key_event; mod keymap_key; mod keys; +#[cfg(feature = "v4_16")] +#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] +mod memory_texture_builder; mod motion_event; mod pad_event; mod popup_layout; diff --git a/gdk4/src/memory_texture_builder.rs b/gdk4/src/memory_texture_builder.rs new file mode 100644 index 000000000000..85398611dc2f --- /dev/null +++ b/gdk4/src/memory_texture_builder.rs @@ -0,0 +1,124 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use crate::{ffi, ColorState, MemoryFormat, MemoryTextureBuilder, Texture}; +use glib::{prelude::*, translate::*}; + +impl MemoryTextureBuilder { + #[doc(alias = "gdk_memory_texture_builder_set_bytes")] + #[doc(alias = "bytes")] + pub fn set_bytes(self, bytes: Option<&glib::Bytes>) -> Self { + unsafe { + ffi::gdk_memory_texture_builder_set_bytes( + self.to_glib_none().0, + bytes.to_glib_none().0, + ); + } + + self + } + + #[doc(alias = "gdk_memory_texture_builder_set_color_state")] + #[doc(alias = "color-state")] + pub fn set_color_state(self, color_state: Option<&ColorState>) -> Self { + unsafe { + ffi::gdk_memory_texture_builder_set_color_state( + self.to_glib_none().0, + color_state.to_glib_none().0, + ); + } + + self + } + + #[doc(alias = "gdk_memory_texture_builder_set_format")] + #[doc(alias = "format")] + pub fn set_format(self, format: MemoryFormat) -> Self { + unsafe { + ffi::gdk_memory_texture_builder_set_format(self.to_glib_none().0, format.into_glib()); + } + + self + } + + #[doc(alias = "gdk_memory_texture_builder_set_height")] + #[doc(alias = "height")] + pub fn set_height(self, height: i32) -> Self { + unsafe { + ffi::gdk_memory_texture_builder_set_height(self.to_glib_none().0, height); + } + + self + } + + #[cfg(feature = "v4_20")] + #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))] + #[doc(alias = "gdk_memory_texture_builder_set_offset")] + pub fn set_offset(self, plane: u32, offset: usize) -> Self { + unsafe { + ffi::gdk_memory_texture_builder_set_offset(self.to_glib_none().0, plane, offset); + } + + self + } + + #[doc(alias = "gdk_memory_texture_builder_set_stride")] + #[doc(alias = "stride")] + pub fn set_stride(self, stride: usize) -> Self { + unsafe { + ffi::gdk_memory_texture_builder_set_stride(self.to_glib_none().0, stride); + } + + self + } + + #[cfg(feature = "v4_20")] + #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))] + #[doc(alias = "gdk_memory_texture_builder_set_stride_for_plane")] + pub fn set_stride_for_plane(self, plane: u32, stride: usize) -> Self { + unsafe { + ffi::gdk_memory_texture_builder_set_stride_for_plane( + self.to_glib_none().0, + plane, + stride, + ); + } + + self + } + + #[doc(alias = "gdk_memory_texture_builder_set_update_region")] + #[doc(alias = "update-region")] + pub fn set_update_region(self, region: Option<&cairo::Region>) -> Self { + unsafe { + ffi::gdk_memory_texture_builder_set_update_region( + self.to_glib_none().0, + mut_override(region.to_glib_none().0), + ); + } + + self + } + + #[doc(alias = "gdk_memory_texture_builder_set_update_texture")] + #[doc(alias = "update-texture")] + pub fn set_update_texture(self, texture: Option<&impl IsA>) -> Self { + unsafe { + ffi::gdk_memory_texture_builder_set_update_texture( + self.to_glib_none().0, + texture.map(|p| p.as_ref()).to_glib_none().0, + ); + } + + self + } + + #[doc(alias = "gdk_memory_texture_builder_set_width")] + #[doc(alias = "width")] + pub fn set_width(self, width: i32) -> Self { + unsafe { + ffi::gdk_memory_texture_builder_set_width(self.to_glib_none().0, width); + } + + self + } +} From 7f001388275d716f67b03e237d6bd4bcad78d41e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 8 May 2025 14:57:21 +0300 Subject: [PATCH 4/4] gdk: Use RawFd for DmabufTextureBuilder fd setter and mark function unsafe The fd must be valid for as long as the texture stays around, which can't be statically guaranteed and is job of the user, e.g. by using the release function. And use Borrowed fd for getter. --- gdk4/Gir.toml | 4 ++++ gdk4/src/auto/dmabuf_texture_builder.rs | 6 ------ gdk4/src/dmabuf_texture_builder.rs | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/gdk4/Gir.toml b/gdk4/Gir.toml index b339d91cd156..d693252524bc 100644 --- a/gdk4/Gir.toml +++ b/gdk4/Gir.toml @@ -453,6 +453,10 @@ status = "generate" # Take by value and return self manual = true [[object.function]] + pattern = "get_fd" + # Use BorrowedFd + manual = true + [[object.function]] name = "build" manual = true # Can't be auto-generated [[object.property]] diff --git a/gdk4/src/auto/dmabuf_texture_builder.rs b/gdk4/src/auto/dmabuf_texture_builder.rs index 1522e02a41f7..6c04b1b1aec8 100644 --- a/gdk4/src/auto/dmabuf_texture_builder.rs +++ b/gdk4/src/auto/dmabuf_texture_builder.rs @@ -47,12 +47,6 @@ impl DmabufTextureBuilder { } } - #[doc(alias = "gdk_dmabuf_texture_builder_get_fd")] - #[doc(alias = "get_fd")] - pub fn fd(&self, plane: u32) -> i32 { - unsafe { ffi::gdk_dmabuf_texture_builder_get_fd(self.to_glib_none().0, plane) } - } - #[doc(alias = "gdk_dmabuf_texture_builder_get_fourcc")] #[doc(alias = "get_fourcc")] pub fn fourcc(&self) -> u32 { diff --git a/gdk4/src/dmabuf_texture_builder.rs b/gdk4/src/dmabuf_texture_builder.rs index fcdfed029a7c..ec6b5ffff404 100644 --- a/gdk4/src/dmabuf_texture_builder.rs +++ b/gdk4/src/dmabuf_texture_builder.rs @@ -36,7 +36,7 @@ impl DmabufTextureBuilder { } #[doc(alias = "gdk_dmabuf_texture_builder_set_fd")] - pub fn set_fd(self, plane: u32, fd: i32) -> Self { + pub unsafe fn set_fd(self, plane: u32, fd: std::os::fd::RawFd) -> Self { unsafe { ffi::gdk_dmabuf_texture_builder_set_fd(self.to_glib_none().0, plane, fd); } @@ -44,6 +44,20 @@ impl DmabufTextureBuilder { self } + #[doc(alias = "gdk_dmabuf_texture_builder_get_fd")] + #[doc(alias = "get_fd")] + pub fn fd(&self, plane: u32) -> Option> { + unsafe { + let fd = ffi::gdk_dmabuf_texture_builder_get_fd(self.to_glib_none().0, plane); + + if fd == -1 { + None + } else { + Some(std::os::fd::BorrowedFd::borrow_raw(fd)) + } + } + } + #[doc(alias = "gdk_dmabuf_texture_builder_set_fourcc")] #[doc(alias = "fourcc")] pub fn set_fourcc(self, fourcc: u32) -> Self {