Clean up some of the screencopy code

This commit is contained in:
Ian Douglas Scott 2024-01-25 15:48:40 -08:00
parent 13b565e013
commit 6262329635
2 changed files with 5 additions and 21 deletions

View file

@ -32,7 +32,6 @@ pub struct CaptureFilter {
pub struct Capture {
pub source: CaptureSource,
first_frame: AtomicBool,
pub session: Mutex<Option<ScreencopySession>>,
}
@ -40,7 +39,6 @@ impl Capture {
pub fn new(source: CaptureSource) -> Arc<Capture> {
Arc::new(Capture {
source,
first_frame: AtomicBool::new(true),
session: Mutex::new(None),
})
}
@ -53,18 +51,6 @@ impl Capture {
session.data::<SessionData>()?.capture.upgrade()
}
pub fn running(&self) -> bool {
self.session.lock().unwrap().is_some()
}
pub fn unset_first_frame(&self) {
self.first_frame.store(false, Ordering::SeqCst);
}
pub fn first_frame(&self) -> bool {
self.first_frame.load(Ordering::SeqCst)
}
// Start capturing frames
pub fn start(
self: &Arc<Self>,
@ -73,7 +59,6 @@ impl Capture {
) {
let mut session = self.session.lock().unwrap();
if session.is_none() {
self.first_frame.store(true, Ordering::SeqCst);
*session = Some(ScreencopySession::new(self, manager, qh));
}
}

View file

@ -16,6 +16,7 @@ use super::{AppData, Buffer, Capture, CaptureImage, CaptureSource, Event};
pub struct ScreencopySession {
buffer: Option<Buffer>,
session: zcosmic_screencopy_session_v1::ZcosmicScreencopySessionV1,
first_frame: bool,
}
impl ScreencopySession {
@ -48,10 +49,11 @@ impl ScreencopySession {
Self {
buffer: None,
session,
first_frame: true,
}
}
fn attach_buffer_and_commit(&self, capture: &Capture, conn: &Connection) {
fn attach_buffer_and_commit(&mut self, capture: &Capture, conn: &Connection) {
let Some(buffer) = self.buffer.as_ref() else {
return;
};
@ -61,10 +63,10 @@ impl ScreencopySession {
.and_then(|x| x.to_str().map(|x| x.to_string()));
self.session.attach_buffer(&buffer.buffer, node, 0); // XXX age?
if capture.first_frame() {
if self.first_frame {
self.session
.commit(zcosmic_screencopy_session_v1::Options::empty());
capture.unset_first_frame();
self.first_frame = false;
} else {
self.session
.commit(zcosmic_screencopy_session_v1::Options::OnDamage);
@ -133,9 +135,6 @@ impl ScreencopyHandler for AppData {
let Some(capture) = Capture::for_session(session) else {
return;
};
if !capture.running() {
return;
}
let mut session = capture.session.lock().unwrap();
let Some(session) = session.as_mut() else {
return;