c1d0898d0a
This reduces the skm44_concat benchmark from 2us to .35us, a 5x speedup. SkCanvas.concat now takes a 3x2, 3x3, or 4x4 matrix and upscales them all to 4x4. This makes concat44 redundant. Removes redundant null checks for matrices, since freeing(0) in WASM is fine like it is in C++. Change-Id: I44a776ffd0babb81d8a34f9d94ae4d7831d02b55 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/281721 Reviewed-by: Mike Reed <reed@google.com>
33 lines
1.8 KiB
JavaScript
33 lines
1.8 KiB
JavaScript
CanvasKit._extraInitializations = CanvasKit._extraInitializations || [];
|
|
CanvasKit._extraInitializations.push(function() {
|
|
CanvasKit.SkRuntimeEffect.prototype.makeShader = function(floats, isOpaque, localMatrix) {
|
|
// We don't need to free these floats because they will become owned by the shader.
|
|
var fptr = copy1dArray(floats, CanvasKit.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.
|
|
var rts = this._makeShader(fptr, floats.length * 4, !!isOpaque, localMatrixPtr);
|
|
CanvasKit._free(localMatrixPtr);
|
|
return rts;
|
|
}
|
|
|
|
// childrenWithShaders is an array of other shaders (e.g. SkImage.makeShader())
|
|
CanvasKit.SkRuntimeEffect.prototype.makeShaderWithChildren = function(floats, isOpaque, childrenShaders, localMatrix) {
|
|
// We don't need to free these floats because they will become owned by the shader.
|
|
var fptr = copy1dArray(floats, CanvasKit.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, CanvasKit.HEAPU32);
|
|
// Our array has 4 bytes per float, so be sure to account for that before
|
|
// sending it over the wire.
|
|
var rts = this._makeShaderWithChildren(fptr, floats.length * 4, !!isOpaque, childrenPointers,
|
|
barePointers.length, localMatrixPtr);
|
|
CanvasKit._free(localMatrixPtr);
|
|
return rts;
|
|
}
|
|
}); |