mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix(core): check's no-draw seeks no longer upload graded images to the GPU (#7264)
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
type HfHueCurvePoint,
|
||||
} from "@hyperframes/core/color-grading";
|
||||
import { findSystemBrowser } from "../browser/manager.js";
|
||||
import { seekInPage } from "./captureCompositionFrame.js";
|
||||
|
||||
interface GradingTestApi {
|
||||
setGrading(target: string, grading: HfColorGrading): boolean;
|
||||
@@ -195,6 +196,33 @@ describe.skipIf(!runsChromium)("color grading curves in Chromium", () => {
|
||||
expect(actual).toEqual([128, 0, 0, 255]);
|
||||
expect(browserErrors).toEqual([]);
|
||||
});
|
||||
|
||||
// fails without the fix: every no-draw seek re-uploaded the image, a GPU copy each until check's batch ended.
|
||||
it("uploads no source frame during check's no-draw seeks, and one on the next drawn seek", async () => {
|
||||
const uploads = await page.evaluate(`(() => {
|
||||
const proto = WebGLRenderingContext.prototype;
|
||||
const upload = proto.texImage2D;
|
||||
let count = 0;
|
||||
proto.texImage2D = function (...args) {
|
||||
if (args.length === 6) count += 1;
|
||||
return Reflect.apply(upload, this, args);
|
||||
};
|
||||
window.__timelines = { main: { pause() {}, seek() { window.__gradingTestRuntime.redraw(); } } };
|
||||
const seek = ${seekInPage};
|
||||
try {
|
||||
for (let time = 1; time <= 8; time++) seek(time, true, false, true);
|
||||
const gated = count;
|
||||
count = 0;
|
||||
seek(9, true, false, false);
|
||||
return [gated, count];
|
||||
} finally {
|
||||
proto.texImage2D = upload;
|
||||
delete window.__timelines;
|
||||
}
|
||||
})()`);
|
||||
expect(uploads).toEqual([0, 1]);
|
||||
expect(browserErrors).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!runsChromium)("a grade group in Chromium", () => {
|
||||
|
||||
@@ -3347,11 +3347,19 @@ function readAnimatedGrading(entry: ColorGradingEntry): ResolvedHfColorGrading {
|
||||
return animated;
|
||||
}
|
||||
|
||||
const CLI_SEEK_DRAW_GATE = Symbol.for("hyperframes.webglDrawGate");
|
||||
|
||||
function drawsGated(): boolean {
|
||||
const gate: unknown = Reflect.get(window, CLI_SEEK_DRAW_GATE);
|
||||
return typeof gate === "object" && gate !== null && Reflect.get(gate, "skip") === true;
|
||||
}
|
||||
|
||||
function uploadSourceTexture(
|
||||
gl: WebGLRenderingContext,
|
||||
texture: WebGLTexture,
|
||||
source: TexImageSource,
|
||||
): void {
|
||||
if (drawsGated()) return;
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
||||
|
||||
Reference in New Issue
Block a user