[PathKit] Write more complete docs and clean up API to be consistent
Breaking Changes (should be minor, as it's mostly just things
for testing):
- PathKit.ApplyPathOp should have returned a new SkPath, but didn't.
It now does and is named "MakeFromOp", which makes the convention of
"Have 'make' in name, needs delete" more consistent.
- PathKit.FromCmds(arr) now only needs to take the JS Array and
will handle the TypedArrays under the hood. If clients want to deal
with TypedArrays themselves, they can use _FromCmds(ptr, len) directly.
- PathKit.MakeLTRBRect is now just PathKit.LTRBRect. The thing
returned is a normal JS Object and doesn't need delete().
As per custom with v0 apps, we are updating the minor version
to v0.3.0 to account for breaking changes.
Docs-Preview: https://skia.org/?cl=147960
Bug: skia:8216
Change-Id: Ia3626e69f3e97698fc62a6aee876af005e29ffca
Reviewed-on: https://skia-review.googlesource.com/147960
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Heather Miller <hcm@google.com>
diff --git a/experimental/pathkit/helper.js b/experimental/pathkit/helper.js
index 0d476ab..4f84782 100644
--- a/experimental/pathkit/helper.js
+++ b/experimental/pathkit/helper.js
@@ -7,9 +7,9 @@
var Float32ArrayCache = {};
// Takes a 2D array of commands and puts them into the WASM heap
- // as a 1D array. This allowing them to referenced from the C++ code.
+ // as a 1D array. This allows them to referenced from the C++ code.
// Returns a 2 element array, with the first item being essentially a
- // pointer to the array and the second item being the lengh of
+ // pointer to the array and the second item being the length of
// the new 1D array.
//
// Example usage:
@@ -26,7 +26,7 @@
//
// If arguments at index 1... in each cmd row are strings, they will be
// parsed as hex, and then converted to floats using SkBits2FloatUnsigned
- PathKit['loadCmdsTypedArray'] = function(arr) {
+ PathKit.loadCmdsTypedArray = function(arr) {
var len = 0;
for (var r = 0; r < arr.length; r++) {
len += arr[r].length;
@@ -57,5 +57,13 @@
PathKit.HEAPF32.set(ta, ptr / ta.BYTES_PER_ELEMENT);
return [ptr, len];
}
+
+ // Experimentation has shown that using TypedArrays to pass arrays from
+ // JS to C++ is faster than passing the JS Arrays across.
+ // See above for example of cmds.
+ PathKit.FromCmds = function(cmds) {
+ var ptrLen = PathKit.loadCmdsTypedArray(cmds);
+ return PathKit._FromCmds(ptrLen[0], ptrLen[1]);
+ }
}(Module)); // When this file is loaded in, the high level object is "Module";