{"version":3,"file":"utils.mjs","sources":["../../../src/filters/utils.ts"],"sourcesContent":["import { getFabricWindow } from '../env';\nimport { createCanvasElement, createCanvasElementFor } from '../util/misc/dom';\nimport { WebGLFilterBackend } from './WebGLFilterBackend';\nimport type { TWebGLPipelineState, T2DPipelineState } from './typedefs';\n\nexport const isWebGLPipelineState = (\n  options: TWebGLPipelineState | T2DPipelineState,\n): options is TWebGLPipelineState => {\n  return (options as TWebGLPipelineState).webgl !== undefined;\n};\n\n/**\n * Pick a method to copy data from GL context to 2d canvas.  In some browsers using\n * drawImage should be faster, but is also bugged for a small combination of old hardware\n * and drivers.\n * putImageData is faster than drawImage for that specific operation.\n */\nexport const isPutImageFaster = (width: number, height: number): boolean => {\n  const targetCanvas = createCanvasElementFor({ width, height });\n  const sourceCanvas = createCanvasElement();\n  const gl = sourceCanvas.getContext('webgl')!;\n  // eslint-disable-next-line no-undef\n  const imageBuffer = new ArrayBuffer(width * height * 4);\n\n  const testContext = {\n    imageBuffer: imageBuffer,\n  } as unknown as Required<WebGLFilterBackend>;\n  const testPipelineState = {\n    destinationWidth: width,\n    destinationHeight: height,\n    targetCanvas: targetCanvas,\n  } as unknown as TWebGLPipelineState;\n  let startTime;\n\n  startTime = getFabricWindow().performance.now();\n  WebGLFilterBackend.prototype.copyGLTo2D.call(\n    testContext,\n    gl,\n    testPipelineState,\n  );\n  const drawImageTime = getFabricWindow().performance.now() - startTime;\n\n  startTime = getFabricWindow().performance.now();\n  WebGLFilterBackend.prototype.copyGLTo2DPutImageData.call(\n    testContext,\n    gl,\n    testPipelineState,\n  );\n  const putImageDataTime = getFabricWindow().performance.now() - startTime;\n\n  return drawImageTime > putImageDataTime;\n};\n"],"names":["isWebGLPipelineState","options","webgl","undefined"],"mappings":";;AAKaA,MAAAA,oBAAoB,GAC/BC,OAA+C,IACZ;AACnC,EAAA,OAAQA,OAAO,CAAyBC,KAAK,KAAKC,SAAS;AAC7D;;;;"}