app: keep a paused clip's layer picture on the pixels it played on
The vendored rune's layer rounded its size and sat at it 1:1, while the window draws a paused clip itself at the exact fractional rect: pausing moved the picture by up to a pixel. The layer's visual now sits at that rect and stretches its buffer onto it (SetTransform2), and the vendored rune takes windows-numerics for the matrix. Also snapshot hooks: LR_DEMO_PLAY starts the demo clip and LR_DEMO_PAUSE_AT pauses it once the clock passes a time.
This commit is contained in:
1 parent
5cbf284841
commit
f3e44a2132
8 files changed
+57
-13
No files matched your search
Generated
+1
@@ -2827,6 +2827,7 @@ dependencies = [
|
||||
"wgpu",
|
||||
"windows",
|
||||
"windows-core",
|
||||
"windows-numerics",
|
||||
"windows-sys 0.61.2",
|
||||
"winit",
|
||||
"x11rb",
|
||||
|
||||
@@ -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::<f64>().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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+1
@@ -3855,6 +3855,7 @@ dependencies = [
|
||||
"wgpu",
|
||||
"windows",
|
||||
"windows-core",
|
||||
"windows-numerics",
|
||||
"windows-sys 0.61.2",
|
||||
"winit",
|
||||
"x11rb",
|
||||
|
||||
Vendored
+1
@@ -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 }
|
||||
|
||||
+1
@@ -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 }
|
||||
|
||||
+30
-11
@@ -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<usize>, at: (i32, i32)) -> Result<(), String> {
|
||||
fn show(handover: Option<&Handover>, entry: &mut Entry, handle: Option<usize>, 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<usize>, 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<bool> = std::sync::OnceLock::new();
|
||||
|
||||
Reference in new issue
Block a user