UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

1 lines 2.9 kB
{"version":3,"file":"utils.min.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","undefined","webgl","isPutImageFaster","width","height","targetCanvas","createCanvasElementFor","gl","createCanvasElement","getContext","testContext","imageBuffer","ArrayBuffer","testPipelineState","destinationWidth","destinationHeight","startTime","getFabricWindow","performance","now","WebGLFilterBackend","prototype","copyGLTo2D","call","drawImageTime","copyGLTo2DPutImageData"],"mappings":"oNAKaA,MAAAA,EACXC,QAEkDC,IAA1CD,EAAgCE,MAS7BC,EAAmBA,CAACC,EAAeC,KAC9C,MAAMC,EAAeC,EAAuB,CAAEH,QAAOC,WAE/CG,EADeC,IACGC,WAAW,SAI7BC,EAAc,CAClBC,YAHkB,IAAIC,YAAYT,EAAQC,EAAS,IAK/CS,EAAoB,CACxBC,iBAAkBX,EAClBY,kBAAmBX,EACnBC,aAAcA,GAEhB,IAAIW,EAEJA,EAAYC,IAAkBC,YAAYC,MAC1CC,EAAmBC,UAAUC,WAAWC,KACtCb,EACAH,EACAM,GAEF,MAAMW,EAAgBP,IAAkBC,YAAYC,MAAQH,EAE5DA,EAAYC,IAAkBC,YAAYC,MAC1CC,EAAmBC,UAAUI,uBAAuBF,KAClDb,EACAH,EACAM,GAIF,OAAOW,EAFkBP,IAAkBC,YAAYC,MAAQH,CAExB"}