blob: 808d478366b0889d4686bc18aae08d3dde638b15 [file] [log] [blame]
Kevin Lubick217056c2018-09-20 17:39:31 -04001/*
2 * This externs file prevents the Closure JS compiler from minifying away
3 * names of objects created by Emscripten.
4 * Basically, by defining empty objects and functions here, Closure will
5 * know not to rename them. This is needed because of our pre-js files,
6 * that is, the JS we hand-write to bundle into the output. That JS will be
7 * hit by the closure compiler and thus needs to know about what functions
8 * have special names and should not be minified.
9 *
10 * Emscripten does not support automatically generating an externs file, so we
11 * do it by hand. The general process is to write some JS code, and then put any
12 * calls to CanvasKit or related things in here. Running ./compile.sh and then
13 * looking at the minified results or running the Release trybot should
14 * verify nothing was missed. Optionally, looking directly at the minified
15 * pathkit.js can be useful when developing locally.
16 *
17 * Docs:
18 * https://github.com/cljsjs/packages/wiki/Creating-Externs
19 * https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System
20 *
21 * Example externs:
22 * https://github.com/google/closure-compiler/tree/master/externs
23 */
24
25var CanvasKit = {
26 // public API (i.e. things we declare in the pre-js file)
27 Color: function(r, g, b, a) {},
28 currentContext: function() {},
Kevin Lubick5b90b842018-10-17 07:57:18 -040029 MakeCanvasSurface: function(htmlID) {},
30 MakeSurface: function(w, h) {},
Kevin Lubick217056c2018-09-20 17:39:31 -040031 MakeSkDashPathEffect: function(intervals, phase) {},
Kevin Lubick5b90b842018-10-17 07:57:18 -040032 setCurrentContext: function(ctx) {},
Kevin Lubick217056c2018-09-20 17:39:31 -040033 LTRBRect: function(l, t, r, b) {},
Kevin Lubick3d99b1e2018-10-16 10:15:01 -040034 gpu: {},
35 skottie: {},
Kevin Lubick217056c2018-09-20 17:39:31 -040036
37 // private API (i.e. things declared in the bindings that we use
38 // in the pre-js file)
39 _getWebGLSurface: function(htmlID, w, h) {},
Kevin Lubick53965c92018-10-11 08:51:55 -040040 _getRasterN32PremulSurface: function(w, h) {},
Kevin Lubick217056c2018-09-20 17:39:31 -040041 _malloc: function(size) {},
Kevin Lubick5b90b842018-10-17 07:57:18 -040042 _free: function(ptr) {},
Kevin Lubick217056c2018-09-20 17:39:31 -040043 onRuntimeInitialized: function() {},
44 _MakeSkDashPathEffect: function(ptr, len, phase) {},
45
46 // Objects and properties on CanvasKit
47
Kevin Lubick53965c92018-10-11 08:51:55 -040048 /** Represents the heap of the WASM code
49 * @type {ArrayBuffer}
50 */
51 buffer: {},
52 /**
53 * @type {Float32Array}
54 */
Kevin Lubick217056c2018-09-20 17:39:31 -040055 HEAPF32: {}, // only needed for TypedArray mallocs
Kevin Lubick53965c92018-10-11 08:51:55 -040056 /**
57 * @type {Uint8Array}
58 */
59 HEAPU8: {},
60
Kevin Lubick217056c2018-09-20 17:39:31 -040061
62 SkPath: {
63 // public API should go below because closure still will
64 // remove things declared here and not on the prototype.
65
66 // private API
67 _addPath: function(path, scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2) {},
68 _arcTo: function(x1, y1, x2, y2, radius) {},
69 _close: function() {},
70 _conicTo: function(x1, y1, x2, y2, w) {},
71 _cubicTo: function(cp1x, cp1y, cp2x, cp2y, x, y) {},
72 _lineTo: function(x1, y1) {},
73 _moveTo: function(x1, y1) {},
74 _op: function(otherPath, op) {},
75 _quadTo: function(cpx, cpy, x, y) {},
76 _rect: function(x, y, w, h) {},
77 _simplify: function() {},
78 _transform: function(scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2) {},
Kevin Lubick5b90b842018-10-17 07:57:18 -040079 delete: function() {},
Kevin Lubick53965c92018-10-11 08:51:55 -040080 },
81
82 SkSurface: {
83 // public API should go below because closure still will
84 // remove things declared here and not on the prototype.
Kevin Lubick3d99b1e2018-10-16 10:15:01 -040085 flush: function() {},
Kevin Lubick53965c92018-10-11 08:51:55 -040086 // private API
87 _readPixels: function(w, h, ptr) {},
Kevin Lubick3d99b1e2018-10-16 10:15:01 -040088 _flush: function() {},
Kevin Lubick5b90b842018-10-17 07:57:18 -040089 delete: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040090 }
91}
92
93// Path public API
94CanvasKit.SkPath.prototype.addPath = function() {};
95CanvasKit.SkPath.prototype.arcTo = function(x1, y1, x2, y2, radius) {};
96CanvasKit.SkPath.prototype.close = function() {};
97CanvasKit.SkPath.prototype.conicTo = function(x1, y1, x2, y2, w) {};
98CanvasKit.SkPath.prototype.cubicTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {};
99CanvasKit.SkPath.prototype.lineTo = function(x, y) {};
100CanvasKit.SkPath.prototype.moveTo = function(x, y) {};
101CanvasKit.SkPath.prototype.op = function(otherPath, op) {};
102CanvasKit.SkPath.prototype.quadTo = function(x1, y1, x2, y2) {};
103CanvasKit.SkPath.prototype.rect = function(x, y, w, h) {};
104CanvasKit.SkPath.prototype.simplify = function() {};
105CanvasKit.SkPath.prototype.transform = function() {};
106
Kevin Lubick53965c92018-10-11 08:51:55 -0400107CanvasKit.SkSurface.prototype.flush = function() {};
Kevin Lubick5b90b842018-10-17 07:57:18 -0400108CanvasKit.SkSurface.prototype.dispose = function() {};
Kevin Lubick53965c92018-10-11 08:51:55 -0400109
Kevin Lubick217056c2018-09-20 17:39:31 -0400110// Not sure why this is needed - might be a bug in emsdk that this isn't properly declared.
111function loadWebAssemblyModule() {}