Skip to content

Commit 256b84a

Browse files
fix(core): check's no-draw seeks no longer upload graded images to the GPU (heygen-com#7264)
1 parent 32eb4c3 commit 256b84a

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎packages/cli/src/capture/colorGrading.chromium.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
type HfHueCurvePoint,
1010
} from "@hyperframes/core/color-grading";
1111
import { findSystemBrowser } from "../browser/manager.js";
12+
import { seekInPage } from "./captureCompositionFrame.js";
1213

1314
interface GradingTestApi {
1415
setGrading(target: string, grading: HfColorGrading): boolean;
@@ -195,6 +196,33 @@ describe.skipIf(!runsChromium)("color grading curves in Chromium", () => {
195196
expect(actual).toEqual([128, 0, 0, 255]);
196197
expect(browserErrors).toEqual([]);
197198
});
199+
200+
// fails without the fix: every no-draw seek re-uploaded the image, a GPU copy each until check's batch ended.
201+
it("uploads no source frame during check's no-draw seeks, and one on the next drawn seek", async () => {
202+
const uploads = await page.evaluate(`(() => {
203+
const proto = WebGLRenderingContext.prototype;
204+
const upload = proto.texImage2D;
205+
let count = 0;
206+
proto.texImage2D = function (...args) {
207+
if (args.length === 6) count += 1;
208+
return Reflect.apply(upload, this, args);
209+
};
210+
window.__timelines = { main: { pause() {}, seek() { window.__gradingTestRuntime.redraw(); } } };
211+
const seek = ${seekInPage};
212+
try {
213+
for (let time = 1; time <= 8; time++) seek(time, true, false, true);
214+
const gated = count;
215+
count = 0;
216+
seek(9, true, false, false);
217+
return [gated, count];
218+
} finally {
219+
proto.texImage2D = upload;
220+
delete window.__timelines;
221+
}
222+
})()`);
223+
expect(uploads).toEqual([0, 1]);
224+
expect(browserErrors).toEqual([]);
225+
});
198226
});
199227

200228
describe.skipIf(!runsChromium)("a grade group in Chromium", () => {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3347,11 +3347,19 @@ function readAnimatedGrading(entry: ColorGradingEntry): ResolvedHfColorGrading {
33473347
return animated;
33483348
}
33493349

3350+
const CLI_SEEK_DRAW_GATE = Symbol.for("hyperframes.webglDrawGate");
3351+
3352+
function drawsGated(): boolean {
3353+
const gate: unknown = Reflect.get(window, CLI_SEEK_DRAW_GATE);
3354+
return typeof gate === "object" && gate !== null && Reflect.get(gate, "skip") === true;
3355+
}
3356+
33503357
function uploadSourceTexture(
33513358
gl: WebGLRenderingContext,
33523359
texture: WebGLTexture,
33533360
source: TexImageSource,
33543361
): void {
3362+
if (drawsGated()) return;
33553363
gl.activeTexture(gl.TEXTURE0);
33563364
gl.bindTexture(gl.TEXTURE_2D, texture);
33573365
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);

0 commit comments

Comments
 (0)