From 543690172dd75e2b8017c55a76661e238a97c159 Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Thu, 14 Aug 2025 00:32:00 +0800 Subject: [PATCH] wip --- apps/desktop/src-tauri/src/camera.rs | 25 +++++++++++++++++++ .../desktop/src-tauri/src/general_settings.rs | 21 +++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src-tauri/src/camera.rs b/apps/desktop/src-tauri/src/camera.rs index e587fa90f..1aedf0fc4 100644 --- a/apps/desktop/src-tauri/src/camera.rs +++ b/apps/desktop/src-tauri/src/camera.rs @@ -23,6 +23,7 @@ use tauri_plugin_store::Store; use tokio::sync::{broadcast, oneshot}; use tracing::error; use wgpu::{CompositeAlphaMode, SurfaceTexture}; +use crate::general_settings::GeneralSettingsStore; static TOOLBAR_HEIGHT: f32 = 56.0; // also defined in Typescript @@ -83,6 +84,22 @@ impl CameraPreview { let mut renderer = Renderer::init(window.clone()).await?; + // Update camera preview setting based on GPU composite alpha support + let supports_transparency = renderer.supports_transparency(); + tracing::info!( + "GPU transparency support detected: {}, updating camera preview setting", + supports_transparency + ); + + if let Err(e) = GeneralSettingsStore::update_camera_preview_for_gpu_support( + &window.app_handle(), + supports_transparency + ) { + error!("Failed to update camera preview setting based on GPU support: {}", e); + } else { + tracing::info!("Successfully updated camera preview setting based on GPU capabilities"); + } + let store = self.store.clone(); let mut reconfigure = self.reconfigure.1.resubscribe(); let loading_state = self.loading.clone(); @@ -794,6 +811,14 @@ impl Renderer { self.queue.submit(Some(encoder.finish())); surface.present(); } + + /// Check if the renderer supports transparency via composite alpha modes + fn supports_transparency(&self) -> bool { + matches!( + self.surface_config.alpha_mode, + CompositeAlphaMode::PreMultiplied | CompositeAlphaMode::PostMultiplied + ) + } } fn render_solid_frame(color: [u8; 4], width: u32, height: u32) -> (Vec, u32) { diff --git a/apps/desktop/src-tauri/src/general_settings.rs b/apps/desktop/src-tauri/src/general_settings.rs index cd178ae39..eb4b3e104 100644 --- a/apps/desktop/src-tauri/src/general_settings.rs +++ b/apps/desktop/src-tauri/src/general_settings.rs @@ -98,10 +98,10 @@ pub struct GeneralSettingsStore { pub post_deletion_behaviour: PostDeletionBehaviour, } +// Initial default based on OS - this will be updated dynamically after GPU initialization +// to reflect actual composite alpha mode support fn default_enable_native_camera_preview() -> bool { - // TODO: - // cfg!(target_os = "macos") - false + cfg!(any(target_os = "macos", target_os = "windows")) } fn default_enable_new_recording_flow() -> bool { @@ -183,6 +183,21 @@ impl GeneralSettingsStore { } } + /// Update the native camera preview setting based on GPU composite alpha support. + /// + /// This method is called after GPU initialization to determine if the hardware + /// actually supports transparency via CompositeAlphaMode::PreMultiplied or + /// CompositeAlphaMode::PostMultiplied. The native camera preview requires + /// transparency support to render properly. + pub fn update_camera_preview_for_gpu_support(app: &AppHandle, supports_composite_alpha: bool) -> Result<(), String> { + // Only enable on macOS/Windows if GPU actually supports transparency + let should_enable = cfg!(any(target_os = "macos", target_os = "windows")) && supports_composite_alpha; + + Self::update(app, |settings| { + settings.enable_native_camera_preview = should_enable; + }) + } + // i don't trust anyone to not overwrite the whole store lols pub fn update(app: &AppHandle, update: impl FnOnce(&mut Self)) -> Result<(), String> { let Ok(store) = app.store("store") else {