Compare commits

...
3 Commits
Author SHA1 Message Date
Mike-Solar 5f8db8e31c app: never re-sync a text field while it is focused
CI / Build & test (Linux) (push) Successful in 21m42s
CI / Build & test (Windows) (push) Successful in 27m41s
The params view reapplies the engine snapshot to every control on each
render (every engine tick), which wiped the in-progress text a frame
after each keystroke - the text effect's field was effectively
untypeable. Skip the re-sync while the field is focused (the same
guard the curve editor has for drags); it re-syncs on blur and the
row's explicit commit writes the edit back. MockEngine gains a
sentinel text parameter for the regression test.
2026-09-10 18:13:06 +08:00
Mike-Solar a97bc19c14 app: refresh the paused frame after the debounced snapshot upload
Edits invalidated the display caches, but the debounced snapshot
upload (150 ms) landed later - meanwhile the viewer had already
rendered and cached a proxy through the stale snapshot, and nothing
invalidated it again, so a paused monitor kept the pre-edit picture
until the playhead moved. Re-invalidate when the fresh snapshot is
actually installed so the next paint re-renders from it.
2026-09-10 18:13:06 +08:00
Mike-Solar d028a45ffa nodes: pivot transform rotation/scale around the frame center
The transform shader sampled in a top-left-origin pixel space while
Olive's transform semantics (and every other node) are center-origin:
rotation swung the image around the top-left corner, pushing it partly
off-frame - reading exactly like an unwanted zoom. Match the C++
transform.vert projection: position (0,0) is the frame center and
rotation/scale pivot around the anchor, so rotation and scale stay
independent user controls. GPU tests pin the 90-degree landing spot
(no smearing) and the 2x scale centroid (stays centered).
2026-09-10 18:13:05 +08:00
5 changed files with 316 additions and 11 deletions
+15
View File
@@ -1404,6 +1404,21 @@ impl AppEngine for MockEngine {
Ok(())
}
fn effect_params(&self, effect: EffectId) -> Option<Vec<crate::oakui::engine::EffectParam>> {
// A canned text parameter behind a sentinel id, for the params
// view's text-field tests.
(effect.0 == 900).then(|| {
vec![crate::oakui::engine::EffectParam {
input_id: "text_in".to_string(),
display_name: "Text".to_string(),
value_type: oak_node::value::ValueType::Text,
value: oak_node::value::NodeValue::Text("<p>engine text</p>".to_string()),
flags: 0,
properties: Vec::new(),
}]
})
}
fn add_node_at(
&mut self,
type_id: &str,
+114 -1
View File
@@ -3118,7 +3118,16 @@ impl RealEngine {
return;
};
if let Some(m) = RenderManager::global() {
let _ = m.set_graph_snapshot(&project, revision);
if m.set_graph_snapshot(&project, revision).is_ok() {
// Every frame rendered since the edit went through workers
// holding the STALE snapshot (the debounce window — the
// proxy that just landed in the cache, a full-res fill,
// the pre-render window). Drop them so the next paint
// re-renders from the fresh snapshot; otherwise a paused
// viewer keeps the pre-edit picture until the playhead
// moves (the "edits only show during playback" report).
self.invalidate_rendered_frames();
}
}
self.last_snapshot_push = Some(std::time::Instant::now());
cx.notify();
@@ -8809,6 +8818,110 @@ mod tests {
}
}
/// An effect edit must reach the PAUSED display: the debounced
/// snapshot upload invalidates the frames rendered through the stale
/// snapshot, so a bounded number of engine ticks after the edit the
/// program frame shows the new picture — without any playback
/// (the "edits only show during playback" report's regression).
#[gpui::test]
async fn effect_edit_updates_the_paused_frame(cx: &mut gpui::TestAppContext) {
let _media = media_lock();
let _worker = WorkerBinGuard::set();
let engine = cx.update(|cx| cx.new(|cx| RealEngine::create(cx)));
cx.update(|app| engine.update(app, |engine, cx| engine.new_project(cx)));
// A solid green clip on the timeline, selected for the stack.
let media = std::env::temp_dir()
.join(format!("oakapp_editframe_{}.mp4", std::process::id()));
cx.update(|app| {
engine.update(app, |engine, _cx| {
let project = engine.project.clone().unwrap();
let seq = engine.sequence.unwrap();
oak_codec::testmedia::write_test_clip_solid(
&media,
64,
64,
10,
10,
[0.0, 1.0, 0.0, 1.0],
)
.expect("green clip");
let footage = graphops::import_footage(&project, &media).expect("import");
graphops::place_footage_clip(&project, seq, footage, TrackType::Video, 0, 0, 10, 0)
.expect("place the clip");
engine.refresh_sequence_info();
engine.rebuild_timeline();
let clip = engine
.tracks
.iter()
.flat_map(|t| t.clips.iter())
.next()
.expect("a clip")
.id();
engine.selected_clip = Some(clip);
})
});
let frame_bytes = |cx: &mut gpui::TestAppContext| -> Vec<u8> {
cx.read(|app| {
engine
.read(app)
.cpu_frame(Monitor::Program, app)
.as_bytes(0)
.expect("frame bytes")
.to_vec()
})
};
let before = frame_bytes(cx);
// Insert an opacity effect and crush it to 0 (the frame goes
// transparent black) — through the same engine paths the
// inspector's add / parameter commit take (the stack appends at
// the chain end, like the panel's add button).
cx.update(|app| {
engine.update(app, |engine, cx| {
engine
.add_effect(usize::MAX, "org.olivevideoeditor.Olive.opacity", cx)
.expect("add opacity");
let effect = engine
.selected_effect_cards()
.last()
.expect("the opacity card (closest to the clip)")
.id();
engine
.set_effect_param(
EffectId(effect.0),
"opacity_in",
oak_node::value::NodeValue::Float(0.0),
cx,
)
.expect("set opacity 0");
})
});
// The paused picture must catch up without any playback: after the
// edit the display caches are invalidated and the debounced
// snapshot upload invalidates whatever was rendered through the
// stale snapshot, so a bounded number of engine ticks later the
// program frame shows the new picture.
let mut pumps = 0usize;
loop {
pumps += 1;
cx.update(|app| engine.update(app, |engine, cx| engine.tick(cx)));
if frame_bytes(cx) != before {
break;
}
assert!(
pumps < 5000,
"the paused frame never picked up the effect edit (still the pre-edit pixels after {pumps} ticks)"
);
std::thread::sleep(Duration::from_millis(10));
}
oak_undo::global::clear().unwrap();
let _ = std::fs::remove_file(&media);
}
/// A fresh sequence starts with the default 2 video + 2 audio track
/// layout (user-mandated: V1, V2 on top, A1, A2 below) — and the
/// default layout is NOT an undoable edit (the undo stack stays
+98 -5
View File
@@ -47,8 +47,8 @@ use crate::oakui::component::text_input;
use gpui::effect_stack::EffectId;
use gpui::colors::DefaultColors;
use gpui::{
div, prelude::*, px, rgb, size, point, ClickEvent, Context, Entity, EventEmitter, Render,
SharedString, Window,
div, prelude::*, px, rgb, size, point, ClickEvent, Context, Entity, EventEmitter, Focusable,
Render, SharedString, Window,
};
use gpui::{
Anchor, App, Bounds, ElementId, Hsla, KeyDownEvent, MouseButton, MouseDownEvent, MouseUpEvent,
@@ -142,7 +142,7 @@ impl<E: AppEngine> OfxParamsView<E> {
/// Applies the engine's current values to every control (called each
/// render so external edits / undo / redo land on the controls).
fn sync_values(&mut self, cx: &mut Context<Self>) {
fn sync_values(&mut self, window: &Window, cx: &mut Context<Self>) {
let params = self.engine.read(cx).effect_params(self.effect).unwrap_or_default();
for control in &self.controls {
let Some(param) = params.iter().find(|p| p.input_id == control.input_id) else {
@@ -207,6 +207,15 @@ impl<E: AppEngine> OfxParamsView<E> {
NodeValue::StrCombo(s) => s.clone(),
_ => continue,
};
// Never re-sync a field the user is editing: the
// params view re-renders on every engine tick, and
// reapplying the engine snapshot mid-edit wipes the
// in-progress text (the "cannot type into the text
// field" report). The field re-syncs on blur, and
// the row's explicit commit writes the edit back.
if editor.read(cx).focus_handle(cx).is_focused(window) {
continue;
}
let editor = editor.clone();
editor.update(cx, |editor, cx| {
if editor.as_str() != text {
@@ -842,9 +851,9 @@ fn patch_component(value: &NodeValue, channel: usize, component: f64) -> NodeVal
}
impl<E: AppEngine> Render for OfxParamsView<E> {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.default_colors().clone();
self.sync_values(cx);
self.sync_values(window, cx);
let mut body = div().flex().flex_col().gap_1().p_2();
let mut last_section: Option<(String, String)> = None;
@@ -2657,4 +2666,88 @@ mod tests {
assert_eq!(point_from_sv(bounds, 0.5, 0.5), at(60.0, 45.0));
assert_eq!(point_from_sv(bounds, -1.0, 2.0), at(10.0, 20.0));
}
/// A text field the user is editing is never re-synced mid-edit: the
/// params view re-renders on every engine change, and reapplying the
/// engine snapshot would wipe the in-progress text (the "cannot type
/// into the text field" report). On blur the field re-syncs to the
/// engine value.
#[gpui::test]
async fn text_field_keeps_in_progress_edits_while_focused(cx: &mut TestAppContext) {
use crate::oakui::mock::MockEngine;
struct Host {
view: Entity<OfxParamsView<MockEngine>>,
}
impl Render for Host {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
div().size_full().child(self.view.clone())
}
}
cx.update(|cx| cx.init_colors());
let window = cx.open_window(size(px(400.0), px(200.0)), |window, cx| {
let engine = cx.new(|cx| MockEngine::create(cx));
let view = cx.new(|cx| OfxParamsView::<MockEngine>::new(EffectId(900), engine, window, cx));
Host { view }
});
cx.run_until_parked();
let host = window.root(cx).expect("host root");
let view = cx.read(|cx| host.read(cx).view.clone());
let editor = cx.read(|cx| {
view.read(cx)
.controls
.iter()
.find_map(|c| match &c.kind {
ControlKind::Text(editor) => Some(editor.clone()),
_ => None,
})
.expect("a text control")
});
assert_eq!(
cx.read(|cx| editor.read(cx).as_str().to_string()),
"<p>engine text</p>"
);
// Focus the field and type: the in-progress text must survive the
// engine-notify re-sync (the tick-rate repaint).
window
.update(cx, |_root, window, cx| {
let handle = editor.read(cx).focus_handle(cx);
window.focus(&handle, cx);
})
.unwrap();
cx.update(|cx| {
editor.update(cx, |editor, cx| editor.emplace("user typed", cx));
});
cx.update(|cx| {
view.update(cx, |view, cx| {
let engine = view.engine.clone();
engine.update(cx, |_engine, cx| cx.notify());
});
});
cx.run_until_parked();
assert_eq!(
cx.read(|cx| editor.read(cx).as_str().to_string()),
"user typed",
"the in-progress text survives the re-sync while focused"
);
// On blur the field re-syncs to the engine value.
window
.update(cx, |_root, window, _cx| {
window.blur();
})
.unwrap();
cx.update(|cx| {
view.update(cx, |view, cx| {
let engine = view.engine.clone();
engine.update(cx, |_engine, cx| cx.notify());
});
});
cx.run_until_parked();
assert_eq!(
cx.read(|cx| editor.read(cx).as_str().to_string()),
"<p>engine text</p>",
"the field re-syncs to the engine value on blur"
);
}
}
@@ -24,9 +24,12 @@
/// The transform fragment shader: samples the input through the inverse
/// of the node's pixel-space transform (`transform_in` carries the
/// CPU-inverted matrix; `resolution_in` is auto-filled by the runner).
/// The C++ path transforms vertices (`ove_mvpmat` in transform.vert);
/// an affine transform is equivalently applied fragment-side by
/// inverse-mapping the sample position — the fixed fullscreen vertex
/// Pixel space is CENTER-origin (C++ `transform.vert` transforms the
/// quad in the frame-centered projection): position (0,0) is the frame
/// center and rotation/scale pivot around the anchor — NOT around the
/// top-left corner, which is what a top-left-origin pixel space would
/// pivot on (a corner pivot swings the image off-frame as it rotates,
/// reading exactly like an unwanted zoom). The fixed fullscreen vertex
/// stage stays unchanged.
const TRANSFORM_FRAG: &str = r#"uniform sampler2D tex_in;
uniform mat4 transform_in;
@@ -36,8 +39,9 @@ in vec2 ove_texcoord;
out vec4 frag_color;
void main(void) {
vec2 px = ove_texcoord * resolution_in;
vec2 src = (transform_in * vec4(px, 0.0, 1.0)).xy;
vec2 half_res = resolution_in * 0.5;
vec2 px = ove_texcoord * resolution_in - half_res;
vec2 src = (transform_in * vec4(px, 0.0, 1.0)).xy + half_res;
frag_color = texture(tex_in, src / resolution_in);
}
"#;
+80
View File
@@ -2935,6 +2935,86 @@ mod tests {
assert_eq!(pixel_at(&out, 0, 0), [0.0, 0.0, 0.0, 0.0]);
}
/// Transform rotation pivots around the FRAME CENTER (the C++
/// center-origin pixel space), not the top-left corner: a 90° turn
/// moves a pixel sitting 2px right of center to 2px below center,
/// with no scaling or smearing (the turn is lossless).
#[test]
fn gpu_transform_rotates_around_the_frame_center() {
if oak_core::backend::GpuContext::shared().is_none() {
eprintln!("no adapter; skipping");
return;
}
// 8x8 black frame with one white pixel at (6, 4) — center+(2, 0).
let mut frame = generate_frame(Rational::new(0, 1), (8, 8), PixelFormat::F32).unwrap();
let at = (4 * 8 + 6) * 16;
for (c, v) in [1.0f32, 1.0, 1.0, 1.0].iter().enumerate() {
frame.data[at + c * 4..at + c * 4 + 4].copy_from_slice(&v.to_le_bytes());
}
let mut inputs = NodeValueRow::new();
inputs.insert("tex_in".into(), texture_value(Texture::wrap_frame(frame)));
inputs.insert("rot_in".into(), NodeValue::Float(90.0));
let out = eval_node_row("org.olivevideoeditor.Olive.transform", inputs, None);
assert_eq!(pixel_at(&out, 6, 4), [0.0, 0.0, 0.0, 0.0], "source spot vacated");
assert_eq!(
pixel_at(&out, 3, 6),
[1.0, 1.0, 1.0, 1.0],
"90° around (4,4) maps texel center (6.5,4.5) -> (3.5,6.5)"
);
let lit = out
.data
.chunks_exact(16)
.filter(|px| f32::from_le_bytes(px[12..16].try_into().unwrap()) > 0.01)
.count();
assert_eq!(lit, 1, "a pure rotation neither scales nor smears: {lit} lit pixels");
}
/// Transform scale pivots around the frame center too: a center 2x2
/// block at 2x uniform scale grows into the surrounding 4x4 (a
/// corner pivot would drag it toward the bottom-right instead).
#[test]
fn gpu_transform_scales_around_the_frame_center() {
if oak_core::backend::GpuContext::shared().is_none() {
eprintln!("no adapter; skipping");
return;
}
// 8x8 black frame with a white 2x2 block at texels (3..4, 3..4).
let mut frame = generate_frame(Rational::new(0, 1), (8, 8), PixelFormat::F32).unwrap();
for (x, y) in [(3usize, 3usize), (4, 3), (3, 4), (4, 4)] {
let at = (y * 8 + x) * 16;
for (c, v) in [1.0f32, 1.0, 1.0, 1.0].iter().enumerate() {
frame.data[at + c * 4..at + c * 4 + 4].copy_from_slice(&v.to_le_bytes());
}
}
let mut inputs = NodeValueRow::new();
inputs.insert("tex_in".into(), texture_value(Texture::wrap_frame(frame)));
inputs.insert("scale_in".into(), NodeValue::Vec2([2.0, 2.0]));
let out = eval_node_row("org.olivevideoeditor.Olive.transform", inputs, None);
// Pivot check via the alpha distribution: the block [3,5] scaled
// 2x around (4,4) grows symmetrically to [2,6] — the centroid
// stays at the frame center. A corner pivot would drag the block
// to [6,10], shifting the centroid off-center and clipping the
// block against the frame edge.
let mut total = 0.0f32;
let mut cx = 0.0f32;
let mut cy = 0.0f32;
for y in 0..8usize {
for x in 0..8usize {
let a = pixel_at(&out, x, y)[3];
total += a;
cx += (x as f32 + 0.5) * a;
cy += (y as f32 + 0.5) * a;
}
}
let (cx, cy) = (cx / total, cy / total);
assert!(
(cx - 4.0).abs() < 0.2 && (cy - 4.0).abs() < 0.2,
"the block grows around the frame center, centroid ({cx}, {cy})"
);
}
/// Shape generator over the real GPU path: a centered 8x8 rectangle
/// on a 16x16 frame fills exactly the middle block (pixel centers
/// with texcoord in [0.25, 0.75)), everything outside stays