Files
effectcraft/crates/ui-egui/src/panels/info.rs
T
Brandon ThomasandClaude Opus 5.5 af651a6f56 M12.2: viewer on gpu
The desktop viewer builds the GPU compositor on egui-wgpu's device and,
with Mercury GPU Acceleration, renders frames into RGBA8 textures that are
registered with egui-wgpu and drawn directly (no readback); the RAM preview
cache holds them under a video-memory budget. Pixels are read back only on
demand (Info panel, eyedroppers, histograms). Project Settings gets the
Video Rendering and Effects renderer choice. ui_gpu test: GPU viewer frame
matches the CPU one (skips without an adapter).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 11:06:05 -04:00

107 lines
5.1 KiB
Rust

//! Info panel: colour and position under the pointer, plus the current selection.
use egui::{Align2, Color32, Rect, pos2, vec2};
use crate::EffectcraftApp;
use crate::theme::Tokens;
pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
let t = app.tokens;
let p = ui.painter().with_clip_rect(rect);
let x0 = rect.min.x + 12.0;
let mut y = rect.min.y + 14.0;
if app.pointer_comp.is_some() {
// GPU frames: read the shown frame back for sampling.
app.viewer_pixels();
}
let (rgba, xy) = match (app.pointer_comp, &app.viewer_image) {
(Some([cx, cy]), Some(img)) => {
let comp = app.session.active_comp();
let (cw, ch) = comp.map(|c| (c.width as f32, c.height as f32)).unwrap_or((1.0, 1.0));
let sx = (cx / cw * img.size[0] as f32) as i64;
let sy = (cy / ch * img.size[1] as f32) as i64;
let px = if sx >= 0 && sy >= 0 && (sx as usize) < img.size[0] && (sy as usize) < img.size[1] {
Some(img.pixels[sy as usize * img.size[0] + sx as usize])
} else {
None
};
(px, Some((cx, cy)))
}
_ => (None, None),
};
let row = |p: &egui::Painter, y: f32, k: &str, v: String, col: Color32| {
p.text(pos2(x0, y), Align2::LEFT_CENTER, k, Tokens::ui(12.0), col);
p.text(pos2(x0 + 22.0, y), Align2::LEFT_CENTER, v, Tokens::mono(12.0), t.text);
};
let unpre = |c: Color32| -> [u8; 4] {
let a = c.a();
if a == 0 {
[0, 0, 0, 0]
} else {
let f = |v: u8| ((v as u32 * 255 + a as u32 / 2) / a as u32).min(255) as u8;
[f(c.r()), f(c.g()), f(c.b()), a]
}
};
let px = rgba.map(unpre).unwrap_or([0, 0, 0, 0]);
row(&p, y, "R :", format!("{}", px[0]), Color32::from_rgb(0xe0, 0x60, 0x60));
row(&p, y + 18.0, "G :", format!("{}", px[1]), Color32::from_rgb(0x60, 0xd0, 0x60));
row(&p, y + 36.0, "B :", format!("{}", px[2]), Color32::from_rgb(0x60, 0x90, 0xf0));
row(&p, y + 54.0, "A :", format!("{}", px[3]), t.text_dim);
let cx = rect.min.x + rect.width() * 0.5;
if let Some((x, yy)) = xy {
p.text(pos2(cx, y), Align2::LEFT_CENTER, format!("X : {x:.0}"), Tokens::mono(12.0), t.text);
p.text(pos2(cx, y + 18.0), Align2::LEFT_CENTER, format!("Y : {yy:.0}"), Tokens::mono(12.0), t.text);
}
if let Some(c) = rgba {
let sw = egui::Rect::from_min_size(pos2(cx, y + 34.0), vec2(36.0, 30.0));
p.rect_filled(sw, 3.0, Color32::from_rgb(px[0], px[1], px[2]));
let _ = c;
}
y += 82.0;
p.line_segment([pos2(rect.min.x + 8.0, y), pos2(rect.max.x - 8.0, y)], egui::Stroke::new(1.0, t.separator));
y += 14.0;
let comp = app.session.active_comp().cloned();
if let Some(c) = comp {
let sel: Vec<String> = app.session.state.selected_layers.iter().filter_map(|id| c.layer(*id)).map(|l| l.name.clone()).collect();
let tc = crate::panels::timecode(&app.session, &c, app.session.time());
p.text(pos2(x0, y), Align2::LEFT_CENTER, if sel.is_empty() { "No layer selected".to_string() } else { sel.join(", ") }, Tokens::semibold(12.0), t.text);
p.text(pos2(x0, y + 18.0), Align2::LEFT_CENTER, format!("Time: {tc}"), Tokens::ui(12.0), t.text_dim);
// One layer selected: Duration, In and Out like AE's Info panel.
let mut ly = y + 36.0;
if let [id] = app.session.state.selected_layers.as_slice()
&& let Some(l) = c.layer(*id)
{
let tc = |t| crate::panels::timecode(&app.session, &c, t);
let lines = [
// A length, so no start-timecode offset.
format!("Duration: {}", {
let fr = c.frame_rate;
let n = fr.frame_at(l.out_point) - fr.frame_at(l.in_point);
let s = effectcraft_engine::time::format_timecode_frames(n, fr, fr.supports_drop_frame());
if fr.supports_drop_frame() { s } else { s.replace(';', ":") }
}),
format!("In: {}, Out: {}", tc(l.in_point), tc(effectcraft_engine::time::Tick(l.out_point.0 - c.frame_duration().0))),
];
for line in lines {
p.text(pos2(x0, ly), Align2::LEFT_CENTER, line, Tokens::ui(12.0), t.text_dim);
ly += 18.0;
}
}
// Settings ▸ Composition ▸ Show Rendering Progress in Info Panel.
if app.session.prefs.composition.show_rendering_progress {
let ms = app.frames.last_ms.lock().map(|v| *v).unwrap_or(0.0);
let rq = app.session.render_job.as_ref().map(|_| " • Rendering queue…").unwrap_or("");
p.text(pos2(x0, ly), Align2::LEFT_CENTER, format!("Render: {ms:.0} ms • UI {:.0} fps{rq}", app.fps), Tokens::ui(11.5), t.text_faint);
}
if !app.session.state.selected_keys.is_empty() {
p.text(
pos2(x0, ly + 18.0),
Align2::LEFT_CENTER,
format!("{} keyframes selected", app.session.state.selected_keys.len()),
Tokens::ui(11.5),
t.text_dim,
);
}
}
}