blob: d398ebb20ddaf8aaaff15534c1f649fd44d37637 [file] [log] [blame]
Kevin Lubickf3d6c362020-01-06 08:11:52 -05001CanvasKit._extraInitializations = CanvasKit._extraInitializations || [];
2CanvasKit._extraInitializations.push(function() {
Kevin Lubick54c1b3d2020-10-07 16:09:22 -04003 CanvasKit.RuntimeEffect.prototype.makeShader = function(floats, isOpaque, localMatrix) {
Kevin Lubick6bffe392020-04-02 15:24:15 -04004 // We don't need to free these floats because they will become owned by the shader.
Kevin Lubick69e46da2020-06-05 07:13:48 -04005 var fptr = copy1dArray(floats, "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
Kevin Lubick54c1b3d2020-10-07 16:09:22 -040012 // childrenWithShaders is an array of other shaders (e.g. Image.makeShader())
13 CanvasKit.RuntimeEffect.prototype.makeShaderWithChildren = function(floats, isOpaque, childrenShaders, localMatrix) {
Kevin Lubick6bffe392020-04-02 15:24:15 -040014 // We don't need to free these floats because they will become owned by the shader.
Kevin Lubick69e46da2020-06-05 07:13:48 -040015 var fptr = copy1dArray(floats, "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 }
Kevin Lubick69e46da2020-06-05 07:13:48 -040023 var childrenPointers = copy1dArray(barePointers, "HEAPU32");
Kevin Lubickecd87622020-02-22 07:37:33 -050024 // 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});