Skip to content

Commit

Permalink
refactor: add vello sync timings
Browse files Browse the repository at this point in the history
  • Loading branch information
Stumblinbear committed Jan 22, 2024
1 parent ac47c7d commit 9afbf34
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion crates/agui_vello/src/view.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::sync::Arc;
use std::{
sync::Arc,
time::{Duration, Instant},
};

use agui_core::{
render::{canvas::Canvas, view::View, RenderObjectId},
Expand Down Expand Up @@ -133,10 +136,14 @@ impl View for VelloView {
fn on_sync(&mut self) {
tracing::trace!("VelloView::on_sync");

let start = Instant::now();

// TODO: if this is locked, we should somehow check if another frame is ready and
// skip this one
let mut scene = self.scene.write();

let lock_scene_end = Instant::now();

for change in self.changes.drain(..) {
match change {
Change::Attach {
Expand All @@ -163,15 +170,32 @@ impl View for VelloView {
}
}

let apply_changes_end = Instant::now();

scene.redraw();

let redraw_end = Instant::now();

let frame_notifier = self.frame_notifier.lock();

if let Some(frame_notifier) = frame_notifier.as_ref() {
frame_notifier.notify();
} else {
tracing::warn!("a frame was rendered, but no frame notifier was set");
}

let frame_notify_end = Instant::now();

let timings = SyncTimings {
duration: start.elapsed(),

lock_scene: lock_scene_end - start,
apply_changes: apply_changes_end - lock_scene_end,
redraw: redraw_end - apply_changes_end,
frame_notify: frame_notify_end - redraw_end,
};

tracing::debug!(?timings, "sync complete");
}
}

Expand Down Expand Up @@ -200,3 +224,14 @@ enum Change {
canvas: Canvas,
},
}

#[derive(Debug)]
#[allow(dead_code)]
struct SyncTimings {
duration: Duration,

lock_scene: Duration,
apply_changes: Duration,
redraw: Duration,
frame_notify: Duration,
}

0 comments on commit 9afbf34

Please sign in to comment.