fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
1 lines • 2.5 kB
Source Map (JSON)
{"version":3,"file":"utils.min.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":"oNAKA,MAAa,EACX,GAEQ,EAAgC,QAFxC,IAEkD,GASvC,GAAoB,EAAe,IAAA,CAC9C,IAAM,EAAe,EAAuB,CAAE,MAAA,EAAO,OAAA,EAAA,CAAA,CAE/C,EADe,GAAA,CACG,WAAW,QAAA,CAI7B,EAAc,CAClB,YAHkB,IAAI,YAAY,EAAQ,EAAS,EAAA,CAAA,CAK/C,EAAoB,CACxB,iBAAkB,EAClB,kBAAmB,EACL,aAAA,EAAA,CAEZ,EAEJ,EAAY,GAAA,CAAkB,YAAY,KAAA,CAC1C,EAAmB,UAAU,WAAW,KACtC,EACA,EACA,EAAA,CAEF,IAAM,EAAgB,GAAA,CAAkB,YAAY,KAAA,CAAQ,EAU5D,MARA,GAAY,GAAA,CAAkB,YAAY,KAAA,CAC1C,EAAmB,UAAU,uBAAuB,KAClD,EACA,EACA,EAAA,CAIK,EAFkB,GAAA,CAAkB,YAAY,KAAA,CAAQ,GAAA,OAAA,KAAA,iBAAA,KAAA"}