skia2/modules/canvaskit/rt_shader.js
Brian Osman 77326adc07 Remove isOpaque parameter from CanvasKit SkRuntimeEffect APIs
Bug: skia:12643
Change-Id: I285d42c908c75532b78c9b80da7b6145e1b47fe7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/506458
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2022-02-10 17:15:13 +00:00

45 lines
2.2 KiB
JavaScript

CanvasKit._extraInitializations = CanvasKit._extraInitializations || [];
CanvasKit._extraInitializations.push(function() {
// sksl is the shader code.
// errorCallback is a function that will be called with an error string if the
// effect cannot be made. If not provided, the error will be logged.
CanvasKit.RuntimeEffect.Make = function(sksl, errorCallback) {
// The easiest way to pass a function into C++ code is to wrap it in an object and
// treat it as an emscripten::val on the other side.
var callbackObj = {
'onError': errorCallback || function(err) {
console.log('RuntimeEffect error', err);
},
};
return CanvasKit.RuntimeEffect._Make(sksl, callbackObj);
};
CanvasKit.RuntimeEffect.prototype.makeShader = function(floats, localMatrix) {
// We don't need to free these floats because they will become owned by the shader.
var fptr = copy1dArray(floats, "HEAPF32");
var localMatrixPtr = copy3x3MatrixToWasm(localMatrix);
// Our array has 4 bytes per float, so be sure to account for that before
// sending it over the wire.
return this._makeShader(fptr, floats.length * 4, localMatrixPtr);
}
// childrenWithShaders is an array of other shaders (e.g. Image.makeShader())
CanvasKit.RuntimeEffect.prototype.makeShaderWithChildren = function(floats, childrenShaders, localMatrix) {
// We don't need to free these floats because they will become owned by the shader.
var fptr = copy1dArray(floats, "HEAPF32");
var localMatrixPtr = copy3x3MatrixToWasm(localMatrix);
var barePointers = [];
for (var i = 0; i < childrenShaders.length; i++) {
// childrenShaders are emscriptens smart pointer type. We want to get the bare pointer
// and send that over the wire, so it can be re-wrapped as an sk_sp.
barePointers.push(childrenShaders[i].$$.ptr);
}
var childrenPointers = copy1dArray(barePointers, "HEAPU32");
// Our array has 4 bytes per float, so be sure to account for that before
// sending it over the wire.
return this._makeShaderWithChildren(fptr, floats.length * 4, childrenPointers,
barePointers.length, localMatrixPtr);
}
});