Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OffscreenCanvasRenderingContext2D support to parseImage #668

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down