Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(desktop): support transparent camera cutout previews
Richie McIlroyd54e27a24002
diff --git a/apps/desktop/src-tauri/src/camera.rs b/apps/desktop/src-tauri/src/camera.rsindex f505e86b5..350bce064 100644--- a/apps/desktop/src-tauri/src/camera.rs+++ b/apps/desktop/src-tauri/src/camera.rs@@ -47,7 +47,7 @@ const CAMERA_PREVIEW_BLUR_MAX_TEXTURE_WIDTH: u32 = 640;const CAMERA_PREVIEW_BLUR_MAX_TEXTURE_HEIGHT: u32 = 360;const CAMERA_PREVIEW_TARGET_FRAME_INTERVAL: Duration = Duration::from_micros(16_666);const CAMERA_PREVIEW_FRAME_INTERVAL_SLACK: Duration = Duration::from_millis(1);-const CAMERA_PREVIEW_BLUR_INFERENCE_INTERVAL: Duration = Duration::from_millis(150);+const CAMERA_PREVIEW_BLUR_INFERENCE_INTERVAL: Duration = Duration::from_millis(33);// ── Low-spec preview profile ────────────────────────────────────────────────// On low-RAM machines (e.g. an 8GB iMac) the full-quality preview is laggy, so@@ -1637,10 +1637,14 @@ impl Renderer {(clamped_size - MIN_CAMERA_SIZE) / (MAX_CAMERA_SIZE - MIN_CAMERA_SIZE);let state_uniforms = StateUniforms {- shape: match state.shape {- CameraPreviewShape::Round => 0.0,- CameraPreviewShape::Square => 1.0,- CameraPreviewShape::Full => 2.0,+ shape: if state.background_blur == cap_project::BackgroundBlurMode::Remove {+ 3.0+ } else {+ match state.shape {+ CameraPreviewShape::Round => 0.0,+ CameraPreviewShape::Square => 1.0,+ CameraPreviewShape::Full => 2.0,+ }},size: normalized_size,mirrored: if state.mirrored { 1.0 } else { 0.0 },@@ -1875,6 +1879,9 @@ fn blur_mode_from_project(cap_project::BackgroundBlurMode::Off => None,cap_project::BackgroundBlurMode::Light => Some(cap_camera_effects::BlurMode::Light),cap_project::BackgroundBlurMode::Heavy => Some(cap_camera_effects::BlurMode::Heavy),+ cap_project::BackgroundBlurMode::Remove => {+ cfg!(target_os = "macos").then_some(cap_camera_effects::BlurMode::Remove)+ }}}diff --git a/apps/desktop/src-tauri/src/camera.wgsl b/apps/desktop/src-tauri/src/camera.wgslindex 332bf5b72..7d5354bc9 100644--- a/apps/desktop/src-tauri/src/camera.wgsl+++ b/apps/desktop/src-tauri/src/camera.wgsl@@ -174,6 +174,6 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {let camera_color = textureSample(t_camera, s_camera, final_uv);- let final_alpha = select(1.0, mask, mask < 0.95);+ let final_alpha = camera_color.a * select(1.0, mask, mask < 0.95);return vec4<f32>(camera_color.rgb, final_alpha);}diff --git a/apps/desktop/src-tauri/src/camera_legacy.rs b/apps/desktop/src-tauri/src/camera_legacy.rsindex b929d9a8e..b428e4d9a 100644--- a/apps/desktop/src-tauri/src/camera_legacy.rs+++ b/apps/desktop/src-tauri/src/camera_legacy.rs@@ -129,7 +129,8 @@ const WS_PREVIEW_BLUR_MAX_WIDTH: u32 = 640;const WS_PREVIEW_BLUR_MAX_HEIGHT: u32 = 360;const WS_PREVIEW_TARGET_FRAME_INTERVAL: Duration = Duration::from_micros(16_666);const WS_PREVIEW_FRAME_INTERVAL_SLACK: Duration = Duration::from_millis(1);-const WS_BLUR_INFERENCE_INTERVAL: Duration = Duration::from_millis(150);+const WS_BLUR_INFERENCE_INTERVAL: Duration =+ Duration::from_millis(if cfg!(target_os = "macos") { 33 } else { 150 });// Low-spec preview profile (mirrors the native path in camera.rs). Only used// when `is_low_spec_preview()` is true (machines <= 8GB RAM detected at@@ -439,6 +440,7 @@ pub async fn create_camera_preview_ws(cap_camera_effects::BlurMode::Light}cap_project::BackgroundBlurMode::Heavy => cap_camera_effects::BlurMode::Heavy,+ cap_project::BackgroundBlurMode::Remove => cap_camera_effects::BlurMode::Remove,};let (mut target_width, mut target_height) =scaled_preview_dimensions(frame.width(), frame.height(), &state);@@ -559,6 +561,11 @@ pub async fn create_camera_preview_ws(}}if ws_active {+ if blur_mode == cap_project::BackgroundBlurMode::Remove+ && matches!(blurred, Ok(None))+ {+ continue;+ }let (data, stride) = blurred.ok().flatten()@@ -610,6 +617,7 @@ struct WsBlurResources {source_texture: Option<(u32, u32, wgpu::Texture)>,readbacks: Option<(u32, u32, [WsReadback; 2])>,current_idx: usize,+ mode: Option<cap_camera_effects::BlurMode>,}impl WsBlurState {@@ -669,6 +677,12 @@ impl WsBlurState {.as_mut().ok_or("Requested camera blur initialization failed")?;+ if res.mode != Some(mode) {+ res.readbacks = None;+ res.current_idx = 0;+ res.mode = Some(mode);+ }+#[cfg(target_os = "linux")]if receipt.as_ref().is_some_and(|receipt| matches!(receipt.timestamp,cap_timestamp::Timestamp::Instant(captured) if captured.elapsed() > Duration::from_secs(1))) {@@ -699,26 +713,6 @@ impl WsBlurState {}};- res.queue.write_texture(- wgpu::TexelCopyTextureInfo {- texture: src,- mip_level: 0,- origin: wgpu::Origin3d::ZERO,- aspect: wgpu::TextureAspect::All,- },- rgba_data,- wgpu::TexelCopyBufferLayout {- offset: 0,- bytes_per_row: Some(stride),- rows_per_image: Some(height),- },- wgpu::Extent3d {- width,- height,- depth_or_array_layers: 1,- },- );-let bytes_per_row_aligned = (width * 4 + 255) & !255;let buf_size = (bytes_per_row_aligned * height) as u64;@@ -793,6 +787,26 @@ impl WsBlurState {};if let Some(idx) = issue_idx {+ res.queue.write_texture(+ wgpu::TexelCopyTextureInfo {+ texture: src,+ mip_level: 0,+ origin: wgpu::Origin3d::ZERO,+ aspect: wgpu::TextureAspect::All,+ },+ rgba_data,+ wgpu::TexelCopyBufferLayout {+ offset: 0,+ bytes_per_row: Some(stride),+ rows_per_image: Some(height),+ },+ wgpu::Extent3d {+ width,+ height,+ depth_or_array_layers: 1,+ },+ );+let output = res.processor.process(&res.device, &res.queue, src, mode);let mut encoder = res@@ -940,6 +954,7 @@ fn init_headless_blur() -> Result<WsBlurResources, String> {source_texture: None,readbacks: None,current_idx: 0,+ mode: None,})}diff --git a/apps/desktop/src-tauri/src/linux_instant_camera.rs b/apps/desktop/src-tauri/src/linux_instant_camera.rsindex 6bb6fb93a..56d0aaa7a 100644--- a/apps/desktop/src-tauri/src/linux_instant_camera.rs+++ b/apps/desktop/src-tauri/src/linux_instant_camera.rs@@ -342,7 +342,9 @@ fn processing(LinuxCameraProcessing {mirrored: state.mirrored,blur: match state.background_blur {- cap_project::BackgroundBlurMode::Off => LinuxCameraBlur::Off,+ cap_project::BackgroundBlurMode::Off | cap_project::BackgroundBlurMode::Remove => {+ LinuxCameraBlur::Off+ }cap_project::BackgroundBlurMode::Light => LinuxCameraBlur::Light,cap_project::BackgroundBlurMode::Heavy => LinuxCameraBlur::Heavy,},diff --git a/apps/desktop/src/routes/camera.tsx b/apps/desktop/src/routes/camera.tsxindex 61905af67..715652f69 100644--- a/apps/desktop/src/routes/camera.tsx+++ b/apps/desktop/src/routes/camera.tsx@@ -597,7 +597,7 @@ function LegacyCameraPreviewPage(props: {if (canvasControls === controls) updateFrameState(frame);},() => commands.refreshCameraFeed().catch(() => {}),- { powerPreference: "low-power" },+ { powerPreference: "low-power", preserveAlpha: type() === "macos" },);canvasControls = controls;initCanvasControls();@@ -999,8 +999,13 @@ function LegacyCameraPreviewPage(props: {<divref={containerRef}class={cx(- "flex flex-col flex-1 relative overflow-hidden pointer-events-none border-none shadow-lg bg-gray-1 text-gray-12",- state.shape === "round" ? "rounded-full" : "rounded-3xl",+ "flex flex-col flex-1 relative overflow-hidden pointer-events-none border-none text-gray-12",+ state.backgroundBlur !== "remove" && "shadow-lg bg-gray-1",+ state.backgroundBlur === "remove"+ ? "rounded-none"+ : state.shape === "round"+ ? "rounded-full"+ : "rounded-3xl",)}data-tauri-drag-region>