mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
feat(core): auto motion blur draws with the filter tier (#7288)
* feat(core): auto motion blur draws with the filter tier Capture stays available as data-motion-blur-tier="capture". auto now draws with the filter tier (reasonCode tier-auto), so the capture-only defects leave the default path. Removes the translation-only hand-off and its Discovery field, adds a filter arm to the differential, and updates the check, guide, skill and Blur panel label. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * docs(core): measured cost and known limits of the filter tier, the new auto default spacex-launch (77 movers) takes 2.9x the CPU of no blur on the filter tier and 1.7x on capture; say so, and list the filter tier's measured limits (sweep D, E, F, I, O, B). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * docs(core): word the filter tier's cost and limits as measured, not as mechanism Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * docs(core): do not say every filter-tier limit is pinned by a sweep test Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * test(engine): split the blur differential so each file fits the flake gate's 120 s run The filter arm moves to its own file and skips fixtures that already draw with the filter tier; inside cases get their own file; a fixture's blur-off page is opened once per file. Shared helpers live in __fixtures__/motionBlur/differentialPage.ts. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
4bee04e4a1
commit
e2bb7da25d
+21
-10
@@ -31,7 +31,7 @@ That is all. The same attribute drives the browser editor preview and `hyperfram
|
||||
| `data-motion-blur-phase` | centred | When the shutter opens, in degrees of a frame, -360 to 360. The window starts at `t + phase / 360 / fps` and lasts `shutter / 360 / fps`. `0` opens on the frame, so the smear trails ahead of it; unset centres it, the same as minus half the shutter. Matches After Effects' Shutter Phase. |
|
||||
| `data-motion-blur-samples` | at least 32 | A fixed number of samples per frame, 2–64. Left unset, each mover gets at least 32, and about one per 2 px of smear when that is more, so a fast move never shows steps. |
|
||||
| `data-motion-blur-events` | off | `on` runs timeline callbacks (`onUpdate` and similar) while blur looks for movers, and at each sample when a callback changes an element's inline style or its box. Needed when the motion is set from a callback, such as a `render(t)` function, which blur cannot otherwise see. |
|
||||
| `data-motion-blur-tier` | `auto` | `capture` or `filter` forces one of the two ways blur is drawn (below). |
|
||||
| `data-motion-blur-tier` | `auto` | `auto` and `filter` draw with the filter tier; `capture` asks for the capture tier (below). |
|
||||
|
||||
## In the browser editor
|
||||
|
||||
@@ -43,15 +43,19 @@ Elements that move quickly in 2D: position, scale and rotation changes from GSAP
|
||||
|
||||
## Two ways it is drawn
|
||||
|
||||
**Capture** copies each mover out of the page with Chrome's [HTML in Canvas](/guides/html-in-canvas) API and redraws it along its path. It draws turns and zooms truthfully: a spinning tile smears along its arc and its centre stays sharp, and a zoom streaks outward.
|
||||
**Filter** puts an SVG filter on each mover: copies of the element along its path, averaged, and softened along the motion. It is what `data-motion-blur-tier="auto"` (the default) draws with. It works in any Chrome and over a WebGL canvas. On a four-whip test it cost about what a render without blur costs; on two real films it cost more than capture (see Cost and limits). Turns and zooms are only softened, not streaked.
|
||||
|
||||
**Filter** puts an SVG filter on each mover: copies of the element along its path, averaged, and softened along the motion. It works in any Chrome, over a WebGL canvas, and costs about what a render without blur costs. Turns and zooms are only softened, not streaked.
|
||||
**Capture** is opt-in with `data-motion-blur-tier="capture"`. It copies each mover out of the page with Chrome's [HTML in Canvas](/guides/html-in-canvas) API and redraws it along its path. It draws turns and zooms truthfully: a spinning tile smears along its arc and its centre stays sharp, and a zoom streaks outward. It has limits of its own, listed here (the filter tier's are listed under Cost and limits, and a few, such as `backdrop-filter`, apply to both), so ask for it only for a film whose spins and zooms need the streak:
|
||||
|
||||
With `data-motion-blur-tier="auto"` (the default), blur uses the filter tier when every mover only translates and capture when anything turns or scales, because for translation the two look the same and the filter tier is much cheaper.
|
||||
- Anything in front of a mover is lost: a static panel, an overlay or a title card over a moving element is drawn behind its smear.
|
||||
- `mix-blend-mode` and `backdrop-filter` on a mover or its ancestor are not applied.
|
||||
- A CSS selector that reaches the root through its parent, such as `body > #root > .m`, stops matching once capture wraps the root.
|
||||
- A mover sliding into an `overflow: hidden` or clipped card drags the clip edge along, two overlapping movers carry each other's pixels, and content past the frame edge leaves a thin band.
|
||||
- In preview, the first frame after every play shows black for a moment.
|
||||
|
||||
Capture needs a browser with HTML in Canvas. Chrome 157 and 158 builds exposed it without a flag in headless and Chrome-for-Testing builds; whether stable Chrome does is unverified. Chrome 155 and earlier need `chrome://flags/#html-in-canvas`.
|
||||
|
||||
Blur uses the filter tier instead of capture when capture cannot run:
|
||||
A page that asks for capture gets the filter tier instead when capture cannot run:
|
||||
|
||||
| Found in the composition | Why capture cannot draw it |
|
||||
| --- | --- |
|
||||
@@ -75,17 +79,24 @@ npx hyperframes check
|
||||
|
||||
| Finding | Severity | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `motion_blur_filter_fallback` | info | Capture could not run, so the filter tier draws. The message names the cause and how to get capture back. |
|
||||
| `motion_blur_filter_fallback` | info | The page asked for capture, which could not run, so the filter tier draws. The message names the cause. |
|
||||
| `motion_blur_no_movers` | info | Blur is on but nothing moves fast enough to blur. If the motion is set from a callback, add `data-motion-blur-events="on"`. |
|
||||
| `motion_blur_unverified` | info | The check browser cannot run capture, so it drew with the filter tier. Render once to see capture. |
|
||||
| `motion_blur_unverified` | info | The page asks for capture and the check browser cannot run it, so it drew with the filter tier. Render once to see capture. |
|
||||
|
||||
In the page, `window.__hfMotionBlur.report()` returns `state`, `tier`, `reason`, `reasonCode` and `movers`. A render logs one line per session with the tier, and a session-end line when any frames fell back to sharp (`failedFrames > 0`).
|
||||
|
||||
## Cost and limits
|
||||
|
||||
- **Render time.** On an 8 s test composition with four whips, a render took 9.8 s with capture, 5.2–5.4 s with the filter tier and 5.3–5.9 s with no blur (two runs each, including startup). Capture adds a second paint per blurred frame; the filter tier adds almost nothing.
|
||||
- **Editing.** With capture the root is wrapped only while playing or rendering; paused, it is plain DOM, so click-to-select works. The filter tier never wraps anything.
|
||||
- **Render time.** It varies by film. On an 8 s test composition with four whips, a render took 9.8 s with capture, 5.2–5.4 s with the filter tier and 5.3–5.9 s with no blur (two runs each, including startup). On two real 1080p films the filter tier cost more than capture, measured as CPU seconds of the whole render (wall time was too noisy on a loaded machine): `spacex-launch` (77 movers, 39.5 s) took 547–552 CPU s with the filter tier, 302–320 with capture and 184–193 with no blur (three runs each, 2.9 times no blur); `k3-promo` (106 movers, 16.5 s) took 236, 205 and 117 (one run per arm, 2.0 times no blur). The two films do not order by mover count, and the cause of the difference was not isolated. The filter tier draws each mover as at least 32 offset copies per frame; capture adds a second paint per blurred frame.
|
||||
- **Editing.** The filter tier never wraps anything. With capture the root is wrapped only while playing or rendering; paused, it is plain DOM, so click-to-select works.
|
||||
- **Capture only.** Blurred preview can run at half the frame rate on heavy compositions, and a `<video>` drawn through the capture looks about 2–3% darker in the browser editor preview than in normal playback. Renders are not affected.
|
||||
- **Preview and render.** A browser without HTML in Canvas previews with the filter tier. A render then uses capture where the composition needs it, so a spin or zoom looks softer in that preview than in the render. Force one tier with `data-motion-blur-tier` for an exact match.
|
||||
- **Preview and render.** `auto` draws the same way in both. A page that asks for capture previews with the filter tier in a browser without HTML in Canvas, so a spin or zoom looks softer there than in the render.
|
||||
- **Worker count.** Output is not bit-identical between worker counts (around 60 dB PSNR), about the size of the difference chunking already causes.
|
||||
- **Not handled.** Pose errors under CSS `zoom`, `position: fixed` and `foreignObject`; a very short Web Animations API animation that falls between scan samples; a large see-through mover (a full-frame translucent sweep), which is left sharp while its fast children still blur. With capture, a mover is drawn above the static content, so a static element that should cover a mover does not.
|
||||
- **Limits of the filter tier** (the default), as measured on one-pattern test compositions:
|
||||
- `::before` or `::after` content outside the mover's box is cut off.
|
||||
- A mover's own `clip-path` or mask gets hard edges: the smear is clipped to the shape it has at that frame.
|
||||
- A `position: fixed` child of a mover that moves via `left` jumps, because the filter makes the mover its containing block.
|
||||
- A `:last-child` selector on the root's children also matches the `<svg>` the tier adds to the root (`nth-last-*` works the same way but was not measured).
|
||||
- A visibility toggle inside the shutter window is drawn at full strength instead of half.
|
||||
- `backdrop-filter` on a mover differs from the 32-sample oracle in the sweep (the backdrop only).
|
||||
|
||||
@@ -9,16 +9,14 @@ Fast-moving elements get a shutter smear along their path. It is opt-in: nothing
|
||||
- `data-motion-blur-phase` — when the shutter opens, in degrees of a frame, -360 to 360: 0 opens on the frame (default: centred on the frame, which is minus half the shutter)
|
||||
- `data-motion-blur-samples` — samples per frame, 2-64 (default: at least 32, sized to the smear)
|
||||
- `data-motion-blur-events` — `on` runs timeline callbacks while blur looks for movers; needed when motion is set from a `render(t)` callback
|
||||
- `data-motion-blur-tier` — `auto` (default), `capture` or `filter`
|
||||
- `data-motion-blur-tier` — `auto` (default, draws with `filter`), `filter` or `capture`
|
||||
|
||||
The same attributes drive the browser editor preview and `hyperframes render`.
|
||||
|
||||
## Two ways it is drawn
|
||||
|
||||
- `capture` redraws each mover along its path, so turns and zooms smear truthfully. Needs a browser with HTML in Canvas.
|
||||
- `filter` puts an SVG filter on each mover. Works in any Chrome and costs little; turns and zooms are only softened.
|
||||
|
||||
`auto` uses `filter` when every mover only translates and `capture` when anything turns or scales.
|
||||
- `filter` puts an SVG filter on each mover. Works in any Chrome; cost varies by film (one with 77 movers took about 2.9 times the CPU of no blur and 1.75 times `capture`'s; the cause was not isolated); turns and zooms are only softened. `auto` draws with it. It cuts off `::before`/`::after` content outside a mover's box, gives a mover's own `clip-path` or mask hard edges, makes a `position: fixed` child of a mover that moves via `left` jump, lets a `:last-child` selector match the `<svg>` it adds to the root, draws a visibility toggle inside the shutter at full strength, and differs from the oracle for `backdrop-filter` on a mover.
|
||||
- `capture` is opt-in. It redraws each mover along its path, so turns and zooms streak truthfully. Needs a browser with HTML in Canvas. It loses anything drawn in front of a mover, ignores `mix-blend-mode` on movers, and breaks selectors that reach the root through its parent.
|
||||
|
||||
## Check and render
|
||||
|
||||
|
||||
@@ -67,10 +67,33 @@ describe("motionBlurDrafts", () => {
|
||||
expect(motionBlurDrafts(filter("accelerated-canvas", 0))[0]?.code).toBe(
|
||||
"motion_blur_no_movers",
|
||||
);
|
||||
expect(motionBlurDrafts(filter("translation-only"))).toEqual([]);
|
||||
expect(motionBlurDrafts(filter("tier-attribute"))).toEqual([]);
|
||||
});
|
||||
|
||||
it("reports nothing when auto draws with the filter tier, wherever the check browser runs", () => {
|
||||
const auto: MotionBlurProbe = {
|
||||
state: "on",
|
||||
tier: "filter",
|
||||
reason: 'auto draws with the filter tier; data-motion-blur-tier="capture" streaks turns',
|
||||
reasonCode: "tier-auto",
|
||||
movers: 3,
|
||||
};
|
||||
expect(motionBlurDrafts(auto)).toEqual([]);
|
||||
});
|
||||
|
||||
it("still informs when capture was forced and the check browser cannot run it", () => {
|
||||
const forced: MotionBlurProbe = {
|
||||
state: "on",
|
||||
tier: "filter",
|
||||
reason: "html-in-canvas (drawElementImage) is unavailable in this browser",
|
||||
reasonCode: "unsupported-browser",
|
||||
movers: 3,
|
||||
};
|
||||
expect(motionBlurDrafts(forced)).toMatchObject([
|
||||
{ code: "motion_blur_unverified", severity: "info" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("only informs, once, when the browser cannot run html-in-canvas", () => {
|
||||
const drafts = motionBlurDrafts(off("unsupported-browser", "html-in-canvas is unavailable"));
|
||||
expect(drafts).toHaveLength(1);
|
||||
|
||||
@@ -32,7 +32,7 @@ const OFF_HINTS: Record<string, string> = {
|
||||
"nested-capture-canvas":
|
||||
"remove the inner <canvas layoutsubtree> / content=drawable, or drop motion blur",
|
||||
};
|
||||
const CHOSEN = new Set(["translation-only", "tier-attribute"]);
|
||||
const CHOSEN = new Set(["tier-auto", "tier-attribute"]);
|
||||
const GENERIC_OFF_HINT = "remove what the reason names, or drop data-motion-blur";
|
||||
|
||||
const ASKED = 'data-motion-blur="on" is set but';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { discoverMovers } from "./discover";
|
||||
|
||||
// jsdom lays nothing out: each element's rect follows the x its fake timeline writes.
|
||||
@@ -303,97 +303,3 @@ describe("discoverMovers", () => {
|
||||
expect(discoverMovers({ scene, durationSeconds: 1, fps: 30, seek }).movers).toEqual([fast]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("discoverMovers translationOnly", () => {
|
||||
// jsdom resolves no transforms: give computed style the inline matrix, as Chrome's would be.
|
||||
beforeEach(() => {
|
||||
const real = window.getComputedStyle.bind(window);
|
||||
vi.spyOn(window, "getComputedStyle").mockImplementation((el: Element) => {
|
||||
const cs = real(el);
|
||||
return new Proxy(cs, {
|
||||
get: (target, key) => {
|
||||
if (key === "transform")
|
||||
return el instanceof HTMLElement ? el.style.transform || "none" : "none";
|
||||
const value = Reflect.get(target, key);
|
||||
return typeof value === "function" ? value.bind(target) : value;
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
// The box follows the matrix's x, or `left` when it has no transform.
|
||||
function mover(parent: Element, size = 10): HTMLElement {
|
||||
const el = document.createElement("div");
|
||||
parent.append(el);
|
||||
el.getBoundingClientRect = () => {
|
||||
const m = /matrix\(([^)]*)\)/.exec(el.style.transform);
|
||||
const x = m ? Number(m[1]?.split(",")[4]) : parseFloat(el.style.left) || 0;
|
||||
return {
|
||||
left: x,
|
||||
top: 0,
|
||||
right: x + size,
|
||||
bottom: size,
|
||||
width: size,
|
||||
height: size,
|
||||
} as DOMRect;
|
||||
};
|
||||
return el;
|
||||
}
|
||||
const scan = (scene: HTMLElement, seek: (t: number) => void) => {
|
||||
seek(0);
|
||||
return discoverMovers({ scene, durationSeconds: 1, fps: 30, seek });
|
||||
};
|
||||
|
||||
it("is true when movers only translate, with their own transform", () => {
|
||||
const scene = document.createElement("div");
|
||||
const el = mover(scene);
|
||||
const found = scan(scene, (t) => {
|
||||
el.style.transform = `matrix(1, 0, 0, 1, ${300 * t}, 0)`;
|
||||
});
|
||||
expect(found.movers).toEqual([el]);
|
||||
expect(found.translationOnly).toBe(true);
|
||||
});
|
||||
|
||||
it("is still true under a parent that scales by a constant", () => {
|
||||
const scene = document.createElement("div");
|
||||
const wrapper = document.createElement("div");
|
||||
wrapper.style.transform = "matrix(1.5, 0, 0, 1.5, 0, 0)";
|
||||
scene.append(wrapper);
|
||||
const el = mover(wrapper);
|
||||
const found = scan(scene, (t) => {
|
||||
el.style.transform = `matrix(1, 0, 0, 1, ${300 * t}, 0)`;
|
||||
});
|
||||
expect(found.translationOnly).toBe(true);
|
||||
});
|
||||
|
||||
it("is false when a mover turns or scales while it moves", () => {
|
||||
for (const linear of ["rotate", "scale"]) {
|
||||
const scene = document.createElement("div");
|
||||
const el = mover(scene);
|
||||
const found = scan(scene, (t) => {
|
||||
const a = linear === "scale" ? 1 + t : Math.cos(t);
|
||||
const b = linear === "scale" ? 0 : Math.sin(t);
|
||||
el.style.transform = `matrix(${a}, ${b}, ${-b}, ${a}, ${300 * t}, 0)`;
|
||||
});
|
||||
expect(found.movers).toEqual([el]);
|
||||
expect(found.translationOnly).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it("is false when a mover is moved without a transform, which a filter would re-stack", () => {
|
||||
const scene = document.createElement("div");
|
||||
const el = mover(scene);
|
||||
const found = scan(scene, (t) => {
|
||||
el.style.left = `${300 * t}px`;
|
||||
});
|
||||
expect(found.movers).toEqual([el]);
|
||||
expect(found.translationOnly).toBe(false);
|
||||
});
|
||||
|
||||
it("is false when nothing moves", () => {
|
||||
const scene = document.createElement("div");
|
||||
mover(scene);
|
||||
expect(scan(scene, () => {}).translationOnly).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
import { isHtmlElement } from "../domRealm";
|
||||
import { inkPad } from "./ink";
|
||||
import { individualIs3d, parseTransform } from "./pose";
|
||||
import { individualIs3d } from "./pose";
|
||||
|
||||
/** Under this peak speed (px per frame) a smear is invisible, so the element stays sharp. */
|
||||
const MIN_SPEED = 2;
|
||||
@@ -47,7 +47,6 @@ export interface Discovery {
|
||||
dynamic: Set<Element>;
|
||||
/** Px each mover's ink reaches past its box (shadows, glows), the largest seen. */
|
||||
pads: Map<HTMLElement, number>;
|
||||
translationOnly: boolean;
|
||||
}
|
||||
|
||||
// The whole inline style in one read; opacity or colour tweens only cost a rect check.
|
||||
@@ -76,22 +75,6 @@ function in3d(el: Element, scene: Element): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
function linearSignature(el: Element, scene: Element): string {
|
||||
const parts: string[] = [];
|
||||
for (let n: Element | null = el; n && n !== scene; n = n.parentElement) {
|
||||
const cs = getComputedStyle(n);
|
||||
const m = parseTransform(cs.transform);
|
||||
parts.push(m ? [m.a, m.b, m.c, m.d].map((v) => v.toFixed(3)).join(",") : "1,0,0,1");
|
||||
parts.push(cs.rotate ?? "none", cs.scale ?? "none");
|
||||
}
|
||||
return parts.join("|");
|
||||
}
|
||||
|
||||
function hasOwnContext(el: Element): boolean {
|
||||
const cs = getComputedStyle(el);
|
||||
return cs.transform !== "none" || (cs.translate ?? "none") !== "none";
|
||||
}
|
||||
|
||||
/** Elements a CSS animation or WAAPI animation moves (no inline style to diff). */
|
||||
function pageAnimated(scene: Element): Set<HTMLElement> {
|
||||
const out = new Set<HTMLElement>();
|
||||
@@ -203,15 +186,8 @@ export function discoverMovers({
|
||||
const fast = new Set<HTMLElement>();
|
||||
const threeD = new Set<HTMLElement>();
|
||||
const pads = new Map<HTMLElement, number>();
|
||||
const signatures = new Map<HTMLElement, string>();
|
||||
const notPlain = new Set<HTMLElement>();
|
||||
const measure = (el: HTMLElement): void => {
|
||||
pads.set(el, Math.max(pads.get(el) ?? 0, inkPad(el)));
|
||||
const sig = linearSignature(el, scene);
|
||||
const first = signatures.get(el);
|
||||
if (first === undefined) signatures.set(el, sig);
|
||||
else if (first !== sig) notPlain.add(el);
|
||||
if (!hasOwnContext(el)) notPlain.add(el);
|
||||
};
|
||||
const seeThrough = new Set<HTMLElement>();
|
||||
const alphaCache = new Map<Bitmap, boolean>();
|
||||
@@ -270,8 +246,7 @@ export function discoverMovers({
|
||||
(el) => fast.has(el) && !threeD.has(el) && !seeThrough.has(el) && !optedOut(el, scene),
|
||||
);
|
||||
const movers = candidates.filter((el) => !candidates.some((o) => o !== el && o.contains(el)));
|
||||
const translationOnly = movers.length > 0 && movers.every((el) => !notPlain.has(el));
|
||||
return { movers, dynamic, pads, translationOnly };
|
||||
return { movers, dynamic, pads };
|
||||
}
|
||||
|
||||
export interface ScanOptions extends Omit<DiscoverOptions, "seek"> {
|
||||
|
||||
@@ -1943,8 +1943,8 @@ describe("filter fallback", () => {
|
||||
return { root, el, h: { ...h, seek } };
|
||||
}
|
||||
|
||||
it("draws with filters where html-in-canvas is missing, and says why", () => {
|
||||
const { root, el, h } = movingHost();
|
||||
it("draws with filters where html-in-canvas is missing and capture was asked for", () => {
|
||||
const { root, el, h } = movingHost(CAPTURE);
|
||||
initCaptureMotionBlur(h);
|
||||
expect(win.__hfMotionBlur?.report()).toMatchObject({
|
||||
state: "on",
|
||||
@@ -2045,7 +2045,7 @@ describe("filter fallback", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("takes the cheaper filter tier when every mover only translates", () => {
|
||||
it("draws with the filter tier on auto, where capture could run, for a mover that translates", () => {
|
||||
installHtmlInCanvas();
|
||||
const { root, el, h } = movingHost();
|
||||
initCaptureMotionBlur(h);
|
||||
@@ -2053,15 +2053,28 @@ describe("filter fallback", () => {
|
||||
expect(win.__hfMotionBlur?.report()).toMatchObject({
|
||||
state: "on",
|
||||
tier: "filter",
|
||||
reasonCode: "translation-only",
|
||||
reasonCode: "tier-auto",
|
||||
});
|
||||
expect(root.parentElement).toBe(document.body);
|
||||
expect(el.style.filter).toMatch(/url\("?#hf-mb-0"?\)/);
|
||||
});
|
||||
|
||||
it("keeps capture for a mover that turns", () => {
|
||||
it("draws with the filter tier on auto for a mover that turns", () => {
|
||||
installHtmlInCanvas();
|
||||
const { root, h } = turningHost({ "data-motion-blur": "on" });
|
||||
const { root, el, h } = turningHost({ "data-motion-blur": "on" });
|
||||
initCaptureMotionBlur(h);
|
||||
void paintCaptureMotionBlur(0.5, PLAY);
|
||||
expect(win.__hfMotionBlur?.report()).toMatchObject({
|
||||
tier: "filter",
|
||||
reasonCode: "tier-auto",
|
||||
});
|
||||
expect(root.parentElement).toBe(document.body);
|
||||
expect(el.style.filter).toMatch(/url\("?#hf-mb-0"?\)/);
|
||||
});
|
||||
|
||||
it("keeps capture for a mover that turns when the page asks for it", () => {
|
||||
installHtmlInCanvas();
|
||||
const { root, h } = turningHost(CAPTURE);
|
||||
initCaptureMotionBlur(h);
|
||||
void paintCaptureMotionBlur(0.5, PLAY);
|
||||
expect(win.__hfMotionBlur?.report()).toMatchObject({ tier: "capture", reasonCode: null });
|
||||
|
||||
@@ -196,7 +196,6 @@ function createInstance(host: CaptureMotionBlurHost, config: Config, form: HtmlI
|
||||
let scannedTimeline: unknown = undefined;
|
||||
let scanDefect: CaptureDefect | null = null;
|
||||
let faceNow: () => boolean = () => false;
|
||||
let translationOnly = false;
|
||||
const loggedBackstops = new Set<string>();
|
||||
let wrapped = false;
|
||||
// Once the engine drives frames, paused-style requests come from the transport, not a user.
|
||||
@@ -275,7 +274,6 @@ function createInstance(host: CaptureMotionBlurHost, config: Config, form: HtmlI
|
||||
faceNow = defects.facesNow;
|
||||
movers = found.movers;
|
||||
pads = found.pads;
|
||||
translationOnly = found.translationOnly;
|
||||
reader = createPoseReader(root, found.dynamic);
|
||||
scanMs = Math.round(performance.now() - s0);
|
||||
}
|
||||
@@ -482,15 +480,9 @@ function createInstance(host: CaptureMotionBlurHost, config: Config, form: HtmlI
|
||||
compositor = createCompositor(width, height, dpr);
|
||||
}
|
||||
|
||||
/** Who should draw instead of capture: it turned itself off, or the filter tier does as well for less. */
|
||||
/** Who should draw instead of capture: it turned itself off. */
|
||||
function handOff(): CaptureDefect | null {
|
||||
if (disabled) return { code: disabledCode ?? "capture-failures", reason: disabled };
|
||||
if (config.tier === "auto" && reader && translationOnly && filterTierAllowed()) {
|
||||
return {
|
||||
code: "translation-only",
|
||||
reason: "every mover only translates, which the filter tier draws as well and far cheaper",
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -629,7 +621,6 @@ let activeConfig: Config | null = null;
|
||||
/** The filter tier stands in for capture; a scene re-init tries capture again. */
|
||||
let onFallback = false;
|
||||
let fallbackEnabled = true;
|
||||
const filterTierAllowed = (): boolean => fallbackEnabled;
|
||||
let suspended = false;
|
||||
let priorResolver: (() => boolean) | null = null;
|
||||
let ourResolver: (() => boolean) | null = null;
|
||||
@@ -667,6 +658,17 @@ const TIER_ATTRIBUTE: CaptureDefect = {
|
||||
reason: 'data-motion-blur-tier="filter"',
|
||||
};
|
||||
|
||||
const TIER_AUTO: CaptureDefect = {
|
||||
code: "tier-auto",
|
||||
reason:
|
||||
'auto draws with the filter tier; data-motion-blur-tier="capture" streaks turns and zooms',
|
||||
};
|
||||
|
||||
function filterReason(tier: Config["tier"], why: CaptureDefect | null): CaptureDefect | null {
|
||||
if (tier === "auto") return TIER_AUTO;
|
||||
return tier === "filter" ? TIER_ATTRIBUTE : why;
|
||||
}
|
||||
|
||||
function selectTier(host: CaptureMotionBlurHost, config: Config, w: CompositeWindow): void {
|
||||
const form = htmlInCanvasForm();
|
||||
const why = unsupported(host.root);
|
||||
@@ -676,8 +678,7 @@ function selectTier(host: CaptureMotionBlurHost, config: Config, w: CompositeWin
|
||||
defect: why,
|
||||
fallback: fallbackEnabled,
|
||||
});
|
||||
if (choice === "filter")
|
||||
startFallback(host, config, config.tier === "filter" ? TIER_ATTRIBUTE : why);
|
||||
if (choice === "filter") startFallback(host, config, filterReason(config.tier, why));
|
||||
else if (choice === "capture" && form) instance = createInstance(host, config, form);
|
||||
else standDown(w, config, why);
|
||||
}
|
||||
|
||||
@@ -5,14 +5,23 @@ const defect = { code: "root-opacity", reason: "why" };
|
||||
const base = { tier: "auto", form: true, defect: null, fallback: true } as const;
|
||||
|
||||
describe("chooseTier", () => {
|
||||
it("draws with capture where it can run", () => {
|
||||
expect(chooseTier(base)).toBe("capture");
|
||||
it("draws with the filter tier on auto", () => {
|
||||
expect(chooseTier({ ...base, tier: "auto", form: true, defect: null, fallback: true })).toBe(
|
||||
"filter",
|
||||
);
|
||||
});
|
||||
|
||||
it("draws with capture only when the page asks", () => {
|
||||
expect(chooseTier({ ...base, tier: "capture" })).toBe("capture");
|
||||
});
|
||||
|
||||
it("draws with the filter tier where capture cannot run", () => {
|
||||
expect(chooseTier({ ...base, defect })).toBe("filter");
|
||||
expect(chooseTier({ ...base, form: false })).toBe("filter");
|
||||
it("judges capture alone when the fallback is off", () => {
|
||||
expect(chooseTier({ ...base, tier: "auto", fallback: false })).toBe("capture");
|
||||
});
|
||||
|
||||
it("draws with the filter tier where capture cannot run, even when asked for", () => {
|
||||
expect(chooseTier({ ...base, tier: "capture", defect })).toBe("filter");
|
||||
expect(chooseTier({ ...base, tier: "capture", form: false })).toBe("filter");
|
||||
});
|
||||
|
||||
it("draws with the filter tier when the page asks for it", () => {
|
||||
|
||||
@@ -63,10 +63,10 @@ export interface TierChoice {
|
||||
fallback: boolean;
|
||||
}
|
||||
|
||||
/** Capture where it can run; the filter tier where it cannot or the page asked for it; off if told to be. */
|
||||
/** The filter tier unless the page asks for capture and it can run; off if told to be. */
|
||||
export function chooseTier(c: TierChoice): "capture" | "filter" | "off" {
|
||||
if (c.defect?.code === "renderer-off") return "off";
|
||||
const capturable = c.form && !c.defect;
|
||||
if (c.fallback && (c.tier === "filter" || !capturable)) return "filter";
|
||||
if (c.fallback && (c.tier !== "capture" || !capturable)) return "filter";
|
||||
return capturable ? "capture" : "off";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
import type { Browser, Page } from "puppeteer-core";
|
||||
import { expect, it } from "vitest";
|
||||
import {
|
||||
compareTiles,
|
||||
meanFrame,
|
||||
trailMask,
|
||||
type Differential,
|
||||
type Rgba,
|
||||
} from "../blurDifferential.js";
|
||||
import { closeTestChrome } from "../loopback.js";
|
||||
import { captureFrame, launch, openFixture } from "./blurPage.js";
|
||||
import { FIXTURES, type BlurFixture } from "./fixtures.js";
|
||||
import { INVARIANTS } from "./thresholds.js";
|
||||
|
||||
export const FPS = 30;
|
||||
export const frameTime = (n: number): number => n / FPS;
|
||||
export const SUB_FRAME_DIVISIONS = 24;
|
||||
export const SHUTTER_SECONDS = 240 / 360 / FPS;
|
||||
export const CASE_TIMEOUT_MS = 60_000;
|
||||
|
||||
export type Tier = "capture" | "filter";
|
||||
|
||||
export const radiusPx = (f: BlurFixture): number => Math.ceil(2 * f.dpr);
|
||||
export const sizeOf = (f: BlurFixture): { width: number; height: number } => ({
|
||||
width: f.width,
|
||||
height: f.height,
|
||||
});
|
||||
|
||||
export async function onFreshPage<T>(
|
||||
browser: Browser,
|
||||
f: BlurFixture,
|
||||
blur: "on" | "off",
|
||||
use: (page: Page) => Promise<T>,
|
||||
tier?: Tier,
|
||||
): Promise<T> {
|
||||
const page = await openFixture(browser, f.html(blur, tier), f.dpr, sizeOf(f));
|
||||
try {
|
||||
return await use(page);
|
||||
} finally {
|
||||
await page.close();
|
||||
}
|
||||
}
|
||||
|
||||
export async function captureInOrder(
|
||||
page: Page,
|
||||
times: readonly number[],
|
||||
options?: { subFrameDivisions?: number },
|
||||
): Promise<Rgba[]> {
|
||||
const frames: Rgba[] = [];
|
||||
for (const t of times) frames.push(await captureFrame(page, t, options));
|
||||
return frames;
|
||||
}
|
||||
|
||||
export function neighbourTimes(t: number): number[] {
|
||||
const n = Math.round(t * FPS);
|
||||
const { radiusFrames } = INVARIANTS;
|
||||
return Array.from({ length: 2 * radiusFrames + 1 }, (_, k) => frameTime(n - radiusFrames + k));
|
||||
}
|
||||
|
||||
export function shutterTimes(t: number): number[] {
|
||||
const { shutterSamples } = INVARIANTS;
|
||||
return Array.from(
|
||||
{ length: shutterSamples },
|
||||
(_, k) => t - SHUTTER_SECONDS / 2 + ((k + 0.5) * SHUTTER_SECONDS) / shutterSamples,
|
||||
);
|
||||
}
|
||||
|
||||
export function firstFive(d: Differential): string {
|
||||
return JSON.stringify(d.bad.slice(0, 5));
|
||||
}
|
||||
|
||||
export async function measureOutside(
|
||||
browser: Browser,
|
||||
f: BlurFixture,
|
||||
t: number,
|
||||
tier?: Tier,
|
||||
): Promise<Differential> {
|
||||
const offFrames = await captureInOrder(await referencePage(f), neighbourTimes(t));
|
||||
const onFrame = await onFreshPage(browser, f, "on", (p) => captureFrame(p, t), tier);
|
||||
const reference = offFrames[INVARIANTS.radiusFrames];
|
||||
if (!reference) throw new Error("missing reference frame");
|
||||
return compareTiles(reference, onFrame, trailMask(offFrames, radiusPx(f)), "outside", {
|
||||
block: INVARIANTS.block,
|
||||
maxMae: INVARIANTS.outsideMaxMae,
|
||||
});
|
||||
}
|
||||
|
||||
export const caseName = (what: string, f: BlurFixture, t: number, tier?: Tier): string =>
|
||||
`${tier ? `${tier} tier, ` : ""}${what}: ${f.name} at ${t}`;
|
||||
|
||||
let launched: Browser | undefined;
|
||||
let supported = false;
|
||||
|
||||
export async function startChrome(): Promise<void> {
|
||||
({ browser: launched, supported } = await launch());
|
||||
}
|
||||
|
||||
export const isSupported = (): boolean => supported;
|
||||
|
||||
let reference: { name: string; page: Promise<Page> } | undefined;
|
||||
|
||||
async function closeReference(): Promise<void> {
|
||||
const open = reference;
|
||||
reference = undefined;
|
||||
if (open) await (await open.page).close();
|
||||
}
|
||||
|
||||
async function referencePage(f: BlurFixture): Promise<Page> {
|
||||
if (reference?.name !== f.name) {
|
||||
await closeReference();
|
||||
reference = { name: f.name, page: openFixture(chrome(), f.html("off"), f.dpr, sizeOf(f)) };
|
||||
}
|
||||
return reference.page;
|
||||
}
|
||||
|
||||
export async function stopChrome(): Promise<void> {
|
||||
await closeReference();
|
||||
await closeTestChrome(launched);
|
||||
}
|
||||
|
||||
export function chrome(): Browser {
|
||||
if (!launched) throw new Error("Chrome did not launch");
|
||||
return launched;
|
||||
}
|
||||
|
||||
export function fixtureNamed(name: string): BlurFixture {
|
||||
const f = FIXTURES.find((x) => x.name === name);
|
||||
if (!f) throw new Error(`missing fixture ${name}`);
|
||||
return f;
|
||||
}
|
||||
|
||||
export function defineOutsideCase(f: BlurFixture, t: number, tier?: Tier): void {
|
||||
it(
|
||||
caseName("outside the trail, blur on equals blur off", f, t, tier),
|
||||
async (ctx) => {
|
||||
if (!supported) ctx.skip();
|
||||
const d = await measureOutside(chrome(), f, t, tier);
|
||||
expect(d.bad, `${f.name} ${firstFive(d)}`).toEqual([]);
|
||||
expect(d.checkedFraction).toBeGreaterThanOrEqual(INVARIANTS.minCheckedFraction);
|
||||
},
|
||||
CASE_TIMEOUT_MS,
|
||||
);
|
||||
}
|
||||
|
||||
export function defineInsideCase(f: BlurFixture, t: number, tier?: Tier): void {
|
||||
it(
|
||||
caseName("inside the trail, blur on matches the shutter average", f, t, tier),
|
||||
async (ctx) => {
|
||||
if (!supported) ctx.skip();
|
||||
const samples = await captureInOrder(await referencePage(f), shutterTimes(t), {
|
||||
subFrameDivisions: SUB_FRAME_DIVISIONS,
|
||||
});
|
||||
const onFrame = await onFreshPage(chrome(), f, "on", (p) => captureFrame(p, t), tier);
|
||||
const d = compareTiles(
|
||||
meanFrame(samples),
|
||||
onFrame,
|
||||
trailMask(samples, radiusPx(f)),
|
||||
"inside",
|
||||
{
|
||||
block: INVARIANTS.block,
|
||||
maxMae: INVARIANTS.insideMaxMae,
|
||||
},
|
||||
);
|
||||
expect(d.checkedBlocks).toBeGreaterThan(0);
|
||||
expect(d.bad, `${f.name} ${firstFive(d)}`).toEqual([]);
|
||||
},
|
||||
CASE_TIMEOUT_MS,
|
||||
);
|
||||
}
|
||||
@@ -13,7 +13,7 @@ export interface BlurFixture {
|
||||
checkpoints: readonly number[];
|
||||
/** Times while a mover moves. */
|
||||
moving: readonly number[];
|
||||
html(blur: "on" | "off"): string;
|
||||
html(blur: "on" | "off", tier?: "capture" | "filter"): string;
|
||||
expectOn: {
|
||||
state: "on" | "off";
|
||||
tier: "capture" | "filter" | null;
|
||||
@@ -43,7 +43,7 @@ interface Spec {
|
||||
checkpoints?: readonly number[];
|
||||
moving?: readonly number[];
|
||||
expectOn?: Partial<BlurFixture["expectOn"]>;
|
||||
/** Pins the capture tier; left out for fixtures that exist to be handed to the filter tier. */
|
||||
/** Pins the capture tier; false leaves the tier to auto, which draws with the filter tier. */
|
||||
captureTier?: boolean;
|
||||
cardLeft?: number;
|
||||
cardTop?: number;
|
||||
@@ -73,10 +73,11 @@ function cssSlide(width: number, duration: number): string {
|
||||
#card { animation: slide ${duration}s linear both }`;
|
||||
}
|
||||
|
||||
const rootAttrs = (spec: Spec, blur: "on" | "off"): string => {
|
||||
const rootAttrs = (spec: Spec, blur: "on" | "off", tier?: "capture" | "filter"): string => {
|
||||
if (blur === "off") return 'data-motion-blur="off"';
|
||||
const tier = spec.captureTier === false ? "" : ' data-motion-blur-tier="capture"';
|
||||
return `data-motion-blur="on" data-motion-blur-events="on" data-motion-blur-shutter="240"${tier}`;
|
||||
const pinned = tier ?? (spec.captureTier === false ? undefined : "capture");
|
||||
const attribute = pinned ? ` data-motion-blur-tier="${pinned}"` : "";
|
||||
return `data-motion-blur="on" data-motion-blur-events="on" data-motion-blur-shutter="240"${attribute}`;
|
||||
};
|
||||
|
||||
const rootBody = (spec: Spec): string => {
|
||||
@@ -95,7 +96,7 @@ const pageScript = (spec: Spec, width: number, duration: number): string =>
|
||||
window.__timelines.root = tl;
|
||||
</script>`;
|
||||
|
||||
function compose(spec: Spec, blur: "on" | "off"): string {
|
||||
function compose(spec: Spec, blur: "on" | "off", tier?: "capture" | "filter"): string {
|
||||
const width = spec.width ?? 320;
|
||||
const height = spec.height ?? 180;
|
||||
const duration = spec.duration ?? 2;
|
||||
@@ -107,7 +108,7 @@ function compose(spec: Spec, blur: "on" | "off"): string {
|
||||
${spec.cssMotion ? cssSlide(width, duration) : ""}
|
||||
${spec.style ?? ""}
|
||||
</style></head><body>
|
||||
<div id="root" data-composition-id="root" data-start="0" data-duration="${duration}" data-width="${width}" data-height="${height}" ${rootAttrs(spec, blur)}
|
||||
<div id="root" data-composition-id="root" data-start="0" data-duration="${duration}" data-width="${width}" data-height="${height}" ${rootAttrs(spec, blur, tier)}
|
||||
style="position:relative;width:${width}px;height:${height}px;background:#10131a;overflow:hidden">${rootBody(spec)}</div>
|
||||
${pageScript(spec, width, duration)}
|
||||
</body></html>`;
|
||||
@@ -123,7 +124,7 @@ function fixture(spec: Spec): BlurFixture {
|
||||
fps: 30,
|
||||
checkpoints: spec.checkpoints ?? frames(15, 30, 45),
|
||||
moving: spec.moving ?? frames(6, 54),
|
||||
html: (blur) => compose(spec, blur),
|
||||
html: (blur, tier) => compose(spec, blur, tier),
|
||||
expectOn: { state: "on", tier: "capture", reasonCode: null, ...spec.expectOn },
|
||||
};
|
||||
}
|
||||
@@ -212,7 +213,7 @@ export const FIXTURES: readonly BlurFixture[] = [
|
||||
over: true,
|
||||
extra: WEBGL_TINT,
|
||||
checkpoints: frames(24, 30, 45),
|
||||
expectOn: { tier: "filter", reasonCode: "accelerated-canvas" },
|
||||
expectOn: { tier: "filter", reasonCode: "tier-auto" },
|
||||
}),
|
||||
// The flip tile stays sharp beside the blurred card: no time in the trail matches an average of its poses.
|
||||
fixture({
|
||||
@@ -222,7 +223,7 @@ export const FIXTURES: readonly BlurFixture[] = [
|
||||
extra: FLIP,
|
||||
style: "@keyframes flip { to { transform: rotateY(180deg) } }",
|
||||
checkpoints: HOLD_AFTER_FLIP,
|
||||
expectOn: { tier: "filter", reasonCode: "backface-visibility" },
|
||||
expectOn: { tier: "filter", reasonCode: "tier-auto" },
|
||||
}),
|
||||
fixture({
|
||||
name: "overflow-wordmark",
|
||||
@@ -242,7 +243,7 @@ export const FIXTURES: readonly BlurFixture[] = [
|
||||
moving: [],
|
||||
captureTier: false,
|
||||
extra: `<iframe id="frame" srcdoc='<body style="margin:0;background:#a33;color:#fff">framed</body>' style="position:absolute;left:10px;top:10px;width:120px;height:60px;border:0"></iframe>`,
|
||||
expectOn: { tier: "filter", reasonCode: "iframe-in-root" },
|
||||
expectOn: { tier: "filter", reasonCode: "tier-auto" },
|
||||
}),
|
||||
// The custom element stays sharp beside the blurred card: no time in the trail matches an average of its poses.
|
||||
fixture({
|
||||
@@ -255,8 +256,14 @@ export const FIXTURES: readonly BlurFixture[] = [
|
||||
connectedCallback() { this.style.background = "#357"; this.textContent = "badge" }
|
||||
});
|
||||
</script>`,
|
||||
expectOn: { tier: "filter", reasonCode: "iframe-in-root" },
|
||||
expectOn: { tier: "filter", reasonCode: "tier-auto" },
|
||||
}),
|
||||
fixture({ name: "dpr2-mover", dpr: 2 }),
|
||||
fixture({ name: "portrait-mover", width: 180, height: 320 }),
|
||||
];
|
||||
|
||||
export const ROTATING_CARD: BlurFixture = fixture({
|
||||
name: "rotating-card",
|
||||
captureTier: false,
|
||||
script: 'tl.fromTo("#card",{rotation:0},{rotation:540,duration:2,ease:"none"},0);',
|
||||
});
|
||||
|
||||
@@ -1,154 +1,34 @@
|
||||
import type { Browser, Page } from "puppeteer-core";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import type { Rgba } from "./__fixtures__/blurDifferential.js";
|
||||
import { captureFrame, hasBrowser } from "./__fixtures__/motionBlur/blurPage.js";
|
||||
import {
|
||||
compareTiles,
|
||||
meanFrame,
|
||||
trailMask,
|
||||
type Differential,
|
||||
type Rgba,
|
||||
} from "./__fixtures__/blurDifferential.js";
|
||||
import { closeTestChrome } from "./__fixtures__/loopback.js";
|
||||
import {
|
||||
captureFrame,
|
||||
hasBrowser,
|
||||
launch,
|
||||
openFixture,
|
||||
} from "./__fixtures__/motionBlur/blurPage.js";
|
||||
SUB_FRAME_DIVISIONS,
|
||||
captureInOrder,
|
||||
chrome,
|
||||
defineOutsideCase,
|
||||
fixtureNamed,
|
||||
frameTime,
|
||||
isSupported,
|
||||
neighbourTimes,
|
||||
onFreshPage,
|
||||
startChrome,
|
||||
stopChrome,
|
||||
FPS,
|
||||
CASE_TIMEOUT_MS,
|
||||
} from "./__fixtures__/motionBlur/differentialPage.js";
|
||||
import { FIXTURES, type BlurFixture } from "./__fixtures__/motionBlur/fixtures.js";
|
||||
import { INVARIANTS } from "./__fixtures__/motionBlur/thresholds.js";
|
||||
|
||||
const FPS = 30;
|
||||
const frameTime = (n: number): number => n / FPS;
|
||||
const SUB_FRAME_DIVISIONS = 24;
|
||||
const SHUTTER_SECONDS = 240 / 360 / FPS;
|
||||
const CASE_TIMEOUT_MS = 60_000;
|
||||
|
||||
/** Before the label's first call: a regression guard that a scan leaves no call's DOM behind to show it early. */
|
||||
const EXTRA_OUTSIDE_TIMES = new Map<string, readonly number[]>([
|
||||
["callbacks", [frameTime(6), frameTime(9), frameTime(12)]],
|
||||
]);
|
||||
|
||||
const radiusPx = (f: BlurFixture): number => Math.ceil(2 * f.dpr);
|
||||
const sizeOf = (f: BlurFixture): { width: number; height: number } => ({
|
||||
width: f.width,
|
||||
height: f.height,
|
||||
});
|
||||
|
||||
async function onFreshPage<T>(
|
||||
browser: Browser,
|
||||
f: BlurFixture,
|
||||
blur: "on" | "off",
|
||||
use: (page: Page) => Promise<T>,
|
||||
): Promise<T> {
|
||||
const page = await openFixture(browser, f.html(blur), f.dpr, sizeOf(f));
|
||||
try {
|
||||
return await use(page);
|
||||
} finally {
|
||||
await page.close();
|
||||
}
|
||||
}
|
||||
|
||||
async function captureInOrder(
|
||||
page: Page,
|
||||
times: readonly number[],
|
||||
options?: { subFrameDivisions?: number },
|
||||
): Promise<Rgba[]> {
|
||||
const frames: Rgba[] = [];
|
||||
for (const t of times) frames.push(await captureFrame(page, t, options));
|
||||
return frames;
|
||||
}
|
||||
|
||||
function neighbourTimes(t: number): number[] {
|
||||
const n = Math.round(t * FPS);
|
||||
const { radiusFrames } = INVARIANTS;
|
||||
return Array.from({ length: 2 * radiusFrames + 1 }, (_, k) => frameTime(n - radiusFrames + k));
|
||||
}
|
||||
|
||||
function shutterTimes(t: number): number[] {
|
||||
const { shutterSamples } = INVARIANTS;
|
||||
return Array.from(
|
||||
{ length: shutterSamples },
|
||||
(_, k) => t - SHUTTER_SECONDS / 2 + ((k + 0.5) * SHUTTER_SECONDS) / shutterSamples,
|
||||
);
|
||||
}
|
||||
|
||||
function firstFive(d: Differential): string {
|
||||
return JSON.stringify(d.bad.slice(0, 5));
|
||||
}
|
||||
|
||||
async function measureOutside(browser: Browser, f: BlurFixture, t: number): Promise<Differential> {
|
||||
const offFrames = await onFreshPage(browser, f, "off", (p) =>
|
||||
captureInOrder(p, neighbourTimes(t)),
|
||||
);
|
||||
const onFrame = await onFreshPage(browser, f, "on", (p) => captureFrame(p, t));
|
||||
const reference = offFrames[INVARIANTS.radiusFrames];
|
||||
if (!reference) throw new Error("missing reference frame");
|
||||
return compareTiles(reference, onFrame, trailMask(offFrames, radiusPx(f)), "outside", {
|
||||
block: INVARIANTS.block,
|
||||
maxMae: INVARIANTS.outsideMaxMae,
|
||||
});
|
||||
}
|
||||
|
||||
const caseName = (what: string, f: BlurFixture, t: number): string => `${what}: ${f.name} at ${t}`;
|
||||
|
||||
let launched: Browser | undefined;
|
||||
let supported = false;
|
||||
|
||||
function chrome(): Browser {
|
||||
if (!launched) throw new Error("Chrome did not launch");
|
||||
return launched;
|
||||
}
|
||||
|
||||
function fixtureNamed(name: string): BlurFixture {
|
||||
const f = FIXTURES.find((x) => x.name === name);
|
||||
if (!f) throw new Error(`missing fixture ${name}`);
|
||||
return f;
|
||||
}
|
||||
|
||||
function defineOutsideCase(f: BlurFixture, t: number): void {
|
||||
it(
|
||||
caseName("outside the trail, blur on equals blur off", f, t),
|
||||
async (ctx) => {
|
||||
if (!supported) ctx.skip();
|
||||
const d = await measureOutside(chrome(), f, t);
|
||||
expect(d.bad, `${f.name} ${firstFive(d)}`).toEqual([]);
|
||||
expect(d.checkedFraction).toBeGreaterThanOrEqual(INVARIANTS.minCheckedFraction);
|
||||
},
|
||||
CASE_TIMEOUT_MS,
|
||||
);
|
||||
}
|
||||
|
||||
function defineInsideCase(f: BlurFixture, t: number): void {
|
||||
it(
|
||||
caseName("inside the trail, blur on matches the shutter average", f, t),
|
||||
async (ctx) => {
|
||||
if (!supported) ctx.skip();
|
||||
const samples = await onFreshPage(chrome(), f, "off", (p) =>
|
||||
captureInOrder(p, shutterTimes(t), { subFrameDivisions: SUB_FRAME_DIVISIONS }),
|
||||
);
|
||||
const onFrame = await onFreshPage(chrome(), f, "on", (p) => captureFrame(p, t));
|
||||
const d = compareTiles(
|
||||
meanFrame(samples),
|
||||
onFrame,
|
||||
trailMask(samples, radiusPx(f)),
|
||||
"inside",
|
||||
{
|
||||
block: INVARIANTS.block,
|
||||
maxMae: INVARIANTS.insideMaxMae,
|
||||
},
|
||||
);
|
||||
expect(d.checkedBlocks).toBeGreaterThan(0);
|
||||
expect(d.bad, `${f.name} ${firstFive(d)}`).toEqual([]);
|
||||
},
|
||||
CASE_TIMEOUT_MS,
|
||||
);
|
||||
}
|
||||
|
||||
function defineHistoryCase(f: BlurFixture, t: number): void {
|
||||
it(
|
||||
`blur off does not depend on seek history: ${f.name} at ${t}`,
|
||||
async (ctx) => {
|
||||
if (!supported) ctx.skip();
|
||||
if (!isSupported()) ctx.skip();
|
||||
const inSequence = await onFreshPage(
|
||||
chrome(),
|
||||
f,
|
||||
@@ -167,7 +47,7 @@ function defineSubFrameCase(): void {
|
||||
it(
|
||||
"renderSeek honours sub-frame times",
|
||||
async (ctx) => {
|
||||
if (!supported) ctx.skip();
|
||||
if (!isSupported()) ctx.skip();
|
||||
const t = 0.2;
|
||||
const [a, mid, b] = await onFreshPage(chrome(), fixtureNamed("held-card"), "off", (p) =>
|
||||
captureInOrder(p, [t, t + 0.5 / FPS, t + 1 / FPS], {
|
||||
@@ -184,17 +64,15 @@ function defineSubFrameCase(): void {
|
||||
}
|
||||
|
||||
function defineFixtureCases(f: BlurFixture): void {
|
||||
for (const t of [...f.checkpoints, ...(EXTRA_OUTSIDE_TIMES.get(f.name) ?? [])]) {
|
||||
defineOutsideCase(f, t);
|
||||
}
|
||||
for (const t of f.moving) defineInsideCase(f, t);
|
||||
const times = [...f.checkpoints, ...(EXTRA_OUTSIDE_TIMES.get(f.name) ?? [])].sort(
|
||||
(a, b) => a - b,
|
||||
);
|
||||
for (const t of times) defineOutsideCase(f, t);
|
||||
}
|
||||
|
||||
describe.skipIf(!hasBrowser)("capture motion blur against blur off in Chrome", () => {
|
||||
beforeAll(async () => {
|
||||
({ browser: launched, supported } = await launch());
|
||||
}, 30_000);
|
||||
afterAll(() => closeTestChrome(launched));
|
||||
beforeAll(startChrome, 30_000);
|
||||
afterAll(stopChrome);
|
||||
|
||||
for (const f of FIXTURES) defineFixtureCases(f);
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { afterAll, beforeAll, describe } from "vitest";
|
||||
import { hasBrowser } from "./__fixtures__/motionBlur/blurPage.js";
|
||||
import {
|
||||
defineInsideCase,
|
||||
defineOutsideCase,
|
||||
startChrome,
|
||||
stopChrome,
|
||||
} from "./__fixtures__/motionBlur/differentialPage.js";
|
||||
import { FIXTURES, type BlurFixture } from "./__fixtures__/motionBlur/fixtures.js";
|
||||
|
||||
// One hold and one move per fixture hold the filter tier to the same two invariants. A fixture that
|
||||
// already expects the filter tier draws with it under the default arm, so it is not repeated here.
|
||||
function defineFilterCases(f: BlurFixture): void {
|
||||
if (f.expectOn.tier === "filter") return;
|
||||
const hold = f.checkpoints[Math.floor(f.checkpoints.length / 2)];
|
||||
const move = f.moving[Math.floor(f.moving.length / 2)];
|
||||
if (hold !== undefined) defineOutsideCase(f, hold, "filter");
|
||||
if (move !== undefined) defineInsideCase(f, move, "filter");
|
||||
}
|
||||
|
||||
describe.skipIf(!hasBrowser)("filter tier motion blur against blur off in Chrome", () => {
|
||||
beforeAll(startChrome, 30_000);
|
||||
afterAll(stopChrome);
|
||||
|
||||
for (const f of FIXTURES) defineFilterCases(f);
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import { afterAll, beforeAll, describe } from "vitest";
|
||||
import { hasBrowser } from "./__fixtures__/motionBlur/blurPage.js";
|
||||
import {
|
||||
defineInsideCase,
|
||||
startChrome,
|
||||
stopChrome,
|
||||
} from "./__fixtures__/motionBlur/differentialPage.js";
|
||||
import { FIXTURES } from "./__fixtures__/motionBlur/fixtures.js";
|
||||
|
||||
describe.skipIf(!hasBrowser)("capture motion blur inside the trail in Chrome", () => {
|
||||
beforeAll(startChrome, 30_000);
|
||||
afterAll(stopChrome);
|
||||
|
||||
for (const f of FIXTURES) {
|
||||
for (const t of f.moving) defineInsideCase(f, t);
|
||||
}
|
||||
});
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
openFixture,
|
||||
type BlurWindow,
|
||||
} from "./__fixtures__/motionBlur/blurPage.js";
|
||||
import { FIXTURES } from "./__fixtures__/motionBlur/fixtures.js";
|
||||
import { FIXTURES, ROTATING_CARD } from "./__fixtures__/motionBlur/fixtures.js";
|
||||
import type { Rgba } from "./__fixtures__/blurDifferential.js";
|
||||
|
||||
// A fixture with no `moving` times still slides its card in at 0.2 s: that is where blur on and blur off must differ.
|
||||
@@ -81,6 +81,39 @@ describe.skipIf(!hasBrowser)("capture motion blur fixtures in Chrome", () => {
|
||||
CASE_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
it(
|
||||
"auto draws a rotating mover with the filter tier and a page that asks for capture keeps it",
|
||||
async (ctx) => {
|
||||
if (!supported) ctx.skip();
|
||||
const f = ROTATING_CARD;
|
||||
const size = { width: f.width, height: f.height };
|
||||
const probeOn = async (tier?: "capture" | "filter") => {
|
||||
const page = await openFixture(browser, f.html("on", tier), f.dpr, size);
|
||||
try {
|
||||
await captureFrame(page, PROBE_WHILE_CARD_SLIDES);
|
||||
return await page.evaluate(() => (window as BlurWindow).__hfMotionBlur?.probe());
|
||||
} finally {
|
||||
await page.close();
|
||||
}
|
||||
};
|
||||
const auto = await probeOn();
|
||||
expect(auto).toMatchObject({
|
||||
state: "on",
|
||||
tier: "filter",
|
||||
reasonCode: "tier-auto",
|
||||
failedFrames: 0,
|
||||
});
|
||||
expect(auto?.movers).toBeGreaterThanOrEqual(1);
|
||||
expect(await probeOn("capture")).toMatchObject({
|
||||
state: "on",
|
||||
tier: "capture",
|
||||
reasonCode: null,
|
||||
failedFrames: 0,
|
||||
});
|
||||
},
|
||||
CASE_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
it.each(FIXTURES)("places the checkpoints of $name inside its holds on frame boundaries", (f) => {
|
||||
const onFrame = (t: number): boolean => Math.abs(t * 30 - Math.round(t * 30)) < 1e-9;
|
||||
expect(f.checkpoints.length).toBeGreaterThan(0);
|
||||
|
||||
@@ -226,7 +226,7 @@ describe.skipIf(!hasBrowser)("capture motion blur pixels in Chrome", () => {
|
||||
it("blurs with filters where capture cannot run, over a page that has a WebGL canvas", async (ctx) => {
|
||||
if (!supported) ctx.skip();
|
||||
const gl = `<canvas id="gl" width="64" height="36" style="position:absolute;left:0;top:0;width:${W}px;height:${H}px"></canvas><script>document.getElementById("gl").getContext("webgl")</script>`;
|
||||
const blurred = await frameOf(gl + BOX, true, FRAME);
|
||||
const blurred = await frameOf(gl + BOX, true, FRAME, "capture");
|
||||
const sharp = await frameOf(gl + BOX, false, FRAME);
|
||||
expect(blurred.report).toMatchObject({
|
||||
state: "on",
|
||||
@@ -326,7 +326,7 @@ describe.skipIf(!hasBrowser)("capture motion blur pixels in Chrome", () => {
|
||||
|
||||
it("blocks a backface-hidden card in a 3D flip and renders the plain frame", async (ctx) => {
|
||||
if (!supported) ctx.skip();
|
||||
const blurred = await frameOf(FLIP, true, 0.4);
|
||||
const blurred = await frameOf(FLIP, true, 0.4, "capture");
|
||||
const sharp = await frameOf(FLIP, false, 0.4);
|
||||
expect(blurred.report).toMatchObject({ tier: "filter", reasonCode: "backface-visibility" });
|
||||
expect(Buffer.from(blurred.frame.data).equals(Buffer.from(sharp.frame.data))).toBe(true);
|
||||
@@ -336,7 +336,7 @@ describe.skipIf(!hasBrowser)("capture motion blur pixels in Chrome", () => {
|
||||
if (!supported) ctx.skip();
|
||||
const sharp = await frameOf(BOX + card(""), false, 0.4);
|
||||
for (const body of [BOX + card("animation: hide 1s both"), BOX + card("") + WAAPI]) {
|
||||
const blurred = await frameOf(body, true, 0.4);
|
||||
const blurred = await frameOf(body, true, 0.4, "capture");
|
||||
expect(blurred.report).toMatchObject({ tier: "filter", reasonCode: "backface-visibility" });
|
||||
// The 3D card is not a mover for either tier: it is drawn as the sharp frame has it.
|
||||
let differing = 0;
|
||||
@@ -369,7 +369,12 @@ describe.skipIf(!hasBrowser)("capture motion blur pixels in Chrome", () => {
|
||||
|
||||
it("leaves a flat animated backface-visibility hack blurred", async (ctx) => {
|
||||
if (!supported) ctx.skip();
|
||||
const { report } = await frameOf(BOX + card("animation: hide 1s both", ""), true, 0.4);
|
||||
const { report } = await frameOf(
|
||||
BOX + card("animation: hide 1s both", ""),
|
||||
true,
|
||||
0.4,
|
||||
"capture",
|
||||
);
|
||||
expect(report).toMatchObject({ state: "on", movers: 1 });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -95,6 +95,10 @@ describe("MotionBlurPanel", () => {
|
||||
).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("labels itself Motion blur (Beta)", async () => {
|
||||
expect((await mount()).textContent).toContain("Motion blur (Beta)");
|
||||
});
|
||||
|
||||
it("shows the level the root is at", async () => {
|
||||
expect(checked(await mount())).toEqual(["Off"]);
|
||||
cleanup();
|
||||
|
||||
@@ -136,7 +136,7 @@ export const MotionBlurPanel = memo(function MotionBlurPanel({
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col gap-3 overflow-y-auto p-3 text-[11px] text-neutral-300">
|
||||
<span className="text-[12px] font-medium text-neutral-100">Motion blur</span>
|
||||
<span className="text-[12px] font-medium text-neutral-100">Motion blur (Beta)</span>
|
||||
<div role="radiogroup" aria-label="Motion blur" className="flex gap-1.5">
|
||||
{BLUR_LEVELS.map(({ level, label }) => (
|
||||
<Button
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"files": 2
|
||||
},
|
||||
"hyperframes": {
|
||||
"hash": "7794480f96489b7d",
|
||||
"hash": "fcbd52e834332599",
|
||||
"files": 78
|
||||
},
|
||||
"hyperframes-cli": {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
Measured frame by frame from the official HyperFrames launch films. These are defaults: a reference the person gave, or a Moment that does otherwise on purpose, wins for its own beat.
|
||||
|
||||
- **Moves**: a fast move takes 0.3–0.6 s and carries motion blur on its own ease, peaking at its fastest frame: 6–12 px on text-sized elements, 15–20 px full-frame, horizontal-only on a horizontal move. One move is one tween.
|
||||
- **Render-time blur**: for fast 2D movers, `data-motion-blur="on"` on the composition root smears them along their real path in preview and render (opt-in; also `data-motion-blur-shutter` for a longer smear, 360 is strong; `-events="on"` when the motion is set from a timeline callback such as a `render(t)` function). Suggest it when the person asks for blur or a filmic look and the piece moves fast. It picks how to draw on its own: a cheap per-element filter for translation, the truer capture for spins and zooms; it works over WebGL and in any Chrome, and is off only for HDR and distributed renders. Opt a subtree out with `data-motion-blur="off"`, e.g. a seam that already carries its own blur. After adding it run `hyperframes check`. Guide: /guides/motion-blur.
|
||||
- **Render-time blur**: for fast 2D movers, `data-motion-blur="on"` on the composition root smears them along their real path in preview and render (opt-in; also `data-motion-blur-shutter` for a longer smear, 360 is strong; `-events="on"` when the motion is set from a timeline callback such as a `render(t)` function). Suggest it when the person asks for blur or a filmic look and the piece moves fast. It draws with a per-element filter that works over WebGL and in any Chrome (cost varies by film; on two real films it cost more than capture) (spins and zooms soften rather than streak); `data-motion-blur-tier="capture"` opts into the truer capture, which loses anything in front of a mover and ignores blend modes. It is off only for HDR and distributed renders. Opt a subtree out with `data-motion-blur="off"`, e.g. a seam that already carries its own blur. After adding it run `hyperframes check`. Guide: /guides/motion-blur.
|
||||
- **Arrive slow, leave clean**: long-tailed ease-outs on arrivals; landing takes longer than leaving. An exit is one smooth motion, never slide, stop, then leave. Entrances that are too snappy read as glitches; slowing the whole video by about a second often fixes it.
|
||||
- **Ease by role**: an arrival lands on a long tail (`expo.out`, `power4.out`), a camera move or a colour flood eases both ways (`power2.inOut`), a zoom through or an exit accelerates (`power3.in`). The same `power2.out` at 0.5 s on everything is the flat default that makes a film feel generated. Linear only for rotation, progress and constant speed that is the point.
|
||||
- **Springs** are named by damping ratio: 1.0 never bounces, 0.7-0.85 reads premium, 0.4-0.6 playful, under 0.3 a cartoon. Position and size may bounce; opacity and colour never do. GSAP's `elastic.out(1, 0.5)` and `back.out(1.4)` are the nearest built-ins; a closed-form spring of `t` keeps any frame renderable on its own.
|
||||
|
||||
Reference in New Issue
Block a user