diff --git a/Cargo.lock b/Cargo.lock index 7b9a14f..f075bc2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4745,7 +4745,7 @@ dependencies = [ [[package]] name = "sf-compositor" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "sf-ipc", @@ -4756,7 +4756,7 @@ dependencies = [ [[package]] name = "sf-core" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "env_logger", @@ -4771,7 +4771,7 @@ dependencies = [ [[package]] name = "sf-dial" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "log", @@ -4781,7 +4781,7 @@ dependencies = [ [[package]] name = "sf-ipc" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "log", @@ -4793,7 +4793,7 @@ dependencies = [ [[package]] name = "sf-launcher" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "chrono", @@ -4813,7 +4813,7 @@ dependencies = [ [[package]] name = "sf-miracast" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "env_logger", @@ -4825,7 +4825,7 @@ dependencies = [ [[package]] name = "sf-remote" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "bluer", @@ -4851,7 +4851,7 @@ dependencies = [ [[package]] name = "sf-update" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index 98fa78a..b6251d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "3" members = ["crates/sf-ipc", "crates/sf-launcher", "crates/sf-remote", "crates/sf-dial", "crates/sf-core", "crates/sf-update", "crates/sf-miracast", "crates/sf-compositor"] [workspace.package] -version = "0.3.0" +version = "0.3.1" edition = "2024" license = "MIT" diff --git a/crates/sf-compositor/src/state.rs b/crates/sf-compositor/src/state.rs index c0c907d..1f246df 100644 --- a/crates/sf-compositor/src/state.rs +++ b/crates/sf-compositor/src/state.rs @@ -1,5 +1,9 @@ //! Compositor state: Wayland protocol handlers, which window is visible, //! the switch animation, the volume OSD and the render element list. +//! +//! Besides what a kiosk needs, it offers what nested compositors need: +//! gamescope (which hosts Steam) refuses to start without presentation-time, +//! relative pointer and pointer constraints (and dmabuf, viewporter). use std::ffi::OsString; use std::io::Write; @@ -16,25 +20,31 @@ use smithay::backend::renderer::gles::GlesRenderer; use smithay::backend::renderer::utils::on_commit_buffer_handler; use smithay::backend::session::Session; use smithay::backend::session::libseat::LibSeatSession; +use smithay::desktop::utils::OutputPresentationFeedback; use smithay::desktop::{PopupKind, PopupManager, Space, Window, find_popup_root_surface, get_popup_toplevel_coords}; use smithay::input::keyboard::{FilterResult, XkbConfig, keysyms}; +use smithay::input::pointer::PointerHandle; use smithay::input::{Seat, SeatHandler, SeatState}; use smithay::output::Output; use smithay::reexports::calloop::generic::Generic; use smithay::reexports::calloop::timer::{TimeoutAction, Timer}; use smithay::reexports::calloop::{EventLoop, Interest, LoopHandle, LoopSignal, Mode, PostAction}; +use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback; use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1; use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; use smithay::reexports::wayland_server::backend::{ClientData, ClientId, DisconnectReason}; use smithay::reexports::wayland_server::protocol::{wl_buffer, wl_output, wl_seat, wl_surface::WlSurface}; use smithay::reexports::wayland_server::{Client, Display, DisplayHandle, Resource}; -use smithay::utils::{IsAlive, Logical, Physical, Point, Rectangle, SERIAL_COUNTER, Scale, Serial, Size}; +use smithay::utils::{Clock, IsAlive, Logical, Monotonic, Physical, Point, Rectangle, SERIAL_COUNTER, Scale, Serial, Size}; use smithay::wayland::buffer::BufferHandler; use smithay::wayland::compositor::{ CompositorClientState, CompositorHandler, CompositorState, get_parent, is_sync_subsurface, with_states, }; use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportNotifier}; use smithay::wayland::output::{OutputHandler, OutputManagerState}; +use smithay::wayland::pointer_constraints::{PointerConstraintsHandler, PointerConstraintsState}; +use smithay::wayland::presentation::PresentationState; +use smithay::wayland::relative_pointer::RelativePointerManagerState; use smithay::wayland::selection::SelectionHandler; use smithay::wayland::selection::data_device::{ ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, ServerDndGrabHandler, set_data_device_focus, @@ -47,8 +57,9 @@ use smithay::wayland::shm::{ShmHandler, ShmState}; use smithay::wayland::socket::ListeningSocketSource; use smithay::wayland::viewporter::ViewporterState; use smithay::{ - delegate_compositor, delegate_data_device, delegate_dmabuf, delegate_output, delegate_seat, delegate_shm, - delegate_viewporter, delegate_xdg_decoration, delegate_xdg_shell, + delegate_compositor, delegate_data_device, delegate_dmabuf, delegate_output, delegate_pointer_constraints, + delegate_presentation, delegate_relative_pointer, delegate_seat, delegate_shm, delegate_viewporter, + delegate_xdg_decoration, delegate_xdg_shell, }; use crate::output_mgmt::{OutputMgmtState, PendingConfig}; @@ -175,6 +186,14 @@ pub struct State { pub viewporter_state: ViewporterState, #[allow(dead_code)] pub decoration_state: XdgDecorationState, + #[allow(dead_code)] + pub presentation_state: PresentationState, + #[allow(dead_code)] + pub relative_pointer_state: RelativePointerManagerState, + #[allow(dead_code)] + pub pointer_constraints_state: PointerConstraintsState, + /// The clock presentation feedback is given in (CLOCK_MONOTONIC). + pub clock: Clock, pub output_mgmt: OutputMgmtState, pub pending_configs: Vec, pub popups: PopupManager, @@ -288,12 +307,19 @@ impl State { let data_device_state = DataDeviceState::new::(&dh); let viewporter_state = ViewporterState::new::(&dh); let decoration_state = XdgDecorationState::new::(&dh); + let clock = Clock::::new(); + let presentation_state = PresentationState::new::(&dh, clock.id() as u32); + let relative_pointer_state = RelativePointerManagerState::new::(&dh); + let pointer_constraints_state = PointerConstraintsState::new::(&dh); let output_mgmt = OutputMgmtState::new(&dh); let mut seat: Seat = seat_state.new_wl_seat(&dh, "seat0"); // Same repeat as cage/wlroots: 600 ms delay, 25 per second. seat.add_keyboard(XkbConfig::default(), 600, 25) .map_err(|e| anyhow::anyhow!("keyboard: {e:?}"))?; + // No pointer device is ever attached (the cursor theme is blank), but + // relative pointer and pointer constraints work on a wl_pointer. + seat.add_pointer(); let socket = ListeningSocketSource::new_auto()?; let socket_name = socket.socket_name().to_os_string(); @@ -331,6 +357,10 @@ impl State { dmabuf_global: None, viewporter_state, decoration_state, + presentation_state, + relative_pointer_state, + pointer_constraints_state, + clock, output_mgmt, pending_configs: vec![], popups: PopupManager::default(), @@ -695,21 +725,37 @@ impl State { out } - /// Frame callbacks for what is on screen (hidden apps get none, so they idle). - pub fn send_frames(&self) { - let Some(output) = self.output.as_ref() else { return }; - let time = self.start.elapsed(); - // The held-back app draws too, so its page is ready when it shows. + /// Windows that get frame callbacks: what is on screen, and the + /// held-back app (it draws, so its page is ready when it shows). + fn shown(&self) -> Vec<&Window> { let mut shown: Vec<&Window> = self.visible.iter().chain(self.held.iter()).collect(); if let Some(t) = &self.transition { shown.push(&t.over); shown.extend(t.under.iter()); } - for w in shown { + shown + } + + /// Frame callbacks for what is on screen (hidden apps get none, so they idle). + pub fn send_frames(&self) { + let Some(output) = self.output.as_ref() else { return }; + let time = self.start.elapsed(); + for w in self.shown() { w.send_frame(output, time, Some(Duration::ZERO), |_, _| Some(output.clone())); } } + /// Presentation feedback requests of the frame being rendered; answered + /// when it is on screen (`presented`) or dropped if it never gets there. + pub fn presentation_feedback(&self) -> Option { + let output = self.output.as_ref()?; + let mut feedback = OutputPresentationFeedback::new(output); + for w in self.shown() { + w.take_presentation_feedback(&mut feedback, |_, _| Some(output.clone()), |_, _| wp_presentation_feedback::Kind::Vsync); + } + Some(feedback) + } + pub fn output_mgmt_refresh(&mut self) { let info = crate::output_mgmt::HeadInfo::from_state(self); self.output_mgmt.update(&self.dh, info); @@ -935,6 +981,12 @@ impl ServerDndGrabHandler for State {} impl OutputHandler for State {} +impl PointerConstraintsHandler for State { + // There is no pointer to lock or confine; the requests are accepted. + fn new_constraint(&mut self, _surface: &WlSurface, _pointer: &PointerHandle) {} + fn cursor_position_hint(&mut self, _surface: &WlSurface, _pointer: &PointerHandle, _location: Point) {} +} + impl DmabufHandler for State { fn dmabuf_state(&mut self) -> &mut DmabufState { &mut self.dmabuf_state @@ -960,3 +1012,6 @@ delegate_data_device!(State); delegate_output!(State); delegate_dmabuf!(State); delegate_viewporter!(State); +delegate_presentation!(State); +delegate_relative_pointer!(State); +delegate_pointer_constraints!(State); diff --git a/crates/sf-compositor/src/udev.rs b/crates/sf-compositor/src/udev.rs index 939d3bb..382e541 100644 --- a/crates/sf-compositor/src/udev.rs +++ b/crates/sf-compositor/src/udev.rs @@ -10,7 +10,7 @@ use smithay::backend::allocator::gbm::{GbmAllocator, GbmBufferFlags, GbmDevice}; use smithay::backend::drm::compositor::FrameFlags; use smithay::backend::drm::exporter::gbm::GbmFramebufferExporter; use smithay::backend::drm::output::{DrmOutput, DrmOutputManager, DrmOutputRenderElements}; -use smithay::backend::drm::{DrmDevice, DrmDeviceFd, DrmEvent, DrmNode}; +use smithay::backend::drm::{DrmDevice, DrmDeviceFd, DrmEvent, DrmEventMetadata, DrmEventTime, DrmNode}; use smithay::backend::egl::{EGLContext, EGLDevice, EGLDisplay}; use smithay::backend::libinput::{LibinputInputBackend, LibinputSessionInterface}; use smithay::backend::renderer::gles::GlesRenderer; @@ -18,13 +18,16 @@ use smithay::backend::renderer::{ImportDma, ImportMemWl}; use smithay::backend::session::libseat::LibSeatSession; use smithay::backend::session::{Event as SessionEvent, Session}; use smithay::backend::udev::{UdevBackend, UdevEvent, all_gpus, primary_gpu}; +use smithay::desktop::utils::OutputPresentationFeedback; use smithay::output::{Mode as WlMode, Output, PhysicalProperties, Subpixel}; use smithay::reexports::calloop::timer::{TimeoutAction, Timer}; use smithay::reexports::calloop::EventLoop; use smithay::reexports::drm::control::{Device as ControlDevice, ModeTypeFlags, connector, crtc}; use smithay::reexports::input::Libinput; use smithay::reexports::rustix::fs::OFlags; +use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback; use smithay::reexports::wayland_server::backend::GlobalId; +use smithay::wayland::presentation::Refresh; use smithay::utils::DeviceFd; use smithay::wayland::dmabuf::DmabufFeedbackBuilder; @@ -33,11 +36,13 @@ use crate::state::{App, Backend, SfElement, State}; type Allocator = GbmAllocator; type Exporter = GbmFramebufferExporter; +/// Travels with a queued frame: the clients' presentation feedback requests. +type Feedback = Option; const FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888, Fourcc::Xrgb8888]; struct Out { - drm_output: DrmOutput, + drm_output: DrmOutput, connector: connector::Handle, crtc: crtc::Handle, modes: Vec, @@ -52,7 +57,7 @@ pub struct UdevData { /// Keeps the seat session (and device access) alive. _session: LibSeatSession, libinput: Libinput, - manager: DrmOutputManager, + manager: DrmOutputManager, renderer: GlesRenderer, out: Option, active: bool, @@ -110,10 +115,10 @@ pub fn init(event_loop: &mut EventLoop<'static, App>, state: &mut State) -> Resu // Vblanks. handle - .insert_source(drm_notifier, |event, _, app: &mut App| match event { + .insert_source(drm_notifier, |event, metadata, app: &mut App| match event { DrmEvent::VBlank(_crtc) => { if let Backend::Udev(u) = &mut app.backend { - u.frame_done(&mut app.state); + u.frame_done(&mut app.state, metadata.take()); } } DrmEvent::Error(e) => tracing::error!("drm: {e:?}"), @@ -285,10 +290,27 @@ impl UdevData { } } - fn frame_done(&mut self, state: &mut State) { + fn frame_done(&mut self, state: &mut State, metadata: Option) { let Some(out) = self.out.as_mut() else { return }; - if let Err(e) = out.drm_output.frame_submitted() { - tracing::warn!("frame_submitted: {e:?}"); + match out.drm_output.frame_submitted() { + Ok(Some(Some(mut feedback))) => { + // The flip time from the kernel, else now (both monotonic). + let (time, seq) = match metadata { + Some(DrmEventMetadata { time: DrmEventTime::Monotonic(t), sequence }) => (t, sequence as u64), + _ => (state.clock.now().into(), 0), + }; + let refresh = out + .output + .current_mode() + .map(|m| Refresh::fixed(Duration::from_nanos(1_000_000_000_000 / m.refresh.max(1) as u64))) + .unwrap_or(Refresh::Unknown); + let flags = wp_presentation_feedback::Kind::Vsync + | wp_presentation_feedback::Kind::HwClock + | wp_presentation_feedback::Kind::HwCompletion; + feedback.presented::<_, smithay::utils::Monotonic>(time, refresh, seq, flags); + } + Ok(_) => {} + Err(e) => tracing::warn!("frame_submitted: {e:?}"), } out.frame_pending = false; state.send_frames(); @@ -329,7 +351,7 @@ impl UdevData { } }; if rendered { - match out.drm_output.queue_frame(()) { + match out.drm_output.queue_frame(state.presentation_feedback()) { Ok(()) => out.frame_pending = true, Err(e) => tracing::warn!("queue_frame: {e:?}"), } diff --git a/crates/sf-compositor/src/winit.rs b/crates/sf-compositor/src/winit.rs index 7401cff..c2e4b2c 100644 --- a/crates/sf-compositor/src/winit.rs +++ b/crates/sf-compositor/src/winit.rs @@ -9,7 +9,9 @@ use smithay::backend::renderer::gles::GlesRenderer; use smithay::backend::winit::{self, WinitEvent, WinitGraphicsBackend}; use smithay::output::{Mode, Output, PhysicalProperties, Subpixel}; use smithay::reexports::calloop::EventLoop; +use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback; use smithay::utils::Transform; +use std::time::Duration; use crate::output_mgmt::{ModeInfo, OutputModes, PendingConfig}; use crate::state::{App, Backend, State}; @@ -86,8 +88,15 @@ fn render(app: &mut App) { } }; if let Some(damage) = damage { - if let Err(e) = w.backend.submit(Some(&damage)) { - tracing::warn!("submit: {e:?}"); + let feedback = app.state.presentation_feedback(); + match w.backend.submit(Some(&damage)) { + Ok(()) => { + if let Some(mut f) = feedback { + let refresh = smithay::wayland::presentation::Refresh::fixed(Duration::from_micros(16_667)); + f.presented::<_, smithay::utils::Monotonic>(app.state.clock.now(), refresh, 0, wp_presentation_feedback::Kind::Vsync); + } + } + Err(e) => tracing::warn!("submit: {e:?}"), } } app.state.send_frames(); diff --git a/docs/store.md b/docs/store.md index 00f558e..9920cbf 100644 --- a/docs/store.md +++ b/docs/store.md @@ -140,5 +140,8 @@ A Steam store app: [`fennec/steam`](https://gitea.bluefox.support/fennec/steam), Az OS adja a rendszerszintű részt (az image-ben): - a `gamescope`-ot; - a 32 bites könyvtárakat (`steam-libs-i386`) a Valve aláírt apt-repójából (`mkosi.postinst.chroot`, a kulcs: `image/mkosi.extra/usr/share/keyrings/valve-archive-keyring.gpg`); -- a kontrollerek udev-szabályait a Valve `steam-launcher` csomagjából (csak a szabályokat, a launchert nem). +- a kontrollerek udev-szabályait a Valve `steam-launcher` csomagjából (csak a szabályokat, a launchert nem); +- a kompozitorban azokat a Wayland-protokollokat, amelyek nélkül a beágyazott `gamescope` el sem indul: `wp_presentation` (valódi képkocka-visszajelzéssel), `zwp_relative_pointer_manager_v1`, `zwp_pointer_constraints_v1` (és a meglévő dmabuf, viewporter). + +A `gamescope`-nak hardveres Vulkan is kell (`VK_EXT_physical_device_drm`). A QEMU-s teszt-VM-ben csak szoftveres Vulkan (llvmpipe) van, ott a `gamescope` emiatt áll le; a Steam teljes útját valódi gépen kell kipróbálni.