Create shm slot pools per output instead of using one in the global state

This allows the release of graphics memory per output when an output is
destroyed, unlike when we had only one shm slot pool that cannot shrink

Hopefully this will help with a claimed leak of graphics memory:
https://github.com/gergo-salyi/multibg-sway/issues/2
This commit is contained in:
Gergő Sályi 2023-08-31 17:35:35 +02:00
parent 54809851d9
commit 71dc725ec7
2 changed files with 26 additions and 22 deletions

View file

@ -24,7 +24,7 @@ use smithay_client_toolkit::{
output::OutputState,
registry::RegistryState,
shell::wlr_layer::LayerShell,
shm::{Shm, slot::SlotPool},
shm::Shm,
};
use smithay_client_toolkit::reexports::client::{
Connection, EventQueue,
@ -67,9 +67,9 @@ fn main()
let layer_shell = LayerShell::bind(&globals, &qh).unwrap();
let shm = Shm::bind(&globals, &qh).unwrap();
// Initialize slot pool with a minimum size (0 is not allowed)
// it will be automatically resized later
let shm_slot_pool = SlotPool::new(1, &shm).unwrap();
// // Initialize slot pool with a minimum size (0 is not allowed)
// // it will be automatically resized later
// let shm_slot_pool = SlotPool::new(1, &shm).unwrap();
// Sync tools for sway ipc tasks
let mut poll = Poll::new().unwrap();
@ -81,7 +81,7 @@ fn main()
registry_state: RegistryState::new(&globals),
output_state: OutputState::new(&globals, &qh),
shm,
shm_slot_pool,
// shm_slot_pool,
layer_shell,
wallpaper_dir,
pixel_format: None,

View file

@ -35,7 +35,6 @@ pub struct State {
pub registry_state: RegistryState,
pub output_state: OutputState,
pub shm: Shm,
pub shm_slot_pool: SlotPool,
pub layer_shell: LayerShell,
pub wallpaper_dir: PathBuf,
pub pixel_format: Option<wl_shm::Format>,
@ -177,11 +176,6 @@ impl OutputHandler for State {
output_name, width, height
);
debug!(
"Slot pool size before loading wallpapers: {} KiB",
self.shm_slot_pool.len() / 1024
);
let surface = self.compositor_state.create_surface(qh);
let layer = self.layer_shell.create_layer_surface(
@ -202,9 +196,13 @@ impl OutputHandler for State {
let output_wallpaper_dir = self.wallpaper_dir.join(&output_name);
// Initialize slot pool with a minimum size (0 is not allowed)
// it will be automatically resized later
let mut shm_slot_pool = SlotPool::new(1, &self.shm).unwrap();
let workspace_backgrounds = match workspace_bgs_from_output_image_dir(
&output_wallpaper_dir,
&mut self.shm_slot_pool,
&mut shm_slot_pool,
pixel_format,
self.brightness,
self.contrast,
@ -231,8 +229,9 @@ impl OutputHandler for State {
};
debug!(
"Slot pool size after loading wallpapers: {} KiB",
self.shm_slot_pool.len() / 1024
"Shm slot pool size for output '{}' after loading wallpapers: {} KiB",
output_name,
shm_slot_pool.len() / 1024
);
self.background_layers.push(BackgroundLayer {
@ -242,7 +241,15 @@ impl OutputHandler for State {
layer,
configured: false,
workspace_backgrounds,
shm_slot_pool,
});
debug!(
"New sum of shm slot pool sizes for all outputs: {} KiB",
self.background_layers.iter()
.map(|bg_layer| bg_layer.shm_slot_pool.len())
.sum::<usize>() / 1024
);
}
fn update_output(
@ -321,12 +328,6 @@ impl OutputHandler for State {
"Output destroyed: {}",
name,
);
debug!(
"Slot pool size before dropping wallpapers: {} KiB",
self.shm_slot_pool.len() / 1024,
);
if let Some(bg_layer_index) = self.background_layers.iter()
.position(|bg_layers| bg_layers.output_name == name)
@ -369,8 +370,10 @@ impl OutputHandler for State {
}
debug!(
"Slot pool size after dropping wallpapers: {} KiB",
self.shm_slot_pool.len() / 1024
"New sum of shm slot pool sizes for all outputs: {} KiB",
self.background_layers.iter()
.map(|bg_layer| bg_layer.shm_slot_pool.len())
.sum::<usize>() / 1024
);
}
}
@ -401,6 +404,7 @@ pub struct BackgroundLayer {
pub layer: LayerSurface,
pub configured: bool,
pub workspace_backgrounds: Vec<WorkspaceBackground>,
pub shm_slot_pool: SlotPool
}
impl BackgroundLayer
{