blob: 801bad620e0c592d63b8bd81a73be70008b4adb0 [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) {},
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) {},
42 onRuntimeInitialized: function() {},
43 _MakeSkDashPathEffect: function(ptr, len, phase) {},
44
45 // Objects and properties on CanvasKit
46
Kevin Lubick53965c92018-10-11 08:51:55 -040047 /** Represents the heap of the WASM code
48 * @type {ArrayBuffer}
49 */
50 buffer: {},
51 /**
52 * @type {Float32Array}
53 */
Kevin Lubick217056c2018-09-20 17:39:31 -040054 HEAPF32: {}, // only needed for TypedArray mallocs
Kevin Lubick53965c92018-10-11 08:51:55 -040055 /**
56 * @type {Uint8Array}
57 */
58 HEAPU8: {},
59
Kevin Lubick217056c2018-09-20 17:39:31 -040060
61 SkPath: {
62 // public API should go below because closure still will
63 // remove things declared here and not on the prototype.
64
65 // private API
66 _addPath: function(path, scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2) {},
67 _arcTo: function(x1, y1, x2, y2, radius) {},
68 _close: function() {},
69 _conicTo: function(x1, y1, x2, y2, w) {},
70 _cubicTo: function(cp1x, cp1y, cp2x, cp2y, x, y) {},
71 _lineTo: function(x1, y1) {},
72 _moveTo: function(x1, y1) {},
73 _op: function(otherPath, op) {},
74 _quadTo: function(cpx, cpy, x, y) {},
75 _rect: function(x, y, w, h) {},
76 _simplify: function() {},
77 _transform: function(scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2) {},
Kevin Lubick53965c92018-10-11 08:51:55 -040078 },
79
80 SkSurface: {
81 // public API should go below because closure still will
82 // remove things declared here and not on the prototype.
Kevin Lubick3d99b1e2018-10-16 10:15:01 -040083 flush: function() {},
Kevin Lubick53965c92018-10-11 08:51:55 -040084
85 // private API
86 _readPixels: function(w, h, ptr) {},
Kevin Lubick3d99b1e2018-10-16 10:15:01 -040087 _flush: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040088 }
89}
90
91// Path public API
92CanvasKit.SkPath.prototype.addPath = function() {};
93CanvasKit.SkPath.prototype.arcTo = function(x1, y1, x2, y2, radius) {};
94CanvasKit.SkPath.prototype.close = function() {};
95CanvasKit.SkPath.prototype.conicTo = function(x1, y1, x2, y2, w) {};
96CanvasKit.SkPath.prototype.cubicTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {};
97CanvasKit.SkPath.prototype.lineTo = function(x, y) {};
98CanvasKit.SkPath.prototype.moveTo = function(x, y) {};
99CanvasKit.SkPath.prototype.op = function(otherPath, op) {};
100CanvasKit.SkPath.prototype.quadTo = function(x1, y1, x2, y2) {};
101CanvasKit.SkPath.prototype.rect = function(x, y, w, h) {};
102CanvasKit.SkPath.prototype.simplify = function() {};
103CanvasKit.SkPath.prototype.transform = function() {};
104
Kevin Lubick53965c92018-10-11 08:51:55 -0400105CanvasKit.SkSurface.prototype.flush = function() {};
106
Kevin Lubick217056c2018-09-20 17:39:31 -0400107// Not sure why this is needed - might be a bug in emsdk that this isn't properly declared.
108function loadWebAssemblyModule() {}