blob: 94bf072c910245d23f022600f3a22cef0f6559db [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 Lubick6bffe392020-04-02 15:24:15 -04009 var rts = this._makeShader(fptr, floats.length * 4, !!isOpaque, localMatrixPtr);
10 localMatrixPtr && CanvasKit._free(localMatrixPtr);
11 return rts;
Kevin Lubickf3d6c362020-01-06 08:11:52 -050012 }
Kevin Lubickecd87622020-02-22 07:37:33 -050013
14 // childrenWithShaders is an array of other shaders (e.g. SkImage.makeShader())
Kevin Lubick6bffe392020-04-02 15:24:15 -040015 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 Lubickecd87622020-02-22 07:37:33 -050017 var fptr = copy1dArray(floats, CanvasKit.HEAPF32);
Kevin Lubick6bffe392020-04-02 15:24:15 -040018 var localMatrixPtr = copy3x3MatrixToWasm(localMatrix);
Kevin Lubickecd87622020-02-22 07:37:33 -050019 var barePointers = [];
Kevin Lubick6bffe392020-04-02 15:24:15 -040020 for (var i = 0; i < childrenShaders.length; i++) {
Kevin Lubickecd87622020-02-22 07:37:33 -050021 // 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 Lubick6bffe392020-04-02 15:24:15 -040028 var rts = this._makeShaderWithChildren(fptr, floats.length * 4, !!isOpaque, childrenPointers,
29 barePointers.length, localMatrixPtr);
30 localMatrixPtr && CanvasKit._free(localMatrixPtr);
31 return rts;
Kevin Lubickecd87622020-02-22 07:37:33 -050032 }
Kevin Lubickf3d6c362020-01-06 08:11:52 -050033});