From 186e023de92480e850359c79b7f0f083d353379e Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Mon, 19 Feb 2024 18:04:13 +0100 Subject: [PATCH] cleanup features --- src/backend/common.rs | 4 +++- src/graphics.rs | 27 ++++++++++++--------- src/main.rs | 3 +-- src/overlays/screen.rs | 53 ++++++++++++++++++++++++++---------------- 4 files changed, 53 insertions(+), 34 deletions(-) diff --git a/src/backend/common.rs b/src/backend/common.rs index 811b063..7f4dbd2 100644 --- a/src/backend/common.rs +++ b/src/backend/common.rs @@ -4,9 +4,11 @@ use std::{ time::Instant, }; +#[cfg(feature = "openxr")] +use openxr as xr; + use glam::{Affine3A, Vec2, Vec3A}; use idmap::IdMap; -use openxr as xr; use thiserror::Error; use crate::{ diff --git a/src/graphics.rs b/src/graphics.rs index 25019cb..3a57494 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -1,17 +1,24 @@ use std::{ collections::HashMap, io::Cursor, - os::{ - fd::{FromRawFd, IntoRawFd}, - raw::c_void, - }, + os::fd::{FromRawFd, IntoRawFd}, slice::Iter, sync::{Arc, OnceLock, RwLock}, }; use anyhow::{anyhow, bail}; -use ash::vk::{self, SubmitInfo}; +use ash::vk::SubmitInfo; 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::{ buffer::{ allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo}, @@ -30,7 +37,6 @@ use vulkano::{ descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, }, - device::physical::PhysicalDeviceType, device::Features, device::{ physical::PhysicalDevice, Device, DeviceCreateInfo, DeviceExtensions, Queue, @@ -44,8 +50,6 @@ use vulkano::{ Image, ImageCreateInfo, ImageLayout, ImageTiling, ImageType, ImageUsage, SampleCount, SubresourceLayout, }, - instance::InstanceCreateFlags, - instance::InstanceExtensions, instance::{Instance, InstanceCreateInfo}, memory::{ allocator::{ @@ -75,7 +79,6 @@ use vulkano::{ SubpassDescription, }, shader::ShaderModule, - swapchain::Surface, sync::{ fence::Fence, future::NowFuture, AccessFlags, DependencyInfo, GpuFuture, ImageMemoryBarrier, PipelineStages, @@ -729,6 +732,7 @@ impl WlxGraphics { )?)) } + #[allow(dead_code)] pub fn create_pipeline_dynamic( self: &Arc, vert: Arc, @@ -763,6 +767,7 @@ impl WlxGraphics { }) } + #[allow(dead_code)] pub fn transition_layout( &self, image: Arc, @@ -827,6 +832,7 @@ pub struct WlxCommandBuffer { pub command_buffer: RecordingCommandBuffer, } +#[allow(dead_code)] impl WlxCommandBuffer { pub fn begin_render_pass( &mut self, @@ -925,9 +931,7 @@ impl WlxCommandBuffer { reader.next_frame(&mut image_data)?; self.texture2d(width, height, Format::R8G8B8A8_UNORM, &image_data) } -} -impl WlxCommandBuffer { pub fn end_render_pass(&mut self) -> anyhow::Result<()> { self.command_buffer .end_render_pass(SubpassEndInfo::default())?; @@ -971,6 +975,7 @@ pub struct WlxPipeline { pub data: D, } +#[allow(dead_code)] impl WlxPipeline { fn new( graphics: Arc, diff --git a/src/main.rs b/src/main.rs index 3944143..d056c3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,7 +53,6 @@ fn main() -> Result<(), Box> { Ok(()) } -#[cfg(all(feature = "openxr", feature = "openvr"))] fn auto_run(running: Arc) { use backend::common::BackendError; @@ -65,7 +64,7 @@ fn auto_run(running: Arc) { }; } - #[cfg(feature = "openxr")] + #[cfg(feature = "openvr")] { use crate::backend::openvr::openvr_run; let Err(BackendError::NotSupported) = openvr_run(running) else { diff --git a/src/overlays/screen.rs b/src/overlays/screen.rs index 86e3c5d..27e2744 100644 --- a/src/overlays/screen.rs +++ b/src/overlays/screen.rs @@ -1,11 +1,7 @@ use core::slice; use serde::{Deserialize, Serialize}; use std::{ - collections::HashMap, - error::Error, - f32::consts::PI, - ops::{Add, Deref}, - path::PathBuf, + ops::Add, ptr, sync::{mpsc::Receiver, Arc}, time::{Duration, Instant}, @@ -19,14 +15,26 @@ use wlx_capture::{ DrmFormat, MouseMeta, 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, - xshm::{XshmCapture, XshmScreen}, + wayland::wayland_client::protocol::wl_output::Transform, 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::{ backend::{ @@ -34,7 +42,6 @@ use crate::{ overlay::{OverlayData, OverlayRenderer, OverlayState, SplitOverlayBackend}, }, config::def_pw_tokens, - config_io, graphics::{fourcc_to_vk, WlxCommandBuffer, WlxPipeline, WlxPipelineLegacy}, hid::{MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT}, state::{AppSession, AppState}, @@ -356,12 +363,15 @@ impl OverlayRenderer for ScreenRenderer { log::error!("Invalid frame"); continue; } - if let Ok(new) = app.graphics.dmabuf_texture(frame) { - let view = ImageView::new_default(new.clone())?; + match app.graphics.dmabuf_texture(frame) { + Ok(new) => { + let view = ImageView::new_default(new.clone())?; - self.last_view = Some(view); - } else { - log::error!("{}: Failed to create DMA-buf texture", self.name); + self.last_view = Some(view); + } + Err(e) => { + log::error!("{}: Failed to create DMA-buf texture: {}", self.name, e); + } } } WlxFrame::MemFd(frame) => { @@ -596,12 +606,14 @@ pub struct TokenConf { pub pw_tokens: Vec<(String, String)>, } +#[cfg(feature = "wayland")] fn get_pw_token_path() -> PathBuf { let mut path = config_io::get_conf_d_path(); path.push("pw_tokens.yaml"); path } +#[cfg(feature = "wayland")] pub fn save_pw_token_config(tokens: &HashMap) -> Result<(), Box> { let mut conf = TokenConf::default(); @@ -615,6 +627,7 @@ pub fn save_pw_token_config(tokens: &HashMap) -> Result<(), Box< Ok(()) } +#[cfg(feature = "wayland")] pub fn load_pw_token_config() -> Result, Box> { let mut map: HashMap = HashMap::new(); @@ -629,11 +642,11 @@ pub fn load_pw_token_config() -> Result, Box> } #[cfg(not(feature = "wayland"))] -pub fn get_screens_wayland(_session: &AppSession) -> (Vec>, Vec2) +pub fn get_screens_wayland(_session: &AppSession) -> anyhow::Result<(Vec>, Vec2)> where O: Default, { - panic!("Wayland support not enabled") + anyhow::bail!("Wayland support not enabled") } #[cfg(feature = "wayland")] @@ -671,11 +684,11 @@ where } #[cfg(not(feature = "x11"))] -pub fn get_screens_x11(session: &AppSession) -> (Vec>, Vec2) +pub fn get_screens_x11(_session: &AppSession) -> anyhow::Result<(Vec>, Vec2)> where O: Default, { - panic!("X11 support not enabled") + anyhow::bail!("X11 support not enabled") } #[cfg(feature = "x11")]