Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

improve: avoid cloning CursorEvents per frame, use Arc sharing

Richie McIlroyd0d230d80d5a
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index 012869016..a80d18b39 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -55,7 +55,7 @@ impl Renderer {
let total_frames = (30_f64 * max_duration).ceil() as u32;
- let (tx, rx) = mpsc::channel(8);
+ let (tx, rx) = mpsc::channel(4);
let this = Self {
rx,
diff --git a/crates/editor/src/editor_instance.rs b/crates/editor/src/editor_instance.rs
index 16b05e33e..a48f65c06 100644
--- a/crates/editor/src/editor_instance.rs
+++ b/crates/editor/src/editor_instance.rs
@@ -513,8 +513,8 @@ impl EditorInstance {
},
);
- let zoom_focus_interpolator = ZoomFocusInterpolator::new(
- &segment_medias.cursor,
+ let zoom_focus_interpolator = ZoomFocusInterpolator::new_arc(
+ segment_medias.cursor.clone(),
cursor_smoothing,
project.screen_movement_spring,
total_duration,
diff --git a/crates/editor/src/playback.rs b/crates/editor/src/playback.rs
index 6ac8571a4..dc304ff53 100644
--- a/crates/editor/src/playback.rs
+++ b/crates/editor/src/playback.rs
@@ -657,8 +657,8 @@ impl Playback {
friction: cached_project.cursor.friction,
});
- let zoom_focus_interpolator = ZoomFocusInterpolator::new(
- &segment_media.cursor,
+ let zoom_focus_interpolator = ZoomFocusInterpolator::new_arc(
+ segment_media.cursor.clone(),
cursor_smoothing,
cached_project.screen_movement_spring,
duration,
diff --git a/crates/rendering/src/zoom_focus_interpolation.rs b/crates/rendering/src/zoom_focus_interpolation.rs
index a622b9c7d..c69802625 100644
--- a/crates/rendering/src/zoom_focus_interpolation.rs
+++ b/crates/rendering/src/zoom_focus_interpolation.rs
@@ -16,7 +16,7 @@ struct SmoothedFocusEvent {
pub struct ZoomFocusInterpolator {
events: Option<Vec<SmoothedFocusEvent>>,
- cursor_events: CursorEvents,
+ cursor_events: std::sync::Arc<CursorEvents>,
cursor_smoothing: Option<SpringMassDamperSimulationConfig>,
screen_spring: ScreenMovementSpring,
duration_secs: f64,
@@ -31,7 +31,22 @@ impl ZoomFocusInterpolator {
) -> Self {
Self {
events: None,
- cursor_events: cursor_events.clone(),
+ cursor_events: std::sync::Arc::new(cursor_events.clone()),
+ cursor_smoothing,
+ screen_spring,
+ duration_secs,
+ }
+ }
+
+ pub fn new_arc(
+ cursor_events: std::sync::Arc<CursorEvents>,
+ cursor_smoothing: Option<SpringMassDamperSimulationConfig>,
+ screen_spring: ScreenMovementSpring,
+ duration_secs: f64,
+ ) -> Self {
+ Self {
+ events: None,
+ cursor_events,
cursor_smoothing,
screen_spring,
duration_secs,