mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-21 09:35:41 +00:00
Merge disk-cache-layer-files (step 3 review fixes) into disk-cache-comp-scope
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
47d8acb694
45 files changed
+539
-82
No files matched your search
@@ -346,32 +346,51 @@ impl ConfinedFootage {
|
||||
fn inside(&self, f: &Footage) -> bool {
|
||||
std::iter::once(&f.path).chain(&f.sequence).filter(|p| !p.is_empty()).all(|p| self.confinement.check(p, Access::Read).is_ok())
|
||||
}
|
||||
|
||||
/// [`Self::inside`] for a read: a refused one is counted on this thread, so the render
|
||||
/// [`recording`](FootageSource::recording) it can't list what it made without the footage.
|
||||
fn readable(&self, f: &Footage) -> bool {
|
||||
let inside = self.inside(f);
|
||||
if !inside {
|
||||
let _ = REFUSED_READS.try_with(|n| n.set(n.get().wrapping_add(1)));
|
||||
}
|
||||
inside
|
||||
}
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
/// Footage reads refused on this thread (see [`ConfinedFootage::readable`]).
|
||||
static REFUSED_READS: std::cell::Cell<u64> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
|
||||
fn refused_reads() -> u64 {
|
||||
REFUSED_READS.try_with(std::cell::Cell::get).unwrap_or(0)
|
||||
}
|
||||
|
||||
impl FootageSource for ConfinedFootage {
|
||||
fn frame(&self, item: ItemId, footage: &Footage, t: Tick) -> Option<Arc<Image>> {
|
||||
self.inside(footage).then(|| self.inner.frame(item, footage, t)).flatten()
|
||||
self.readable(footage).then(|| self.inner.frame(item, footage, t)).flatten()
|
||||
}
|
||||
fn frame_at_size(&self, item: ItemId, footage: &Footage, t: Tick, width: u32, height: u32) -> Option<Arc<Image>> {
|
||||
self.inside(footage).then(|| self.inner.frame_at_size(item, footage, t, width, height)).flatten()
|
||||
self.readable(footage).then(|| self.inner.frame_at_size(item, footage, t, width, height)).flatten()
|
||||
}
|
||||
fn frame_with(&self, item: ItemId, footage: &Footage, t: Tick, size: Option<(u32, u32)>, float: FloatCurve) -> Option<Arc<Image>> {
|
||||
self.inside(footage).then(|| self.inner.frame_with(item, footage, t, size, float)).flatten()
|
||||
self.readable(footage).then(|| self.inner.frame_with(item, footage, t, size, float)).flatten()
|
||||
}
|
||||
fn audio(&self, item: ItemId, footage: &Footage, t: Tick, frames: usize, rate: u32) -> Option<Vec<f32>> {
|
||||
self.inside(footage).then(|| self.inner.audio(item, footage, t, frames, rate)).flatten()
|
||||
self.readable(footage).then(|| self.inner.audio(item, footage, t, frames, rate)).flatten()
|
||||
}
|
||||
fn aux(&self, item: ItemId, footage: &Footage, t: Tick) -> Option<Arc<AuxChannels>> {
|
||||
self.inside(footage).then(|| self.inner.aux(item, footage, t)).flatten()
|
||||
self.readable(footage).then(|| self.inner.aux(item, footage, t)).flatten()
|
||||
}
|
||||
fn set_aux_footage(&self, paths: &[String]) {
|
||||
self.inner.set_aux_footage(paths)
|
||||
}
|
||||
fn model(&self, item: ItemId, footage: &Footage) -> Option<Arc<effectcraft_model::Model>> {
|
||||
self.inside(footage).then(|| self.inner.model(item, footage)).flatten()
|
||||
self.readable(footage).then(|| self.inner.model(item, footage)).flatten()
|
||||
}
|
||||
fn vector_frame(&self, item: ItemId, footage: &Footage, scale: f64) -> Option<Arc<Image>> {
|
||||
self.inside(footage).then(|| self.inner.vector_frame(item, footage, scale)).flatten()
|
||||
self.readable(footage).then(|| self.inner.vector_frame(item, footage, scale)).flatten()
|
||||
}
|
||||
/// Says why footage outside the roots shows nothing, so the agent can act on it.
|
||||
fn problem(&self, footage: &Footage) -> Option<String> {
|
||||
@@ -401,10 +420,16 @@ impl FootageSource for ConfinedFootage {
|
||||
fn called_off(&self) -> bool {
|
||||
self.inner.called_off()
|
||||
}
|
||||
/// The files read inside the roots, as the inner source notes them (footage outside reads
|
||||
/// nothing).
|
||||
/// The files read inside the roots, as the inner source notes them. Footage outside reads
|
||||
/// nothing, and what is made without it can't be listed by its files: a refused read makes
|
||||
/// the list incomplete, so it never outlives the session in a disk cache (another session
|
||||
/// with other roots would read the footage).
|
||||
fn recording(&self, reads: &effectcraft_engine::render::reads::ReadLog, f: &mut dyn FnMut()) {
|
||||
self.inner.recording(reads, f)
|
||||
let refused = refused_reads();
|
||||
self.inner.recording(reads, f);
|
||||
if refused_reads() != refused {
|
||||
reads.mark_incomplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -598,6 +623,52 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// Footage outside the roots shows nothing: a render that asked for it can't be listed by its
|
||||
/// files (#3184), or a disk cache would keep the empty picture for a session with other
|
||||
/// roots. Reads inside the roots record as the inner source tells.
|
||||
#[test]
|
||||
fn a_refused_footage_read_makes_the_render_unlisted() {
|
||||
use effectcraft_engine::render::reads::{FileStamp, ReadFile, ReadLog};
|
||||
/// Reads every file, noting it.
|
||||
struct Noting;
|
||||
impl FootageSource for Noting {
|
||||
fn frame(&self, _: ItemId, f: &Footage, _: Tick) -> Option<Arc<Image>> {
|
||||
NOTED.with(|n| n.borrow_mut().push(f.path.clone()));
|
||||
Some(Arc::new(Image::new(1, 1)))
|
||||
}
|
||||
fn recording(&self, reads: &ReadLog, f: &mut dyn FnMut()) {
|
||||
f();
|
||||
for p in NOTED.with(|n| std::mem::take(&mut *n.borrow_mut())) {
|
||||
reads.note(ReadFile::new(p, FileStamp::Missing));
|
||||
}
|
||||
}
|
||||
}
|
||||
thread_local! {
|
||||
static NOTED: std::cell::RefCell<Vec<String>> = const { std::cell::RefCell::new(Vec::new()) };
|
||||
}
|
||||
let base = std::env::temp_dir().join(format!("ec-confine-3184-{}", std::process::id()));
|
||||
let (inside, outside) = (base.join("in"), base.join("elsewhere"));
|
||||
for d in [&inside, &outside] {
|
||||
std::fs::create_dir_all(d).unwrap();
|
||||
}
|
||||
let c = Confinement::new(std::slice::from_ref(&inside), &[]).unwrap();
|
||||
let src = ConfinedFootage::new(Arc::new(Noting), c);
|
||||
let footage = |d: &std::path::Path| Footage { path: d.join("a.png").to_string_lossy().into_owned(), ..Default::default() };
|
||||
let read = |f: &Footage| {
|
||||
let log = ReadLog::new();
|
||||
let mut got = None;
|
||||
src.recording(&log, &mut || got = src.frame(ItemId(1), f, Tick::ZERO));
|
||||
(got.is_some(), log.into_files())
|
||||
};
|
||||
let (shown, files) = read(&footage(&inside));
|
||||
assert!(shown && files.is_complete() && files.len() == 1, "inside the roots: {files:?}");
|
||||
let (shown, files) = read(&footage(&outside));
|
||||
assert!(!shown && !files.is_complete(), "outside the roots: {files:?}");
|
||||
// The next render on the thread is not affected.
|
||||
assert!(read(&footage(&inside)).1.is_complete());
|
||||
let _ = std::fs::remove_dir_all(&base);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relative_and_outside_paths_of_newly_listed_commands_are_refused() {
|
||||
let base = std::env::temp_dir().join(format!("ec-confine-1243-{}", std::process::id()));
|
||||
|
||||
@@ -208,7 +208,7 @@ pub(crate) fn source_frame(
|
||||
t: Tick,
|
||||
expr: Option<&dyn ExprHost>,
|
||||
) -> Option<(Arc<Image>, [f64; 2])> {
|
||||
let ctx = EvalCtx { project, comp_id: cid, comp, time: t, expr, footage: None, property_overrides: &[], media_overrides: &[] };
|
||||
let ctx = EvalCtx { project, comp_id: cid, comp, time: t, expr, footage: None, property_overrides: &[], media_overrides: &[], reads: None };
|
||||
if let effectcraft_project::LayerSource::Footage { item } = &layer.source
|
||||
&& let Some(effectcraft_project::ItemKind::Footage(f)) = project.item(*item).map(|i| &i.kind)
|
||||
&& f.has_video
|
||||
|
||||
@@ -345,6 +345,7 @@ fn warning(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
Ok(json!({"effect": uid, "warning": effectcraft_effects::warning(g, &mut |pr| ctx.value(layer, pr))}))
|
||||
}
|
||||
@@ -378,6 +379,7 @@ fn pick_color(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let mut r = effectcraft_render::Renderer::new(&s.project, &*s.footage, effectcraft_render::RenderOpts::default());
|
||||
r.expr = s.expr.as_deref();
|
||||
@@ -515,6 +517,7 @@ impl CryptoProbe {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let params = effectcraft_effects::flatten_params(g, &mut |pr| ctx.value(layer, pr));
|
||||
let aux = r.layer_aux(&ctx, layer).ok_or(NO_CRYPTO)?;
|
||||
@@ -586,6 +589,7 @@ fn probe_key<'a>(s: &'a Session, p: &Value, cmd: &str) -> Result<(ProbeKey, Tick
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let frame = probe_frame(&ctx, layer, pos);
|
||||
let o = s.render_opts(Default::default());
|
||||
@@ -780,6 +784,7 @@ fn crypto_hit(s: &Session, p: &Value, cmd: &str) -> Result<Hit> {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let selection = effectcraft_effects::flatten_params(g, &mut |pr| ctx.value(layer, pr)).s("selection").to_string();
|
||||
let driven = prop.expr.as_ref().is_some_and(|e| e.enabled);
|
||||
|
||||
@@ -371,6 +371,7 @@ pub(crate) fn parent_fixes(s: &Session, cid: ItemId, ids: &[LayerId], parent: Op
|
||||
footage: Some(s.footage.as_ref()),
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let space = |id: Option<LayerId>| -> effectcraft_geom::Mat3 {
|
||||
id.and_then(|i| comp.layer(i)).filter(|l| !l.is_3d()).map(|l| ectx.layer_to_comp(l).0).unwrap_or(effectcraft_geom::Mat3::IDENTITY)
|
||||
|
||||
@@ -194,6 +194,7 @@ fn freeze(s: &mut Session, p: &Value, last: bool) -> Result<Value> {
|
||||
footage: Some(s.footage.as_ref()),
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let now: Vec<(effectcraft_project::LayerId, f64)> = comp
|
||||
.layers
|
||||
|
||||
@@ -87,6 +87,7 @@ fn info(s: &Session, cid: ItemId, lid: LayerId, uid: Uid, cmd: &str) -> Result<P
|
||||
footage: Some(s.footage.as_ref()),
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let KV::Path(path) = ctx.value(layer, pr) else { return Err(bad(cmd, "that property is not a path")) };
|
||||
if path.vertices.is_empty() {
|
||||
@@ -165,6 +166,7 @@ fn pin_targets(s: &Session, p: &Value, cmd: &str) -> Result<Option<(ItemId, Vec<
|
||||
footage: Some(s.footage.as_ref()),
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let mut out = vec![];
|
||||
for (_, lid, uid) in pins {
|
||||
|
||||
@@ -1397,6 +1397,7 @@ fn convert_one_expr(s: &mut Session, cid: ItemId, lid: LayerId, uid: Uid) -> Res
|
||||
footage: Some(s.footage.as_ref()),
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
keys.push(Keyframe::new(layer.layer_time(t), ctx.value(&layer, &pr)));
|
||||
t += fd;
|
||||
|
||||
@@ -39,8 +39,17 @@ pub fn puppet_eval(s: &Session, cid: ItemId, lid: LayerId, fx_uid: Uid, t: Tick)
|
||||
let fx = layer.effects()?;
|
||||
let index = fx.groups().position(|g| g.uid == fx_uid)?;
|
||||
let g = fx.groups().nth(index)?;
|
||||
let ctx =
|
||||
EvalCtx { project: &s.project, comp_id: cid, comp, time: t, expr: s.expr.as_deref(), footage: None, property_overrides: &[], media_overrides: &[] };
|
||||
let ctx = EvalCtx {
|
||||
project: &s.project,
|
||||
comp_id: cid,
|
||||
comp,
|
||||
time: t,
|
||||
expr: s.expr.as_deref(),
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let mut r = Renderer::new(&s.project, &*s.footage, RenderOpts::default());
|
||||
r.expr = s.expr.as_deref();
|
||||
r.cache = Some(&s.layer_cache);
|
||||
|
||||
@@ -57,6 +57,7 @@ impl Env {
|
||||
footage: Some(self.footage.as_ref()),
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,8 +424,17 @@ fn get_3d(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let (w, h) = (comp.width as f64, comp.height as f64);
|
||||
let vs = s.state.views3d.get(&cid).cloned().unwrap_or_default();
|
||||
let t = s.state.times.get(&cid).copied().unwrap_or(Tick::ZERO);
|
||||
let ctx =
|
||||
EvalCtx { project: &s.project, comp_id: cid, comp, time: t, expr: s.expr.as_deref(), footage: None, property_overrides: &[], media_overrides: &[] };
|
||||
let ctx = EvalCtx {
|
||||
project: &s.project,
|
||||
comp_id: cid,
|
||||
comp,
|
||||
time: t,
|
||||
expr: s.expr.as_deref(),
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let cam = vs.override_camera(w, h).unwrap_or_else(|| camera::active_camera(&ctx));
|
||||
let f = cam.forward();
|
||||
let lights: Vec<Value> = comp
|
||||
@@ -567,8 +576,17 @@ fn auto_orient(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
/// through each layer's world matrix; cameras and lights contribute their position).
|
||||
fn layer_points(s: &Session, cid: ItemId, ids: &[LayerId], t: Tick) -> Vec<Vec3> {
|
||||
let Some(comp) = s.project.comp(cid) else { return vec![] };
|
||||
let ctx =
|
||||
EvalCtx { project: &s.project, comp_id: cid, comp, time: t, expr: s.expr.as_deref(), footage: None, property_overrides: &[], media_overrides: &[] };
|
||||
let ctx = EvalCtx {
|
||||
project: &s.project,
|
||||
comp_id: cid,
|
||||
comp,
|
||||
time: t,
|
||||
expr: s.expr.as_deref(),
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let mut out = vec![];
|
||||
for l in comp.layers.iter().filter(|l| ids.contains(&l.id)) {
|
||||
let m = ctx.world_matrix(l);
|
||||
|
||||
@@ -214,6 +214,7 @@ fn rendered_matte_of_pick(s: &mut Session, x: f64, y: f64, scale: f64) -> (Strin
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let buf = s.renderer(effectcraft_render::RenderOpts { scale, ..Default::default() }).content_buf(&ctx, layer).unwrap();
|
||||
let (px, py) = buf.to_px([x, y]);
|
||||
|
||||
@@ -40,7 +40,17 @@ fn close3(a: [f64; 3], b: [f64; 3], tol: f64) -> bool {
|
||||
fn frame(s: &Session, id: u64) -> (Vec3, Vec3) {
|
||||
let c = cid(s);
|
||||
let comp = s.project.comp(c).unwrap();
|
||||
let ctx = EvalCtx { project: &s.project, comp_id: c, comp, time: Tick::ZERO, expr: None, footage: None, property_overrides: &[], media_overrides: &[] };
|
||||
let ctx = EvalCtx {
|
||||
project: &s.project,
|
||||
comp_id: c,
|
||||
comp,
|
||||
time: Tick::ZERO,
|
||||
expr: None,
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let (e, f, _) = layer_frame(&ctx, comp.layer(LayerId(id)).unwrap());
|
||||
(e, f)
|
||||
}
|
||||
@@ -244,7 +254,7 @@ fn parented_camera_keeps_its_frame_under_an_offset_null() {
|
||||
fn frame_at(s: &Session, id: u64, t: Tick) -> (Vec3, Vec3, Vec3) {
|
||||
let c = cid(s);
|
||||
let comp = s.project.comp(c).unwrap();
|
||||
let ctx = EvalCtx { project: &s.project, comp_id: c, comp, time: t, expr: None, footage: None, property_overrides: &[], media_overrides: &[] };
|
||||
let ctx = EvalCtx { project: &s.project, comp_id: c, comp, time: t, expr: None, footage: None, property_overrides: &[], media_overrides: &[], reads: None };
|
||||
layer_frame(&ctx, comp.layer(LayerId(id)).unwrap())
|
||||
}
|
||||
|
||||
|
||||
@@ -309,6 +309,7 @@ impl<'a> Resolver<'a> {
|
||||
footage: self.ctx.footage,
|
||||
property_overrides: if same_comp { self.ctx.property_overrides } else { &[] },
|
||||
media_overrides: if same_comp { self.ctx.media_overrides } else { &[] },
|
||||
reads: self.ctx.reads,
|
||||
})
|
||||
}
|
||||
fn prop(&self, c: u64, l: u64, path: &str) -> Option<(&'a Layer, &'a Property)> {
|
||||
|
||||
@@ -172,6 +172,7 @@ fn evaluate_out(
|
||||
footage: ctx.footage,
|
||||
property_overrides: ctx.property_overrides,
|
||||
media_overrides: ctx.media_overrides,
|
||||
reads: ctx.reads,
|
||||
};
|
||||
let comp = ctx.comp_id.0;
|
||||
let path = layer.props.path_of(prop.uid).unwrap_or_else(|| format!("@{}", prop.uid));
|
||||
|
||||
@@ -4,13 +4,16 @@
|
||||
//! expression (its footage source; [`EvalCtx::footage`]): source → masks → effects for
|
||||
//! `postEffect = true`, the bare source otherwise, in layer space (before the transform). Buffers
|
||||
//! are cached per thread for the frame, so many expressions sampling the same layer at the same
|
||||
//! time render it once.
|
||||
//! time render it once. The source files a sampled render reads are kept with its buffer and
|
||||
//! noted in the evaluating render's log ([`EvalCtx::reads`]) on every use, so a frame whose
|
||||
//! expressions sample footage lists that footage too (#3184).
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use effectcraft_project::{ItemId, Layer};
|
||||
use effectcraft_render::reads::{ReadFiles, ReadLog};
|
||||
use effectcraft_render::{EvalCtx, NoFootage, RenderOpts, Renderer};
|
||||
use effectcraft_time::Tick;
|
||||
|
||||
@@ -26,7 +29,8 @@ struct Sampled {
|
||||
type Key = (usize, u64, u64, u64, bool, u64);
|
||||
|
||||
thread_local! {
|
||||
static CACHE: RefCell<HashMap<Key, Option<Sampled>>> = RefCell::new(HashMap::new());
|
||||
/// The sampled buffers and the source files each was made of.
|
||||
static CACHE: RefCell<HashMap<Key, (Option<Sampled>, Arc<ReadFiles>)>> = RefCell::new(HashMap::new());
|
||||
/// Nested sampleImage renders (a sampled layer whose expressions sample again).
|
||||
static DEPTH: RefCell<usize> = const { RefCell::new(0) };
|
||||
}
|
||||
@@ -48,7 +52,13 @@ fn render(ctx: EvalCtx, comp: ItemId, layer: &Layer, post: bool, t: f64) -> Opti
|
||||
return None;
|
||||
}
|
||||
let key: Key = (ctx.project as *const _ as usize, comp.0, layer.id.0, t.to_bits(), post, fingerprint(layer));
|
||||
if let Some(hit) = CACHE.with(|c| c.borrow().get(&key).cloned()) {
|
||||
let note = |files: &ReadFiles| {
|
||||
if let Some(log) = ctx.reads {
|
||||
log.note_all(files);
|
||||
}
|
||||
};
|
||||
if let Some((hit, files)) = CACHE.with(|c| c.borrow().get(&key).cloned()) {
|
||||
note(&files);
|
||||
return hit;
|
||||
}
|
||||
DEPTH.with(|d| *d.borrow_mut() += 1);
|
||||
@@ -60,20 +70,24 @@ fn render(ctx: EvalCtx, comp: ItemId, layer: &Layer, post: bool, t: f64) -> Opti
|
||||
}
|
||||
let _pop = Pop;
|
||||
let footage: &dyn effectcraft_render::FootageSource = ctx.footage.unwrap_or(&NoFootage);
|
||||
let log = ReadLog::new();
|
||||
let mut r = Renderer::new(ctx.project, footage, RenderOpts { motion_blur: false, ..Default::default() });
|
||||
r.expr = ctx.expr;
|
||||
r.reads = Some(&log);
|
||||
let ectx = r.eval_ctx(comp, Tick::from_seconds_f64(t))?;
|
||||
let out = if post {
|
||||
r.content_buf(&ectx, layer).map(|b| Sampled { img: Arc::new(b.img.clone()), offset: b.offset, scale: b.scale })
|
||||
} else {
|
||||
r.layer_source(&ectx, layer).map(|b| Sampled { img: Arc::new(b.img), offset: b.offset, scale: b.scale })
|
||||
};
|
||||
let files = Arc::new(log.into_files());
|
||||
note(&files);
|
||||
CACHE.with(|c| {
|
||||
let mut c = c.borrow_mut();
|
||||
if c.len() >= MAX_CACHE {
|
||||
c.clear();
|
||||
}
|
||||
c.insert(key, out.clone());
|
||||
c.insert(key, (out.clone(), files));
|
||||
});
|
||||
out
|
||||
}
|
||||
|
||||
@@ -1326,6 +1326,7 @@ fn source_dimensions_follow_media_replacement() {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[media],
|
||||
reads: None,
|
||||
};
|
||||
assert_eq!(ctx.value(l, l.props.prop(ROT).unwrap()), Value::Scalar(130.0));
|
||||
}
|
||||
@@ -1548,6 +1549,7 @@ fn text_expression_selector_values() {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let doc = effectcraft_render::text::source_text(&ctx, l).unwrap();
|
||||
let lay = effectcraft_text::layout_doc(&doc);
|
||||
@@ -1600,6 +1602,43 @@ fn sample_image_reads_rendered_pixels() {
|
||||
assert_close!(f.num(&code("thisComp.layer(\"B\").sampleImage([-50, -50])"), 0.0), 0.0);
|
||||
}
|
||||
|
||||
/// The footage `sampleImage` renders is a file the evaluating render read (#3184): it is noted in
|
||||
/// the render's log, also when the sampled buffer comes from the per-thread cache.
|
||||
#[test]
|
||||
fn sample_image_notes_the_files_it_reads() {
|
||||
use effectcraft_render::reads::{FileStamp, ReadFile, ReadLog};
|
||||
/// A grey picture of any footage, noting `/clip.png` for every read.
|
||||
struct Clip;
|
||||
impl effectcraft_render::FootageSource for Clip {
|
||||
fn frame(&self, _: ItemId, f: &effectcraft_project::Footage, _: Tick) -> Option<std::sync::Arc<effectcraft_render::Image>> {
|
||||
let mut img = effectcraft_render::Image::new(f.width, f.height);
|
||||
img.data.fill([0.5, 0.5, 0.5, 1.0]);
|
||||
Some(std::sync::Arc::new(img))
|
||||
}
|
||||
fn recording(&self, reads: &ReadLog, f: &mut dyn FnMut()) {
|
||||
f();
|
||||
reads.note(ReadFile::new("/clip.png", FileStamp::Native { len: 3, modified: Some(1) }));
|
||||
}
|
||||
}
|
||||
let mut p = Project::default();
|
||||
let comp = Comp::new(20, 20, FrameRate::FPS_30, Tick::from_seconds_f64(1.0));
|
||||
let footage =
|
||||
effectcraft_project::Footage { path: "/clip.png".into(), width: 8, height: 8, has_video: true, frame_rate: FrameRate::FPS_30, ..Default::default() };
|
||||
let item = p.add_item("Clip", Label::Aqua, None, ItemKind::Footage(footage));
|
||||
let layer = build::layer(&mut p, &comp, "Clip", LayerSource::Footage { item }, (8, 8), None);
|
||||
let cid = p.add_item("C", Label::Sandstone, None, ItemKind::Comp(comp.into()));
|
||||
let c = p.comp(cid).unwrap();
|
||||
for pass in ["rendered", "cached"] {
|
||||
let log = ReadLog::new();
|
||||
let ctx = EvalCtx { footage: Some(&Clip), reads: Some(&log), ..EvalCtx::new(&p, cid, c, Tick::ZERO) };
|
||||
let px = crate::sample::sample_image(ctx, cid, &layer, [4.0, 4.0], [0.5, 0.5], false, 0.0).unwrap();
|
||||
assert!((px[0] - 0.5).abs() < 1e-3 && px[3] > 0.99, "{pass}: {px:?}");
|
||||
let files = log.into_files();
|
||||
assert_eq!(files.files().iter().map(|f| &*f.path).collect::<Vec<_>>(), ["/clip.png"], "{pass}");
|
||||
assert!(files.is_complete(), "{pass}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A huge sample point saturates the pixel coordinates; it must not overflow the loop bounds.
|
||||
#[test]
|
||||
fn sample_image_huge_point_is_transparent() {
|
||||
|
||||
@@ -123,6 +123,7 @@ pub(crate) fn scene(p: &Project, cid: ItemId) -> Scene {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let run: Vec<&effectcraft_project::Layer> = ctx.comp.layers.iter().rev().filter(|l| l.is_3d() && l.has_video()).collect();
|
||||
adv::scene_of(&r, &ctx, &run, (ctx.comp.width, ctx.comp.height))
|
||||
@@ -315,6 +316,7 @@ pub(crate) fn run_of(p: &Project, cid: ItemId) -> (EvalCtx<'_>, Vec<&effectcraft
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let run: Vec<&effectcraft_project::Layer> = ctx.comp.layers.iter().rev().filter(|l| l.is_3d() && l.has_video()).collect();
|
||||
(ctx, run)
|
||||
|
||||
@@ -343,6 +343,7 @@ fn value(s: &effectcraft_engine::Session, l: u64, path: &str) -> effectcraft_eng
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
ctx.value(layer, layer.props.prop(path).unwrap())
|
||||
}
|
||||
@@ -606,6 +607,7 @@ fn stereo_rig_expressions_follow_the_master_camera() {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
ctx.value(layer, layer.props.prop(path).unwrap()).as_vec3()
|
||||
};
|
||||
|
||||
@@ -358,7 +358,7 @@ impl<'a> Renderer<'a> {
|
||||
Some(foot)
|
||||
});
|
||||
// The buffer the cache keeps (another worker's, if it kept one first).
|
||||
Some(self.keep(key, Arc::new(foot?), &files))
|
||||
Some(self.keep(key, Arc::new(foot?), &files).0)
|
||||
}
|
||||
|
||||
/// Draw one 2D layer into `canvas` on the CPU (any kind: adjustment, wireframe, styled…).
|
||||
|
||||
+49
-15
@@ -173,7 +173,7 @@ impl LayerCache {
|
||||
let id = self.virtual_id();
|
||||
let (buf, files) = store.get_layer(layer_disk_key(key), id.as_deref())?;
|
||||
let files = Arc::new(files);
|
||||
Some((self.insert_mem(key, buf, files.clone()), files))
|
||||
Some(self.insert_mem(key, buf, files))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -184,12 +184,13 @@ impl LayerCache {
|
||||
/// and packs it once instead of once per worker, which ran it out of memory). Renders don't
|
||||
/// wait for each other: on the frame workers' shared thread pool a wait can end up under
|
||||
/// the very work it waits for. `files`: the source files `buf` was made of (see
|
||||
/// [`crate::reads`]); a buffer whose files can't all be named stays in memory.
|
||||
pub fn insert(&self, key: u64, buf: Arc<Buf>, files: Arc<ReadFiles>) -> Arc<Buf> {
|
||||
/// [`crate::reads`]); a buffer whose files can't all be named stays in memory. The files
|
||||
/// returned are the ones the returned buffer was made of.
|
||||
pub fn insert(&self, key: u64, buf: Arc<Buf>, files: Arc<ReadFiles>) -> (Arc<Buf>, Arc<ReadFiles>) {
|
||||
if self.gated() {
|
||||
return buf;
|
||||
return (buf, files);
|
||||
}
|
||||
if let Some(kept) = self.inner.lock().ok().and_then(|g| g.map.get(&key).map(|e| e.buf.clone())) {
|
||||
if let Some(kept) = self.inner.lock().ok().and_then(|g| g.map.get(&key).map(|e| (e.buf.clone(), e.files.clone()))) {
|
||||
return kept;
|
||||
}
|
||||
let started = self.inner.lock().ok().and_then(|mut g| g.missed_at.remove(&key));
|
||||
@@ -204,21 +205,21 @@ impl LayerCache {
|
||||
self.insert_mem(key, buf, files)
|
||||
}
|
||||
|
||||
/// See [`LayerCache::insert`]: the buffer kept under `key` (`buf`, unless one was kept first
|
||||
/// or `buf` is too large to keep).
|
||||
fn insert_mem(&self, key: u64, buf: Arc<Buf>, files: Arc<ReadFiles>) -> Arc<Buf> {
|
||||
/// See [`LayerCache::insert`]: the buffer kept under `key` and its files (`buf` and `files`,
|
||||
/// unless one was kept first or `buf` is too large to keep).
|
||||
fn insert_mem(&self, key: u64, buf: Arc<Buf>, files: Arc<ReadFiles>) -> (Arc<Buf>, Arc<ReadFiles>) {
|
||||
let bytes = buf.img.data.len() * std::mem::size_of::<effectcraft_raster::Px>();
|
||||
let Ok(mut g) = self.inner.lock() else { return buf };
|
||||
let Ok(mut g) = self.inner.lock() else { return (buf, files) };
|
||||
if bytes > g.budget / 4 {
|
||||
return buf;
|
||||
return (buf, files);
|
||||
}
|
||||
g.clock += 1;
|
||||
let now = g.clock;
|
||||
if let Some(e) = g.map.get_mut(&key) {
|
||||
e.last_use = now;
|
||||
return e.buf.clone();
|
||||
return (e.buf.clone(), e.files.clone());
|
||||
}
|
||||
g.map.insert(key, Entry { buf: buf.clone(), files, bytes, last_use: now });
|
||||
g.map.insert(key, Entry { buf: buf.clone(), files: files.clone(), bytes, last_use: now });
|
||||
g.bytes += bytes;
|
||||
if g.bytes > g.budget {
|
||||
// Evict least-recently used entries down to 3/4 of the budget.
|
||||
@@ -234,7 +235,7 @@ impl LayerCache {
|
||||
}
|
||||
}
|
||||
}
|
||||
buf
|
||||
(buf, files)
|
||||
}
|
||||
|
||||
/// The memory budget in bytes.
|
||||
@@ -834,8 +835,8 @@ mod shared_insert_tests {
|
||||
let cache = LayerCache::default();
|
||||
let buf = || Arc::new(Buf { img: Image::new(4, 4), offset: [0.0; 2], scale: 1.0 });
|
||||
let (a, b) = (buf(), buf());
|
||||
assert!(Arc::ptr_eq(&cache.insert(3, a.clone(), Default::default()), &a));
|
||||
assert!(Arc::ptr_eq(&cache.insert(3, b, Default::default()), &a), "the later render gets the first buffer");
|
||||
assert!(Arc::ptr_eq(&cache.insert(3, a.clone(), Default::default()).0, &a));
|
||||
assert!(Arc::ptr_eq(&cache.insert(3, b, Default::default()).0, &a), "the later render gets the first buffer");
|
||||
assert!(Arc::ptr_eq(&cache.get(3).unwrap().0, &a));
|
||||
}
|
||||
|
||||
@@ -881,4 +882,37 @@ mod shared_insert_tests {
|
||||
let written: Vec<u128> = store.take_writes().into_iter().map(|w| w.0).collect();
|
||||
assert_eq!(written, [layer_disk_key(11)], "only the buffer whose files are all named");
|
||||
}
|
||||
|
||||
/// A render that gets another render's buffer gets that buffer's files too (#3184): when a
|
||||
/// file changed between the two reads, its frame lists the file with both identities, so the
|
||||
/// list is incomplete and the frame is not kept on disk with the new identity and the old
|
||||
/// pixels.
|
||||
#[test]
|
||||
fn the_buffer_kept_first_brings_its_files() {
|
||||
use crate::reads::{FileStamp, ReadFile, ReadFiles, ReadLog};
|
||||
use crate::{NoFootage, RenderOpts, Renderer};
|
||||
let cache = LayerCache::default();
|
||||
let buf = || Arc::new(Buf { img: Image::new(4, 4), offset: [0.0; 2], scale: 1.0 });
|
||||
let files = |len| Arc::new([ReadFile::new("/a.png", FileStamp::Native { len, modified: Some(1) })].into_iter().collect::<ReadFiles>());
|
||||
let (first, second) = (files(1), files(2));
|
||||
let a = buf();
|
||||
cache.insert(3, a.clone(), first.clone());
|
||||
let project = effectcraft_project::Project::default();
|
||||
let log = ReadLog::new();
|
||||
let mut r = Renderer::new(&project, &NoFootage, RenderOpts::default());
|
||||
r.cache = Some(&cache);
|
||||
r.reads = Some(&log);
|
||||
// (what `Renderer::recorded` noted for the second render)
|
||||
log.note_all(&second);
|
||||
let (kept, kept_files) = r.keep(Some(3), buf(), &second);
|
||||
assert!(Arc::ptr_eq(&kept, &a));
|
||||
assert_eq!(kept_files, first);
|
||||
assert!(!log.files().is_complete());
|
||||
// The same files: nothing changes.
|
||||
let same = ReadLog::new();
|
||||
r.reads = Some(&same);
|
||||
same.note_all(&first);
|
||||
let _ = r.keep(Some(3), buf(), &files(1));
|
||||
assert!(same.files().is_complete());
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,14 @@
|
||||
//! layer cache's content key (which names the footage items a buffer uses with their settings
|
||||
//! and paths) and the renderer version ([`layer_disk_key`]). A changed project therefore never
|
||||
//! reads stale pixels: its keys simply change, and an edit elsewhere keeps them.
|
||||
//! * Frame and layer entries keep the source files they were made of, each with the size and
|
||||
//! modification time it was read with ([`EntryFiles`], #3184). An entry is used only while
|
||||
//! those files are unchanged: a handful of `metadata` calls when it is read, never a scan of
|
||||
//! the project's files. A frame or buffer whose files can't all be named is not stored. File ▸
|
||||
//! Reload Footage deletes the entries made of the reloaded files ([`DiskCache::drop_files`]):
|
||||
//! a file replaced by one of the same size and time is read again.
|
||||
//! * Frame and layer entries keep the source files they were made of (footage, and the font
|
||||
//! files text is drawn with), each with the size and modification time it was read with
|
||||
//! ([`EntryFiles`], #3184). An entry is used only while those files are unchanged: a handful
|
||||
//! of `metadata` calls when it is read, never a scan of the project's files. A frame or
|
||||
//! buffer whose files can't all be named is not stored (text in a family that isn't installed
|
||||
//! or with fallback glyphs, footage refused by automation read roots, …). File ▸ Reload
|
||||
//! Footage deletes the entries made of the reloaded files ([`DiskCache::drop_files`]): a file
|
||||
//! replaced by one of the same size and time is read again.
|
||||
//! * Payloads are LZ4-compressed (`lz4_flex`, MIT): frames as 8-bit premultiplied RGBA (or, for
|
||||
//! 32 bpc viewer frames, half-float RGBA with the bytes shuffled into planes; the entry
|
||||
//! header's format byte tells them apart: 2 and 3, both with their source files first), layer
|
||||
@@ -1265,7 +1267,7 @@ pub type SharedVirtualFileId = Arc<dyn Fn(&str) -> Option<(u64, u64)> + Send + S
|
||||
/// Layer entries with their source files (#3184), part of every layer disk key: entries of the
|
||||
/// earlier format (keyed by a project-wide footage salt instead) are never looked up again;
|
||||
/// least recently used, they are evicted.
|
||||
const LAYER_ENTRY_VERSION: &[u8] = b"layer-entry-files-1";
|
||||
const LAYER_ENTRY_VERSION: &[u8] = b"layer-entry-files-2";
|
||||
|
||||
/// Disk key of a layer buffer: the layer cache's content key ([`crate::cache::layer_key`] and
|
||||
/// the keys derived from it), the layer entry format and the renderer version. The content key
|
||||
@@ -1342,7 +1344,7 @@ fn comp_content_key_for_renderer(project: &effectcraft_project::Project, comp: e
|
||||
/// Frame entries with their source files (#3184), part of every frame key: entries of the
|
||||
/// earlier format (keyed by footage stamps instead) are never looked up again; least recently
|
||||
/// used, they are evicted.
|
||||
const FRAME_ENTRY_VERSION: &[u8] = b"frame-entry-files-1";
|
||||
const FRAME_ENTRY_VERSION: &[u8] = b"frame-entry-files-2";
|
||||
|
||||
/// Disk key of one viewer frame.
|
||||
pub fn frame_key(content: u128, frame: i64, scale_milli: u32, view: u64) -> u128 {
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
//!
|
||||
//! Layout (little endian), before the frame's pixel payload:
|
||||
//! `u32 count`, then per file `u32 path length`, the path (UTF-8), a tag byte and its fields:
|
||||
//! `0` a file on disk (`u64 size`, `u8 has time`, `u64 time`), `1` bytes from the browser's file
|
||||
//! table (`u64 size`, `u64 content hash`), `2` a file that could not be read.
|
||||
//! `0` a file on disk (`u64 size`, `u8 has time`, `i128 time`: nanoseconds since the Unix epoch,
|
||||
//! negative before it), `1` bytes from the browser's file table (`u64 size`, `u64 content
|
||||
//! hash`), `2` a file that could not be read.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -18,8 +19,9 @@ const MAX_PATH_BYTES: usize = 1 << 16;
|
||||
/// A file's identity as a frame entry keeps it.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum EntryStamp {
|
||||
/// Size and modification time (nanoseconds since the Unix epoch) on disk.
|
||||
Native { len: u64, modified: Option<u64> },
|
||||
/// Size and modification time (nanoseconds since the Unix epoch, negative before it) on
|
||||
/// disk.
|
||||
Native { len: u64, modified: Option<i128> },
|
||||
/// Size and content hash from the [`VirtualFileId`] hook (the browser's file table).
|
||||
Virtual { len: u64, hash: u64 },
|
||||
/// It could not be read when the frame was made: it still must not be readable.
|
||||
@@ -134,7 +136,7 @@ impl EntryFiles {
|
||||
0 => {
|
||||
let len = r.u64()?;
|
||||
let has = r.u8()?;
|
||||
let t = r.u64()?;
|
||||
let t = r.i128()?;
|
||||
match has {
|
||||
0 => EntryStamp::Native { len, modified: None },
|
||||
1 => EntryStamp::Native { len, modified: Some(t) },
|
||||
@@ -179,6 +181,9 @@ impl<'a> Reader<'a> {
|
||||
fn u64(&mut self) -> Option<u64> {
|
||||
Some(u64::from_le_bytes(self.take(8)?.try_into().ok()?))
|
||||
}
|
||||
fn i128(&mut self) -> Option<i128> {
|
||||
Some(i128::from_le_bytes(self.take(16)?.try_into().ok()?))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -189,6 +194,9 @@ mod tests {
|
||||
[
|
||||
ReadFile::new("/a.png", FileStamp::Native { len: 3, modified: Some(9) }),
|
||||
ReadFile::new("/b.png", FileStamp::Native { len: 4, modified: None }),
|
||||
// Before 1970, and past where `u64` nanoseconds end (2554).
|
||||
ReadFile::new("/d.png", FileStamp::Native { len: 5, modified: Some(-86_400_000_000_000) }),
|
||||
ReadFile::new("/e.png", FileStamp::Native { len: 6, modified: Some(i128::from(u64::MAX) + 1) }),
|
||||
ReadFile::new("/c.png", FileStamp::Missing),
|
||||
ReadFile::new("/v.mov", FileStamp::Virtual),
|
||||
]
|
||||
@@ -200,7 +208,7 @@ mod tests {
|
||||
fn lists_round_trip_and_damage_is_caught() {
|
||||
let id = |p: &str| (p == "/v.mov").then_some((8, 77));
|
||||
let list = EntryFiles::of(&files(), Some(&id)).unwrap();
|
||||
assert_eq!(list.files()[3].stamp, EntryStamp::Virtual { len: 8, hash: 77 });
|
||||
assert_eq!(list.files()[5].stamp, EntryStamp::Virtual { len: 8, hash: 77 });
|
||||
let mut bytes = vec![];
|
||||
list.encode(&mut bytes);
|
||||
bytes.extend_from_slice(b"rest");
|
||||
|
||||
@@ -44,11 +44,14 @@ pub struct EvalCtx<'a> {
|
||||
/// Media Replacement values overridden by the Essential Properties of a collapsed precomp
|
||||
/// instance.
|
||||
pub media_overrides: &'a [crate::MediaOverride],
|
||||
/// Where the source files of what expressions render (`sampleImage`) are noted: the
|
||||
/// renderer's [`Renderer::reads`](crate::Renderer::reads) while rendering.
|
||||
pub reads: Option<&'a crate::reads::ReadLog>,
|
||||
}
|
||||
|
||||
impl<'a> EvalCtx<'a> {
|
||||
pub fn new(project: &'a Project, comp_id: ItemId, comp: &'a Comp, time: Tick) -> EvalCtx<'a> {
|
||||
EvalCtx { project, comp_id, comp, time, expr: None, footage: None, property_overrides: &[], media_overrides: &[] }
|
||||
EvalCtx { project, comp_id, comp, time, expr: None, footage: None, property_overrides: &[], media_overrides: &[], reads: None }
|
||||
}
|
||||
pub fn at(&self, time: Tick) -> EvalCtx<'a> {
|
||||
EvalCtx { time, ..*self }
|
||||
|
||||
@@ -59,10 +59,27 @@ impl<'a> Renderer<'a> {
|
||||
t.effects.push(("layerStyles".into(), t0.elapsed().as_secs_f64() * 1e3));
|
||||
}
|
||||
// The buffers the cache keeps (another worker's, if it kept them first), made of the
|
||||
// content's files.
|
||||
let body = self.keep(key, Arc::new(st.body), &files);
|
||||
let passes: Vec<_> =
|
||||
st.passes.into_iter().enumerate().map(|(i, (b, m))| (self.keep(key.map(|k| cache::derive(k, i as u64 + 1)), Arc::new(b), &files), m)).collect();
|
||||
// content's files; the styled layer then lists the files of every buffer it holds.
|
||||
let mut kept_files = vec![];
|
||||
let (body, f) = self.keep(key, Arc::new(st.body), &files);
|
||||
kept_files.push(f);
|
||||
let passes: Vec<_> = st
|
||||
.passes
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(i, (b, m))| {
|
||||
let (b, f) = self.keep(key.map(|k| cache::derive(k, i as u64 + 1)), Arc::new(b), &files);
|
||||
kept_files.push(f);
|
||||
(b, m)
|
||||
})
|
||||
.collect();
|
||||
let files = if kept_files.iter().all(|f| Arc::ptr_eq(f, &files)) {
|
||||
files
|
||||
} else {
|
||||
let mut all = (*files).clone();
|
||||
kept_files.iter().for_each(|f| all.extend(f));
|
||||
Arc::new(all)
|
||||
};
|
||||
Some(StyledLayer { passes, body, content, key, ckey, plain: false, files })
|
||||
}
|
||||
|
||||
|
||||
@@ -140,6 +140,13 @@ impl<'a> Renderer<'a> {
|
||||
out
|
||||
}
|
||||
|
||||
/// `ctx` noting what it reads (fonts, `sampleImage`) in this render's [`Renderer::reads`]:
|
||||
/// a context made by an outer render carries that render's log, not the one of the buffer
|
||||
/// [`Renderer::recorded`] makes.
|
||||
pub(crate) fn with_reads<'c>(&'c self, ctx: &EvalCtx<'c>) -> EvalCtx<'c> {
|
||||
EvalCtx { reads: self.reads, ..*ctx }
|
||||
}
|
||||
|
||||
/// The buffer the layer cache keeps under `key`, with the files it was made of noted in
|
||||
/// [`Renderer::reads`].
|
||||
pub(crate) fn cached(&self, key: Option<u64>) -> Option<(Arc<Buf>, Arc<ReadFiles>)> {
|
||||
@@ -151,12 +158,19 @@ impl<'a> Renderer<'a> {
|
||||
}
|
||||
|
||||
/// Keep `buf`, made of `files`, under `key` (see [`Renderer::recorded`]): the buffer the cache
|
||||
/// keeps (another worker's, if it kept one first), or `buf` when nothing is kept.
|
||||
pub(crate) fn keep(&self, key: Option<u64>, buf: Arc<Buf>, files: &Arc<ReadFiles>) -> Arc<Buf> {
|
||||
match (self.cache_to_keep(), key) {
|
||||
(Some(c), Some(k)) => c.insert(k, buf, files.clone()),
|
||||
_ => buf,
|
||||
/// keeps (another worker's, if it kept one first), or `buf` when nothing is kept, with the
|
||||
/// files that buffer was made of. Another worker's files are noted in [`Renderer::reads`]
|
||||
/// too: its pixels are the ones this render uses (a file that changed between the two reads
|
||||
/// then has two identities, and the list is incomplete).
|
||||
pub(crate) fn keep(&self, key: Option<u64>, buf: Arc<Buf>, files: &Arc<ReadFiles>) -> (Arc<Buf>, Arc<ReadFiles>) {
|
||||
let (Some(c), Some(k)) = (self.cache_to_keep(), key) else { return (buf, files.clone()) };
|
||||
let (kept, kept_files) = c.insert(k, buf, files.clone());
|
||||
if !Arc::ptr_eq(&kept_files, files)
|
||||
&& let Some(log) = self.reads
|
||||
{
|
||||
log.note_all(&kept_files);
|
||||
}
|
||||
(kept, kept_files)
|
||||
}
|
||||
|
||||
/// Run `make`, which makes a buffer to keep under `key` in the layer cache, on this renderer
|
||||
@@ -415,7 +429,17 @@ impl<'a> Renderer<'a> {
|
||||
}
|
||||
|
||||
pub(crate) fn ctx(&self, comp_id: ItemId, comp: &'a Comp, t: Tick) -> EvalCtx<'a> {
|
||||
EvalCtx { project: self.project, comp_id, comp, time: t, expr: self.expr, footage: Some(self.footage), property_overrides: &[], media_overrides: &[] }
|
||||
EvalCtx {
|
||||
project: self.project,
|
||||
comp_id,
|
||||
comp,
|
||||
time: t,
|
||||
expr: self.expr,
|
||||
footage: Some(self.footage),
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: self.reads,
|
||||
}
|
||||
}
|
||||
|
||||
/// This renderer with another accelerator (or none): the passes of
|
||||
@@ -824,7 +848,9 @@ impl<'a> Renderer<'a> {
|
||||
let img = self.footage_frame(ctx, layer, item, pf, lt, size)?;
|
||||
Some(self.footage_buf(&img, pf, f.width, f.height))
|
||||
}
|
||||
LayerSource::Text => Some(self.authored(text::render(ctx, layer, self.raster_scale(ctx, layer)))),
|
||||
// (the font files go to this render's log, which `ctx` may not carry: see
|
||||
// [`Renderer::with_reads`])
|
||||
LayerSource::Text => Some(self.authored(text::render(&self.with_reads(ctx), layer, self.raster_scale(ctx, layer)))),
|
||||
LayerSource::Shape => layer.props.sub("contents").map(|c| self.authored(shapes::render(ctx, layer, c, self.raster_scale(ctx, layer)))),
|
||||
_ => None,
|
||||
}
|
||||
@@ -926,7 +952,7 @@ impl<'a> Renderer<'a> {
|
||||
});
|
||||
if let (Some(a), Some(b)) = (a, b) {
|
||||
let img = blend_frames(mode, &a, &b, w as f32);
|
||||
self.keep(key, Arc::new(Buf { img: img.clone(), offset: [0.0; 2], scale: 1.0 }), &files);
|
||||
let _kept = self.keep(key, Arc::new(Buf { img: img.clone(), offset: [0.0; 2], scale: 1.0 }), &files);
|
||||
return Some(Arc::new(img));
|
||||
}
|
||||
}
|
||||
@@ -970,7 +996,7 @@ impl<'a> Renderer<'a> {
|
||||
}
|
||||
let mut nb = (*b).clone();
|
||||
color::convert(&mut nb.img, &c);
|
||||
self.keep(key, Arc::new(nb), files)
|
||||
self.keep(key, Arc::new(nb), files).0
|
||||
}
|
||||
|
||||
/// The flattened layer buffer, its cache key and the source files it was made of.
|
||||
@@ -984,7 +1010,8 @@ impl<'a> Renderer<'a> {
|
||||
return Some((b, key, files));
|
||||
}
|
||||
let flat = Arc::new(styles::Styled { passes: st.passes.iter().map(|(b, m)| ((**b).clone(), *m)).collect(), body: (*st.body).clone() }.flatten());
|
||||
Some((self.keep(key, flat, &st.files), key, st.files))
|
||||
let (flat, files) = self.keep(key, flat, &st.files);
|
||||
Some((flat, key, files))
|
||||
}
|
||||
|
||||
/// A layer's source pixels at the context time, before masks, effects and the transform
|
||||
@@ -1042,7 +1069,8 @@ impl<'a> Renderer<'a> {
|
||||
let buf = r.masked_source(ctx, layer)?;
|
||||
Some(r.apply_effects_timed(ctx, layer, buf, false, usize::MAX, timing.map(|t| &mut t.effects)))
|
||||
});
|
||||
Some((self.keep(key, Arc::new(buf?), &files), key, files))
|
||||
let (buf, files) = self.keep(key, Arc::new(buf?), &files);
|
||||
Some((buf, key, files))
|
||||
}
|
||||
|
||||
/// A layer's input at the context time: source → masks → its first `effects` effects
|
||||
@@ -1064,6 +1092,6 @@ impl<'a> Renderer<'a> {
|
||||
}
|
||||
Some(buf)
|
||||
});
|
||||
Some(self.keep(key, Arc::new(buf?), &files))
|
||||
Some(self.keep(key, Arc::new(buf?), &files).0)
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,8 @@ use std::sync::{Arc, Mutex, PoisonError};
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum FileStamp {
|
||||
/// A file on disk: its size in bytes and its modification time (nanoseconds since the Unix
|
||||
/// epoch; `None` where the file system has none).
|
||||
Native { len: u64, modified: Option<u64> },
|
||||
/// epoch, negative before it; `None` only where the file system has none).
|
||||
Native { len: u64, modified: Option<i128> },
|
||||
/// Bytes given from memory instead of the file system (the browser's file table): their
|
||||
/// identity is the size and content hash a
|
||||
/// [`VirtualFileId`](crate::disk_cache::VirtualFileId) gives for the path.
|
||||
@@ -31,8 +31,7 @@ pub enum FileStamp {
|
||||
impl FileStamp {
|
||||
/// The identity of a file from metadata the caller already has (of an open file).
|
||||
pub fn of_metadata(md: &std::fs::Metadata) -> FileStamp {
|
||||
let modified = md.modified().ok().and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok()).map(|d| d.as_nanos() as u64);
|
||||
FileStamp::Native { len: md.len(), modified }
|
||||
FileStamp::Native { len: md.len(), modified: md.modified().ok().map(epoch_nanos) }
|
||||
}
|
||||
|
||||
/// The identity of the file at `path` now: one `metadata` call. `None` when the file system
|
||||
@@ -42,6 +41,16 @@ impl FileStamp {
|
||||
}
|
||||
}
|
||||
|
||||
/// `t` in nanoseconds since the Unix epoch, negative before it: every time a file system can
|
||||
/// store fits (`i128` nanoseconds span far more than any `SystemTime`), saturating otherwise.
|
||||
pub fn epoch_nanos(t: std::time::SystemTime) -> i128 {
|
||||
let nanos = |d: std::time::Duration| i128::try_from(d.as_nanos()).unwrap_or(i128::MAX);
|
||||
match t.duration_since(std::time::UNIX_EPOCH) {
|
||||
Ok(after) => nanos(after),
|
||||
Err(before) => nanos(before.duration()).saturating_neg(),
|
||||
}
|
||||
}
|
||||
|
||||
/// One file a render read.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct ReadFile {
|
||||
@@ -209,6 +218,39 @@ mod tests {
|
||||
assert!(!files.is_complete());
|
||||
}
|
||||
|
||||
/// Modification times keep their full value: before 1970 (not "no time") and past 2554
|
||||
/// (where `u64` nanoseconds end), so two such files never look alike.
|
||||
#[test]
|
||||
fn modification_times_are_kept_whole() {
|
||||
use std::time::{Duration, UNIX_EPOCH};
|
||||
let day = Duration::from_secs(86_400);
|
||||
assert_eq!(epoch_nanos(UNIX_EPOCH), 0);
|
||||
assert_eq!(epoch_nanos(UNIX_EPOCH - day), -86_400_000_000_000);
|
||||
let far = 600 * 365 * day;
|
||||
if let Some(t) = UNIX_EPOCH.checked_add(far) {
|
||||
assert_eq!(epoch_nanos(t), i128::try_from(far.as_nanos()).unwrap());
|
||||
}
|
||||
let dir = std::env::temp_dir().join(format!("effectcraft-stamp-1969-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let (a, b) = (dir.join("a.bin"), dir.join("b.bin"));
|
||||
let mut stamps = vec![];
|
||||
for (p, back) in [(&a, day), (&b, 2 * day)] {
|
||||
std::fs::write(p, b"abc").unwrap();
|
||||
let f = std::fs::File::options().write(true).open(p).unwrap();
|
||||
if f.set_modified(UNIX_EPOCH - back).is_err() {
|
||||
// (a file system that can't store times before 1970)
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
return;
|
||||
}
|
||||
drop(f);
|
||||
stamps.push(FileStamp::native(&p.to_string_lossy()).unwrap());
|
||||
}
|
||||
assert!(matches!(stamps[0], FileStamp::Native { modified: Some(t), .. } if t < 0), "{:?}", stamps[0]);
|
||||
assert_ne!(stamps[0], stamps[1], "two files from before 1970 with the same size");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_list_is_bounded() {
|
||||
let files: ReadFiles = (0..MAX_READ_FILES + 3).map(|i| file(&format!("/f{i:06}"), 1)).collect();
|
||||
|
||||
@@ -161,8 +161,17 @@ fn referenced_layer_overrides_change_the_owner_cache_key() {
|
||||
let opacity = comp.layer(aid).unwrap().props.prop("transform/opacity").unwrap().uid;
|
||||
let key = |value: f64| {
|
||||
let overrides = [crate::PropertyOverride { layer: aid, prop: opacity, value: Value::Scalar(value), font: false }];
|
||||
let ctx =
|
||||
EvalCtx { project: &p, comp_id: cid, comp, time: Tick::ZERO, expr: None, footage: None, property_overrides: &overrides, media_overrides: &[] };
|
||||
let ctx = EvalCtx {
|
||||
project: &p,
|
||||
comp_id: cid,
|
||||
comp,
|
||||
time: Tick::ZERO,
|
||||
expr: None,
|
||||
footage: None,
|
||||
property_overrides: &overrides,
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
crate::cache::layer_key(&ctx, b, 1.0, false, false)
|
||||
};
|
||||
let (opaque, half) = (key(100.0), key(50.0));
|
||||
|
||||
@@ -143,6 +143,7 @@ fn input_keys_ignore_later_effects() {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let l = &comp.layers[0];
|
||||
(crate::cache::input_key(&ctx, l, 1.0, false, false, 1), crate::cache::input_key(&ctx, l, 1.0, false, false, 2))
|
||||
|
||||
@@ -638,11 +638,49 @@ fn align_index(j: Justify) -> u8 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Note the font files `lay` is drawn with in [`EvalCtx::reads`] (#3184), each with its identity
|
||||
/// as its bytes were read, so a cache entry of the text is checked against them. What the
|
||||
/// files can't vouch for makes the list incomplete: a family that is not installed (installing
|
||||
/// it changes the text), a character drawn with a fallback face or with none (another installed
|
||||
/// font could take it), a font from memory.
|
||||
fn note_fonts(ctx: &EvalCtx, lay: &TextLayout) {
|
||||
use crate::reads::{FileStamp, ReadFile};
|
||||
use effectcraft_text::fonts;
|
||||
let Some(log) = ctx.reads else { return };
|
||||
let resolved: Vec<fonts::Resolved> = lay.styles.iter().map(|s| fonts::resolve(&s.font, &s.style)).collect();
|
||||
if resolved.iter().any(|r| r.missing) {
|
||||
log.mark_incomplete();
|
||||
}
|
||||
let mut faces: Vec<fonts::FaceId> = Vec::new();
|
||||
for g in &lay.layout.glyphs {
|
||||
if g.id == 0 || resolved.get(g.run).is_none_or(|r| r.face != g.face) {
|
||||
log.mark_incomplete();
|
||||
}
|
||||
if !faces.contains(&g.face) {
|
||||
faces.push(g.face);
|
||||
}
|
||||
}
|
||||
for id in faces {
|
||||
let face = fonts::face(id);
|
||||
match &face.info.data {
|
||||
fonts::FaceData::Static(_) => {}
|
||||
fonts::FaceData::Shared(_) => log.mark_incomplete(),
|
||||
fonts::FaceData::File(_) => {
|
||||
if let Some((path, meta)) = face.file_read() {
|
||||
let stamp = meta.map_or(FileStamp::Missing, FileStamp::of_metadata);
|
||||
log.note(ReadFile::new(path.to_string_lossy().as_ref(), stamp));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Lay out and animate a text layer.
|
||||
pub fn text_geom(ctx: &EvalCtx, layer: &Layer) -> Option<TextGeom> {
|
||||
let doc = source_text(ctx, layer)?;
|
||||
let text = layer.props.sub("text")?;
|
||||
let lay = layout_doc(&doc);
|
||||
note_fonts(ctx, &lay);
|
||||
let xfs = char_transforms(ctx, layer, text, &lay);
|
||||
let three = per_char_3d(ctx, layer);
|
||||
let more = text.sub("moreOptions");
|
||||
@@ -665,6 +703,7 @@ pub fn text_geom(ctx: &EvalCtx, layer: &Layer) -> Option<TextGeom> {
|
||||
// Same character count: the style runs still line up.
|
||||
let d2 = TextDoc { text: chars.into_iter().collect(), ..doc.clone() };
|
||||
let l2 = layout_doc(&d2);
|
||||
note_fonts(ctx, &l2);
|
||||
let by_char: std::collections::HashMap<usize, CharXf> = lay.glyphs.iter().zip(&xfs).map(|(g, x)| (g.char_index, *x)).collect();
|
||||
let x2: Vec<CharXf> = l2.glyphs.iter().map(|g| by_char.get(&g.char_index).copied().unwrap_or_default()).collect();
|
||||
subs = vec![None; l2.glyphs.len()];
|
||||
|
||||
@@ -715,3 +715,58 @@ fn range_bar_drag_values() {
|
||||
assert_eq!(range_value_of(3.6 / 7.0, 0.0, true, 7), 4.0);
|
||||
assert_eq!(range_value_of(3.6 / 7.0, 2.0 / 7.0, true, 7), 2.0, "less a 2-character Offset");
|
||||
}
|
||||
|
||||
/// Text names the font files it is drawn with (#3184), with their identity as they were read, so
|
||||
/// a cache entry of it is checked against them; what the files can't vouch for (a family that
|
||||
/// isn't installed) leaves the list incomplete.
|
||||
#[test]
|
||||
fn text_notes_the_font_files_it_draws_with() {
|
||||
use crate::reads::{FileStamp, ReadLog};
|
||||
use effectcraft_text::fonts::{self, FaceData, FaceInfo, FontSource};
|
||||
struct OneFile(std::path::PathBuf);
|
||||
impl FontSource for OneFile {
|
||||
fn faces(&self) -> Vec<FaceInfo> {
|
||||
vec![FaceInfo {
|
||||
family: "Reads Test Sans".into(),
|
||||
style: "Regular".into(),
|
||||
weight: 400,
|
||||
italic: false,
|
||||
index: 0,
|
||||
data: FaceData::File(self.0.clone()),
|
||||
origin: "system",
|
||||
native_family: None,
|
||||
full_name: "Reads Test Sans Regular".into(),
|
||||
postscript: None,
|
||||
variable: false,
|
||||
instances: vec![],
|
||||
}]
|
||||
}
|
||||
}
|
||||
let dir = std::env::temp_dir().join(format!("effectcraft-font-reads-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let font = dir.join("reads-test-sans.ttf");
|
||||
std::fs::write(&font, fonts::INTER_REGULAR).unwrap();
|
||||
fonts::add_source(&OneFile(font.clone()));
|
||||
let stamp = FileStamp::native(&font.to_string_lossy()).unwrap();
|
||||
let files_of = |family: &str| {
|
||||
let (mut p, cid, comp) = setup(200, 80);
|
||||
let l =
|
||||
text_layer(&mut p, &comp, TextDoc { text: "Hi there\rtwo".into(), font: family.into(), style: "Regular".into(), size: 30.0, ..Default::default() });
|
||||
p.comp_mut(cid).unwrap().layers.push(l);
|
||||
let log = ReadLog::new();
|
||||
let c = EvalCtx { reads: Some(&log), ..ctx(&p, cid, 0.0) };
|
||||
assert!(text_geom(&c, &p.comp(cid).unwrap().layers[0]).is_some());
|
||||
log.into_files()
|
||||
};
|
||||
let files = files_of("Reads Test Sans");
|
||||
assert!(files.is_complete(), "{files:?}");
|
||||
assert_eq!(files.files().len(), 1, "{files:?}");
|
||||
assert_eq!(files.get(&font.to_string_lossy()), Some(stamp));
|
||||
// The bundled family reads no file.
|
||||
let files = files_of(effectcraft_text::fonts::DEFAULT_FAMILY);
|
||||
assert!(files.is_complete() && files.is_empty(), "{files:?}");
|
||||
// A family that isn't installed falls back: installing it would change the text.
|
||||
assert!(!files_of("No Such Family 3184").is_complete());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
@@ -656,7 +656,7 @@ fn extruded_layer(r: &Renderer, ctx: &EvalCtx, layer: &Layer, p: &model::extrude
|
||||
let opacity = (ctx.opacity(layer) as f32 * r.opacity_mul()).clamp(0.0, 1.0);
|
||||
let world = b.outer * ctx.world_matrix(layer);
|
||||
let lin = b.s.linear_io;
|
||||
for (mesh, c, local) in extruded_meshes(ctx, layer, p) {
|
||||
for (mesh, c, local) in extruded_meshes(&r.with_reads(ctx), layer, p) {
|
||||
let l = |v: f32| if lin { v } else { srgb_to_linear(v) };
|
||||
let m = b.material(Material {
|
||||
base: [l(c[0]), l(c[1]), l(c[2]), c[3]],
|
||||
@@ -699,7 +699,7 @@ fn card_layer(r: &Renderer, ctx: &EvalCtx, layer: &Layer, b: &mut Builder) {
|
||||
mat.opacity = (ctx.opacity(layer) as f32 * r.opacity_mul()).clamp(0.0, 1.0);
|
||||
let world = b.outer * ctx.world_matrix(layer);
|
||||
if crate::text::per_char_3d(ctx, layer) {
|
||||
for (buf, m) in crate::text::per_char_planes(ctx, layer, r.opts.scale) {
|
||||
for (buf, m) in crate::text::per_char_planes(&r.with_reads(ctx), layer, r.opts.scale) {
|
||||
let buf = r.to_blend(Arc::new(buf), None, &Arc::default());
|
||||
card(b, &buf, world * m, mat);
|
||||
}
|
||||
|
||||
@@ -822,6 +822,7 @@ fn extruded_text_renders_as_a_mesh() {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let l = &ctx.comp.layers[0];
|
||||
let params = scene::extrusion_params(&ctx, l).unwrap();
|
||||
@@ -870,6 +871,7 @@ fn shape_surface_items_colour_the_extruded_surfaces() {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let l = &ctx.comp.layers[0];
|
||||
let params = scene::extrusion_params(&ctx, l).unwrap();
|
||||
@@ -915,6 +917,7 @@ fn text_animators_colour_the_extruded_surfaces() {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let l = &ctx.comp.layers[0];
|
||||
let params = scene::extrusion_params(&ctx, l).unwrap();
|
||||
@@ -1122,6 +1125,7 @@ fn extruded_strokes_render_as_bevelled_meshes() {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let l = &ctx.comp.layers[0];
|
||||
let params = scene::extrusion_params(&ctx, l).unwrap();
|
||||
|
||||
@@ -203,7 +203,7 @@ pub(crate) fn prepare<'a>(r: &Renderer, ctx: &EvalCtx<'_>, layer: &'a Layer, ord
|
||||
/// Prepare a layer as planes: one per character for per-character 3D text, else one.
|
||||
pub(crate) fn prepare_all<'a>(r: &Renderer, ctx: &EvalCtx<'_>, layer: &'a Layer, order: usize, out: (u32, u32), in_run: bool) -> Vec<Item<'a>> {
|
||||
if crate::text::per_char_3d(ctx, layer) {
|
||||
return crate::text::per_char_planes(ctx, layer, r.opts.scale)
|
||||
return crate::text::per_char_planes(&r.with_reads(ctx), layer, r.opts.scale)
|
||||
.into_iter()
|
||||
.filter_map(|(buf, m)| {
|
||||
prepare_with(r, ctx, layer, order, out, in_run, PlaneInput { buf: r.to_blend(Arc::new(buf), None, &Arc::default()), local: m })
|
||||
|
||||
@@ -231,6 +231,7 @@ fn position_now(s: &Session, layer: u64) -> [f64; 2] {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let v = ctx.value(l, l.props.prop("transform/position").unwrap()).components();
|
||||
[v[0], v[1]]
|
||||
|
||||
@@ -158,11 +158,24 @@ fn info_from(n: FaceNames, data: FaceData, origin: &'static str) -> FaceInfo {
|
||||
}
|
||||
}
|
||||
|
||||
/// A font file's bytes and its metadata from the same open file (so the metadata describes the
|
||||
/// bytes, not a later version of the file).
|
||||
fn read_with_metadata(path: &std::path::Path) -> std::io::Result<(Vec<u8>, std::fs::Metadata)> {
|
||||
use std::io::Read;
|
||||
let mut f = std::fs::File::open(path)?;
|
||||
let meta = f.metadata()?;
|
||||
let mut bytes = Vec::new();
|
||||
f.read_to_end(&mut bytes)?;
|
||||
Ok((bytes, meta))
|
||||
}
|
||||
|
||||
/// A loaded (or loadable) face.
|
||||
pub struct Face {
|
||||
pub id: FaceId,
|
||||
pub info: FaceInfo,
|
||||
bytes: OnceLock<Option<FaceBytes>>,
|
||||
/// The file's metadata as its bytes were read (a [`FaceData::File`] face, once loaded).
|
||||
file_meta: OnceLock<std::fs::Metadata>,
|
||||
shaper: OnceLock<harfrust::ShaperData>,
|
||||
}
|
||||
|
||||
@@ -200,11 +213,23 @@ impl Face {
|
||||
.get_or_init(|| match &self.info.data {
|
||||
FaceData::Static(b) => Some(FaceBytes::Static(b)),
|
||||
FaceData::Shared(b) => Some(FaceBytes::Shared(b.clone())),
|
||||
FaceData::File(p) => std::fs::read(p).ok().map(|v| FaceBytes::Shared(Arc::new(v))),
|
||||
FaceData::File(p) => {
|
||||
let (bytes, meta) = read_with_metadata(p).ok()?;
|
||||
let _ = self.file_meta.set(meta);
|
||||
Some(FaceBytes::Shared(Arc::new(bytes)))
|
||||
}
|
||||
})
|
||||
.as_ref()
|
||||
.map(FaceBytes::get)
|
||||
}
|
||||
/// The file a [`FaceData::File`] face is drawn from, with its metadata as its bytes were read
|
||||
/// (`None` when it could not be read): what text drawn with the face was made of. Loads the
|
||||
/// face. `None` for bundled faces and faces from memory.
|
||||
pub fn file_read(&self) -> Option<(&std::path::Path, Option<&std::fs::Metadata>)> {
|
||||
let FaceData::File(p) = &self.info.data else { return None };
|
||||
let _ = self.bytes();
|
||||
Some((p, self.file_meta.get()))
|
||||
}
|
||||
/// The parsed font (None if the file is missing or unreadable).
|
||||
pub fn font(&self) -> Option<FontRef<'_>> {
|
||||
FontRef::from_index(self.bytes()?, self.info.index).ok()
|
||||
@@ -314,7 +339,7 @@ fn bundled_default_face() -> Arc<Face> {
|
||||
variable: false,
|
||||
instances: Vec::new(),
|
||||
});
|
||||
Arc::new(Face { id: 0, info, bytes: OnceLock::new(), shaper: OnceLock::new() })
|
||||
Arc::new(Face { id: 0, info, bytes: OnceLock::new(), file_meta: OnceLock::new(), shaper: OnceLock::new() })
|
||||
}
|
||||
|
||||
fn db() -> &'static RwLock<Db> {
|
||||
@@ -333,7 +358,7 @@ fn db() -> &'static RwLock<Db> {
|
||||
|
||||
fn push(db: &mut Db, info: FaceInfo) -> FaceId {
|
||||
let id = db.faces.len();
|
||||
db.faces.push(Arc::new(Face { id, info, bytes: OnceLock::new(), shaper: OnceLock::new() }));
|
||||
db.faces.push(Arc::new(Face { id, info, bytes: OnceLock::new(), file_meta: OnceLock::new(), shaper: OnceLock::new() }));
|
||||
id
|
||||
}
|
||||
|
||||
|
||||
@@ -163,6 +163,7 @@ fn vertex_delta(app: &EffectcraftApp, layer: effectcraft_engine::project::LayerI
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let (l2c, _) = crate::panels::viewer::l2c(&ectx, l);
|
||||
l2c.inverse().map_or(d, |inv| {
|
||||
|
||||
@@ -186,6 +186,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let hdr = Rect::from_min_size(rect.min, vec2(rect.width(), 24.0));
|
||||
p.text(pos2(hdr.min.x + 10.0, hdr.center().y), Align2::LEFT_CENTER, format!("{} • {}", comp_name, layer.name), Tokens::ui(11.5), t.text_dim);
|
||||
|
||||
@@ -113,6 +113,7 @@ fn render_tex(
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let mut r = Renderer::new(&app.session.project, &*app.session.footage, RenderOpts { scale, ..Default::default() });
|
||||
r.expr = app.session.expr.as_deref();
|
||||
|
||||
@@ -79,6 +79,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let scroll = widgets::PanelScroll::begin(ui, egui::Id::unique("props-scroll"), rect);
|
||||
let rect = scroll.content;
|
||||
|
||||
@@ -114,6 +114,7 @@ pub fn draw_overlay(
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let mut r = Renderer::new(&app.session.project, &*app.session.footage, RenderOpts { scale, ..Default::default() });
|
||||
r.expr = app.session.expr.as_deref();
|
||||
|
||||
@@ -66,6 +66,7 @@ pub fn text_target(app: &EffectcraftApp) -> Option<TextTarget> {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
effectcraft_engine::render::text::source_text(&ectx, layer).map(|d| TextTarget { layer: layer.id.0, doc: d, range: None })
|
||||
}
|
||||
|
||||
@@ -1982,6 +1982,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let mut rw = begin_rows(app, ui, tl);
|
||||
let g = &mut rw;
|
||||
|
||||
@@ -212,6 +212,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
phase_guides(app, &ectx, &mut v);
|
||||
phase_layers(app, ui, &ectx, &mut v);
|
||||
|
||||
@@ -219,6 +219,7 @@ pub(super) fn create_shape(app: &mut EffectcraftApp, tool: Tool, a: [f64; 2], b:
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let inv = l2c(&ectx, &l).0.inverse().unwrap_or(Mat3::IDENTITY);
|
||||
let p0 = inv.apply(gv2(cx - w / 2.0, cy - h / 2.0));
|
||||
|
||||
@@ -53,6 +53,7 @@ pub(super) fn aux_views(
|
||||
footage: None,
|
||||
property_overrides: &[],
|
||||
media_overrides: &[],
|
||||
reads: None,
|
||||
};
|
||||
let selected = app.session.state.selected_layers.clone();
|
||||
let mut picked: Option<(usize, View3D)> = None;
|
||||
|
||||
Reference in new issue
Block a user