diff --git a/app/Cargo.lock b/app/Cargo.lock index cdffabf..c21a334 100644 --- a/app/Cargo.lock +++ b/app/Cargo.lock @@ -2827,6 +2827,7 @@ dependencies = [ "wgpu", "windows", "windows-core", + "windows-numerics", "windows-sys 0.61.2", "winit", "x11rb", diff --git a/app/src/app.rs b/app/src/app.rs index b9470ff..5a1734c 100644 --- a/app/src/app.rs +++ b/app/src/app.rs @@ -962,6 +962,17 @@ impl App { // --------------------------------------------------------------------------- pub fn poll(app: &mut App, t: f64, tx: &mut Tx) -> bool { + // Snapshot hook: pause the demo clip when its clock passes `LR_DEMO_PAUSE_AT` seconds. + if let Some(at) = std::env::var("LR_DEMO_PAUSE_AT") + .ok() + .and_then(|v| v.parse::().ok()) + { + if let Some(player) = &app.review.player { + if player.is_playing() && player.time() >= at { + app.review.playback(); + } + } + } app.handle_poll(t, tx) } @@ -1337,6 +1348,11 @@ pub fn demo_review(app: &mut App) { player.set_looping(false); app.review.player = Some(player); app.review.error = None; + if std::env::var("LR_DEMO_PLAY").is_ok() + && let Some(player) = &app.review.player + { + player.play(); + } if let Ok(tracks) = std::env::var("LR_DEMO_TRACKS") { if let Some(game) = app.review.game.as_mut() { game.audio_tracks = tracks diff --git a/app/src/screens/review.rs b/app/src/screens/review.rs index dbe4c04..cf6865f 100644 --- a/app/src/screens/review.rs +++ b/app/src/screens/review.rs @@ -229,7 +229,7 @@ impl Review { } } - fn playback(&mut self) { + pub(crate) fn playback(&mut self) { let playing = self.player.as_ref().is_some_and(Player::is_playing); if let Some(player) = &self.player { if playing { diff --git a/app/vendor/rune/Cargo.lock b/app/vendor/rune/Cargo.lock index acffc29..81d5c82 100644 --- a/app/vendor/rune/Cargo.lock +++ b/app/vendor/rune/Cargo.lock @@ -3855,6 +3855,7 @@ dependencies = [ "wgpu", "windows", "windows-core", + "windows-numerics", "windows-sys 0.61.2", "winit", "x11rb", diff --git a/app/vendor/rune/Cargo.toml b/app/vendor/rune/Cargo.toml index daa3401..5f65a80 100644 --- a/app/vendor/rune/Cargo.toml +++ b/app/vendor/rune/Cargo.toml @@ -214,6 +214,7 @@ web-sys = "0.3" wgpu = { version = "~30.0.1", default-features = false } wgpu-naga-bridge = "~30.0.1" windows = "0.62" +windows-numerics = "0.3" windows-core = "0.62" windows-sys = "0.61" winit = { version = "0.30.13", default-features = false } diff --git a/app/vendor/rune/crates/rune/Cargo.toml b/app/vendor/rune/crates/rune/Cargo.toml index 18b7863..caa8acf 100644 --- a/app/vendor/rune/crates/rune/Cargo.toml +++ b/app/vendor/rune/crates/rune/Cargo.toml @@ -171,6 +171,7 @@ xkbcommon = "0.9" # DirectComposition handover (`platform::win32::dcomp_handover`), OLE drag and drop # (`drag_out::windows`, `platform::win32::drop_target`), jump lists and the taskbar button's # progress and badge (`platform::win32::{jump_list,taskbar}`). +windows-numerics.workspace = true windows = { workspace = true, features = ["Win32_Foundation", "Win32_Graphics_DirectComposition", "Win32_Graphics_Gdi", "Win32_System_Com", "Win32_System_Com_StructuredStorage", "Win32_System_Ole", "Win32_System_SystemServices", "Win32_UI_Shell", "Win32_UI_Shell_Common", "Win32_UI_Shell_PropertiesSystem", "Win32_UI_WindowsAndMessaging"] } # `#[windows::core::implement]` (the OLE drop target, `platform::win32::drop_target`) names this crate. windows-core = { workspace = true } diff --git a/app/vendor/rune/crates/rune/src/window/win32/video_layer.rs b/app/vendor/rune/crates/rune/src/window/win32/video_layer.rs index 624ecba..08b9080 100644 --- a/app/vendor/rune/crates/rune/src/window/win32/video_layer.rs +++ b/app/vendor/rune/crates/rune/src/window/win32/video_layer.rs @@ -18,6 +18,7 @@ use crate::platform::win32::dcomp_handover::Handover; use crate::time::Instant; use std::sync::Arc; use std::time::Duration; +use windows_numerics::Matrix3x2; use windows::Win32::Graphics::DirectComposition::IDCompositionVisual; /// How long no layer shows before the UI's swap chain goes back to opaque. @@ -47,14 +48,17 @@ pub(super) struct Seen { pub showing: bool, pub size: (u32, u32), pub at: (i32, i32), + // The picture's rect in device pixels, as the window drew it: the exact place the layer + // covers, before the rounding the layer's own placement does. + pub rect: [f32; 4], } -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq)] pub(super) enum Effect { /// The decoder presents on the layer at this size, or (None) leaves the pictures to the UI. Ask(Option<(u32, u32)>), - /// Move the layer's visual to `at`, commit, and wait for DWM to take it. - Show { at: (i32, i32) }, + /// Place the layer's visual over the picture's rect, commit, and wait for DWM to take it. + Show { rect: [f32; 4] }, /// Punch the clip's place out this frame. Punch, } @@ -72,7 +76,7 @@ pub(super) fn step(phase: &mut Phase, seen: Seen) -> Effect { } Phase::Placing { size } if seen.showing => { *phase = Phase::Layered { size, at: seen.at }; - Effect::Show { at: seen.at } + Effect::Show { rect: seen.rect } } Phase::Placing { size } => Effect::Ask(Some(size)), Phase::Layered { size, at } if seen.still && seen.ready && seen.showing && seen.size == size && seen.at == at => Effect::Punch, @@ -166,7 +170,7 @@ impl VideoLayers { let status = crate::video::layer(&entry.video, ask); let layerable = status.running && !status.refused && !entry.isolated && d.opacity > 0.0; wanted |= layerable && still && enabled(); - let seen = Seen { still, ready: layerable && window_ready, showing: status.showing, size, at }; + let seen = Seen { still, ready: layerable && window_ready, showing: status.showing, size, at, rect: image }; let before = entry.phase; let effect = step(&mut entry.phase, seen); if logging() { @@ -191,7 +195,7 @@ impl VideoLayers { } out.again |= next.is_some(); } - Effect::Show { at } => match show(handover, entry, status.handle, at) { + Effect::Show { rect } => match show(handover, entry, status.handle, rect) { Ok(()) => out.punched.push(key), Err(e) => { eprintln!("rune: a clip's layer couldn't show, the window draws it: {e}"); @@ -265,10 +269,13 @@ impl VideoLayers { } } -/// Puts the clip's visual at `at`, made from the layer's surface handle the first time, and waits -/// for DWM to take it, so the frame that punches lands over it. +/// Puts the clip's visual over the picture's `rect`, made from the layer's surface handle the first +/// time, and waits for DWM to take it, so the frame that punches lands over it. The visual sits at +/// the exact rect and stretches the swap chain's buffer onto it: the buffer has even sides (NV12) +/// and the place the window asks is fractional, so a 1:1 visual sits up to a pixel off, and a +/// paused clip's picture, which the window draws itself at the exact rect, would sit elsewhere. #[allow(unsafe_code)] -fn show(handover: Option<&Handover>, entry: &mut Entry, handle: Option, at: (i32, i32)) -> Result<(), String> { +fn show(handover: Option<&Handover>, entry: &mut Entry, handle: Option, rect: [f32; 4]) -> Result<(), String> { let handover = handover.ok_or("the window isn't on DirectComposition")?; let handle = handle.ok_or("the layer has no surface yet")?; if entry.visual.as_ref().is_none_or(|(_, shown)| *shown != handle) { @@ -278,14 +285,26 @@ fn show(handover: Option<&Handover>, entry: &mut Entry, handle: Option, a entry.visual = Some((handover.add_under(handle)?, handle)); } let (visual, _) = entry.visual.as_ref().unwrap(); + // The swap chain's buffer has even sides and `size` rounded (see `video::windows::layer`), + // while the window's place is exact: stretch the buffer onto the rect, so a paused clip's + // picture, which the window draws itself at the exact rect, sits on the same pixels. + let asked = (rect[2].round().max(1.0) as u32, rect[3].round().max(1.0) as u32); + let buffer = even(asked); + let stretch = Matrix3x2 { M11: rect[2] / (buffer.0 as f32), M22: rect[3] / (buffer.1 as f32), ..Default::default() }; // SAFETY: COM calls on a visual of the window's DirectComposition device. unsafe { - visual.SetOffsetX2(at.0 as f32).map_err(|e| format!("SetOffsetX: {e}"))?; - visual.SetOffsetY2(at.1 as f32).map_err(|e| format!("SetOffsetY: {e}"))?; + visual.SetOffsetX2(rect[0]).map_err(|e| format!("SetOffsetX: {e}"))?; + visual.SetOffsetY2(rect[1]).map_err(|e| format!("SetOffsetY: {e}"))?; + visual.SetTransform2(&stretch).map_err(|e| format!("SetTransform: {e}"))?; } handover.commit_and_wait() } +/// The swap chain's buffer size for an asked `size`: NV12 needs even sides (`video::windows::layer`). +fn even((w, h): (u32, u32)) -> (u32, u32) { + (w & !1, h & !1) +} + /// `RUNE_VIDEO_LAYER=0` keeps every clip's pictures in the UI, as without layers. fn enabled() -> bool { static ON: std::sync::OnceLock = std::sync::OnceLock::new(); diff --git a/docs/rune-upstream.md b/docs/rune-upstream.md index 2c710d1..2de9fd5 100644 --- a/docs/rune-upstream.md +++ b/docs/rune-upstream.md @@ -48,7 +48,12 @@ the refactors that landed since): clip again. This fixes faults 1 and 2 above. - #1325, two commits: a video's sound is read ahead of the clock on a reader of its own, and the sound leads the clock from the device's own position. This fixes fault 3 above. +- one local commit of our own: the layer's visual now sits at the picture's exact (fractional) + rect and stretches its buffer onto it with `SetTransform2`. The buffer has even sides (NV12) + and the layer rounded its size, so a pause released the layer and the window's own drawing of + the clip (at the exact rect) landed up to a pixel off the pixels it played on, and a paused + clip visibly jumped. `app/Cargo.toml` points `rune`, `rune-kit` and `rune-notify` at the checkout's crates by path. -To take a newer upstream rev: fetch in `app/vendor/rune`, rebase or re-apply the four commits +To take a newer upstream rev: fetch in `app/vendor/rune`, rebase or re-apply the five commits of `ported` on the new rev.