[js/web] add OffscreenCanvas support to WebGL backend (#12159)

* Add OffscreenCanvas support to WebGL backend

* fix format

* fix lint
This commit is contained in:
101arrowz 2022-07-20 14:06:03 -07:00 committed by GitHub
parent 471dbfc250
commit c72bb8aaa9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -83,7 +83,16 @@ export function createNewWebGLContext(contextId?: 'webgl'|'webgl2'): WebGLContex
throw new Error('WebGL is not supported');
}
// eslint-disable-next-line @typescript-eslint/naming-convention
declare let OffscreenCanvas: {new (width: number, height: number): HTMLCanvasElement};
function createCanvas(): HTMLCanvasElement {
if (typeof document === 'undefined') {
if (typeof OffscreenCanvas === 'undefined') {
throw new TypeError('failed to create canvas: OffscreenCanvas is not supported');
}
return new OffscreenCanvas(1, 1);
}
const canvas: HTMLCanvasElement = document.createElement('canvas');
canvas.width = 1;
canvas.height = 1;