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",
|
"wgpu",
|
||||||
"windows",
|
"windows",
|
||||||
"windows-core",
|
"windows-core",
|
||||||
|
"windows-numerics",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
"winit",
|
"winit",
|
||||||
"x11rb",
|
"x11rb",
|
||||||
|
|||||||
@@ -962,6 +962,17 @@ impl App {
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
pub fn poll(app: &mut App, t: f64, tx: &mut Tx) -> bool {
|
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)
|
app.handle_poll(t, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1337,6 +1348,11 @@ pub fn demo_review(app: &mut App) {
|
|||||||
player.set_looping(false);
|
player.set_looping(false);
|
||||||
app.review.player = Some(player);
|
app.review.player = Some(player);
|
||||||
app.review.error = None;
|
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 Ok(tracks) = std::env::var("LR_DEMO_TRACKS") {
|
||||||
if let Some(game) = app.review.game.as_mut() {
|
if let Some(game) = app.review.game.as_mut() {
|
||||||
game.audio_tracks = tracks
|
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);
|
let playing = self.player.as_ref().is_some_and(Player::is_playing);
|
||||||
if let Some(player) = &self.player {
|
if let Some(player) = &self.player {
|
||||||
if playing {
|
if playing {
|
||||||
|
|||||||
+1
@@ -3855,6 +3855,7 @@ dependencies = [
|
|||||||
"wgpu",
|
"wgpu",
|
||||||
"windows",
|
"windows",
|
||||||
"windows-core",
|
"windows-core",
|
||||||
|
"windows-numerics",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
"winit",
|
"winit",
|
||||||
"x11rb",
|
"x11rb",
|
||||||
|
|||||||
Vendored
+1
@@ -214,6 +214,7 @@ web-sys = "0.3"
|
|||||||
wgpu = { version = "~30.0.1", default-features = false }
|
wgpu = { version = "~30.0.1", default-features = false }
|
||||||
wgpu-naga-bridge = "~30.0.1"
|
wgpu-naga-bridge = "~30.0.1"
|
||||||
windows = "0.62"
|
windows = "0.62"
|
||||||
|
windows-numerics = "0.3"
|
||||||
windows-core = "0.62"
|
windows-core = "0.62"
|
||||||
windows-sys = "0.61"
|
windows-sys = "0.61"
|
||||||
winit = { version = "0.30.13", default-features = false }
|
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
|
# DirectComposition handover (`platform::win32::dcomp_handover`), OLE drag and drop
|
||||||
# (`drag_out::windows`, `platform::win32::drop_target`), jump lists and the taskbar button's
|
# (`drag_out::windows`, `platform::win32::drop_target`), jump lists and the taskbar button's
|
||||||
# progress and badge (`platform::win32::{jump_list,taskbar}`).
|
# 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 = { 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::implement]` (the OLE drop target, `platform::win32::drop_target`) names this crate.
|
||||||
windows-core = { workspace = true }
|
windows-core = { workspace = true }
|
||||||
|
|||||||
+30
-11
@@ -18,6 +18,7 @@ use crate::platform::win32::dcomp_handover::Handover;
|
|||||||
use crate::time::Instant;
|
use crate::time::Instant;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use windows_numerics::Matrix3x2;
|
||||||
use windows::Win32::Graphics::DirectComposition::IDCompositionVisual;
|
use windows::Win32::Graphics::DirectComposition::IDCompositionVisual;
|
||||||
|
|
||||||
/// How long no layer shows before the UI's swap chain goes back to opaque.
|
/// 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 showing: bool,
|
||||||
pub size: (u32, u32),
|
pub size: (u32, u32),
|
||||||
pub at: (i32, i32),
|
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 {
|
pub(super) enum Effect {
|
||||||
/// The decoder presents on the layer at this size, or (None) leaves the pictures to the UI.
|
/// The decoder presents on the layer at this size, or (None) leaves the pictures to the UI.
|
||||||
Ask(Option<(u32, u32)>),
|
Ask(Option<(u32, u32)>),
|
||||||
/// Move the layer's visual to `at`, commit, and wait for DWM to take it.
|
/// Place the layer's visual over the picture's rect, commit, and wait for DWM to take it.
|
||||||
Show { at: (i32, i32) },
|
Show { rect: [f32; 4] },
|
||||||
/// Punch the clip's place out this frame.
|
/// Punch the clip's place out this frame.
|
||||||
Punch,
|
Punch,
|
||||||
}
|
}
|
||||||
@@ -72,7 +76,7 @@ pub(super) fn step(phase: &mut Phase, seen: Seen) -> Effect {
|
|||||||
}
|
}
|
||||||
Phase::Placing { size } if seen.showing => {
|
Phase::Placing { size } if seen.showing => {
|
||||||
*phase = Phase::Layered { size, at: seen.at };
|
*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::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,
|
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 status = crate::video::layer(&entry.video, ask);
|
||||||
let layerable = status.running && !status.refused && !entry.isolated && d.opacity > 0.0;
|
let layerable = status.running && !status.refused && !entry.isolated && d.opacity > 0.0;
|
||||||
wanted |= layerable && still && enabled();
|
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 before = entry.phase;
|
||||||
let effect = step(&mut entry.phase, seen);
|
let effect = step(&mut entry.phase, seen);
|
||||||
if logging() {
|
if logging() {
|
||||||
@@ -191,7 +195,7 @@ impl VideoLayers {
|
|||||||
}
|
}
|
||||||
out.again |= next.is_some();
|
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),
|
Ok(()) => out.punched.push(key),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("rune: a clip's layer couldn't show, the window draws it: {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
|
/// Puts the clip's visual over the picture's `rect`, made from the layer's surface handle the first
|
||||||
/// for DWM to take it, so the frame that punches lands over it.
|
/// 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)]
|
#[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 handover = handover.ok_or("the window isn't on DirectComposition")?;
|
||||||
let handle = handle.ok_or("the layer has no surface yet")?;
|
let handle = handle.ok_or("the layer has no surface yet")?;
|
||||||
if entry.visual.as_ref().is_none_or(|(_, shown)| *shown != handle) {
|
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));
|
entry.visual = Some((handover.add_under(handle)?, handle));
|
||||||
}
|
}
|
||||||
let (visual, _) = entry.visual.as_ref().unwrap();
|
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.
|
// SAFETY: COM calls on a visual of the window's DirectComposition device.
|
||||||
unsafe {
|
unsafe {
|
||||||
visual.SetOffsetX2(at.0 as f32).map_err(|e| format!("SetOffsetX: {e}"))?;
|
visual.SetOffsetX2(rect[0]).map_err(|e| format!("SetOffsetX: {e}"))?;
|
||||||
visual.SetOffsetY2(at.1 as f32).map_err(|e| format!("SetOffsetY: {e}"))?;
|
visual.SetOffsetY2(rect[1]).map_err(|e| format!("SetOffsetY: {e}"))?;
|
||||||
|
visual.SetTransform2(&stretch).map_err(|e| format!("SetTransform: {e}"))?;
|
||||||
}
|
}
|
||||||
handover.commit_and_wait()
|
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.
|
/// `RUNE_VIDEO_LAYER=0` keeps every clip's pictures in the UI, as without layers.
|
||||||
fn enabled() -> bool {
|
fn enabled() -> bool {
|
||||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||||
|
|||||||
@@ -48,7 +48,12 @@ the refactors that landed since):
|
|||||||
clip again. This fixes faults 1 and 2 above.
|
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
|
- #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.
|
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.
|
`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.
|
of `ported` on the new rev.
|
||||||
Reference in new issue
Block a user