blob: b1b8cc27c8ed04fc08584fe5431537c5f7bceff9 [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)
Kevin Lubick006a6f32018-10-19 14:34:34 -040027 Color: function() {},
28 /** @return {CanvasKit.SkRect} */
29 LTRBRect: function() {},
30 MakeCanvas: function() {},
31 MakeCanvasSurface: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040032 MakeImageShader: function() {},
33 MakeLinearGradientShader: function() {},
34 MakeRadialGradientShader: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040035 MakeNimaActor: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040036 MakeSkDashPathEffect: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040037 MakeSkVertices: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040038 MakeSurface: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040039 currentContext: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040040 getSkDataBytes: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040041 initFonts: function() {},
42 setCurrentContext: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040043
44 // private API (i.e. things declared in the bindings that we use
45 // in the pre-js file)
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040046 _MakeImageShader: function() {},
47 _MakeLinearGradientShader: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040048 _MakeNimaActor: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040049 _MakeRadialGradientShader: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040050 _MakeSkDashPathEffect: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040051 _MakeSkVertices: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040052 _getRasterN32PremulSurface: function() {},
53 _getWebGLSurface: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040054
55 // Objects and properties on CanvasKit
56
Kevin Lubick134be1d2018-10-30 15:05:04 -040057 NimaActor: {
58 // public API (from C++ bindings)
59 duration: function() {},
60 getAnimationNames: function() {},
61 render: function() {},
62 seek: function() {},
63 setAnimationByIndex: function() {},
64 setAnimationByName: function() {},
65
66 // private API
67 },
68
Kevin Lubick006a6f32018-10-19 14:34:34 -040069 SkCanvas: {
70 // public API (from C++ bindings)
71 clear: function() {},
72 drawPaint: function() {},
73 drawPath: function() {},
74 drawText: function() {},
75 flush: function() {},
76 rotate: function() {},
77 save: function() {},
78 scale: function() {},
79 setMatrix: function() {},
80 skew: function() {},
81 translate: function() {},
82
83 // private API
84 delete: function() {},
85 },
86
87 SkImage: {
Alexander Khovansky3e119332018-11-15 02:01:19 +030088 // private API
89 _encodeToData: function() {},
90 _encodeToDataWithFormat: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040091 },
92
93 SkPath: {
94 // public API (from C++ bindings)
95
96 // private API
97 _addPath: function() {},
Alexander Khovansky3e119332018-11-15 02:01:19 +030098 _arc: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040099 _arcTo: function() {},
100 _close: function() {},
101 _conicTo: function() {},
102 _cubicTo: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400103 _dash: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400104 _lineTo: function() {},
105 _moveTo: function() {},
106 _op: function() {},
107 _quadTo: function() {},
108 _rect: function() {},
109 _simplify: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400110 _stroke: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400111 _transform: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400112 _trim: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400113 delete: function() {},
114 },
115
116 SkPaint: {
117 // public API (from C++ bindings)
118 /** @return {CanvasKit.SkPaint} */
119 copy: function() {},
120 measureText: function() {},
121 setAntiAlias: function() {},
122 setColor: function() {},
123 setPathEffect: function() {},
124 setShader: function() {},
125 setStrokeWidth: function() {},
126 setStyle: function() {},
127 setTextSize: function() {},
128
129 //private API
130 delete: function() {},
131 },
132
133 SkRect: {
134 fLeft: {},
135 fTop: {},
136 fRight: {},
137 fBottom: {},
138 },
139
140 SkSurface: {
141 // public API (from C++ bindings)
142 /** @return {CanvasKit.SkCanvas} */
143 getCanvas: function() {},
144 /** @return {CanvasKit.SkImage} */
145 makeImageSnapshot: function() {},
146
147 // private API
148 _flush: function() {},
149 _getRasterN32PremulSurface: function() {},
150 _readPixels: function() {},
151 delete: function() {},
152 },
153
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400154 SkVertices: {
155 // public API (from C++ bindings)
156 /** @return {CanvasKit.SkVertices} */
157 applyBones: function() {},
158
159 // private API
160 /** @return {CanvasKit.SkVertices} */
161 _applyBones: function() {},
162 },
163
Kevin Lubick006a6f32018-10-19 14:34:34 -0400164 // Constants and Enums
165 gpu: {},
166 skottie: {},
167 PaintStyle: {
168 FILL: {},
169 STROKE: {},
170 STROKE_AND_FILL: {},
171 },
172
173 FillType: {
174 WINDING: {},
175 EVENODD: {},
176 INVERSE_WINDING: {},
177 INVERSE_EVENODD: {},
178 },
179
Alexander Khovansky3e119332018-11-15 02:01:19 +0300180 ImageFormat: {
181 PNG: {},
182 JPEG: {},
183 },
184
Kevin Lubick006a6f32018-10-19 14:34:34 -0400185 // Things Enscriptem adds for us
186
Kevin Lubick53965c92018-10-11 08:51:55 -0400187 /** Represents the heap of the WASM code
188 * @type {ArrayBuffer}
189 */
190 buffer: {},
191 /**
192 * @type {Float32Array}
193 */
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400194 HEAPF32: {},
Kevin Lubick53965c92018-10-11 08:51:55 -0400195 /**
196 * @type {Uint8Array}
197 */
198 HEAPU8: {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400199 /**
200 * @type {Uint16Array}
201 */
202 HEAPU16: {},
203 /**
204 * @type {Int32Array}
205 */
206 HEAP32: {},
Kevin Lubick53965c92018-10-11 08:51:55 -0400207
Kevin Lubick006a6f32018-10-19 14:34:34 -0400208 _malloc: function() {},
209 _free: function() {},
210 onRuntimeInitialized: function() {},
211};
Kevin Lubick217056c2018-09-20 17:39:31 -0400212
Kevin Lubick006a6f32018-10-19 14:34:34 -0400213// Public API things that are newly declared in the JS should go here.
214// It's not enough to declare them above, because closure can still erase them
215// unless they go on the prototype.
Kevin Lubick217056c2018-09-20 17:39:31 -0400216CanvasKit.SkPath.prototype.addPath = function() {};
Alexander Khovansky3e119332018-11-15 02:01:19 +0300217CanvasKit.SkPath.prototype.arc = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400218CanvasKit.SkPath.prototype.arcTo = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400219CanvasKit.SkPath.prototype.close = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400220CanvasKit.SkPath.prototype.conicTo = function() {};
221CanvasKit.SkPath.prototype.cubicTo = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400222CanvasKit.SkPath.prototype.dash = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400223CanvasKit.SkPath.prototype.lineTo = function() {};
224CanvasKit.SkPath.prototype.moveTo = function() {};
225CanvasKit.SkPath.prototype.op = function() {};
226CanvasKit.SkPath.prototype.quadTo = function() {};
227CanvasKit.SkPath.prototype.rect = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400228CanvasKit.SkPath.prototype.simplify = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400229CanvasKit.SkPath.prototype.stroke = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400230CanvasKit.SkPath.prototype.transform = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400231CanvasKit.SkPath.prototype.trim = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400232
Kevin Lubick53965c92018-10-11 08:51:55 -0400233CanvasKit.SkSurface.prototype.flush = function() {};
Kevin Lubick5b90b842018-10-17 07:57:18 -0400234CanvasKit.SkSurface.prototype.dispose = function() {};
Kevin Lubick53965c92018-10-11 08:51:55 -0400235
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400236CanvasKit.SkVertices.prototype.applyBones = function() {};
237
Alexander Khovansky3e119332018-11-15 02:01:19 +0300238CanvasKit.SkImage.prototype.encodeToData = function() {};
239
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400240// Define StrokeOpts object
241var StrokeOpts = {};
242StrokeOpts.prototype.width;
243StrokeOpts.prototype.miter_limit;
244StrokeOpts.prototype.cap;
245StrokeOpts.prototype.join;
246
Kevin Lubick217056c2018-09-20 17:39:31 -0400247// Not sure why this is needed - might be a bug in emsdk that this isn't properly declared.
248function loadWebAssemblyModule() {}