Switch to malloc/free to be compatible with CanvasKit.Malloc
Inspired by https://skia-review.googlesource.com/c/skia/+/410876 Change-Id: Iaf64f379e74d46b46c795dd5f04db32406b976b4 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/411576 Auto-Submit: Mike Reed <reed@google.com> Reviewed-by: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
parent
09eb337d30
commit
0e4477e713
@ -56,6 +56,9 @@ template <typename T> TypedArray MakeTypedArray(int count, const T src[]) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gives read access to a JSArray
|
* Gives read access to a JSArray
|
||||||
|
*
|
||||||
|
* We explicitly use malloc/free (not new/delete) so this can be used with allocations from the JS
|
||||||
|
* side (ala CanvasKit.Malloc).
|
||||||
*/
|
*/
|
||||||
template <typename T> class JSSpan {
|
template <typename T> class JSSpan {
|
||||||
public:
|
public:
|
||||||
@ -69,7 +72,7 @@ public:
|
|||||||
data = reinterpret_cast<T*>(src["byteOffset"].as<size_t>());
|
data = reinterpret_cast<T*>(src["byteOffset"].as<size_t>());
|
||||||
} else {
|
} else {
|
||||||
fOwned = true;
|
fOwned = true;
|
||||||
data = new T[len];
|
data = static_cast<T*>(sk_malloc_throw(len, sizeof(T)));
|
||||||
|
|
||||||
// now actually copy into 'data'
|
// now actually copy into 'data'
|
||||||
if (src.instanceof(emscripten::val::global(JSArrayType<T>::gName))) {
|
if (src.instanceof(emscripten::val::global(JSArrayType<T>::gName))) {
|
||||||
@ -86,7 +89,7 @@ public:
|
|||||||
|
|
||||||
~JSSpan() {
|
~JSSpan() {
|
||||||
if (fOwned) {
|
if (fOwned) {
|
||||||
delete[] fSpan.data();
|
sk_free(fSpan.data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user