Clean up some of the screencopy code
This commit is contained in:
parent
13b565e013
commit
6262329635
2 changed files with 5 additions and 21 deletions
|
|
@ -32,7 +32,6 @@ pub struct CaptureFilter {
|
||||||
|
|
||||||
pub struct Capture {
|
pub struct Capture {
|
||||||
pub source: CaptureSource,
|
pub source: CaptureSource,
|
||||||
first_frame: AtomicBool,
|
|
||||||
pub session: Mutex<Option<ScreencopySession>>,
|
pub session: Mutex<Option<ScreencopySession>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,7 +39,6 @@ impl Capture {
|
||||||
pub fn new(source: CaptureSource) -> Arc<Capture> {
|
pub fn new(source: CaptureSource) -> Arc<Capture> {
|
||||||
Arc::new(Capture {
|
Arc::new(Capture {
|
||||||
source,
|
source,
|
||||||
first_frame: AtomicBool::new(true),
|
|
||||||
session: Mutex::new(None),
|
session: Mutex::new(None),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -53,18 +51,6 @@ impl Capture {
|
||||||
session.data::<SessionData>()?.capture.upgrade()
|
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
|
// Start capturing frames
|
||||||
pub fn start(
|
pub fn start(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
|
|
@ -73,7 +59,6 @@ impl Capture {
|
||||||
) {
|
) {
|
||||||
let mut session = self.session.lock().unwrap();
|
let mut session = self.session.lock().unwrap();
|
||||||
if session.is_none() {
|
if session.is_none() {
|
||||||
self.first_frame.store(true, Ordering::SeqCst);
|
|
||||||
*session = Some(ScreencopySession::new(self, manager, qh));
|
*session = Some(ScreencopySession::new(self, manager, qh));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ use super::{AppData, Buffer, Capture, CaptureImage, CaptureSource, Event};
|
||||||
pub struct ScreencopySession {
|
pub struct ScreencopySession {
|
||||||
buffer: Option<Buffer>,
|
buffer: Option<Buffer>,
|
||||||
session: zcosmic_screencopy_session_v1::ZcosmicScreencopySessionV1,
|
session: zcosmic_screencopy_session_v1::ZcosmicScreencopySessionV1,
|
||||||
|
first_frame: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ScreencopySession {
|
impl ScreencopySession {
|
||||||
|
|
@ -48,10 +49,11 @@ impl ScreencopySession {
|
||||||
Self {
|
Self {
|
||||||
buffer: None,
|
buffer: None,
|
||||||
session,
|
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 {
|
let Some(buffer) = self.buffer.as_ref() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
@ -61,10 +63,10 @@ impl ScreencopySession {
|
||||||
.and_then(|x| x.to_str().map(|x| x.to_string()));
|
.and_then(|x| x.to_str().map(|x| x.to_string()));
|
||||||
|
|
||||||
self.session.attach_buffer(&buffer.buffer, node, 0); // XXX age?
|
self.session.attach_buffer(&buffer.buffer, node, 0); // XXX age?
|
||||||
if capture.first_frame() {
|
if self.first_frame {
|
||||||
self.session
|
self.session
|
||||||
.commit(zcosmic_screencopy_session_v1::Options::empty());
|
.commit(zcosmic_screencopy_session_v1::Options::empty());
|
||||||
capture.unset_first_frame();
|
self.first_frame = false;
|
||||||
} else {
|
} else {
|
||||||
self.session
|
self.session
|
||||||
.commit(zcosmic_screencopy_session_v1::Options::OnDamage);
|
.commit(zcosmic_screencopy_session_v1::Options::OnDamage);
|
||||||
|
|
@ -133,9 +135,6 @@ impl ScreencopyHandler for AppData {
|
||||||
let Some(capture) = Capture::for_session(session) else {
|
let Some(capture) = Capture::for_session(session) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if !capture.running() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let mut session = capture.session.lock().unwrap();
|
let mut session = capture.session.lock().unwrap();
|
||||||
let Some(session) = session.as_mut() else {
|
let Some(session) = session.as_mut() else {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue