Rename the free_graphics_resources to component_destroyed

And do not iterate over the items anymore
This commit is contained in:
Olivier Goffart 2022-05-30 15:58:00 +02:00 committed by Olivier Goffart
parent 6cbf2c0609
commit ad2d19165a
10 changed files with 17 additions and 60 deletions

View file

@ -112,11 +112,11 @@ public:
float scale_factor() const { return slint_windowrc_get_scale_factor(&inner); }
void set_scale_factor(float value) const { slint_windowrc_set_scale_factor(&inner, value); }
template<typename Component, typename ItemArray>
void free_graphics_resources(Component *c, ItemArray items) const
template<typename Component>
void component_destroyed(Component *c) const
{
cbindgen_private::slint_component_free_item_array_graphics_resources(
vtable::VRef<ComponentVTable> { &Component::static_vtable, c }, items, &inner);
cbindgen_private::slint_component_destroyed(
vtable::VRef<ComponentVTable> { &Component::static_vtable, c }, &inner);
}
void set_focus_item(const ComponentRc &component_rc, uintptr_t item_index)

View file

@ -287,8 +287,8 @@ pub mod re_exports {
pub use i_slint_core::animations::EasingCurve;
pub use i_slint_core::callbacks::Callback;
pub use i_slint_core::component::{
free_component_item_graphics_resources, init_component_items, Component, ComponentRefPin,
ComponentVTable, ComponentWeak, IndexRange,
init_component_items, Component, ComponentRefPin, ComponentVTable, ComponentWeak,
IndexRange,
};
pub use i_slint_core::graphics::*;
pub use i_slint_core::input::{

View file

@ -299,11 +299,7 @@ impl PlatformWindow for GLWindow {
}
}
fn free_graphics_resources<'a>(
&self,
component: corelib::component::ComponentRef,
_items: &mut dyn Iterator<Item = Pin<ItemRef<'a>>>,
) {
fn component_destroyed<'a>(&self, component: corelib::component::ComponentRef) {
match &*self.map_state.borrow() {
GraphicsWindowBackendState::Unmapped => {}
GraphicsWindowBackendState::Mapped(_) => {

View file

@ -1515,11 +1515,7 @@ impl PlatformWindow for QtWindow {
}};
}
fn free_graphics_resources<'a>(
&self,
component: ComponentRef,
_: &mut dyn Iterator<Item = Pin<ItemRef<'a>>>,
) {
fn component_destroyed<'a>(&self, component: ComponentRef) {
self.cache.component_destroyed(component);
}

View file

@ -93,12 +93,7 @@ impl PlatformWindow for TestingWindow {
fn request_redraw(&self) {}
fn free_graphics_resources<'a>(
&self,
_: i_slint_core::component::ComponentRef,
_items: &mut dyn Iterator<Item = Pin<i_slint_core::items::ItemRef<'a>>>,
) {
}
fn component_destroyed<'a>(&self, _: i_slint_core::component::ComponentRef) {}
fn show_popup(&self, _popup: &ComponentRc, _position: i_slint_core::graphics::Point) {
todo!()

View file

@ -1091,10 +1091,8 @@ fn generate_item_tree(
let mut destructor = vec!["auto self = this;".to_owned()];
destructor.push(format!(
"{}->m_window.window_handle().free_graphics_resources(self, item_array());",
root_access
));
destructor
.push(format!("{}->m_window.window_handle().component_destroyed(self);", root_access));
target_struct.members.push((
Access::Public,

View file

@ -1124,7 +1124,7 @@ fn generate_item_tree(
fn drop(self: core::pin::Pin<&mut #inner_component_id>) {
use slint::re_exports::*;
new_vref!(let vref : VRef<ComponentVTable> for Component = self.as_ref().get_ref());
slint::re_exports::free_component_item_graphics_resources(self.as_ref(), vref, Self::item_array(), self.window.get().unwrap().window_handle());
self.window.get().unwrap().window_handle().component_destroyed(vref);
}
}

View file

@ -105,19 +105,6 @@ pub fn init_component_items<Base>(
item_array.iter().for_each(|item| item.apply_pin(base).as_ref().init(window));
}
/// Free the backend graphics resources allocated by the component's items.
pub fn free_component_item_graphics_resources<Base>(
base: core::pin::Pin<&Base>,
component: ComponentRef,
item_array: &[vtable::VOffset<Base, ItemVTable, vtable::AllowPin>],
window: &WindowRc,
) {
window.free_graphics_resources(
component,
&mut item_array.iter().map(|item| item.apply_pin(base)),
);
}
#[cfg(feature = "ffi")]
pub(crate) mod ffi {
#![allow(unsafe_code)]
@ -141,17 +128,11 @@ pub(crate) mod ffi {
/// Free the backend graphics resources allocated in the item array.
#[no_mangle]
pub unsafe extern "C" fn slint_component_free_item_array_graphics_resources(
component: ComponentRefPin,
item_array: Slice<vtable::VOffset<u8, ItemVTable, vtable::AllowPin>>,
pub unsafe extern "C" fn slint_component_destroyed(
component: ComponentRef,
window_handle: *const crate::window::ffi::WindowRcOpaque,
) {
let window = &*(window_handle as *const WindowRc);
super::free_component_item_graphics_resources(
core::pin::Pin::new_unchecked(&*(component.as_ptr() as *const u8)),
core::pin::Pin::into_inner(component),
item_array.as_slice(),
window,
)
window.component_destroyed(component)
}
}

View file

@ -41,11 +41,7 @@ pub trait PlatformWindow {
/// This function is called by the generated code when a component and therefore its tree of items are destroyed. The
/// implementation typically uses this to free the underlying graphics resources cached via [`crate::graphics::RenderingCache`].
fn free_graphics_resources<'a>(
&self,
component: ComponentRef,
items: &mut dyn Iterator<Item = Pin<ItemRef<'a>>>,
);
fn component_destroyed(&self, component: ComponentRef);
/// This function is called through the public API to register a callback that the backend needs to invoke during
/// different phases of rendering.

View file

@ -68,12 +68,7 @@ impl<'id> Drop for ComponentBox<'id> {
fn drop(&mut self) {
let instance_ref = self.borrow_instance();
if let Some(window) = eval::window_ref(instance_ref) {
i_slint_core::component::free_component_item_graphics_resources(
instance_ref.instance,
Pin::into_inner(instance_ref.borrow()),
instance_ref.component_type.item_array.as_slice(),
window,
);
window.component_destroyed(Pin::into_inner(instance_ref.borrow()))
}
}
}