Skip to content

Commit

Permalink
winit: Schedule render after transaction finish
Browse files Browse the repository at this point in the history
Fixes #255
  • Loading branch information
Ottatop committed Jun 18, 2024
1 parent 39fd958 commit fe182fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/backend/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ impl Winit {
/// Render the winit window if a render has been scheduled.
pub fn render_if_scheduled(&mut self, pinnacle: &mut Pinnacle) {
if self.output_render_scheduled {
self.render_winit_window(pinnacle);
self.output_render_scheduled = false;
self.render_winit_window(pinnacle);
}
}

Expand Down Expand Up @@ -343,24 +343,22 @@ impl Winit {
));
}

let mut clear_snapshots = false;
// HACK: Taking the transaction before creating render elements
// leads to a possibility where the original buffer still gets displayed.
// Need to figure that out.
// In the meantime we take the transaction afterwards and schedule another render.
let mut render_after_transaction_finish = false;
self.output.with_state_mut(|state| {
if state
.layout_transaction
.as_ref()
.is_some_and(|ts| ts.ready())
{
state.layout_transaction.take();
clear_snapshots = true;
render_after_transaction_finish = true;
}
});

if clear_snapshots {
for win in pinnacle.windows.iter() {
win.with_state_mut(|state| state.snapshot.take());
}
}

let render_res = self.backend.bind().and_then(|_| {
let age = if *full_redraw > 0 {
0
Expand Down Expand Up @@ -447,6 +445,11 @@ impl Winit {
warn!("{}", err);
}
}

// At the end cuz borrow checker
if render_after_transaction_finish {
self.schedule_render();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ impl Pinnacle {
pub fn shutdown(&mut self) {
info!("Shutting down Pinnacle");
self.loop_signal.stop();
self.loop_signal.wakeup();
if let Some(join_handle) = self.config.config_join_handle.take() {
join_handle.abort();
}
Expand Down

0 comments on commit fe182fd

Please sign in to comment.