cleanup features

This commit is contained in:
galister
2024-02-19 18:04:13 +01:00
parent 0eebc206a2
commit 186e023de9
4 changed files with 53 additions and 34 deletions

View File

@@ -4,9 +4,11 @@ use std::{
time::Instant, time::Instant,
}; };
#[cfg(feature = "openxr")]
use openxr as xr;
use glam::{Affine3A, Vec2, Vec3A}; use glam::{Affine3A, Vec2, Vec3A};
use idmap::IdMap; use idmap::IdMap;
use openxr as xr;
use thiserror::Error; use thiserror::Error;
use crate::{ use crate::{

View File

@@ -1,17 +1,24 @@
use std::{ use std::{
collections::HashMap, collections::HashMap,
io::Cursor, io::Cursor,
os::{ os::fd::{FromRawFd, IntoRawFd},
fd::{FromRawFd, IntoRawFd},
raw::c_void,
},
slice::Iter, slice::Iter,
sync::{Arc, OnceLock, RwLock}, sync::{Arc, OnceLock, RwLock},
}; };
use anyhow::{anyhow, bail}; use anyhow::{anyhow, bail};
use ash::vk::{self, SubmitInfo}; use ash::vk::SubmitInfo;
use smallvec::smallvec; use smallvec::smallvec;
#[cfg(feature = "openvr")]
use vulkano::{
device::physical::PhysicalDeviceType, instance::InstanceCreateFlags,
instance::InstanceExtensions,
};
#[cfg(feature = "openxr")]
use {ash::vk, std::os::raw::c_void, vulkano::swapchain::Surface};
use vulkano::{ use vulkano::{
buffer::{ buffer::{
allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo}, allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo},
@@ -30,7 +37,6 @@ use vulkano::{
descriptor_set::{ descriptor_set::{
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
}, },
device::physical::PhysicalDeviceType,
device::Features, device::Features,
device::{ device::{
physical::PhysicalDevice, Device, DeviceCreateInfo, DeviceExtensions, Queue, physical::PhysicalDevice, Device, DeviceCreateInfo, DeviceExtensions, Queue,
@@ -44,8 +50,6 @@ use vulkano::{
Image, ImageCreateInfo, ImageLayout, ImageTiling, ImageType, ImageUsage, SampleCount, Image, ImageCreateInfo, ImageLayout, ImageTiling, ImageType, ImageUsage, SampleCount,
SubresourceLayout, SubresourceLayout,
}, },
instance::InstanceCreateFlags,
instance::InstanceExtensions,
instance::{Instance, InstanceCreateInfo}, instance::{Instance, InstanceCreateInfo},
memory::{ memory::{
allocator::{ allocator::{
@@ -75,7 +79,6 @@ use vulkano::{
SubpassDescription, SubpassDescription,
}, },
shader::ShaderModule, shader::ShaderModule,
swapchain::Surface,
sync::{ sync::{
fence::Fence, future::NowFuture, AccessFlags, DependencyInfo, GpuFuture, fence::Fence, future::NowFuture, AccessFlags, DependencyInfo, GpuFuture,
ImageMemoryBarrier, PipelineStages, ImageMemoryBarrier, PipelineStages,
@@ -729,6 +732,7 @@ impl WlxGraphics {
)?)) )?))
} }
#[allow(dead_code)]
pub fn create_pipeline_dynamic( pub fn create_pipeline_dynamic(
self: &Arc<Self>, self: &Arc<Self>,
vert: Arc<ShaderModule>, vert: Arc<ShaderModule>,
@@ -763,6 +767,7 @@ impl WlxGraphics {
}) })
} }
#[allow(dead_code)]
pub fn transition_layout( pub fn transition_layout(
&self, &self,
image: Arc<Image>, image: Arc<Image>,
@@ -827,6 +832,7 @@ pub struct WlxCommandBuffer {
pub command_buffer: RecordingCommandBuffer, pub command_buffer: RecordingCommandBuffer,
} }
#[allow(dead_code)]
impl WlxCommandBuffer { impl WlxCommandBuffer {
pub fn begin_render_pass( pub fn begin_render_pass(
&mut self, &mut self,
@@ -925,9 +931,7 @@ impl WlxCommandBuffer {
reader.next_frame(&mut image_data)?; reader.next_frame(&mut image_data)?;
self.texture2d(width, height, Format::R8G8B8A8_UNORM, &image_data) self.texture2d(width, height, Format::R8G8B8A8_UNORM, &image_data)
} }
}
impl WlxCommandBuffer {
pub fn end_render_pass(&mut self) -> anyhow::Result<()> { pub fn end_render_pass(&mut self) -> anyhow::Result<()> {
self.command_buffer self.command_buffer
.end_render_pass(SubpassEndInfo::default())?; .end_render_pass(SubpassEndInfo::default())?;
@@ -971,6 +975,7 @@ pub struct WlxPipeline<D> {
pub data: D, pub data: D,
} }
#[allow(dead_code)]
impl WlxPipeline<WlxPipelineDynamic> { impl WlxPipeline<WlxPipelineDynamic> {
fn new( fn new(
graphics: Arc<WlxGraphics>, graphics: Arc<WlxGraphics>,

View File

@@ -53,7 +53,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(()) Ok(())
} }
#[cfg(all(feature = "openxr", feature = "openvr"))]
fn auto_run(running: Arc<AtomicBool>) { fn auto_run(running: Arc<AtomicBool>) {
use backend::common::BackendError; use backend::common::BackendError;
@@ -65,7 +64,7 @@ fn auto_run(running: Arc<AtomicBool>) {
}; };
} }
#[cfg(feature = "openxr")] #[cfg(feature = "openvr")]
{ {
use crate::backend::openvr::openvr_run; use crate::backend::openvr::openvr_run;
let Err(BackendError::NotSupported) = openvr_run(running) else { let Err(BackendError::NotSupported) = openvr_run(running) else {

View File

@@ -1,11 +1,7 @@
use core::slice; use core::slice;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{ use std::{
collections::HashMap, ops::Add,
error::Error,
f32::consts::PI,
ops::{Add, Deref},
path::PathBuf,
ptr, ptr,
sync::{mpsc::Receiver, Arc}, sync::{mpsc::Receiver, Arc},
time::{Duration, Instant}, time::{Duration, Instant},
@@ -19,14 +15,26 @@ use wlx_capture::{
DrmFormat, MouseMeta, WlxFrame, DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888, DrmFormat, MouseMeta, WlxFrame, DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888,
DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888, DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888,
}, },
pipewire::{pipewire_select_screen, PipewireCapture}, wayland::wayland_client::protocol::wl_output::Transform,
wayland::{wayland_client::protocol::wl_output::Transform, WlxClient, WlxOutput},
wlr_dmabuf::WlrDmabufCapture,
xshm::{XshmCapture, XshmScreen},
WlxCapture, WlxCapture,
}; };
use glam::{vec2, vec3a, Affine2, Quat, Vec2, Vec3}; #[cfg(feature = "wayland")]
use {
crate::config_io,
glam::Vec3,
std::{collections::HashMap, error::Error, f32::consts::PI, ops::Deref, path::PathBuf},
wlx_capture::{
pipewire::{pipewire_select_screen, PipewireCapture},
wayland::{WlxClient, WlxOutput},
wlr_dmabuf::WlrDmabufCapture,
},
};
#[cfg(feature = "x11")]
use wlx_capture::xshm::{XshmCapture, XshmScreen};
use glam::{vec2, vec3a, Affine2, Quat, Vec2};
use crate::{ use crate::{
backend::{ backend::{
@@ -34,7 +42,6 @@ use crate::{
overlay::{OverlayData, OverlayRenderer, OverlayState, SplitOverlayBackend}, overlay::{OverlayData, OverlayRenderer, OverlayState, SplitOverlayBackend},
}, },
config::def_pw_tokens, config::def_pw_tokens,
config_io,
graphics::{fourcc_to_vk, WlxCommandBuffer, WlxPipeline, WlxPipelineLegacy}, graphics::{fourcc_to_vk, WlxCommandBuffer, WlxPipeline, WlxPipelineLegacy},
hid::{MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT}, hid::{MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT},
state::{AppSession, AppState}, state::{AppSession, AppState},
@@ -356,12 +363,15 @@ impl OverlayRenderer for ScreenRenderer {
log::error!("Invalid frame"); log::error!("Invalid frame");
continue; continue;
} }
if let Ok(new) = app.graphics.dmabuf_texture(frame) { match app.graphics.dmabuf_texture(frame) {
Ok(new) => {
let view = ImageView::new_default(new.clone())?; let view = ImageView::new_default(new.clone())?;
self.last_view = Some(view); self.last_view = Some(view);
} else { }
log::error!("{}: Failed to create DMA-buf texture", self.name); Err(e) => {
log::error!("{}: Failed to create DMA-buf texture: {}", self.name, e);
}
} }
} }
WlxFrame::MemFd(frame) => { WlxFrame::MemFd(frame) => {
@@ -596,12 +606,14 @@ pub struct TokenConf {
pub pw_tokens: Vec<(String, String)>, pub pw_tokens: Vec<(String, String)>,
} }
#[cfg(feature = "wayland")]
fn get_pw_token_path() -> PathBuf { fn get_pw_token_path() -> PathBuf {
let mut path = config_io::get_conf_d_path(); let mut path = config_io::get_conf_d_path();
path.push("pw_tokens.yaml"); path.push("pw_tokens.yaml");
path path
} }
#[cfg(feature = "wayland")]
pub fn save_pw_token_config(tokens: &HashMap<String, String>) -> Result<(), Box<dyn Error>> { pub fn save_pw_token_config(tokens: &HashMap<String, String>) -> Result<(), Box<dyn Error>> {
let mut conf = TokenConf::default(); let mut conf = TokenConf::default();
@@ -615,6 +627,7 @@ pub fn save_pw_token_config(tokens: &HashMap<String, String>) -> Result<(), Box<
Ok(()) Ok(())
} }
#[cfg(feature = "wayland")]
pub fn load_pw_token_config() -> Result<HashMap<String, String>, Box<dyn Error>> { pub fn load_pw_token_config() -> Result<HashMap<String, String>, Box<dyn Error>> {
let mut map: HashMap<String, String> = HashMap::new(); let mut map: HashMap<String, String> = HashMap::new();
@@ -629,11 +642,11 @@ pub fn load_pw_token_config() -> Result<HashMap<String, String>, Box<dyn Error>>
} }
#[cfg(not(feature = "wayland"))] #[cfg(not(feature = "wayland"))]
pub fn get_screens_wayland<O>(_session: &AppSession) -> (Vec<OverlayData<O>>, Vec2) pub fn get_screens_wayland<O>(_session: &AppSession) -> anyhow::Result<(Vec<OverlayData<O>>, Vec2)>
where where
O: Default, O: Default,
{ {
panic!("Wayland support not enabled") anyhow::bail!("Wayland support not enabled")
} }
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
@@ -671,11 +684,11 @@ where
} }
#[cfg(not(feature = "x11"))] #[cfg(not(feature = "x11"))]
pub fn get_screens_x11<O>(session: &AppSession) -> (Vec<OverlayData<O>>, Vec2) pub fn get_screens_x11<O>(_session: &AppSession) -> anyhow::Result<(Vec<OverlayData<O>>, Vec2)>
where where
O: Default, O: Default,
{ {
panic!("X11 support not enabled") anyhow::bail!("X11 support not enabled")
} }
#[cfg(feature = "x11")] #[cfg(feature = "x11")]