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