Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion packages/producer/src/services/renderOrchestrator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { join, win32 } from "node:path";
import { tmpdir } from "node:os";
import type { CaptureOptions, EngineConfig, ExtractedFrames } from "@hyperframes/engine";
import type {
CaptureOptions,
CaptureSession,
EngineConfig,
ExtractedFrames,
} from "@hyperframes/engine";
import {
DEFAULT_CONFIG,
DrawElementCaptureError,
Expand Down Expand Up @@ -32,6 +37,7 @@ import {
getNextRetryWorkerCount,
isRecoverableParallelCaptureError,
MAX_TRANSIENT_CAPTURE_RETRIES,
pageInstallsShaderCompositor,
resolveCaptureForceScreenshotForPageSideCompositing,
resolveRenderWorkDirPrefix,
shouldDiscardProbeSessionForPageSideCompositing,
Expand Down Expand Up @@ -1654,6 +1660,50 @@ describe("resolveCaptureForceScreenshotForPageSideCompositing", () => {
});
});

describe("pageInstallsShaderCompositor", () => {
// A page whose shader-transitions build added (or did not add) its compositor canvas.
const pageWith = (ids: string[]) =>
({
page: {
evaluate: async (fn: (id: string) => boolean, id: string) => {
vi.stubGlobal("document", {
getElementById: (x: string) => (ids.includes(x) ? {} : null),
});
try {
return fn(id);
} finally {
vi.unstubAllGlobals();
}
},
},
}) as unknown as CaptureSession;
const lifecycle = () => ({
initializeSession: vi.fn(async () => {}),
closeCaptureSession: vi.fn(async () => {}),
});

it("answers from the canvas every published shader-transitions build adds once it composites", async () => {
const hooks = lifecycle();
expect(
await pageInstallsShaderCompositor(
async () => pageWith(["__hf-page-side-compositor"]),
hooks,
),
).toBe(true);
expect(await pageInstallsShaderCompositor(async () => pageWith([]), hooks)).toBe(false);
expect(hooks.closeCaptureSession).toHaveBeenCalledTimes(2);
});

it("closes the page when it fails to load", async () => {
const hooks = lifecycle();
hooks.initializeSession.mockRejectedValueOnce(new Error("page never ready"));
await expect(pageInstallsShaderCompositor(async () => pageWith([]), hooks)).rejects.toThrow(
"page never ready",
);
expect(hooks.closeCaptureSession).toHaveBeenCalledTimes(1);
});
});

