linux_wayland_support: init merge, windows build

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2022-07-07 01:27:21 +08:00
parent 6533b30cac
commit aae6e2b16b
30 changed files with 1902 additions and 656 deletions

View File

@@ -21,6 +21,10 @@ impl Capturer {
})
}
pub fn set_use_yuv(&mut self, use_yuv: bool) {
self.inner.set_use_yuv(use_yuv);
}
pub fn is_gdi(&self) -> bool {
self.inner.is_gdi()
}
@@ -41,8 +45,8 @@ impl Capturer {
self.height
}
pub fn frame<'a>(&'a mut self, timeout_ms: Duration) -> io::Result<Frame<'a>> {
match self.inner.frame(timeout_ms.as_millis() as _) {
pub fn frame<'a>(&'a mut self, timeout: Duration) -> io::Result<Frame<'a>> {
match self.inner.frame(timeout.as_millis() as _) {
Ok(frame) => Ok(Frame(frame)),
Err(ref error) if error.kind() == TimedOut => Err(WouldBlock.into()),
Err(error) => Err(error),
@@ -129,6 +133,11 @@ impl CapturerMag {
data: Vec::new(),
})
}
pub fn set_use_yuv(&mut self, use_yuv: bool) {
self.inner.set_use_yuv(use_yuv)
}
pub fn exclude(&mut self, cls: &str, name: &str) -> io::Result<bool> {
self.inner.exclude(cls, name)
}

View File

@@ -17,6 +17,13 @@ impl Capturer {
})
}
pub fn set_use_yuv(&mut self, use_yuv: bool) {
match self {
Capturer::X11(d) => d.set_use_yuv(use_yuv),
Capturer::WAYLAND(d) => d.set_use_yuv(use_yuv),
}
}
pub fn width(&self) -> usize {
match self {
Capturer::X11(d) => d.width(),
@@ -31,10 +38,10 @@ impl Capturer {
}
}
pub fn frame<'a>(&'a mut self, timeout_ms: u32) -> io::Result<Frame<'a>> {
pub fn frame<'a>(&'a mut self, timeout: Duration) -> io::Result<Frame<'a>> {
match self {
Capturer::X11(d) => d.frame(timeout_ms),
Capturer::WAYLAND(d) => d.frame(timeout_ms),
Capturer::X11(d) => d.frame(timeout),
Capturer::WAYLAND(d) => d.frame(timeout),
}
}
}
@@ -45,7 +52,7 @@ pub enum Display {
}
#[inline]
fn is_wayland() -> bool {
pub fn is_wayland() -> bool {
std::env::var("IS_WAYLAND").is_ok()
|| std::env::var("XDG_SESSION_TYPE") == Ok("wayland".to_owned())
}

View File

@@ -11,6 +11,7 @@ cfg_if! {
mod wayland;
mod x11;
pub use self::linux::*;
pub use self::x11::Frame;
} else {
mod x11;
pub use self::x11::*;

View File

@@ -1,6 +1,6 @@
use crate::common::x11::Frame;
use crate::wayland::{capturable::*, *};
use std::io;
use std::{io, time::Duration};
pub struct Capturer(Display, Box<dyn Recorder>, bool, Vec<u8>);
@@ -14,6 +14,10 @@ impl Capturer {
Ok(Capturer(display, r, yuv, Default::default()))
}
pub fn set_use_yuv(&mut self, use_yuv: bool) {
self.2 = use_yuv;
}
pub fn width(&self) -> usize {
self.0.width()
}
@@ -22,8 +26,8 @@ impl Capturer {
self.0.height()
}
pub fn frame<'a>(&'a mut self, timeout_ms: u32) -> io::Result<Frame<'a>> {
match self.1.capture(timeout_ms as _).map_err(map_err)? {
pub fn frame<'a>(&'a mut self, timeout: Duration) -> io::Result<Frame<'a>> {
match self.1.capture(timeout.as_millis() as _).map_err(map_err)? {
PixelProvider::BGR0(w, h, x) => Ok(Frame(if self.2 {
crate::common::bgra_to_i420(w as _, h as _, &x, &mut self.3);
&self.3[..]

View File

@@ -8,6 +8,10 @@ impl Capturer {
x11::Capturer::new(display.0, yuv).map(Capturer)
}
pub fn set_use_yuv(&mut self, use_yuv: bool) {
self.0.set_use_yuv(use_yuv);
}
pub fn width(&self) -> usize {
self.0.display().rect().w as usize
}

View File

@@ -446,6 +446,10 @@ impl CapturerMag {
Ok(s)
}
pub(crate) fn set_use_yuv(&mut self, use_yuv: bool) {
self.use_yuv = use_yuv;
}
pub(crate) fn exclude(&mut self, cls: &str, name: &str) -> Result<bool> {
let name_c = CString::new(name).unwrap();
unsafe {

View File

@@ -156,6 +156,10 @@ impl Capturer {
})
}
pub fn set_use_yuv(&mut self, use_yuv: bool) {
self.use_yuv = use_yuv;
}
pub fn is_gdi(&self) -> bool {
self.gdi_capturer.is_some()
}

View File

@@ -74,6 +74,10 @@ impl Capturer {
Ok(c)
}
pub fn set_use_yuv(&mut self, use_yuv: bool) {
self.use_yuv = use_yuv;
}
pub fn display(&self) -> &Display {
&self.display
}