blob: 92127c245573d17cbbb01bf9686c6cf5ee6151fb [file] [log] [blame]
Kevin Lubickf3d6c362020-01-06 08:11:52 -05001CanvasKit._extraInitializations = CanvasKit._extraInitializations || [];
2CanvasKit._extraInitializations.push(function() {
Kevin Lubick6bffe392020-04-02 15:24:15 -04003 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 Lubickf3d6c362020-01-06 08:11:52 -05005 var fptr = copy1dArray(floats, CanvasKit.HEAPF32);
Kevin Lubick6bffe392020-04-02 15:24:15 -04006 var localMatrixPtr = copy3x3MatrixToWasm(localMatrix);
Kevin Lubickf3d6c362020-01-06 08:11:52 -05007 // Our array has 4 bytes per float, so be sure to account for that before
8 // sending it over the wire.
Kevin Lubick6aa38692020-06-01 11:25:47 -04009 return this._makeShader(fptr, floats.length * 4, !!isOpaque, localMatrixPtr);
Kevin Lubickf3d6c362020-01-06 08:11:52 -050010 }
Kevin Lubickecd87622020-02-22 07:37:33 -050011
12 // childrenWithShaders is an array of other shaders (e.g. SkImage.makeShader())
Kevin Lubick6bffe392020-04-02 15:24:15 -040013 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 Lubickecd87622020-02-22 07:37:33 -050015 var fptr = copy1dArray(floats, CanvasKit.HEAPF32);
Kevin Lubick6bffe392020-04-02 15:24:15 -040016 var localMatrixPtr = copy3x3MatrixToWasm(localMatrix);
Kevin Lubickecd87622020-02-22 07:37:33 -050017 var barePointers = [];
Kevin Lubick6bffe392020-04-02 15:24:15 -040018 for (var i = 0; i < childrenShaders.length; i++) {
Kevin Lubickecd87622020-02-22 07:37:33 -050019 // 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 Lubick6aa38692020-06-01 11:25:47 -040026 return this._makeShaderWithChildren(fptr, floats.length * 4, !!isOpaque, childrenPointers,
27 barePointers.length, localMatrixPtr);
Kevin Lubickecd87622020-02-22 07:37:33 -050028 }
Kevin Lubick6aa38692020-06-01 11:25:47 -040029});