Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

improve: keep preview layers on EditorInstance instead of process-wide pool

Wraient90e36b6c6cc2
diff --git a/crates/editor/src/editor_instance.rs b/crates/editor/src/editor_instance.rs
index f670c27a4..81f4953cd 100644
--- a/crates/editor/src/editor_instance.rs
+++ b/crates/editor/src/editor_instance.rs
@@ -8,8 +8,8 @@ use cap_project::{
};
use cap_rendering::{
PrecomputedCursorTimeline, ProjectRecordingsMeta, ProjectUniforms, RecordingSegmentDecoders,
- RenderVideoConstants, SegmentVideoPaths, SharedWgpuDevice, Video, ZoomTransformTimeline,
- get_duration, spring_mass_damper::SpringMassDamperSimulationConfig,
+ RenderVideoConstants, RendererLayers, SegmentVideoPaths, SharedWgpuDevice, Video,
+ ZoomTransformTimeline, get_duration, spring_mass_damper::SpringMassDamperSimulationConfig,
};
use std::{
path::{Path, PathBuf},
@@ -201,6 +201,7 @@ pub struct EditorInstance {
meta: RecordingMeta,
pub export_preview_active: AtomicBool,
pub export_active: AtomicBool,
+ pub preview_layers: std::sync::Mutex<Option<RendererLayers>>,
runtime_handle: tokio::runtime::Handle,
audio_output: Arc<crate::AudioOutput>,
}
@@ -600,6 +601,7 @@ impl EditorInstance {
playback_active_rx,
export_preview_active: AtomicBool::new(false),
export_active: AtomicBool::new(false),
+ preview_layers: std::sync::Mutex::new(None),
playback_epoch: AtomicU64::new(0),
runtime_handle: tokio::runtime::Handle::current(),
audio_output,
@@ -726,6 +728,7 @@ impl EditorInstance {
meta: self.meta.clone(),
export_preview_active: AtomicBool::new(false),
export_active: AtomicBool::new(false),
+ preview_layers: std::sync::Mutex::new(None),
runtime_handle: self.runtime_handle.clone(),
audio_output: self.audio_output.clone(),
});
diff --git a/crates/export/src/preview.rs b/crates/export/src/preview.rs
index 567ee0e90..218f44e33 100644
--- a/crates/export/src/preview.rs
+++ b/crates/export/src/preview.rs
@@ -100,7 +100,7 @@ struct PreviewSource<'a> {
render_constants: &'a RenderVideoConstants,
segments: Vec<PreviewSegment<'a>>,
total_duration: f64,
- layers_reuse_key: Option<String>,
+ layers_cache: Option<&'a std::sync::Mutex<Option<RendererLayers>>>,
}
struct PreviewSegment<'a> {
@@ -131,7 +131,7 @@ async fn render_preview_with_base(
})
.collect(),
total_duration,
- layers_reuse_key: None,
+ layers_cache: None,
};
render_preview_frame(source, frame_time, settings).await
}
@@ -186,7 +186,7 @@ pub async fn render_preview_with_editor(
})
.collect(),
total_duration,
- layers_reuse_key: Some(format!("preview:{}", editor.project_path.display())),
+ layers_cache: Some(&editor.preview_layers),
};
render_preview_frame(source, frame_time, settings).await
}
@@ -222,7 +222,7 @@ async fn render_preview_frame(
render_constants,
segments,
total_duration,
- layers_reuse_key,
+ layers_cache,
} = source;
let transition_mapping = project_config.timeline.as_ref().and_then(|timeline| {
if timeline.transitions.is_empty() {
@@ -289,9 +289,15 @@ async fn render_preview_frame(
);
let mut frame_renderer = FrameRenderer::new(render_constants);
- let mut layers = layers_reuse_key
- .as_deref()
- .and_then(|key| cap_rendering::take_reusable_layers(&render_constants.device, key))
+ let mut layers = layers_cache
+ .and_then(|cache| {
+ let mut guard = cache.lock().ok()?;
+ guard.take()
+ })
+ .map(|mut cached| {
+ cached.reset_frame_state();
+ cached
+ })
.unwrap_or_else(|| {
RendererLayers::new_with_options(
&render_constants.device,
@@ -396,8 +402,10 @@ async fn render_preview_frame(
(total_bitrate * encoder_efficiency * duration_seconds) / (8.0 * 1024.0 * 1024.0)
};
- if let Some(key) = layers_reuse_key {
- cap_rendering::return_reusable_layers(render_constants.device.clone(), key, layers);
+ if let Some(cache) = layers_cache {
+ if let Ok(mut guard) = cache.lock() {
+ *guard = Some(layers);
+ }
}
Ok(ExportPreviewResult {