{"version":3,"file":"utils.min.mjs","sources":["../../../src/filters/utils.ts"],"sourcesContent":["import { getFabricWindow } from '../env';\nimport { createCanvasElement } 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 = createCanvasElement();\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  targetCanvas.width = width;\n  targetCanvas.height = height;\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","undefined","webgl","isPutImageFaster","width","height","targetCanvas","createCanvasElement","gl","getContext","testContext","imageBuffer","ArrayBuffer","testPipelineState","destinationWidth","destinationHeight","startTime","getFabricWindow","performance","now","WebGLFilterBackend","prototype","copyGLTo2D","call","drawImageTime","copyGLTo2DPutImageData"],"mappings":"wLAKaA,MAAAA,EACXC,QAEkDC,IAA1CD,EAAgCE,MAS7BC,EAAmBA,CAACC,EAAeC,KAC9C,MAAMC,EAAeC,IAEfC,EADeD,IACGE,WAAW,SAI7BC,EAAc,CAClBC,YAHkB,IAAIC,YAAYR,EAAQC,EAAS,IAK/CQ,EAAoB,CACxBC,iBAAkBV,EAClBW,kBAAmBV,EACnBC,aAAcA,GAEhB,IAAIU,EACJV,EAAaF,MAAQA,EACrBE,EAAaD,OAASA,EAEtBW,EAAYC,IAAkBC,YAAYC,MAC1CC,EAAmBC,UAAUC,WAAWC,KACtCb,EACAF,EACAK,GAEF,MAAMW,EAAgBP,IAAkBC,YAAYC,MAAQH,EAE5DA,EAAYC,IAAkBC,YAAYC,MAC1CC,EAAmBC,UAAUI,uBAAuBF,KAClDb,EACAF,EACAK,GAIF,OAAOW,EAFkBP,IAAkBC,YAAYC,MAAQH,CAExB"}