Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
refactor(rendering): wire background cache and alpha through pipeline
Richie McIlroy503ce3d2bc7d
diff --git a/crates/rendering/src/layers/cursor.rs b/crates/rendering/src/layers/cursor.rsindex ce093260f..5a51a903c 100644--- a/crates/rendering/src/layers/cursor.rs+++ b/crates/rendering/src/layers/cursor.rs@@ -941,6 +941,7 @@ mod tests {let options = crate::RenderOptions {camera_size: None,screen_size: XY::new(1080, 1080),+ preserve_screen_alpha: false,};let mut project = ProjectConfiguration::default();project.background.padding = 0.0;diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rsindex ceebed81b..d901544bf 100644--- a/crates/rendering/src/lib.rs+++ b/crates/rendering/src/lib.rs@@ -21,10 +21,7 @@ use layers::{};use specta::Type;use spring_mass_damper::SpringMassDamperSimulationConfig;-use std::{- collections::HashMap,- sync::{Arc, Mutex},-};+use std::sync::{Arc, Mutex};use std::{path::PathBuf, time::Instant};use tokio::sync::mpsc;@@ -51,8 +48,18 @@ pub mod zoom_focus_interpolation;pub use coord::*;pub use decoder::{DecodedFrame, DecoderStatus, DecoderType, PixelFormat};pub use frame_pipeline::{GpuOutputFormat, Nv12RenderedFrame, RenderedFrame, SharedNv12Buffer};+pub use layers::{BackgroundTextureCache, clean_background_path};pub use project_recordings::{ProjectRecordingsMeta, SegmentRecordings, Video};+/// Warms the process-wide system-font scan used by the text/captions/keyboard+/// layers. The first scan is the slow part (hundreds of ms to over a second on+/// macOS); calling this off the hot path at startup keeps the first editor or+/// screenshot-editor open fast. Subsequent `FontSystem` creations clone the cached+/// font database cheaply.+pub fn prewarm_fonts() {+ drop(layers::new_font_system());+}+pub use cursor_interpolation::PrecomputedCursorTimeline;use mask::interpolate_masks;use scene::*;@@ -200,6 +207,7 @@ fn rounding_type_value(style: CornerStyle) -> f32 {pub struct RenderOptions {pub camera_size: Option<XY<u32>>,pub screen_size: XY<u32>,+ pub preserve_screen_alpha: bool,}#[derive(Debug, Clone, Copy)]@@ -1502,7 +1510,7 @@ pub struct RenderVideoConstants {pub options: RenderOptions,pub meta: StudioRecordingMeta,pub recording_meta: RecordingMeta,- pub background_textures: std::sync::Arc<tokio::sync::RwLock<HashMap<String, wgpu::Texture>>>,+ pub background_textures: std::sync::Arc<BackgroundTextureCache>,pub is_software_adapter: bool,adapter_name: String,}@@ -1530,9 +1538,10 @@ impl RenderVideoConstants {.camera.as_ref().map(|c| XY::new(c.width, c.height)),+ preserve_screen_alpha: false,};- let background_textures = Arc::new(tokio::sync::RwLock::new(HashMap::new()));+ let background_textures = Arc::new(BackgroundTextureCache::default());let adapter_name = shared.adapter.get_info().name;@@ -1559,6 +1568,7 @@ impl RenderVideoConstants {options: RenderOptions,meta: StudioRecordingMeta,recording_meta: RecordingMeta,+ background_textures: Arc<BackgroundTextureCache>,) -> Self {let adapter_name = shared.adapter.get_info().name;Self {@@ -1567,7 +1577,7 @@ impl RenderVideoConstants {device: shared.device,queue: shared.queue,options,- background_textures: Arc::new(tokio::sync::RwLock::new(HashMap::new())),+ background_textures,meta,recording_meta,is_software_adapter: shared.is_software_adapter,@@ -1588,6 +1598,7 @@ impl RenderVideoConstants {.camera.as_ref().map(|c| XY::new(c.width, c.height)),+ preserve_screen_alpha: false,};let instance = create_wgpu_instance().await;@@ -1665,7 +1676,7 @@ impl RenderVideoConstants {let (device, queue) = adapter.request_device(&device_descriptor).await?;- let background_textures = Arc::new(tokio::sync::RwLock::new(HashMap::new()));+ let background_textures = Arc::new(BackgroundTextureCache::default());Ok(Self {_instance: instance,@@ -3038,7 +3049,12 @@ impl ProjectUniforms {0.0},border_width: project.background.border.as_ref().map_or(5.0, |b| b.width),- _padding1: [0.0; 4],+ preserve_source_alpha: if options.preserve_screen_alpha {+ 1.0+ } else {+ 0.0+ },+ _padding1: [0.0; 3],border_color: if let Some(b) = project.background.border.as_ref() {[b.color[0] as f32 / 255.0,@@ -3236,7 +3252,8 @@ impl ProjectUniforms {opacity: scene.regular_camera_transition_opacity() as f32,border_enabled: 0.0,border_width: 0.0,- _padding1: [0.0; 4],+ preserve_source_alpha: 0.0,+ _padding1: [0.0; 3],border_color: [0.0, 0.0, 0.0, 0.0],}});@@ -3327,7 +3344,8 @@ impl ProjectUniforms {opacity: scene.camera_only_transition_opacity() as f32,border_enabled: 0.0,border_width: 0.0,- _padding1: [0.0; 4],+ preserve_source_alpha: 0.0,+ _padding1: [0.0; 3],border_color: [0.0, 0.0, 0.0, 0.0],}});@@ -3390,6 +3408,7 @@ mod tests {RenderOptions {screen_size: XY::new(screen_width, screen_height),camera_size: None,+ preserve_screen_alpha: false,}}@@ -4207,7 +4226,10 @@ impl RendererLayers {.prepare(constants,uniforms,- Background::from(uniforms.project.background.source.clone()),+ Background::from_source(+ uniforms.project.background.source.clone(),+ constants.options.preserve_screen_alpha,+ ),).await?;@@ -4324,7 +4346,10 @@ impl RendererLayers {.prepare(constants,uniforms,- Background::from(uniforms.project.background.source.clone()),+ Background::from_source(+ uniforms.project.background.source.clone(),+ constants.options.preserve_screen_alpha,+ ),).await?;timings.background_prepare_duration = start.elapsed();