Skip to content

Commit b6d51bd

Browse files
vanceingallsclaude
andcommitted
fix(runtime): capture a visible ref while its host is hidden; review nits
Addresses PR #4330 review feedback (jrusso1020, CHANGES_REQUESTED). Blocking: both the engine-mode and preview-mode capture paths treated "host not paintable" as binary — a backdrop entry got a pass-through capture, everything else was skipped outright, including a ref source that lives on a different, independently-visible element (e.g. retro-wave's Logo Anim layer, which is simultaneously layer 4's displacement map and its own fully opaque visible layer). Adds visibleRefSources()/captureVisibleRefsOnly() and a unified FrameCaptureMode discriminator so a visible ref still gets captured even while its own host is hidden, on both paths. Non-blocking, addressed: - luma-matte's mandatory ref that names its own host now resolves to an explicit RefResolution {kind:"self"} and binds u_src2 to unit 0, instead of relying on an unbound sampler's implicit default. displacement-map's optional self-ref is unaffected (still folds into {kind:"none"}, using its existing u_hasSrc2 shader branch). - noise shader now enforces rgb<=a (valid premultiplied alpha) after adding noise, independent of u_clipping — documented why u_clipping is currently a permanent no-op on this runtime's 8-bit render targets. - added a hash-pinning test for hfJenkinsMix; documented, with a brute-force proof, which one of the reviewer's suggested mutations is unobservable within this fixture's reachable seed range. - fixed two misplaced doc comments. fallow flagged resolveVfxCapture/resolveRefSource as newly over the complexity threshold after this diff; extracted resolveEmptyRefParam() and captureHiddenEntry() to bring both back under. Co-Authored-By: Claude Sonnet 5 <[email protected]>
1 parent 6579803 commit b6d51bd

4 files changed

Lines changed: 384 additions & 75 deletions

File tree

‎packages/core/src/runtime/vfx.test.ts‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,30 @@ describe("vfx runtime — ref (second source) params", () => {
912912
expect(matteCtx.drawn).toHaveLength(1);
913913
});
914914

915+
it("binds u_src2 explicitly when a MANDATORY ref names its own host", () => {
916+
// Unlike displacement-map's optional `map` (self-reference there is
917+
// treated exactly like "empty"), a mandatory ref like luma-matte's
918+
// `matte` has no shader-side branch to fall back on — the shader always
919+
// samples `u_src2`, so a self-reference needs u_src2 pointed at u_src's
920+
// own texture unit rather than left to an unbound sampler's default.
921+
const ctx = createMockCtx2d();
922+
makeCaptureHost(
923+
ctx,
924+
"cap",
925+
'{"version":1,"nodes":[{"type":"fractal-noise","id":"n1","params":{"matte":"cap"}}]}',
926+
);
927+
928+
expect(initVfx(document.body, 30)).toHaveLength(1);
929+
paintVfx(0, { engineMode: true });
930+
compositeWindow().__hf_page_composite_resolve!();
931+
932+
// One capture only — no second `drawElementImage` for the same image.
933+
expect(ctx.drawn).toHaveLength(1);
934+
expect(gl!.uniforms["u_src2"]).toBe(0);
935+
expect(gl!.uniforms["u_hasSrc2"]).toBe(1);
936+
expect(errors).toEqual([]);
937+
});
938+
915939
it("refuses a ref whose element carries no capture wrapper", () => {
916940
makeRefTarget(undefined, "matte-1", false);
917941
makeCaptureHost(createMockCtx2d(), "cap", REF_NODE);
@@ -1034,6 +1058,57 @@ describe("vfx runtime — ref (second source) params", () => {
10341058
matte: 1,
10351059
});
10361060
});
1061+
1062+
it("still captures a visible ref while its own host is hidden", () => {
1063+
// retro-wave `Logo Anim` layer 5's own AE layer can outlive layer 4's (the
1064+
// kernel host's) data-start/data-duration window. Before the fix, a
1065+
// hidden non-backdrop host was dropped entirely, so this ref went missing
1066+
// before its host's window and stale (last captured frame) after it.
1067+
const ctx = createMockCtx2d();
1068+
const matteCtx = createMockCtx2d();
1069+
const matte = makeRefTarget(matteCtx);
1070+
matte.querySelector("canvas.hf-vfx-src")!.setAttribute("data-vfx-ref-visible", "");
1071+
sizeHost(matte.querySelector(".hf-vfx-in") as HTMLElement, 640, 360);
1072+
const host = makeCaptureHost(ctx, "cap", REF_NODE);
1073+
initVfx(document.body, 30);
1074+
host.style.visibility = "hidden";
1075+
1076+
paintVfx(0, { engineMode: true });
1077+
1078+
expect(compositeWindow().__hf_page_composite_pending).toBe(true);
1079+
expect(compositeWindow().__hf_page_composite_resolve!()).toBe(true);
1080+
expect(matteCtx.drawn).toEqual([{ el: matte.querySelector(".hf-vfx-in"), w: 640, h: 360 }]);
1081+
// Cleared once, before the draw — kept, not re-cleared after: the bitmap
1082+
// that is left is the ref's own on-page layer.
1083+
expect(matteCtx.cleared).toEqual([[640, 360]]);
1084+
// Never uploaded: no kernel runs for a hidden host, so nothing binds it.
1085+
// The hidden host's own (non-ref) capture never runs either.
1086+
expect({ ctx: ctx.drawn.length, calls: gl!.calls }).toEqual({ ctx: 0, calls: [] });
1087+
expect(errors).toEqual([]);
1088+
});
1089+
1090+
it("captures a visible ref through the preview path even while its host is hidden", async () => {
1091+
const ctx = createMockCtx2d();
1092+
const matteCtx = createMockCtx2d();
1093+
const matte = makeRefTarget(matteCtx);
1094+
matte.querySelector("canvas.hf-vfx-src")!.setAttribute("data-vfx-ref-visible", "");
1095+
sizeHost(matte.querySelector(".hf-vfx-in") as HTMLElement, 640, 360);
1096+
const host = makeCaptureHost(ctx, "cap", REF_NODE);
1097+
initVfx(document.body, 30);
1098+
host.style.visibility = "hidden";
1099+
1100+
paintVfx(0.5);
1101+
// A ref-only frame waits on the REF's own canvas, never the hidden host's
1102+
// — the host's canvas fires no "paint" at all while it stays hidden.
1103+
matte.querySelector("canvas.hf-vfx-src")!.dispatchEvent(new Event("paint"));
1104+
await flushTasks();
1105+
1106+
expect({ matte: matteCtx.drawn.length, ctx: ctx.drawn.length, calls: gl!.calls }).toEqual({
1107+
matte: 1,
1108+
ctx: 0,
1109+
calls: [],
1110+
});
1111+
});
10371112
});
10381113

10391114
/**

0 commit comments

Comments
 (0)