From 8230faf082c405c9fd0fa640f4ce2284315782ae Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Mon, 13 Apr 2026 04:40:29 +0200 Subject: feat: wasm compositor Made-with: Cursor --- rust/crates/compositor/src/texture_pool.rs | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 rust/crates/compositor/src/texture_pool.rs (limited to 'rust/crates/compositor/src/texture_pool.rs') diff --git a/rust/crates/compositor/src/texture_pool.rs b/rust/crates/compositor/src/texture_pool.rs new file mode 100644 index 00000000..f2c59ee7 --- /dev/null +++ b/rust/crates/compositor/src/texture_pool.rs @@ -0,0 +1,36 @@ +use std::collections::HashMap; + +use gpu::{GpuContext, wgpu}; + +type TextureKey = (u32, u32); + +#[derive(Default)] +pub struct TexturePool { + available: HashMap>, + in_use: Vec<(TextureKey, wgpu::Texture)>, +} + +impl TexturePool { + pub fn recycle_frame(&mut self) { + for (key, texture) in self.in_use.drain(..) { + self.available.entry(key).or_default().push(texture); + } + } + + pub fn acquire( + &mut self, + context: &GpuContext, + width: u32, + height: u32, + label: &'static str, + ) -> wgpu::Texture { + let key = (width, height); + let texture = self + .available + .get_mut(&key) + .and_then(Vec::pop) + .unwrap_or_else(|| context.create_render_texture(width, height, label)); + self.in_use.push((key, texture.clone())); + texture + } +} -- cgit v1.3.1