use cranpose_core::collections::growth_slack::GrowthSlack;
use super::LayerScene;
use crate::scene::{CompositorScene, SceneCapacityHint};
#[derive(Default)]
pub(crate) struct LayerSceneRecycler {
#[expect(clippy::vec_box, reason = "scenes are recycled by box, so none moves")]
scenes: Vec<Box<LayerScene>>,
}
impl LayerSceneRecycler {
pub(crate) fn take(&mut self, capacity: SceneCapacityHint) -> Box<LayerScene> {
match self.scenes.pop() {
Some(mut scene) => {
scene.has_backdrop = false;
scene
}
None => Box::new(LayerScene::new(
CompositorScene::with_capacity(capacity),
Vec::new(),
)),
}
}
pub(crate) fn recycle(&mut self, mut scene: Box<LayerScene>) {
while let Some(child) = scene.children.pop() {
self.recycle(child.content);
}
scene.scene.settle_room();
scene.scene.clear();
scene.has_backdrop = false;
scene.shown.clear();
self.scenes.push(scene);
}
pub(crate) fn clear(&mut self) {
self.scenes.clear();
}
pub(crate) fn trim(&mut self) {
self.scenes.clear();
self.scenes.trim_growth_slack();
crate::scene::trim_scene_buffer_pool();
}
}