ferroui_base/rendering/composition/server/
compositor_pools.rs1use super::{IDirtyRectCollector, TreeWalkerFrame};
2use crate::platform::LtrbRect;
3use crate::Matrix;
4use std::cell::RefCell;
5use std::rc::Rc;
6
7pub struct StackPool<T> {
9 stacks: RefCell<Vec<Vec<T>>>,
10}
11
12impl<T> Default for StackPool<T> {
13 fn default() -> Self {
14 Self { stacks: RefCell::new(Vec::new()) }
15 }
16}
17
18impl<T> StackPool<T> {
19 pub fn rent(&self) -> Vec<T> {
20 self.stacks.borrow_mut().pop().unwrap_or_default()
21 }
22
23 pub fn return_stack(&self, mut stack: Vec<T>) {
24 stack.clear();
25 self.stacks.borrow_mut().push(stack);
26 }
27}
28
29#[derive(Default)]
31pub struct CompositorPools {
32 pub tree_walker_frame_stack_pool: StackPool<TreeWalkerFrame>,
33 pub matrix_stack_pool: StackPool<Matrix>,
34 pub ltrb_rect_stack_pool: StackPool<LtrbRect>,
35 pub double_stack_pool: StackPool<f64>,
36 pub int_stack_pool: StackPool<i32>,
37 pub dirty_rect_collector_stack_pool: StackPool<Rc<dyn IDirtyRectCollector>>,
38}