Skip to content

Commit e83100f

Browse files
committed
fix: keep WebGPU presentation active during render seeks
1 parent fa621e3 commit e83100f

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

packages/core/src/runtime/init.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// fallow-ignore-file code-duplication
22
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
33
import { initSandboxRuntimeModular } from "./init";
4+
import { TYPEGPU_PRESENT_HEARTBEAT_MS } from "./adapters/typegpu";
45
import type { RuntimeTimelineLike } from "./types";
56

67
function createMockTimeline(duration: number): RuntimeTimelineLike {
@@ -122,6 +123,7 @@ describe("initSandboxRuntimeModular", () => {
122123
delete (window as { __hfAutoNoopRegistered?: boolean }).__hfAutoNoopRegistered;
123124
delete window.gsap;
124125
vi.restoreAllMocks();
126+
vi.useRealTimers();
125127
window.requestAnimationFrame = originalRequestAnimationFrame;
126128
window.cancelAnimationFrame = originalCancelAnimationFrame;
127129
});
@@ -370,6 +372,31 @@ describe("initSandboxRuntimeModular", () => {
370372
expect(child.style.visibility).toBe("visible");
371373
});
372374

375+
it("keeps WebGPU presentation active after renderSeek pauses the frame", async () => {
376+
vi.useFakeTimers();
377+
378+
const root = document.createElement("div");
379+
root.setAttribute("data-composition-id", "main");
380+
root.setAttribute("data-root", "true");
381+
root.setAttribute("data-requires-webgpu", "");
382+
root.setAttribute("data-duration", "10");
383+
document.body.appendChild(root);
384+
window.__timelines = { main: createMockTimeline(10) };
385+
386+
const times: number[] = [];
387+
const onSeek = (event: Event) => {
388+
times.push((event as CustomEvent<{ time: number }>).detail.time);
389+
};
390+
window.addEventListener("hf-seek", onSeek);
391+
392+
initSandboxRuntimeModular();
393+
window.__player?.renderSeek(4);
394+
await vi.advanceTimersByTimeAsync(TYPEGPU_PRESENT_HEARTBEAT_MS);
395+
396+
window.removeEventListener("hf-seek", onSeek);
397+
expect(times).toEqual([0, 4, 4]);
398+
});
399+
373400
it("uses export render fps when quantizing renderSeek", () => {
374401
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
375402
const root = document.createElement("div");

packages/core/src/runtime/init.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,7 @@ export function initSandboxRuntimeModular(): void {
24122412
activateChildren: true,
24132413
suppressEvents: options?.suppressEvents,
24142414
});
2415+
runAdapters("pause");
24152416
syncMediaForCurrentState();
24162417
colorGrading.redraw();
24172418
postState(true);

0 commit comments

Comments
 (0)