{"version":3,"file":"utils.mjs","names":[],"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\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"],"mappings":";;;;AAKA,MAAa,wBACX,YACmC;AACnC,QAAQ,QAAgC,UAAU,KAAA;;;;;;;;AASpD,MAAa,oBAAoB,OAAe,WAA4B;CAC1E,MAAM,eAAe,uBAAuB;EAAE;EAAO;EAAQ,CAAC;CAE9D,MAAM,KADe,qBAAqB,CAClB,WAAW,QAAQ;CAI3C,MAAM,cAAc,EAClB,6BAHkB,IAAI,YAAY,QAAQ,SAAS,EAAE,EAItD;CACD,MAAM,oBAAoB;EACxB,kBAAkB;EAClB,mBAAmB;EACL;EACf;CACD,IAAI;AAEJ,aAAY,iBAAiB,CAAC,YAAY,KAAK;AAC/C,oBAAmB,UAAU,WAAW,KACtC,aACA,IACA,kBACD;CACD,MAAM,gBAAgB,iBAAiB,CAAC,YAAY,KAAK,GAAG;AAE5D,aAAY,iBAAiB,CAAC,YAAY,KAAK;AAC/C,oBAAmB,UAAU,uBAAuB,KAClD,aACA,IACA,kBACD;AAGD,QAAO,gBAFkB,iBAAiB,CAAC,YAAY,KAAK,GAAG"}