Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions apps/desktop/src-tauri/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<u8>, u32) {
Expand Down
21 changes: 18 additions & 3 deletions apps/desktop/src-tauri/src/general_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Loading