diff --git a/packages/core/src/runtime/colorGrading.test.ts b/packages/core/src/runtime/colorGrading.test.ts index 66b241fe9e9..b157540e70e 100644 --- a/packages/core/src/runtime/colorGrading.test.ts +++ b/packages/core/src/runtime/colorGrading.test.ts @@ -2205,6 +2205,45 @@ describe("createColorGradingRuntime", () => { }); }); +describe("createColorGradingRuntime after a context loss", () => { + it("grades a clip that came on screen while the context was lost once it is restored", () => { + let lost = false; + const gl = createMockWebGl(); + gl.createTexture = vi.fn(() => (lost ? null : ({} as WebGLTexture))); + const spy = vi + .spyOn(HTMLCanvasElement.prototype, "getContext") + .mockImplementation(((type: string) => + type === "webgl" ? gl : type === "2d" ? mock2d() : null) as never); + try { + document.body.innerHTML = ""; + const first = makeDrawableVideo(); + first.id = "first"; + const second = makeDrawableVideo(); + second.id = "second"; + second.style.visibility = "hidden"; + document.body.append(first, second); + const runtime = createColorGradingRuntime(); + const shared = spy.mock.instances[0] as HTMLCanvasElement; + + lost = true; + shared.dispatchEvent(new Event("webglcontextlost", { cancelable: true })); + second.style.visibility = "visible"; + runtime.refresh(); + expect(runtime.getStatus("#second").state).toBe("unavailable"); + + lost = false; + shared.dispatchEvent(new Event("webglcontextrestored")); + + expect(runtime.getStatus("#first").state).toBe("active"); + expect(runtime.getStatus("#second").state).toBe("active"); + runtime.destroy(); + } finally { + spy.mockRestore(); + document.body.innerHTML = ""; + } + }); +}); + describe("installAuthoredOpacityCapture", () => { it("stamps graded elements at insertion and never overwrites the stamp", async () => { installAuthoredOpacityCapture(); diff --git a/packages/core/src/runtime/colorGrading.ts b/packages/core/src/runtime/colorGrading.ts index 110774fc1c0..6aacb0a6f31 100644 --- a/packages/core/src/runtime/colorGrading.ts +++ b/packages/core/src/runtime/colorGrading.ts @@ -3867,6 +3867,7 @@ export function createColorGradingRuntime(pausedMediaLease?: { if (entry.contextLost) restoreSourceElement(entry); else drawEntry(entry); } + refresh(); }); shared = { canvas, gl }; return shared;