(cpuKernel, name)
| 27 | } |
| 28 | |
| 29 | function cpuKernelString(cpuKernel, name) { |
| 30 | const header = []; |
| 31 | const thisProperties = []; |
| 32 | const beforeReturn = []; |
| 33 | |
| 34 | const useFunctionKeyword = !/^function/.test(cpuKernel.color.toString()); |
| 35 | |
| 36 | header.push( |
| 37 | ' const { context, canvas, constants: incomingConstants } = settings;', |
| 38 | ` const output = new Int32Array(${JSON.stringify(Array.from(cpuKernel.output))});`, |
| 39 | ` const _constantTypes = ${JSON.stringify(cpuKernel.constantTypes)};`, |
| 40 | ` const _constants = ${constantsToString(cpuKernel.constants, cpuKernel.constantTypes)};` |
| 41 | ); |
| 42 | |
| 43 | thisProperties.push( |
| 44 | ' constants: _constants,', |
| 45 | ' context,', |
| 46 | ' output,', |
| 47 | ' thread: {x: 0, y: 0, z: 0},' |
| 48 | ); |
| 49 | |
| 50 | if (cpuKernel.graphical) { |
| 51 | header.push(` const _imageData = context.createImageData(${cpuKernel.output[0]}, ${cpuKernel.output[1]});`); |
| 52 | header.push(` const _colorData = new Uint8ClampedArray(${cpuKernel.output[0]} * ${cpuKernel.output[1]} * 4);`); |
| 53 | |
| 54 | const colorFn = utils.flattenFunctionToString((useFunctionKeyword ? 'function ' : '') + cpuKernel.color.toString(), { |
| 55 | thisLookup: (propertyName) => { |
| 56 | switch (propertyName) { |
| 57 | case '_colorData': |
| 58 | return '_colorData'; |
| 59 | case '_imageData': |
| 60 | return '_imageData'; |
| 61 | case 'output': |
| 62 | return 'output'; |
| 63 | case 'thread': |
| 64 | return 'this.thread'; |
| 65 | } |
| 66 | return JSON.stringify(cpuKernel[propertyName]); |
| 67 | }, |
| 68 | findDependency: (object, name) => { |
| 69 | return null; |
| 70 | } |
| 71 | }); |
| 72 | |
| 73 | const getPixelsFn = utils.flattenFunctionToString((useFunctionKeyword ? 'function ' : '') + cpuKernel.getPixels.toString(), { |
| 74 | thisLookup: (propertyName) => { |
| 75 | switch (propertyName) { |
| 76 | case '_colorData': |
| 77 | return '_colorData'; |
| 78 | case '_imageData': |
| 79 | return '_imageData'; |
| 80 | case 'output': |
| 81 | return 'output'; |
| 82 | case 'thread': |
| 83 | return 'this.thread'; |
| 84 | } |
| 85 | return JSON.stringify(cpuKernel[propertyName]); |
| 86 | }, |
no test coverage detected
searching dependent graphs…