1 | {"version":3,"file":"BaseImageResource.mjs","sources":["../../../src/textures/resources/BaseImageResource.ts"],"sourcesContent":["import { ALPHA_MODES } from '@pixi/constants';\nimport { determineCrossOrigin } from '@pixi/utils';\nimport { Resource } from './Resource';\n\nimport type { Renderer } from '../../Renderer';\nimport type { BaseTexture, ImageSource } from '../BaseTexture';\nimport type { GLTexture } from '../GLTexture';\n\n/**\n * Base for all the image/canvas resources.\n * @memberof PIXI\n */\nexport class BaseImageResource extends Resource\n{\n /**\n * The source element.\n * @member {PIXI.ImageSourcee}\n * @readonly\n */\n public source: ImageSource;\n\n /**\n * If set to `true`, will force `texImage2D` over `texSubImage2D` for uploading.\n * Certain types of media (e.g. video) using `texImage2D` is more performant.\n * @default false\n * @private\n */\n public noSubImage: boolean;\n\n /**\n * @param {PIXI.ImageSourcee} source\n */\n constructor(source: ImageSource)\n {\n const sourceAny = source as any;\n const width = sourceAny.naturalWidth || sourceAny.videoWidth || sourceAny.displayWidth || sourceAny.width;\n const height = sourceAny.naturalHeight || sourceAny.videoHeight || sourceAny.displayHeight || sourceAny.height;\n\n super(width, height);\n\n this.source = source;\n this.noSubImage = false;\n }\n\n /**\n * Set cross origin based detecting the url and the crossorigin\n * @param element - Element to apply crossOrigin\n * @param url - URL to check\n * @param crossorigin - Cross origin value to use\n */\n static crossOrigin(element: HTMLImageElement | HTMLVideoElement, url: string, crossorigin?: boolean | string): void\n {\n if (crossorigin === undefined && !url.startsWith('data:'))\n {\n element.crossOrigin = determineCrossOrigin(url);\n }\n else if (crossorigin !== false)\n {\n element.crossOrigin = typeof crossorigin === 'string' ? crossorigin : 'anonymous';\n }\n }\n\n /**\n * Upload the texture to the GPU.\n * @param renderer - Upload to the renderer\n * @param baseTexture - Reference to parent texture\n * @param glTexture\n * @param {PIXI.ImageSourcee} [source] - (optional)\n * @returns - true is success\n */\n override upload(renderer: Renderer, baseTexture: BaseTexture, glTexture: GLTexture, source?: ImageSource): boolean\n {\n const gl = renderer.gl;\n const width = baseTexture.realWidth;\n const height = baseTexture.realHeight;\n\n source = source || this.source;\n\n if (typeof HTMLImageElement !== 'undefined' && source instanceof HTMLImageElement)\n {\n if (!source.complete || source.naturalWidth === 0)\n {\n return false;\n }\n }\n else if (typeof HTMLVideoElement !== 'undefined' && source instanceof HTMLVideoElement)\n {\n if (source.readyState <= 1)\n {\n return false;\n }\n }\n\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.alphaMode === ALPHA_MODES.UNPACK);\n\n if (!this.noSubImage\n && baseTexture.target === gl.TEXTURE_2D\n && glTexture.width === width\n && glTexture.height === height)\n {\n gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, baseTexture.format, glTexture.type, source);\n }\n else\n {\n glTexture.width = width;\n glTexture.height = height;\n\n gl.texImage2D(baseTexture.target, 0, glTexture.internalFormat, baseTexture.format, glTexture.type, source);\n }\n\n return true;\n }\n\n /**\n * Checks if source width/height was changed, resize can cause extra baseTexture update.\n * Triggers one update in any case.\n */\n override update(): void\n {\n if (this.destroyed)\n {\n return;\n }\n\n const source = this.source as any;\n\n const width = source.naturalWidth || source.videoWidth || source.width;\n const height = source.naturalHeight || source.videoHeight || source.height;\n\n this.resize(width, height);\n\n super.update();\n }\n\n /** Destroy this {@link PIXI.BaseImageResource} */\n override dispose(): void\n {\n this.source = null;\n }\n}\n"],"names":[],"mappings":";;;AAYO,MAAM,0BAA0B,SACvC;AAAA;AAAA;AAAA;AAAA,EAmBI,YAAY,QACZ;AACI,UAAM,YAAY,QACZ,QAAQ,UAAU,gBAAgB,UAAU,cAAc,UAAU,gBAAgB,UAAU,OAC9F,SAAS,UAAU,iBAAiB,UAAU,eAAe,UAAU,iBAAiB,UAAU;AAExG,UAAM,OAAO,MAAM,GAEd,KAAA,SAAS,QACd,KAAK,aAAa;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,YAAY,SAA8C,KAAa,aAC9E;AACQ,oBAAgB,UA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