blob: 6ecb327b1fbf9819608bfb38e3391ecd6569638f [file] [log] [blame]
Kevin Lubick217056c2018-09-20 17:39:31 -04001// Adds JS functions to augment the CanvasKit interface.
2// For example, if there is a wrapper around the C++ call or logic to allow
3// chaining, it should go here.
Kevin Lubickb5ae3b52018-11-03 07:51:19 -04004(function(CanvasKit) {
Kevin Lubick217056c2018-09-20 17:39:31 -04005 // CanvasKit.onRuntimeInitialized is called after the WASM library has loaded.
6 // Anything that modifies an exposed class (e.g. SkPath) should be set
7 // after onRuntimeInitialized, otherwise, it can happen outside of that scope.
8 CanvasKit.onRuntimeInitialized = function() {
9 // All calls to 'this' need to go in externs.js so closure doesn't minify them away.
Kevin Lubick1a05fce2018-11-20 12:51:16 -050010
11
12 // Add some helpers for matrices. This is ported from SkMatrix.cpp
13 // to save complexity and overhead of going back and forth between
14 // C++ and JS layers.
15 CanvasKit.SkMatrix = {};
16 function sdot(a, b, c, d, e, f) {
17 e = e || 0;
18 f = f || 0;
19 return a * b + c * d + e * f;
20 }
21
Kevin Lubickb9db3902018-11-26 11:47:54 -050022 CanvasKit.SkMatrix.identity = function() {
23 return [
24 1, 0, 0,
25 0, 1, 0,
26 0, 0, 1,
27 ];
28 };
29
30 // Maps the given points according to the passed in matrix.
31 // Results are done in place.
32 // See SkMatrix.h::mapPoints for the docs on the math.
33 CanvasKit.SkMatrix.mapPoints = function(matrix, ptArr) {
34 if (ptArr.length % 2) {
35 throw 'mapPoints requires an even length arr';
36 }
37 for (var i = 0; i < ptArr.length; i+=2) {
38 var x = ptArr[i], y = ptArr[i+1];
39 // Gx+Hy+I
40 var denom = matrix[6]*x + matrix[7]*y + matrix[8];
41 // Ax+By+C
42 var xTrans = matrix[0]*x + matrix[1]*y + matrix[2];
43 // Dx+Ey+F
44 var yTrans = matrix[3]*x + matrix[4]*y + matrix[5];
45 ptArr[i] = xTrans/denom;
46 ptArr[i+1] = yTrans/denom;
47 }
48 return ptArr;
49 };
50
51 CanvasKit.SkMatrix.multiply = function(m1, m2) {
52 var result = [0,0,0, 0,0,0, 0,0,0];
53 for (var r = 0; r < 3; r++) {
54 for (var c = 0; c < 3; c++) {
55 // m1 and m2 are 1D arrays pretending to be 2D arrays
56 result[3*r + c] = sdot(m1[3*r + 0], m2[3*0 + c],
57 m1[3*r + 1], m2[3*1 + c],
58 m1[3*r + 2], m2[3*2 + c]);
59 }
60 }
61 return result;
62 }
63
64 // Return a matrix representing a rotation by n radians.
Kevin Lubick1a05fce2018-11-20 12:51:16 -050065 // px, py optionally say which point the rotation should be around
66 // with the default being (0, 0);
Kevin Lubickb9db3902018-11-26 11:47:54 -050067 CanvasKit.SkMatrix.rotated = function(radians, px, py) {
Kevin Lubick1a05fce2018-11-20 12:51:16 -050068 px = px || 0;
69 py = py || 0;
Kevin Lubickb9db3902018-11-26 11:47:54 -050070 var sinV = Math.sin(radians);
71 var cosV = Math.cos(radians);
Kevin Lubick1a05fce2018-11-20 12:51:16 -050072 return [
73 cosV, -sinV, sdot( sinV, py, 1 - cosV, px),
74 sinV, cosV, sdot(-sinV, px, 1 - cosV, py),
75 0, 0, 1,
76 ];
77 };
Kevin Lubick1a05fce2018-11-20 12:51:16 -050078
Kevin Lubickb9db3902018-11-26 11:47:54 -050079 CanvasKit.SkMatrix.scaled = function(sx, sy, px, py) {
80 px = px || 0;
81 py = py || 0;
82 return [
83 sx, 0, px - sx * px,
84 0, sy, py - sy * py,
85 0, 0, 1,
86 ];
87 };
88
89 CanvasKit.SkMatrix.skewed = function(kx, ky, px, py) {
90 px = px || 0;
91 py = py || 0;
92 return [
93 1, kx, -kx * px,
94 ky, 1, -ky * py,
95 0, 0, 1,
96 ];
97 };
98
99 CanvasKit.SkMatrix.translated = function(dx, dy) {
100 return [
101 1, 0, dx,
102 0, 1, dy,
103 0, 0, 1,
104 ];
105 };
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500106
107 CanvasKit.SkPath.prototype.addArc = function(oval, startAngle, sweepAngle) {
108 // see arc() for the HTMLCanvas version
109 // note input angles are degrees.
110 this._addArc(oval, startAngle, sweepAngle);
111 return this;
112 };
113
Kevin Lubick217056c2018-09-20 17:39:31 -0400114 CanvasKit.SkPath.prototype.addPath = function() {
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500115 // Takes 1, 2, 7, or 10 required args, where the first arg is always the path.
116 // The last arg is optional and chooses between add or extend mode.
Kevin Lubick217056c2018-09-20 17:39:31 -0400117 // The options for the remaining args are:
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500118 // - an array of 6 or 9 parameters (perspective is optional)
119 // - the 9 parameters of a full matrix or
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400120 // the 6 non-perspective params of a matrix.
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500121 var args = Array.prototype.slice.call(arguments);
122 var path = args[0];
123 var extend = false;
124 if (typeof args[args.length-1] === "boolean") {
125 extend = args.pop();
126 }
127 if (args.length === 1) {
128 // Add path, unchanged. Use identity matrix
129 this._addPath(path, 1, 0, 0,
130 0, 1, 0,
131 0, 0, 1,
132 extend);
133 } else if (args.length === 2) {
Kevin Lubick217056c2018-09-20 17:39:31 -0400134 // User provided the 9 params of a full matrix as an array.
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500135 var a = args[1];
136 this._addPath(path, a[0], a[1], a[2],
137 a[3], a[4], a[5],
138 a[6] || 0, a[7] || 0, a[8] || 1,
139 extend);
140 } else if (args.length === 7 || args.length === 10) {
Kevin Lubick217056c2018-09-20 17:39:31 -0400141 // User provided the 9 params of a (full) matrix directly.
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400142 // (or just the 6 non perspective ones)
Kevin Lubick217056c2018-09-20 17:39:31 -0400143 // These are in the same order as what Skia expects.
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500144 var a = args;
145 this._addPath(path, a[1], a[2], a[3],
146 a[4], a[5], a[6],
147 a[7] || 0, a[8] || 0, a[9] || 1,
148 extend);
Kevin Lubick217056c2018-09-20 17:39:31 -0400149 } else {
Kevin Lubick6fccc9d2018-11-20 15:55:10 -0500150 SkDebug('addPath expected to take 1, 2, 7, or 10 required args. Got ' + args.length);
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500151 return null;
152 }
153 return this;
154 };
155
156 CanvasKit.SkPath.prototype.addRect = function() {
157 // Takes 1, 2, 4 or 5 args
158 // - SkRect
159 // - SkRect, isCCW
160 // - left, top, right, bottom
161 // - left, top, right, bottom, isCCW
162 if (arguments.length === 1 || arguments.length === 2) {
163 var r = arguments[0];
164 var ccw = arguments[1] || false;
165 this._addRect(r.fLeft, r.fTop, r.fRight, r.fBottom, ccw);
166 } else if (arguments.length === 4 || arguments.length === 5) {
167 var a = arguments;
168 this._addRect(a[0], a[1], a[2], a[3], a[4] || false);
169 } else {
Kevin Lubick6fccc9d2018-11-20 15:55:10 -0500170 SkDebug('addRect expected to take 1, 2, 4, or 5 args. Got ' + arguments.length);
Kevin Lubick217056c2018-09-20 17:39:31 -0400171 return null;
172 }
173 return this;
174 };
175
Alexander Khovansky3e119332018-11-15 02:01:19 +0300176 CanvasKit.SkPath.prototype.arc = function(x, y, radius, startAngle, endAngle, ccw) {
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500177 // emulates the HTMLCanvas behavior. See addArc() for the SkPath version.
178 // Note input angles are radians.
179 var bounds = CanvasKit.LTRBRect(x-radius, y-radius, x+radius, y+radius);
180 var sweep = radiansToDegrees(endAngle - startAngle) - (360 * !!ccw);
181 var temp = new CanvasKit.SkPath();
182 temp.addArc(bounds, radiansToDegrees(startAngle), sweep);
183 this.addPath(temp, true);
184 temp.delete();
Alexander Khovansky3e119332018-11-15 02:01:19 +0300185 return this;
186 };
187
Kevin Lubick217056c2018-09-20 17:39:31 -0400188 CanvasKit.SkPath.prototype.arcTo = function(x1, y1, x2, y2, radius) {
189 this._arcTo(x1, y1, x2, y2, radius);
190 return this;
191 };
192
193 CanvasKit.SkPath.prototype.close = function() {
194 this._close();
195 return this;
196 };
197
198 CanvasKit.SkPath.prototype.conicTo = function(x1, y1, x2, y2, w) {
199 this._conicTo(x1, y1, x2, y2, w);
200 return this;
201 };
202
203 CanvasKit.SkPath.prototype.cubicTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {
204 this._cubicTo(cp1x, cp1y, cp2x, cp2y, x, y);
205 return this;
206 };
207
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400208 CanvasKit.SkPath.prototype.dash = function(on, off, phase) {
209 if (this._dash(on, off, phase)) {
210 return this;
211 }
212 return null;
213 };
214
Kevin Lubick217056c2018-09-20 17:39:31 -0400215 CanvasKit.SkPath.prototype.lineTo = function(x, y) {
216 this._lineTo(x, y);
217 return this;
218 };
219
220 CanvasKit.SkPath.prototype.moveTo = function(x, y) {
221 this._moveTo(x, y);
222 return this;
223 };
224
225 CanvasKit.SkPath.prototype.op = function(otherPath, op) {
226 if (this._op(otherPath, op)) {
227 return this;
228 }
229 return null;
230 };
231
232 CanvasKit.SkPath.prototype.quadTo = function(cpx, cpy, x, y) {
233 this._quadTo(cpx, cpy, x, y);
234 return this;
235 };
236
237 CanvasKit.SkPath.prototype.simplify = function() {
238 if (this._simplify()) {
239 return this;
240 }
241 return null;
242 };
243
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400244 CanvasKit.SkPath.prototype.stroke = function(opts) {
245 // Fill out any missing values with the default values.
246 /**
247 * See externs.js for this definition
248 * @type {StrokeOpts}
249 */
250 opts = opts || {};
251 opts.width = opts.width || 1;
252 opts.miter_limit = opts.miter_limit || 4;
Kevin Lubickb9db3902018-11-26 11:47:54 -0500253 opts.cap = opts.cap || CanvasKit.StrokeCap.Butt;
254 opts.join = opts.join || CanvasKit.StrokeJoin.Miter;
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400255 if (this._stroke(opts)) {
256 return this;
257 }
258 return null;
259 };
260
Kevin Lubick217056c2018-09-20 17:39:31 -0400261 CanvasKit.SkPath.prototype.transform = function() {
262 // Takes 1 or 9 args
263 if (arguments.length === 1) {
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400264 // argument 1 should be a 6 or 9 element array.
Kevin Lubick217056c2018-09-20 17:39:31 -0400265 var a = arguments[0];
266 this._transform(a[0], a[1], a[2],
267 a[3], a[4], a[5],
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400268 a[6] || 0, a[7] || 0, a[8] || 1);
269 } else if (arguments.length === 6 || arguments.length === 9) {
270 // these arguments are the 6 or 9 members of the matrix
Kevin Lubick217056c2018-09-20 17:39:31 -0400271 var a = arguments;
272 this._transform(a[0], a[1], a[2],
273 a[3], a[4], a[5],
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400274 a[6] || 0, a[7] || 0, a[8] || 1);
Kevin Lubick217056c2018-09-20 17:39:31 -0400275 } else {
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400276 throw 'transform expected to take 1 or 9 arguments. Got ' + arguments.length;
Kevin Lubick217056c2018-09-20 17:39:31 -0400277 }
278 return this;
279 };
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400280 // isComplement is optional, defaults to false
281 CanvasKit.SkPath.prototype.trim = function(startT, stopT, isComplement) {
282 if (this._trim(startT, stopT, !!isComplement)) {
283 return this;
284 }
285 return null;
286 };
287
288 // bones should be a 3d array.
289 // Each bone is a 3x2 transformation matrix in column major order:
290 // | scaleX skewX transX |
291 // | skewY scaleY transY |
292 // and bones is an array of those matrices.
293 // Returns a copy of this (SkVertices) with the bones applied.
294 CanvasKit.SkVertices.prototype.applyBones = function(bones) {
295 var bPtr = copy3dArray(bones, CanvasKit.HEAPF32);
296 var vert = this._applyBones(bPtr, bones.length);
297 CanvasKit._free(bPtr);
298 return vert;
299 }
Kevin Lubick53965c92018-10-11 08:51:55 -0400300
Alexander Khovansky3e119332018-11-15 02:01:19 +0300301 CanvasKit.SkImage.prototype.encodeToData = function() {
302 if (arguments.length === 0) {
303 return this._encodeToData();
304 }
305
306 if (arguments.length === 2) {
307 var a = arguments;
308 return this._encodeToDataWithFormat(a[0], a[1]);
309 }
310
311 throw 'encodeToData expected to take 0 or 2 arguments. Got ' + arguments.length;
312 }
313
Kevin Lubick5b90b842018-10-17 07:57:18 -0400314 // Run through the JS files that are added at compile time.
315 if (CanvasKit._extraInitializations) {
316 CanvasKit._extraInitializations.forEach(function(init) {
317 init();
318 });
Kevin Lubick217056c2018-09-20 17:39:31 -0400319 }
Kevin Lubick3d99b1e2018-10-16 10:15:01 -0400320 } // end CanvasKit.onRuntimeInitialized, that is, anything changing prototypes or dynamic.
Kevin Lubick53965c92018-10-11 08:51:55 -0400321
Kevin Lubick217056c2018-09-20 17:39:31 -0400322 CanvasKit.LTRBRect = function(l, t, r, b) {
323 return {
324 fLeft: l,
325 fTop: t,
326 fRight: r,
327 fBottom: b,
328 };
329 }
330
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400331 var nullptr = 0; // emscripten doesn't like to take null as uintptr_t
332
333 // arr can be a normal JS array or a TypedArray
334 // dest is something like CanvasKit.HEAPF32
335 function copy1dArray(arr, dest) {
336 if (!arr || !arr.length) {
337 return nullptr;
338 }
339 var ptr = CanvasKit._malloc(arr.length * dest.BYTES_PER_ELEMENT);
340 // In c++ terms, the WASM heap is a uint8_t*, a long buffer/array of single
341 // byte elements. When we run _malloc, we always get an offset/pointer into
342 // that block of memory.
343 // CanvasKit exposes some different views to make it easier to work with
344 // different types. HEAPF32 for example, exposes it as a float*
345 // However, to make the ptr line up, we have to do some pointer arithmetic.
346 // Concretely, we need to convert ptr to go from an index into a 1-byte-wide
347 // buffer to an index into a 4-byte-wide buffer (in the case of HEAPF32)
348 // and thus we divide ptr by 4.
349 dest.set(arr, ptr / dest.BYTES_PER_ELEMENT);
350 return ptr;
351 }
352
353 // arr should be a non-jagged 2d JS array (TypeyArrays can't be nested
354 // inside themselves.)
355 // dest is something like CanvasKit.HEAPF32
356 function copy2dArray(arr, dest) {
357 if (!arr || !arr.length) {
358 return nullptr;
359 }
360 var ptr = CanvasKit._malloc(arr.length * arr[0].length * dest.BYTES_PER_ELEMENT);
361 var idx = 0;
362 var adjustedPtr = ptr / dest.BYTES_PER_ELEMENT;
363 for (var r = 0; r < arr.length; r++) {
364 for (var c = 0; c < arr[0].length; c++) {
365 dest[adjustedPtr + idx] = arr[r][c];
366 idx++;
367 }
368 }
369 return ptr;
370 }
371
372 // arr should be a non-jagged 3d JS array (TypeyArrays can't be nested
373 // inside themselves.)
374 // dest is something like CanvasKit.HEAPF32
375 function copy3dArray(arr, dest) {
376 if (!arr || !arr.length || !arr[0].length) {
377 return nullptr;
378 }
379 var ptr = CanvasKit._malloc(arr.length * arr[0].length * arr[0][0].length * dest.BYTES_PER_ELEMENT);
380 var idx = 0;
381 var adjustedPtr = ptr / dest.BYTES_PER_ELEMENT;
382 for (var x = 0; x < arr.length; x++) {
383 for (var y = 0; y < arr[0].length; y++) {
384 for (var z = 0; z < arr[0][0].length; z++) {
385 dest[adjustedPtr + idx] = arr[x][y][z];
386 idx++;
387 }
388 }
389 }
390 return ptr;
391 }
392
Kevin Lubick217056c2018-09-20 17:39:31 -0400393 CanvasKit.MakeSkDashPathEffect = function(intervals, phase) {
394 if (!phase) {
395 phase = 0;
396 }
397 if (!intervals.length || intervals.length % 2 === 1) {
398 throw 'Intervals array must have even length';
399 }
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400400 var ptr = copy1dArray(intervals, CanvasKit.HEAPF32);
401 var dpe = CanvasKit._MakeSkDashPathEffect(ptr, intervals.length, phase);
402 CanvasKit._free(ptr);
403 return dpe;
404 }
405
406 CanvasKit.MakeImageShader = function(imgData, xTileMode, yTileMode) {
407 var iptr = CanvasKit._malloc(imgData.byteLength);
408 CanvasKit.HEAPU8.set(new Uint8Array(imgData), iptr);
409 // No need to _free iptr, ImageShader takes it with SkData::MakeFromMalloc
410
411 return CanvasKit._MakeImageShader(iptr, imgData.byteLength, xTileMode, yTileMode);
412 }
413
414 CanvasKit.MakeLinearGradientShader = function(start, end, colors, pos, mode, localMatrix, flags) {
415 var colorPtr = copy1dArray(colors, CanvasKit.HEAP32);
416 var posPtr = copy1dArray(pos, CanvasKit.HEAPF32);
417 flags = flags || 0;
418
419 if (localMatrix) {
420 // Add perspective args if not provided.
421 if (localMatrix.length === 6) {
422 localMatrix.push(0, 0, 1);
423 }
424 var lgs = CanvasKit._MakeLinearGradientShader(start, end, colorPtr, posPtr,
425 colors.length, mode, flags, localMatrix);
426 } else {
427 var lgs = CanvasKit._MakeLinearGradientShader(start, end, colorPtr, posPtr,
428 colors.length, mode, flags);
Kevin Lubick217056c2018-09-20 17:39:31 -0400429 }
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400430
431 CanvasKit._free(colorPtr);
432 CanvasKit._free(posPtr);
433 return lgs;
434 }
435
436 CanvasKit.MakeRadialGradientShader = function(center, radius, colors, pos, mode, localMatrix, flags) {
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400437 var colorPtr = copy1dArray(colors, CanvasKit.HEAP32);
438 var posPtr = copy1dArray(pos, CanvasKit.HEAPF32);
439 flags = flags || 0;
440
441 if (localMatrix) {
442 // Add perspective args if not provided.
443 if (localMatrix.length === 6) {
444 localMatrix.push(0, 0, 1);
445 }
446 var rgs = CanvasKit._MakeRadialGradientShader(center, radius, colorPtr, posPtr,
447 colors.length, mode, flags, localMatrix);
448 } else {
449 var rgs = CanvasKit._MakeRadialGradientShader(center, radius, colorPtr, posPtr,
450 colors.length, mode, flags);
451 }
452
453 CanvasKit._free(colorPtr);
454 CanvasKit._free(posPtr);
455 return rgs;
456 }
457
Kevin Lubickeb2f6b02018-11-29 15:07:02 -0500458 CanvasKit.MakeTwoPointConicalGradientShader = function(start, startRadius, end, endRadius,
459 colors, pos, mode, localMatrix, flags) {
460 var colorPtr = copy1dArray(colors, CanvasKit.HEAP32);
461 var posPtr = copy1dArray(pos, CanvasKit.HEAPF32);
462 flags = flags || 0;
463
464 if (localMatrix) {
465 // Add perspective args if not provided.
466 if (localMatrix.length === 6) {
467 localMatrix.push(0, 0, 1);
468 }
469 var rgs = CanvasKit._MakeTwoPointConicalGradientShader(
470 start, startRadius, end, endRadius,
471 colorPtr, posPtr, colors.length, mode, flags, localMatrix);
472 } else {
473 var rgs = CanvasKit._MakeTwoPointConicalGradientShader(
474 start, startRadius, end, endRadius,
475 colorPtr, posPtr, colors.length, mode, flags);
476 }
477
478 CanvasKit._free(colorPtr);
479 CanvasKit._free(posPtr);
480 return rgs;
481 }
482
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400483 CanvasKit.MakeSkVertices = function(mode, positions, textureCoordinates, colors,
484 boneIndices, boneWeights, indices) {
485 var positionPtr = copy2dArray(positions, CanvasKit.HEAPF32);
486 var texPtr = copy2dArray(textureCoordinates, CanvasKit.HEAPF32);
487 // Since we write the colors to memory as signed integers (JSColor), we can
488 // read them out on the other side as unsigned ints (SkColor) just fine
489 // - it's effectively casting.
490 var colorPtr = copy1dArray(colors, CanvasKit.HEAP32);
491
492 var boneIdxPtr = copy2dArray(boneIndices, CanvasKit.HEAP32);
493 var boneWtPtr = copy2dArray(boneWeights, CanvasKit.HEAPF32);
494 var idxPtr = copy1dArray(indices, CanvasKit.HEAPU16);
495
496 var idxCount = (indices && indices.length) || 0;
497 // _MakeVertices will copy all the values in, so we are free to release
498 // the memory after.
499 var vertices = CanvasKit._MakeSkVertices(mode, positions.length, positionPtr,
500 texPtr, colorPtr, boneIdxPtr, boneWtPtr,
501 idxCount, idxPtr);
502 positionPtr && CanvasKit._free(positionPtr);
503 texPtr && CanvasKit._free(texPtr);
504 colorPtr && CanvasKit._free(colorPtr);
505 idxPtr && CanvasKit._free(idxPtr);
506 boneIdxPtr && CanvasKit._free(boneIdxPtr);
507 boneWtPtr && CanvasKit._free(boneWtPtr);
508 return vertices;
Kevin Lubick217056c2018-09-20 17:39:31 -0400509 }
510
Kevin Lubick134be1d2018-10-30 15:05:04 -0400511 CanvasKit.MakeNimaActor = function(nimaFile, nimaTexture) {
512 var nptr = CanvasKit._malloc(nimaFile.byteLength);
513 CanvasKit.HEAPU8.set(new Uint8Array(nimaFile), nptr);
514 var tptr = CanvasKit._malloc(nimaTexture.byteLength);
515 CanvasKit.HEAPU8.set(new Uint8Array(nimaTexture), tptr);
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400516 // No need to _free these ptrs, NimaActor takes them with SkData::MakeFromMalloc
Kevin Lubick134be1d2018-10-30 15:05:04 -0400517
518 return CanvasKit._MakeNimaActor(nptr, nimaFile.byteLength, tptr, nimaTexture.byteLength);
519 }
520
Kevin Lubick217056c2018-09-20 17:39:31 -0400521}(Module)); // When this file is loaded in, the high level object is "Module";
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500522
523// Intentionally added outside the scope to allow usage in canvas2d.js and other
524// pre-js files. These names are unlikely to cause emscripten collisions.
525function radiansToDegrees(rad) {
526 return (rad / Math.PI) * 180;
527}
528
529function degreesToRadians(deg) {
530 return (deg / 180) * Math.PI;
531}
532