blob: c0f6c66444ce148cc51fa311ff2426e4a4cf629a [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() {},
29 getWebGLSurface: function(htmlID) {},
Kevin Lubick53965c92018-10-11 08:51:55 -040030 getRasterN32PremulSurface: function(htmlID) {},
Kevin Lubick217056c2018-09-20 17:39:31 -040031 MakeSkDashPathEffect: function(intervals, phase) {},
32 setCurrentContext: function() {},
33 LTRBRect: function(l, t, r, b) {},
34
35 // private API (i.e. things declared in the bindings that we use
36 // in the pre-js file)
37 _getWebGLSurface: function(htmlID, w, h) {},
Kevin Lubick53965c92018-10-11 08:51:55 -040038 _getRasterN32PremulSurface: function(w, h) {},
Kevin Lubick217056c2018-09-20 17:39:31 -040039 _malloc: function(size) {},
40 onRuntimeInitialized: function() {},
41 _MakeSkDashPathEffect: function(ptr, len, phase) {},
42
43 // Objects and properties on CanvasKit
44
Kevin Lubick53965c92018-10-11 08:51:55 -040045 /** Represents the heap of the WASM code
46 * @type {ArrayBuffer}
47 */
48 buffer: {},
49 /**
50 * @type {Float32Array}
51 */
Kevin Lubick217056c2018-09-20 17:39:31 -040052 HEAPF32: {}, // only needed for TypedArray mallocs
Kevin Lubick53965c92018-10-11 08:51:55 -040053 /**
54 * @type {Uint8Array}
55 */
56 HEAPU8: {},
57
Kevin Lubick217056c2018-09-20 17:39:31 -040058
59 SkPath: {
60 // public API should go below because closure still will
61 // remove things declared here and not on the prototype.
62
63 // private API
64 _addPath: function(path, scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2) {},
65 _arcTo: function(x1, y1, x2, y2, radius) {},
66 _close: function() {},
67 _conicTo: function(x1, y1, x2, y2, w) {},
68 _cubicTo: function(cp1x, cp1y, cp2x, cp2y, x, y) {},
69 _lineTo: function(x1, y1) {},
70 _moveTo: function(x1, y1) {},
71 _op: function(otherPath, op) {},
72 _quadTo: function(cpx, cpy, x, y) {},
73 _rect: function(x, y, w, h) {},
74 _simplify: function() {},
75 _transform: function(scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2) {},
Kevin Lubick53965c92018-10-11 08:51:55 -040076 },
77
78 SkSurface: {
79 // public API should go below because closure still will
80 // remove things declared here and not on the prototype.
81
82 // private API
83 _readPixels: function(w, h, ptr) {},
Kevin Lubick217056c2018-09-20 17:39:31 -040084 }
85}
86
87// Path public API
88CanvasKit.SkPath.prototype.addPath = function() {};
89CanvasKit.SkPath.prototype.arcTo = function(x1, y1, x2, y2, radius) {};
90CanvasKit.SkPath.prototype.close = function() {};
91CanvasKit.SkPath.prototype.conicTo = function(x1, y1, x2, y2, w) {};
92CanvasKit.SkPath.prototype.cubicTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {};
93CanvasKit.SkPath.prototype.lineTo = function(x, y) {};
94CanvasKit.SkPath.prototype.moveTo = function(x, y) {};
95CanvasKit.SkPath.prototype.op = function(otherPath, op) {};
96CanvasKit.SkPath.prototype.quadTo = function(x1, y1, x2, y2) {};
97CanvasKit.SkPath.prototype.rect = function(x, y, w, h) {};
98CanvasKit.SkPath.prototype.simplify = function() {};
99CanvasKit.SkPath.prototype.transform = function() {};
100
Kevin Lubick53965c92018-10-11 08:51:55 -0400101CanvasKit.SkSurface.prototype.flush = function() {};
102
Kevin Lubick217056c2018-09-20 17:39:31 -0400103// Not sure why this is needed - might be a bug in emsdk that this isn't properly declared.
104function loadWebAssemblyModule() {}