Kevin Lubick | f3d6c36 | 2020-01-06 08:11:52 -0500 | [diff] [blame] | 1 | CanvasKit._extraInitializations = CanvasKit._extraInitializations || []; |
| 2 | CanvasKit._extraInitializations.push(function() { |
| 3 | CanvasKit.SkRuntimeEffect.prototype.makeShader = function(floats, isOpaque, matrix) { |
| 4 | var fptr = copy1dArray(floats, CanvasKit.HEAPF32); |
| 5 | // Our array has 4 bytes per float, so be sure to account for that before |
| 6 | // sending it over the wire. |
| 7 | if (!matrix) { |
| 8 | return this._makeShader(fptr, floats.length * 4, !!isOpaque); |
| 9 | } |
| 10 | return this._makeShader(fptr, floats.length * 4, !!isOpaque, matrix); |
| 11 | } |
Kevin Lubick | ecd8762 | 2020-02-22 07:37:33 -0500 | [diff] [blame] | 12 | |
| 13 | // childrenWithShaders is an array of other shaders (e.g. SkImage.makeShader()) |
| 14 | CanvasKit.SkRuntimeEffect.prototype.makeShaderWithChildren = function(floats, isOpaque, childrenShaders, matrix) { |
| 15 | var fptr = copy1dArray(floats, CanvasKit.HEAPF32); |
| 16 | var barePointers = []; |
| 17 | for (var i = 0; i<childrenShaders.length;i++) { |
| 18 | // childrenShaders are emscriptens smart pointer type. We want to get the bare pointer |
| 19 | // and send that over the wire, so it can be re-wrapped as an sk_sp. |
| 20 | barePointers.push(childrenShaders[i].$$.ptr); |
| 21 | } |
| 22 | var childrenPointers = copy1dArray(barePointers, CanvasKit.HEAPU32); |
| 23 | // Our array has 4 bytes per float, so be sure to account for that before |
| 24 | // sending it over the wire. |
| 25 | if (!matrix) { |
| 26 | return this._makeShaderWithChildren(fptr, floats.length * 4, !!isOpaque, childrenPointers, barePointers.length); |
| 27 | } |
| 28 | return this._makeShaderWithChildren(fptr, floats.length * 4, !!isOpaque, childrenPointers, barePointers.length, matrix); |
| 29 | } |
Kevin Lubick | f3d6c36 | 2020-01-06 08:11:52 -0500 | [diff] [blame] | 30 | }); |