diff --git a/src/core/lib/validateImageBitmap.ts b/src/core/lib/validateImageBitmap.ts index 70f7d4fd..fac177de 100644 --- a/src/core/lib/validateImageBitmap.ts +++ b/src/core/lib/validateImageBitmap.ts @@ -52,14 +52,21 @@ export async function validateCreateImageBitmap( // Test basic createImageBitmap support const blob = new Blob([pngBinaryData], { type: 'image/png' }); const bitmap = await platform.createImageBitmap(blob); - bitmap.close?.(); + if ('close' in bitmap && typeof bitmap.close === 'function') { + bitmap.close(); + } support.basic = true; // Test createImageBitmap with options support try { const options = { premultiplyAlpha: 'none' as const }; const bitmapWithOptions = await platform.createImageBitmap(blob, options); - bitmapWithOptions.close?.(); + if ( + 'close' in bitmapWithOptions && + typeof bitmapWithOptions.close === 'function' + ) { + bitmapWithOptions.close(); + } support.options = true; } catch (e) { /* ignore */ @@ -77,7 +84,12 @@ export async function validateCreateImageBitmap( premultiplyAlpha: 'none', }, ); - bitmapWithFullOptions.close?.(); + if ( + 'close' in bitmapWithFullOptions && + typeof bitmapWithFullOptions.close === 'function' + ) { + bitmapWithFullOptions.close(); + } support.full = true; } catch (e) { /* ignore */ diff --git a/src/core/platforms/Platform.ts b/src/core/platforms/Platform.ts index e4323ab8..01fdec32 100644 --- a/src/core/platforms/Platform.ts +++ b/src/core/platforms/Platform.ts @@ -48,18 +48,20 @@ export abstract class Platform { * @param options - The ImageBitmapOptions. * @returns A promise that resolves with the created ImageBitmap. */ - abstract createImageBitmap(blob: ImageBitmapSource): Promise; + abstract createImageBitmap( + blob: ImageBitmapSource, + ): Promise; abstract createImageBitmap( blob: ImageBitmapSource, options: ImageBitmapOptions, - ): Promise; + ): Promise; abstract createImageBitmap( blob: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, - ): Promise; + ): Promise; abstract createImageBitmap( blob: ImageBitmapSource, sx: number, @@ -67,7 +69,7 @@ export abstract class Platform { sw: number, sh: number, options: ImageBitmapOptions, - ): Promise; + ): Promise; /** * Retrieves the current timestamp. diff --git a/src/core/renderers/webgl/WebGlCtxSubTexture.ts b/src/core/renderers/webgl/WebGlCtxSubTexture.ts index eac634d2..7a450fc2 100644 --- a/src/core/renderers/webgl/WebGlCtxSubTexture.ts +++ b/src/core/renderers/webgl/WebGlCtxSubTexture.ts @@ -58,6 +58,7 @@ export class WebGlCtxSubTexture extends WebGlCtxTexture { | SubTextureProps | CompressedData | HTMLImageElement + | WebGLTexture | null, ): Dimensions { if (data === null) { diff --git a/src/core/renderers/webgl/WebGlCtxTexture.ts b/src/core/renderers/webgl/WebGlCtxTexture.ts index e8f238d2..796c5529 100644 --- a/src/core/renderers/webgl/WebGlCtxTexture.ts +++ b/src/core/renderers/webgl/WebGlCtxTexture.ts @@ -112,6 +112,17 @@ export class WebGlCtxTexture extends CoreContextTexture { this.state = 'loading'; this.textureSource.setState('loading'); + // Special case for the ION runtime which creates WebGLTextures directly + // as a result of the createImageBitmap platform method. + if (this.textureSource.textureData?.data instanceof WebGLTexture) { + this._nativeCtxTexture = this.textureSource.textureData.data; + this.state = 'loaded'; + this.textureSource.setState('loaded'); + + //FIXME get width and height from texture somehow + return; + } + // Await the native texture creation to ensure GPU buffer is fully allocated this._nativeCtxTexture = this.createNativeCtxTexture(); diff --git a/src/core/textures/ImageTexture.ts b/src/core/textures/ImageTexture.ts index d59becac..5d329546 100644 --- a/src/core/textures/ImageTexture.ts +++ b/src/core/textures/ImageTexture.ts @@ -193,7 +193,7 @@ export class ImageTexture extends Texture { sw: number | null, sh: number | null, ): Promise<{ - data: ImageBitmap | HTMLImageElement; + data: ImageBitmap | HTMLImageElement | WebGLTexture; premultiplyAlpha: boolean; }> { const hasAlphaChannel = premultiplyAlpha ?? blob.type.includes('image/png'); diff --git a/src/core/textures/Texture.ts b/src/core/textures/Texture.ts index 1cbca244..2e9c5280 100644 --- a/src/core/textures/Texture.ts +++ b/src/core/textures/Texture.ts @@ -102,6 +102,7 @@ export interface TextureData { | CompressedData | HTMLImageElement | Uint8Array + | WebGLTexture | null; /** * Premultiply alpha when uploading texture data to the GPU