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

View File

@@ -66,9 +66,9 @@ impl OverlayData<OpenVrOverlayData> {
pub(super) fn after_input(&mut self, overlay: &mut OverlayManager, app: &mut AppState) {
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 {
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 {
Some(handle) => handle,
None => self.initialize(overlay, app),
@@ -92,9 +92,10 @@ impl OverlayData<OpenVrOverlayData> {
panic!("Failed to show overlay: {}", e);
}
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 {
return;
};
@@ -103,6 +104,7 @@ impl OverlayData<OpenVrOverlayData> {
panic!("Failed to hide overlay: {}", e);
}
self.data.visible = false;
self.backend.pause(app);
}
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
.session
.locate_views(

View File

@@ -6,12 +6,14 @@ use super::{swapchain::SwapchainRenderData, transform_to_posef, XrState};
use crate::{
backend::{openxr::swapchain::create_swapchain_render_data, overlay::OverlayData},
graphics::WlxCommandBuffer,
state::AppState,
};
use vulkano::image::view::ImageView;
#[derive(Default)]
pub struct OpenXrOverlayData {
last_view: Option<Arc<ImageView>>,
last_visible: bool,
pub(super) swapchain: Option<SwapchainRenderData>,
pub(super) init: bool,
}
@@ -67,4 +69,15 @@ impl OverlayData<OpenXrOverlayData> {
});
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>> {
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 {

View File

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

View File

@@ -12,7 +12,10 @@ use std::{
};
use vulkano::{command_buffer::CommandBufferUsage, image::view::ImageView};
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},
wayland::{wayland_client::protocol::wl_output::Transform, WlxClient, WlxOutput},
wlr_dmabuf::WlrDmabufCapture,
@@ -33,6 +36,8 @@ use crate::{
state::{AppSession, AppState},
};
static DRM_FORMATS: once_cell::sync::OnceCell<Vec<DrmFormat>> = once_cell::sync::OnceCell::new();
pub struct ScreenInteractionHandler {
next_scroll: Instant,
next_move: Instant,
@@ -154,7 +159,37 @@ impl OverlayRenderer for ScreenRenderer {
}
fn render(&mut self, app: &mut AppState) {
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();
rx
});