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