describe("shouldDiscardProbeSessionForPageSideCompositing", () => {
it("discards a previously-loaded probe page when page-side compositing is selected", () => {
expect(
Expand Down
46 changes: 45 additions & 1 deletion packages/producer/src/services/renderOrchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2993,6 +2993,26 @@ export function shouldDiscardProbeSessionForPageSideCompositing(args: {
return args.hasProbeSession && args.usePageSideCompositing;
}

// Every published @hyperframes/shader-transitions build adds this canvas once its page-side compositor installs.
const PAGE_SIDE_COMPOSITOR_CANVAS_ID = "__hf-page-side-compositor";

/** Loads the page with the page-side stub and reports whether its shader-transitions build installed the compositor. */
export async function pageInstallsShaderCompositor(
open: () => Promise<CaptureSession>,
session = { initializeSession, closeCaptureSession },
): Promise<boolean> {
const probe = await open();
try {
await session.initializeSession(probe);
return await probe.page.evaluate(
(id) => document.getElementById(id) !== null,
PAGE_SIDE_COMPOSITOR_CANVAS_ID,
);
} finally {
await session.closeCaptureSession(probe);
}
}

/**
* Main render pipeline
*/
Expand Down Expand Up @@ -4657,7 +4677,7 @@ async function executeRenderPipeline(input: {
// path so the palette encoder can preserve transparency. HDR content still
// forces the layered path (HDR layers need per-layer alpha + native HDR raw
// frame compositing in Node; that's out of scope for this opt-in).
const usePageSideCompositingForTransitions =
let usePageSideCompositingForTransitions =
(cfg.enablePageSideCompositing || isGif) &&
compiled.hasShaderTransitions &&
!hasHdrContent &&
Expand All @@ -4678,6 +4698,30 @@ async function executeRenderPipeline(input: {
"[Render] Recreating capture session so page-side compositing pre-head script is loaded.",
);
}
// The composition's own shader-transitions build decides whether it can composite in this
// browser; a build that cannot leaves the blend to the Node-side layered path.
try {
usePageSideCompositingForTransitions = await pageInstallsShaderCompositor(() =>
createCaptureSession(activeFileServer.url, framesDir, buildPrepCaptureOptions(), null, {
...cfg,
forceScreenshot: true,
}),
);
} catch (error) {
assertNotAborted();
// The capture stage opens its own session and owns retrying or failing it.
log.warn("[Render] Shader compositor check failed; keeping page-side compositing.", {
error: error instanceof Error ? error.message : String(error),
});
}
if (!usePageSideCompositingForTransitions) {
log.warn(
"[Render] The page's shader-transitions build cannot composite in this browser; " +
"shader transitions blend on the Node-side layered path.",
);
}
}
if (usePageSideCompositingForTransitions) {
captureForceScreenshot = resolveCaptureForceScreenshotForPageSideCompositing({
forceScreenshot: captureForceScreenshot,
usePageSideCompositing: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "page-side-shader-compositor-unavailable",
"description": "A browser whose html-in-canvas form the composition's shader-transitions build does not know (Chrome 157 replaced canvas layoutsubtree with content=\"drawable\"): the page deletes layoutSubtree before the build loads, so its page-side compositor declines to install. The shader transition must still render, blended on the Node-side layered path, instead of the bare opacity flip.",
"tags": [
"regression",
"render-compat",
"shader"
],
"minPsnr": 30,
"maxFrameFailures": 0,
"minAudioCorrelation": 0,
"maxAudioLagWindows": 1,
"renderConfig": {
"fps": 30,
"workers": 1
}
}
Git LFS file not shown
Git LFS file not shown
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Page-Side Shader Compositor Unavailable</title>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
<script>
delete HTMLCanvasElement.prototype.layoutSubtree;
</script>
<script src="vendor/hyper-shader.global.js"></script>
<style>
html,
body {
margin: 0;
padding: 0;
width: 640px;
height: 360px;
overflow: hidden;
background: #05070c;
}

#main {
position: relative;
width: 640px;
height: 360px;
overflow: hidden;
background: #05070c;
font-family: Arial, sans-serif;
}

.scene {
position: absolute;
inset: 0;
display: grid;
place-items: center;
opacity: 0;
overflow: hidden;
}

#scene-a {
opacity: 1;
background:
radial-gradient(circle at 22% 24%, rgba(255, 255, 255, 0.78) 0 42px, transparent 43px),
linear-gradient(135deg, #ff3f6e 0%, #6812d6 52%, #0b1030 100%);
}

#scene-b {
background:
radial-gradient(circle at 78% 70%, rgba(255, 255, 255, 0.72) 0 54px, transparent 55px),
linear-gradient(135deg, #03131f 0%, #06966d 45%, #e0fb55 100%);
}

.word {
position: relative;
z-index: 2;
color: #ffffff;
font-size: 92px;
font-weight: 900;
line-height: 0.9;
letter-spacing: 0;
text-shadow: 0 8px 28px rgba(0, 0, 0, 0.42);
}

.stripes {
position: absolute;
inset: -80px;
background: repeating-linear-gradient(
90deg,
rgba(255, 255, 255, 0.42) 0 18px,
transparent 18px 46px
);
transform: rotate(-18deg);
}
</style>
</head>
<body>
<div
id="main"
data-composition-id="page-side-shader-compositor-render-compat"
data-width="640"
data-height="360"
data-start="0"
data-duration="2"
>
<audio id="probe-audio" src="silent.wav" data-start="0" data-duration="2"></audio>

<section id="scene-a" class="scene clip" data-start="0" data-duration="2">
<div class="stripes"></div>
<div class="word">ALPHA</div>
</section>

<section id="scene-b" class="scene clip" data-start="0" data-duration="2">
<div class="stripes"></div>
<div class="word">BETA</div>
</section>
</div>

<script>
const probeAudio = document.getElementById("probe-audio");
probeAudio.volume = 0.25;

const tl = gsap.timeline({ paused: true });
HyperShader.init({
bgColor: "#05070c",
accentColor: "#7dd3fc",
scenes: ["scene-a", "scene-b"],
transitions: [{ time: 0.75, shader: "glitch", duration: 0.85, ease: "none" }],
timeline: tl,
compositionId: "page-side-shader-compositor-render-compat",
});

window.__timelines = window.__timelines || {};
window.__timelines["page-side-shader-compositor-render-compat"] = tl;
</script>
</body>
</html>
Binary file not shown.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/producer/tests/shard-schedule.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"shardCount": 9,
"distributedShardCount": 1,
"timings": {
"page-side-shader-compositor-unavailable": 30,
"animejs-adapter": 16,
"nested-sequential-video-local-start": 3,
"audio-mux-parity": 16,
Expand Down
Loading