Skip to content

Commit

Permalink
kms: Only pause device after all surfaces are successfully suspended
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Aug 21, 2024
1 parent 1b16b98 commit f60499f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/backend/kms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ impl State {
let backend = self.backend.kms();
backend.libinput.suspend();
for device in backend.drm_devices.values_mut() {
device.drm.pause();
if let Some(lease_state) = device.leasing_global.as_mut() {
lease_state.suspend();
}
for surface in device.surfaces.values_mut() {
surface.suspend();
let _ = surface.suspend();
}
device.drm.pause();
}
}
}
Expand Down
20 changes: 15 additions & 5 deletions src/backend/kms/surface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ impl Default for QueueState {

#[derive(Debug)]
pub enum ThreadCommand {
Suspend,
Suspend {
result: SyncSender<Result<()>>,
},
Resume {
surface: DrmSurface,
gbm: GbmDevice<DrmDeviceFd>,
Expand Down Expand Up @@ -389,8 +391,12 @@ impl Surface {
rx.recv().context("Surface thread died")?
}

pub fn suspend(&mut self) {
let _ = self.thread_command.send(ThreadCommand::Suspend);
pub fn suspend(&mut self) -> Result<()> {
let (tx, rx) = std::sync::mpsc::sync_channel(1);
let _ = self
.thread_command
.send(ThreadCommand::Suspend { result: tx });
rx.recv().context("Surface thread died")?
}

pub fn resume(
Expand Down Expand Up @@ -496,7 +502,9 @@ fn surface_thread(
event_loop
.handle()
.insert_source(thread_receiver, move |command, _, state| match command {
Event::Msg(ThreadCommand::Suspend) => state.suspend(),
Event::Msg(ThreadCommand::Suspend { result }) => {
let _ = result.send(state.suspend());
}
Event::Msg(ThreadCommand::Resume {
surface,
gbm,
Expand Down Expand Up @@ -546,7 +554,7 @@ fn surface_thread(
}

impl SurfaceThreadState {
fn suspend(&mut self) {
fn suspend(&mut self) -> Result<()> {
self.active.store(false, Ordering::SeqCst);
let _ = self.compositor.take();

Expand All @@ -564,6 +572,8 @@ impl SurfaceThreadState {
self.loop_handle.remove(queued_render);
}
};

Ok(())
}

fn resume(
Expand Down

0 comments on commit f60499f

Please sign in to comment.