From 990b9526efce19ac2f82f7c307f2aa193f9a6f9b Mon Sep 17 00:00:00 2001 From: Hao Ye Date: Tue, 29 Aug 2023 14:25:06 +0800 Subject: [PATCH] Add OffscreenCanvasRenderingContext2D support to parseImage --- lib/texture.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/texture.js b/lib/texture.js index 858be9f6..938d0018 100644 --- a/lib/texture.js +++ b/lib/texture.js @@ -135,6 +135,7 @@ function objectName (str) { var CANVAS_CLASS = objectName('HTMLCanvasElement') var OFFSCREENCANVAS_CLASS = objectName('OffscreenCanvas') var CONTEXT2D_CLASS = objectName('CanvasRenderingContext2D') +var OFFSCREEN_CONTEXT2D_CLASS = objectName('OffscreenCanvasRenderingContext2D') var BITMAP_CLASS = objectName('ImageBitmap') var IMAGE_CLASS = objectName('HTMLImageElement') var VIDEO_CLASS = objectName('HTMLVideoElement') @@ -143,6 +144,7 @@ var PIXEL_CLASSES = Object.keys(dtypes).concat([ CANVAS_CLASS, OFFSCREENCANVAS_CLASS, CONTEXT2D_CLASS, + OFFSCREEN_CONTEXT2D_CLASS, BITMAP_CLASS, IMAGE_CLASS, VIDEO_CLASS @@ -214,6 +216,10 @@ function isContext2D (object) { return classString(object) === CONTEXT2D_CLASS } +function isOffscreenContext2D (object) { + return classString(object) === OFFSCREEN_CONTEXT2D_CLASS +} + function isBitmap (object) { return classString(object) === BITMAP_CLASS } @@ -769,7 +775,7 @@ module.exports = function createTextureSet ( image.format = image.internalformat = CHANNELS_FORMAT[shapeC] image.needsFree = true transposeData(image, array, strideX, strideY, strideC, data.offset) - } else if (isCanvasElement(data) || isOffscreenCanvas(data) || isContext2D(data)) { + } else if (isCanvasElement(data) || isOffscreenCanvas(data) || isContext2D(data) || isOffscreenContext2D(data)) { if (isCanvasElement(data) || isOffscreenCanvas(data)) { image.element = data } else {