{"version":3,"file":"getTemporaryCanvasFromImage.mjs","sources":["../../../../src/scene/text-html/utils/getTemporaryCanvasFromImage.ts"],"sourcesContent":["import { type ImageLike } from '../../../environment/ImageLike';\nimport { CanvasPool } from '../../../rendering/renderers/shared/texture/CanvasPool';\n\nimport type { CanvasAndContext } from '../../../rendering/renderers/shared/texture/CanvasPool';\n\n/**\n * This function converts an image to a canvas, and returns the canvas.\n * It is used to convert images to canvases to work around a CORS issue where WebGPU cannot\n * upload an SVGImage to a texture.\n *\n * It uses the CanvasPool to get an optimal canvas and context, and then draws the image onto it.\n * Remember to return this canvas is immediately to the CanvasPool for reuse when you are done with it.\n * (eg upload it to the GPU!)\n * @param image - The image to convert to a canvas.\n * @param resolution - The resolution of the canvas.\n * @internal\n */\nexport function getTemporaryCanvasFromImage(image: ImageLike, resolution: number): CanvasAndContext\n{\n    // Get an optimal canvas and context from the CanvasPool, based on the\n    // dimensions of the image and the desired resolution.\n    const canvasAndContext = CanvasPool.getOptimalCanvasAndContext(\n        image.width,\n        image.height,\n        resolution\n    );\n\n    // Clear the context of the canvas, and draw the image onto it.\n    const { context } = canvasAndContext;\n\n    context.clearRect(0, 0, image.width, image.height);\n    context.drawImage(image, 0, 0);\n\n    // Return the canvas.\n    return canvasAndContext;\n}\n\n"],"names":[],"mappings":";;;AAiBO,SAAS,2BAAA,CAA4B,OAAkB,UAAA,EAC9D;AAGI,EAAA,MAAM,mBAAmB,UAAA,CAAW,0BAAA;AAAA,IAChC,KAAA,CAAM,KAAA;AAAA,IACN,KAAA,CAAM,MAAA;AAAA,IACN;AAAA,GACJ;AAGA,EAAA,MAAM,EAAE,SAAQ,GAAI,gBAAA;AAEpB,EAAA,OAAA,CAAQ,UAAU,CAAA,EAAG,CAAA,EAAG,KAAA,CAAM,KAAA,EAAO,MAAM,MAAM,CAAA;AACjD,EAAA,OAAA,CAAQ,SAAA,CAAU,KAAA,EAAO,CAAA,EAAG,CAAC,CAAA;AAG7B,EAAA,OAAO,gBAAA;AACX;;;;"}