pipewire pause/resume, update wlx-capture, pipewire dmabuf preps

This commit is contained in:
galister
2024-02-02 19:05:33 +01:00
parent d71bf65ee8
commit 93e4058f7f
7 changed files with 114 additions and 45 deletions

68
Cargo.lock generated
View File

@@ -288,7 +288,7 @@ dependencies = [
"futures-lite 2.2.0", "futures-lite 2.2.0",
"parking", "parking",
"polling 3.3.2", "polling 3.3.2",
"rustix 0.38.30", "rustix 0.38.31",
"slab", "slab",
"tracing", "tracing",
"windows-sys 0.52.0", "windows-sys 0.52.0",
@@ -338,7 +338,7 @@ dependencies = [
"cfg-if", "cfg-if",
"event-listener 3.1.0", "event-listener 3.1.0",
"futures-lite 1.13.0", "futures-lite 1.13.0",
"rustix 0.38.30", "rustix 0.38.31",
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
@@ -365,7 +365,7 @@ dependencies = [
"cfg-if", "cfg-if",
"futures-core", "futures-core",
"futures-io", "futures-io",
"rustix 0.38.30", "rustix 0.38.31",
"signal-hook-registry", "signal-hook-registry",
"slab", "slab",
"windows-sys 0.48.0", "windows-sys 0.48.0",
@@ -683,7 +683,7 @@ dependencies = [
"bitflags 2.4.2", "bitflags 2.4.2",
"log", "log",
"polling 3.3.2", "polling 3.3.2",
"rustix 0.38.30", "rustix 0.38.31",
"slab", "slab",
"thiserror", "thiserror",
] ]
@@ -695,7 +695,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f0ea9b9476c7fad82841a8dbb380e2eae480c21910feba80725b46931ed8f02" checksum = "0f0ea9b9476c7fad82841a8dbb380e2eae480c21910feba80725b46931ed8f02"
dependencies = [ dependencies = [
"calloop 0.12.4", "calloop 0.12.4",
"rustix 0.38.30", "rustix 0.38.31",
"wayland-backend 0.3.3", "wayland-backend 0.3.3",
"wayland-client 0.31.2", "wayland-client 0.31.2",
] ]
@@ -1070,9 +1070,9 @@ dependencies = [
[[package]] [[package]]
name = "darling" name = "darling"
version = "0.20.4" version = "0.20.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da01daa5f6d41c91358398e8db4dde38e292378da1f28300b59ef4732b879454" checksum = "fc5d6b04b3fd0ba9926f945895de7d806260a2d7431ba82e7edaecb043c4c6b8"
dependencies = [ dependencies = [
"darling_core", "darling_core",
"darling_macro", "darling_macro",
@@ -1080,9 +1080,9 @@ dependencies = [
[[package]] [[package]]
name = "darling_core" name = "darling_core"
version = "0.20.4" version = "0.20.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f44f6238b948a3c6c3073cdf53bb0c2d5e024ee27e0f35bfe9d556a12395808a" checksum = "04e48a959bcd5c761246f5d090ebc2fbf7b9cd527a492b07a67510c108f1e7e3"
dependencies = [ dependencies = [
"fnv", "fnv",
"ident_case", "ident_case",
@@ -1093,9 +1093,9 @@ dependencies = [
[[package]] [[package]]
name = "darling_macro" name = "darling_macro"
version = "0.20.4" version = "0.20.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d2d88bd93979b1feb760a6b5c531ac5ba06bd63e74894c377af02faee07b9cd" checksum = "1d1545d67a2149e1d93b7e5c7752dce5a7426eb5d1357ddcfd89336b94444f77"
dependencies = [ dependencies = [
"darling_core", "darling_core",
"quote", "quote",
@@ -1729,9 +1729,9 @@ dependencies = [
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.2.1" version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "433de089bd45971eecf4668ee0ee8f4cec17db4f8bd8f7bc3197a6ce37aa7d9b" checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520"
dependencies = [ dependencies = [
"equivalent", "equivalent",
"hashbrown 0.14.3", "hashbrown 0.14.3",
@@ -1790,7 +1790,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455"
dependencies = [ dependencies = [
"hermit-abi 0.3.4", "hermit-abi 0.3.4",
"rustix 0.38.30", "rustix 0.38.31",
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
@@ -1900,9 +1900,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.152" version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]] [[package]]
name = "libloading" name = "libloading"
@@ -2580,7 +2580,7 @@ dependencies = [
"cfg-if", "cfg-if",
"concurrent-queue", "concurrent-queue",
"pin-project-lite", "pin-project-lite",
"rustix 0.38.30", "rustix 0.38.31",
"tracing", "tracing",
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
@@ -2841,9 +2841,9 @@ dependencies = [
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.38.30" version = "0.38.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949"
dependencies = [ dependencies = [
"bitflags 2.4.2", "bitflags 2.4.2",
"errno", "errno",
@@ -2969,7 +2969,7 @@ version = "0.9.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adf8a49373e98a4c5f0ceb5d05aa7c648d75f63774981ed95b7c7443bbd50c6e" checksum = "adf8a49373e98a4c5f0ceb5d05aa7c648d75f63774981ed95b7c7443bbd50c6e"
dependencies = [ dependencies = [
"indexmap 2.2.1", "indexmap 2.2.2",
"itoa", "itoa",
"ryu", "ryu",
"serde", "serde",
@@ -3096,7 +3096,7 @@ dependencies = [
"libc", "libc",
"log", "log",
"memmap2 0.9.4", "memmap2 0.9.4",
"rustix 0.38.30", "rustix 0.38.31",
"thiserror", "thiserror",
"wayland-backend 0.3.3", "wayland-backend 0.3.3",
"wayland-client 0.31.2", "wayland-client 0.31.2",
@@ -3224,7 +3224,7 @@ dependencies = [
"cfg-if", "cfg-if",
"fastrand 2.0.1", "fastrand 2.0.1",
"redox_syscall 0.4.1", "redox_syscall 0.4.1",
"rustix 0.38.30", "rustix 0.38.31",
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
@@ -3334,7 +3334,7 @@ version = "0.19.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
dependencies = [ dependencies = [
"indexmap 2.2.1", "indexmap 2.2.2",
"toml_datetime", "toml_datetime",
"winnow", "winnow",
] ]
@@ -3345,7 +3345,7 @@ version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338"
dependencies = [ dependencies = [
"indexmap 2.2.1", "indexmap 2.2.2",
"serde", "serde",
"serde_spanned", "serde_spanned",
"toml_datetime", "toml_datetime",
@@ -3496,7 +3496,7 @@ dependencies = [
"crossbeam-queue", "crossbeam-queue",
"half", "half",
"heck", "heck",
"indexmap 2.2.1", "indexmap 2.2.2",
"libloading 0.8.1", "libloading 0.8.1",
"objc", "objc",
"once_cell", "once_cell",
@@ -3649,7 +3649,7 @@ checksum = "9d50fa61ce90d76474c87f5fc002828d81b32677340112b4ef08079a9d459a40"
dependencies = [ dependencies = [
"cc", "cc",
"downcast-rs", "downcast-rs",
"rustix 0.38.30", "rustix 0.38.31",
"scoped-tls", "scoped-tls",
"smallvec", "smallvec",
"wayland-sys 0.31.1", "wayland-sys 0.31.1",
@@ -3675,7 +3675,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f" checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f"
dependencies = [ dependencies = [
"bitflags 2.4.2", "bitflags 2.4.2",
"rustix 0.38.30", "rustix 0.38.31",
"wayland-backend 0.3.3", "wayland-backend 0.3.3",
"wayland-scanner 0.31.1", "wayland-scanner 0.31.1",
] ]
@@ -3708,7 +3708,7 @@ version = "0.31.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71ce5fa868dd13d11a0d04c5e2e65726d0897be8de247c0c5a65886e283231ba" checksum = "71ce5fa868dd13d11a0d04c5e2e65726d0897be8de247c0c5a65886e283231ba"
dependencies = [ dependencies = [
"rustix 0.38.30", "rustix 0.38.31",
"wayland-client 0.31.2", "wayland-client 0.31.2",
"xcursor", "xcursor",
] ]
@@ -3850,7 +3850,7 @@ dependencies = [
"either", "either",
"home", "home",
"once_cell", "once_cell",
"rustix 0.38.30", "rustix 0.38.31",
] ]
[[package]] [[package]]
@@ -4129,7 +4129,7 @@ dependencies = [
"percent-encoding", "percent-encoding",
"raw-window-handle 0.6.0", "raw-window-handle 0.6.0",
"redox_syscall 0.3.5", "redox_syscall 0.3.5",
"rustix 0.38.30", "rustix 0.38.31",
"sctk-adwaita", "sctk-adwaita",
"smithay-client-toolkit 0.18.0", "smithay-client-toolkit 0.18.0",
"smol_str", "smol_str",
@@ -4150,9 +4150,9 @@ dependencies = [
[[package]] [[package]]
name = "winnow" name = "winnow"
version = "0.5.35" version = "0.5.36"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1931d78a9c73861da0134f453bb1f790ce49b2e30eba8410b4b79bac72b46a2d" checksum = "818ce546a11a9986bc24f93d0cdf38a8a1a400f1473ea8c82e59f6e0ffab9249"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@@ -4160,7 +4160,7 @@ dependencies = [
[[package]] [[package]]
name = "wlx-capture" name = "wlx-capture"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/galister/wlx-capture#9532ba1cc95453fd78d620a621c5073d10996d6c" source = "git+https://github.com/galister/wlx-capture#19fe836043dca52f273a4c487780608c5f56b157"
dependencies = [ dependencies = [
"ashpd", "ashpd",
"drm-fourcc", "drm-fourcc",
@@ -4238,7 +4238,7 @@ dependencies = [
"libc", "libc",
"libloading 0.8.1", "libloading 0.8.1",
"once_cell", "once_cell",
"rustix 0.38.30", "rustix 0.38.31",
"x11rb-protocol", "x11rb-protocol",
] ]

View File

@@ -66,9 +66,9 @@ impl OverlayData<OpenVrOverlayData> {
pub(super) fn after_input(&mut self, overlay: &mut OverlayManager, app: &mut AppState) { pub(super) fn after_input(&mut self, overlay: &mut OverlayManager, app: &mut AppState) {
if self.state.want_visible && !self.data.visible { if self.state.want_visible && !self.data.visible {
self.show(overlay, app); self.show_internal(overlay, app);
} else if !self.state.want_visible && self.data.visible { } else if !self.state.want_visible && self.data.visible {
self.hide(overlay); self.hide_internal(overlay, app);
} }
} }
@@ -82,7 +82,7 @@ impl OverlayData<OpenVrOverlayData> {
} }
} }
fn show(&mut self, overlay: &mut OverlayManager, app: &mut AppState) { fn show_internal(&mut self, overlay: &mut OverlayManager, app: &mut AppState) {
let handle = match self.data.handle { let handle = match self.data.handle {
Some(handle) => handle, Some(handle) => handle,
None => self.initialize(overlay, app), None => self.initialize(overlay, app),
@@ -92,9 +92,10 @@ impl OverlayData<OpenVrOverlayData> {
panic!("Failed to show overlay: {}", e); panic!("Failed to show overlay: {}", e);
} }
self.data.visible = true; self.data.visible = true;
self.backend.resume(app);
} }
fn hide(&mut self, overlay: &mut OverlayManager) { fn hide_internal(&mut self, overlay: &mut OverlayManager, app: &mut AppState) {
let Some(handle) = self.data.handle else { let Some(handle) = self.data.handle else {
return; return;
}; };
@@ -103,6 +104,7 @@ impl OverlayData<OpenVrOverlayData> {
panic!("Failed to hide overlay: {}", e); panic!("Failed to hide overlay: {}", e);
} }
self.data.visible = false; self.data.visible = false;
self.backend.pause(app);
} }
pub(super) fn upload_color(&self, overlay: &mut OverlayManager) { pub(super) fn upload_color(&self, overlay: &mut OverlayManager) {

View File

@@ -204,6 +204,10 @@ pub fn openxr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
} }
} }
overlays
.iter_mut()
.for_each(|o| o.after_input(&mut app_state));
let (_, views) = xr_state let (_, views) = xr_state
.session .session
.locate_views( .locate_views(

View File

@@ -6,12 +6,14 @@ use super::{swapchain::SwapchainRenderData, transform_to_posef, XrState};
use crate::{ use crate::{
backend::{openxr::swapchain::create_swapchain_render_data, overlay::OverlayData}, backend::{openxr::swapchain::create_swapchain_render_data, overlay::OverlayData},
graphics::WlxCommandBuffer, graphics::WlxCommandBuffer,
state::AppState,
}; };
use vulkano::image::view::ImageView; use vulkano::image::view::ImageView;
#[derive(Default)] #[derive(Default)]
pub struct OpenXrOverlayData { pub struct OpenXrOverlayData {
last_view: Option<Arc<ImageView>>, last_view: Option<Arc<ImageView>>,
last_visible: bool,
pub(super) swapchain: Option<SwapchainRenderData>, pub(super) swapchain: Option<SwapchainRenderData>,
pub(super) init: bool, pub(super) init: bool,
} }
@@ -67,4 +69,15 @@ impl OverlayData<OpenXrOverlayData> {
}); });
Some(quad) Some(quad)
} }
pub(super) fn after_input(&mut self, app: &mut AppState) {
if self.data.last_visible != self.state.want_visible {
if self.state.want_visible {
self.backend.resume(app);
} else {
self.backend.pause(app);
}
}
self.data.last_visible = self.state.want_visible;
}
} }

View File

@@ -169,6 +169,17 @@ where
pub fn view(&mut self) -> Option<Arc<ImageView>> { pub fn view(&mut self) -> Option<Arc<ImageView>> {
self.backend.view() self.backend.view()
} }
pub fn set_visible(&mut self, app: &mut AppState, visible: bool) {
let old_visible = self.state.want_visible;
self.state.want_visible = visible;
if visible != old_visible {
if visible {
self.backend.resume(app);
} else {
self.backend.pause(app);
}
}
}
} }
pub trait OverlayRenderer { pub trait OverlayRenderer {

View File

@@ -127,7 +127,9 @@ impl WlxGraphics {
use winit::event_loop::EventLoop; use winit::event_loop::EventLoop;
let event_loop = EventLoop::new().unwrap(); let event_loop = EventLoop::new().unwrap();
let instance_extensions = Surface::required_extensions(&event_loop).unwrap(); let mut instance_extensions = Surface::required_extensions(&event_loop).unwrap();
instance_extensions.khr_get_physical_device_properties2 = true;
let instance_extensions_raw = instance_extensions let instance_extensions_raw = instance_extensions
.clone() .clone()
@@ -320,18 +322,20 @@ impl WlxGraphics {
#[cfg(feature = "openvr")] #[cfg(feature = "openvr")]
pub fn new_openvr( pub fn new_openvr(
vk_instance_extensions: InstanceExtensions, mut vk_instance_extensions: InstanceExtensions,
mut vk_device_extensions_fn: impl FnMut(&PhysicalDevice) -> DeviceExtensions, mut vk_device_extensions_fn: impl FnMut(&PhysicalDevice) -> DeviceExtensions,
) -> Arc<Self> { ) -> Arc<Self> {
#[cfg(debug_assertions)] //#[cfg(debug_assertions)]
let layers = vec!["VK_LAYER_KHRONOS_validation".to_owned()]; //let layers = vec!["VK_LAYER_KHRONOS_validation".to_owned()];
#[cfg(not(debug_assertions))] //#[cfg(not(debug_assertions))]
let layers = vec![]; let layers = vec![];
let library = VulkanLibrary::new().unwrap(); let library = VulkanLibrary::new().unwrap();
log::debug!("Instance exts for runtime: {:?}", &vk_instance_extensions); log::debug!("Instance exts for runtime: {:?}", &vk_instance_extensions);
vk_instance_extensions.khr_get_physical_device_properties2 = true;
let instance = Instance::new( let instance = Instance::new(
library, library,
InstanceCreateInfo { InstanceCreateInfo {

View File

@@ -12,7 +12,10 @@ use std::{
}; };
use vulkano::{command_buffer::CommandBufferUsage, image::view::ImageView}; use vulkano::{command_buffer::CommandBufferUsage, image::view::ImageView};
use wlx_capture::{ use wlx_capture::{
frame::WlxFrame, frame::{
DrmFormat, WlxFrame, DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888, DRM_FORMAT_XBGR8888,
DRM_FORMAT_XRGB8888,
},
pipewire::{pipewire_select_screen, PipewireCapture}, pipewire::{pipewire_select_screen, PipewireCapture},
wayland::{wayland_client::protocol::wl_output::Transform, WlxClient, WlxOutput}, wayland::{wayland_client::protocol::wl_output::Transform, WlxClient, WlxOutput},
wlr_dmabuf::WlrDmabufCapture, wlr_dmabuf::WlrDmabufCapture,
@@ -33,6 +36,8 @@ use crate::{
state::{AppSession, AppState}, state::{AppSession, AppState},
}; };
static DRM_FORMATS: once_cell::sync::OnceCell<Vec<DrmFormat>> = once_cell::sync::OnceCell::new();
pub struct ScreenInteractionHandler { pub struct ScreenInteractionHandler {
next_scroll: Instant, next_scroll: Instant,
next_move: Instant, next_move: Instant,
@@ -154,7 +159,37 @@ impl OverlayRenderer for ScreenRenderer {
} }
fn render(&mut self, app: &mut AppState) { fn render(&mut self, app: &mut AppState) {
let receiver = self.receiver.get_or_insert_with(|| { let receiver = self.receiver.get_or_insert_with(|| {
let rx = self.capture.init(); let _drm_formats = DRM_FORMATS.get_or_init({
let graphics = app.graphics.clone();
move || {
let possible_formats = [
DRM_FORMAT_ABGR8888.into(),
DRM_FORMAT_XBGR8888.into(),
DRM_FORMAT_ARGB8888.into(),
DRM_FORMAT_XRGB8888.into(),
];
let mut final_formats = vec![];
for &f in &possible_formats {
let vk_fmt = fourcc_to_vk(f);
let Ok(props) = graphics.device.physical_device().format_properties(vk_fmt)
else {
continue;
};
final_formats.push(DrmFormat {
fourcc: f,
modifiers: props
.drm_format_modifier_properties
.iter()
.map(|m| m.drm_format_modifier)
.collect(),
})
}
final_formats
}
});
let rx = self.capture.init(&[]); // TODO: use drm_formats
self.capture.request_new_frame(); self.capture.request_new_frame();
rx rx
}); });