Skip to content

Commit 91f1495

Browse files
fix(core): stop a graded plate painting through an inactive clip (#3196)
A color-graded image or video inside a timed sub-composition kept painting after its clip window closed. The runtime hid the sub-composition wrapper with `visibility: hidden`, but the grading canvas carried an explicit inline `visibility: visible`, and an explicit value on a descendant escapes an ancestor's inherited `hidden`. The treated plate composited over whichever scene was actually on screen, in preview and in the encoded render alike. `drawEntry` only refreshed its cached view of the source's visibility inside `if (injectedFrameSource || !hiddenByColorGrading)`. That gate exists for opacity: `hideSourceElement` sets `opacity: 0 !important` on the source while grading is active, so mirroring the source's computed opacity onto the canvas would blank it. Visibility was swept into the same gate by accident. Grading never writes `visibility`, so the source's computed visibility always tracks the clip window — and because every graded source is hidden-by-grading, the mirror could never self-heal once it went stale. Split the two mirrors: opacity stays gated, visibility is re-read from computed style every frame. Deriving it from the source rather than from a notification means any way of hiding a clip works, including ones that do not exist yet.
1 parent c9dd841 commit 91f1495

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,35 @@ describe("createColorGradingRuntime", () => {
770770
expect(canvas.style.opacity).toBe("0.75");
771771
});
772772

773+
it("hides the canvas when an ancestor clip goes out of its visibility window", () => {
774+
// A graded <img> inside a timed sub-composition carries no data-start of its
775+
// own, so nothing tells grading the clip left the screen — the canvas has to
776+
// notice from the source's inherited visibility. Before the fix, grading's own
777+
// opacity hide short-circuited that read and the canvas kept an explicit
778+
// `visibility: visible`, painting the treated plate over the active scene.
779+
const scene = document.createElement("div");
780+
const image = makeDrawableImage();
781+
scene.appendChild(image);
782+
document.body.appendChild(scene);
783+
784+
runtime = createColorGradingRuntime();
785+
const canvas = document.querySelector<HTMLCanvasElement>("[data-hf-color-grading-canvas]");
786+
if (!canvas) throw new Error("Expected color grading canvas");
787+
expect(canvas.style.visibility).toBe("visible");
788+
789+
scene.style.visibility = "hidden";
790+
runtime.redraw();
791+
792+
expect(canvas.style.visibility).toBe("hidden");
793+
794+
scene.style.visibility = "visible";
795+
runtime.redraw();
796+
797+
expect(canvas.style.visibility).toBe("visible");
798+
// Grading still owns the source's opacity hide, so the canvas keeps full opacity.
799+
expect(canvas.style.opacity).toBe("1");
800+
});
801+
773802
it("allows a drawable producer render frame to initialize hidden source grading", () => {
774803
const video = makeDrawableVideo();
775804
video.style.display = "none";

‎packages/core/src/runtime/colorGrading.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3065,12 +3065,19 @@ function drawEntry(entry: ColorGradingEntry): boolean {
30653065
const sourceVisibility = entry.element.style.getPropertyValue("visibility");
30663066
const injectedFrameSource = isRenderFrameImage(source);
30673067
if (injectedFrameSource) keepCanvasAboveSource(entry, source);
3068+
const computed = window.getComputedStyle(injectedFrameSource ? source : entry.element);
3069+
// `hideSourceElement` owns the source's inline opacity while grading is active
3070+
// (opacity:0 !important), so reading it back would mirror grading's own hide
3071+
// onto the canvas and blank it. That gate is about opacity ONLY: grading never
3072+
// writes `visibility`, so the source's computed visibility always tracks the
3073+
// clip window and has to be re-read every frame. Leaving it stale let the
3074+
// canvas keep an explicit `visibility: visible` and paint straight through an
3075+
// inactive ancestor clip's inherited `visibility: hidden`.
30683076
if (injectedFrameSource || !hiddenByColorGrading) {
3069-
const computed = window.getComputedStyle(injectedFrameSource ? source : entry.element);
30703077
entry.sourceOpacityForCanvas = computed.opacity || "1";
3071-
entry.sourceVisibleForCanvas =
3072-
(injectedFrameSource || sourceVisibility !== "hidden") && computed.visibility !== "hidden";
30733078
}
3079+
entry.sourceVisibleForCanvas =
3080+
(injectedFrameSource || sourceVisibility !== "hidden") && computed.visibility !== "hidden";
30743081
const layout = updateCanvasLayout(entry, styleSource);
30753082
if (!layout) return false;
30763083

0 commit comments

Comments
 (0)