drm_lease: Disable overlay planes when active

This commit is contained in:
Victoria Brekenfeld 2025-01-02 17:39:16 +01:00 committed by Victoria Brekenfeld
parent 8b87d6524e
commit 546966bf15
3 changed files with 120 additions and 4 deletions

View file

@ -612,6 +612,59 @@ impl Device {
}
}
pub fn allow_overlay_scanout(
&mut self,
flag: bool,
renderer: &mut GlMultiRenderer,
clock: &Clock<Monotonic>,
shell: &Arc<RwLock<Shell>>,
) -> Result<()> {
for surface in self.surfaces.values_mut() {
surface.allow_overlay_scanout(flag);
}
if !flag {
let now = clock.now();
let output_map = self
.surfaces
.iter()
.map(|(crtc, surface)| (*crtc, surface.output.clone()))
.collect::<HashMap<_, _>>();
self.drm.with_compositors::<Result<()>>(|map| {
for (crtc, compositor) in map.iter() {
let elements = match output_map.get(crtc) {
Some(output) => output_elements(
Some(&self.render_node),
renderer,
shell,
now,
&output,
CursorMode::All,
None,
)
.with_context(|| "Failed to render outputs")?,
None => Vec::new(),
};
let mut compositor = compositor.lock().unwrap();
compositor.render_frame(
renderer,
&elements,
CLEAR_COLOR,
FrameFlags::empty(),
)?;
compositor.commit_frame()?;
}
Ok(())
})?;
}
Ok(())
}
pub fn in_use(&self, primary: Option<&DrmNode>) -> bool {
Some(&self.render_node) == primary
|| !self.surfaces.is_empty()

View file

@ -423,6 +423,14 @@ impl Surface {
Ok(true)
}
pub fn allow_overlay_scanout(&mut self, flag: bool) {
let (tx, rx) = std::sync::mpsc::sync_channel(1);
let _ = self
.thread_command
.send(ThreadCommand::AllowOverlayScanout(flag, tx));
let _ = rx.recv();
}
pub fn suspend(&mut self) {
let (tx, rx) = std::sync::mpsc::sync_channel(1);
let _ = self.thread_command.send(ThreadCommand::Suspend(tx));
@ -607,6 +615,23 @@ fn surface_thread(
};
}
}
Event::Msg(ThreadCommand::AllowOverlayScanout(flag, tx)) => {
if !crate::utils::env::bool_var("COSMIC_DISABLE_DIRECT_SCANOUT").unwrap_or(false)
&& !crate::utils::env::bool_var("COSMIC_DISABLE_OVERLAY_SCANOUT")
.unwrap_or(false)
{
if flag {
state
.frame_flags
.insert(FrameFlags::ALLOW_OVERLAY_PLANE_SCANOUT);
} else {
state
.frame_flags
.remove(FrameFlags::ALLOW_OVERLAY_PLANE_SCANOUT);
}
}
let _ = tx.send(());
}
Event::Closed | Event::Msg(ThreadCommand::End) => {
signal.stop();
signal.wakeup();