Skip to content
Merged
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
12 changes: 12 additions & 0 deletions apps/desktop-gpui/src/editor_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,11 @@ impl EditorWindow {
});

loop {
let mut latest: Option<(u32, u32)> = None;
while let Ok((rendered, total)) = progress_rx.try_recv() {
latest = Some((rendered, total));
}
if let Some((rendered, total)) = latest {
let _ = this.update(cx, |this, cx| {
if let Some(ui) = this.export.as_mut() {
ui.rendered = rendered;
Expand Down Expand Up @@ -1184,7 +1188,11 @@ impl EditorWindow {
});

loop {
let mut latest: Option<(u32, u32)> = None;
while let Ok((rendered, total)) = progress_rx.try_recv() {
latest = Some((rendered, total));
}
if let Some((rendered, total)) = latest {
let _ = this.update(cx, |this, cx| {
if let Some(ui) = this.export.as_mut() {
ui.rendered = rendered;
Expand Down Expand Up @@ -1229,7 +1237,11 @@ impl EditorWindow {
});

loop {
let mut latest: Option<f64> = None;
while let Ok(progress) = upload_rx.try_recv() {
latest = Some(progress);
}
if let Some(progress) = latest {
let _ = this.update(cx, |this, cx| {
if let Some(ui) = this.export.as_mut() {
ui.upload_progress = progress as f32;
Expand Down
7 changes: 5 additions & 2 deletions crates/editor/src/editor_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
collections::HashMap,
Expand Down Expand Up @@ -248,6 +248,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>,
}
Expand Down Expand Up @@ -655,6 +656,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,
Expand Down Expand Up @@ -781,6 +783,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(),
});
Expand Down
31 changes: 26 additions & 5 deletions crates/export/src/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct PreviewSource<'a> {
render_constants: &'a RenderVideoConstants,
segments: Vec<PreviewSegment<'a>>,
total_duration: f64,
layers_cache: Option<&'a std::sync::Mutex<Option<RendererLayers>>>,
}

struct PreviewSegment<'a> {
Expand Down Expand Up @@ -130,6 +131,7 @@ async fn render_preview_with_base(
})
.collect(),
total_duration,
layers_cache: None,
};
render_preview_frame(source, frame_time, settings).await
}
Expand Down Expand Up @@ -184,6 +186,7 @@ pub async fn render_preview_with_editor(
})
.collect(),
total_duration,
layers_cache: Some(&editor.preview_layers),
};
render_preview_frame(source, frame_time, settings).await
}
Expand Down Expand Up @@ -219,6 +222,7 @@ async fn render_preview_frame(
render_constants,
segments,
total_duration,
layers_cache,
} = source;
let project_config = &Arc::new(project_config.clone());
let transition_mapping = project_config.timeline.as_ref().and_then(|timeline| {
Expand Down Expand Up @@ -286,11 +290,22 @@ async fn render_preview_frame(
);

let mut frame_renderer = FrameRenderer::new(render_constants);
let mut layers = RendererLayers::new_with_options(
&render_constants.device,
&render_constants.queue,
render_constants.is_software_adapter,
);
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,
&render_constants.queue,
render_constants.is_software_adapter,
)
});

let frame = if let Some((outgoing, kind, progress)) = transition_mapping {
let outgoing_media = segments
Expand Down Expand Up @@ -392,6 +407,12 @@ async fn render_preview_frame(
(total_bitrate * encoder_efficiency * duration_seconds) / (8.0 * 1024.0 * 1024.0)
};

if let Some(cache) = layers_cache
&& let Ok(mut guard) = cache.lock()
{
*guard = Some(layers);
}

Ok(ExportPreviewResult {
jpeg_base64: STANDARD.encode(&jpeg_buffer),
estimated_size_mb,
Expand Down
2 changes: 2 additions & 0 deletions crates/rendering/src/layers/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ impl CursorLayer {
let time_s = segment_frames.recording_time;

let Some(interpolated_cursor) = &uniforms.interpolated_cursor else {
self.bind_group = None;
return;
};

Expand Down Expand Up @@ -565,6 +566,7 @@ impl CursorLayer {
}
let Some(tex) = self.cursors.get(&interpolated_cursor.cursor_id) else {
error!("Cursor {:?} not found!", interpolated_cursor.cursor_id);
self.bind_group = None;
return;
};
tex
Expand Down
2 changes: 1 addition & 1 deletion crates/rendering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8116,7 +8116,7 @@ fn join_layer<T>(handle: std::thread::ScopedJoinHandle<'_, T>) -> T {
}

impl RendererLayers {
fn reset_frame_state(&mut self) {
pub fn reset_frame_state(&mut self) {
self.display.reset_frame_state();
self.camera.reset_frame_state();
self.camera_only.reset_frame_state();
Expand Down
Loading