blob: 7c5159f3bf74dd35f244e6cbf76b3cfa1031206b [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
Kevin Lubick1a05fce2018-11-20 12:51:16 -050055 // The testing object is meant to expose internal functions
56 // for more fine-grained testing, e.g. parseColor
57 _testing: {},
58
Kevin Lubick217056c2018-09-20 17:39:31 -040059 // Objects and properties on CanvasKit
60
Kevin Lubick134be1d2018-10-30 15:05:04 -040061 NimaActor: {
62 // public API (from C++ bindings)
63 duration: function() {},
64 getAnimationNames: function() {},
65 render: function() {},
66 seek: function() {},
67 setAnimationByIndex: function() {},
68 setAnimationByName: function() {},
69
70 // private API
71 },
72
Kevin Lubick006a6f32018-10-19 14:34:34 -040073 SkCanvas: {
74 // public API (from C++ bindings)
75 clear: function() {},
76 drawPaint: function() {},
77 drawPath: function() {},
78 drawText: function() {},
79 flush: function() {},
80 rotate: function() {},
81 save: function() {},
82 scale: function() {},
83 setMatrix: function() {},
84 skew: function() {},
85 translate: function() {},
86
87 // private API
88 delete: function() {},
89 },
90
91 SkImage: {
Alexander Khovansky3e119332018-11-15 02:01:19 +030092 // private API
93 _encodeToData: function() {},
94 _encodeToDataWithFormat: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040095 },
96
Kevin Lubick1a05fce2018-11-20 12:51:16 -050097 SkMatrix: {
98 rotated: function() {},
99 },
100
Kevin Lubick006a6f32018-10-19 14:34:34 -0400101 SkPath: {
102 // public API (from C++ bindings)
103
104 // private API
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500105 _addArc: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400106 _addPath: function() {},
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500107 _addRect: function() {},
Alexander Khovansky3e119332018-11-15 02:01:19 +0300108 _arc: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400109 _arcTo: function() {},
110 _close: function() {},
111 _conicTo: function() {},
112 _cubicTo: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400113 _dash: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400114 _lineTo: function() {},
115 _moveTo: function() {},
116 _op: function() {},
117 _quadTo: function() {},
118 _rect: function() {},
119 _simplify: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400120 _stroke: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400121 _transform: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400122 _trim: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400123 delete: function() {},
124 },
125
126 SkPaint: {
127 // public API (from C++ bindings)
128 /** @return {CanvasKit.SkPaint} */
129 copy: function() {},
130 measureText: function() {},
131 setAntiAlias: function() {},
132 setColor: function() {},
133 setPathEffect: function() {},
134 setShader: function() {},
135 setStrokeWidth: function() {},
136 setStyle: function() {},
137 setTextSize: function() {},
138
139 //private API
140 delete: function() {},
141 },
142
143 SkRect: {
144 fLeft: {},
145 fTop: {},
146 fRight: {},
147 fBottom: {},
148 },
149
150 SkSurface: {
151 // public API (from C++ bindings)
152 /** @return {CanvasKit.SkCanvas} */
153 getCanvas: function() {},
154 /** @return {CanvasKit.SkImage} */
155 makeImageSnapshot: function() {},
156
157 // private API
158 _flush: function() {},
159 _getRasterN32PremulSurface: function() {},
160 _readPixels: function() {},
161 delete: function() {},
162 },
163
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400164 SkVertices: {
165 // public API (from C++ bindings)
166 /** @return {CanvasKit.SkVertices} */
167 applyBones: function() {},
168
169 // private API
170 /** @return {CanvasKit.SkVertices} */
171 _applyBones: function() {},
172 },
173
Kevin Lubick006a6f32018-10-19 14:34:34 -0400174 // Constants and Enums
175 gpu: {},
176 skottie: {},
177 PaintStyle: {
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500178 Fill: {},
179 Stroke: {},
180 StrokeAndFill: {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400181 },
182
183 FillType: {
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500184 Winding: {},
185 EvenOdd: {},
186 InverseWinding: {},
187 InverseEvenOdd: {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400188 },
189
Alexander Khovansky3e119332018-11-15 02:01:19 +0300190 ImageFormat: {
191 PNG: {},
192 JPEG: {},
193 },
194
Kevin Lubick006a6f32018-10-19 14:34:34 -0400195 // Things Enscriptem adds for us
196
Kevin Lubick53965c92018-10-11 08:51:55 -0400197 /** Represents the heap of the WASM code
198 * @type {ArrayBuffer}
199 */
200 buffer: {},
201 /**
202 * @type {Float32Array}
203 */
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400204 HEAPF32: {},
Kevin Lubick53965c92018-10-11 08:51:55 -0400205 /**
206 * @type {Uint8Array}
207 */
208 HEAPU8: {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400209 /**
210 * @type {Uint16Array}
211 */
212 HEAPU16: {},
213 /**
214 * @type {Int32Array}
215 */
216 HEAP32: {},
Kevin Lubick53965c92018-10-11 08:51:55 -0400217
Kevin Lubick006a6f32018-10-19 14:34:34 -0400218 _malloc: function() {},
219 _free: function() {},
220 onRuntimeInitialized: function() {},
221};
Kevin Lubick217056c2018-09-20 17:39:31 -0400222
Kevin Lubick006a6f32018-10-19 14:34:34 -0400223// Public API things that are newly declared in the JS should go here.
224// It's not enough to declare them above, because closure can still erase them
225// unless they go on the prototype.
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500226CanvasKit.SkPath.prototype.addArc = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400227CanvasKit.SkPath.prototype.addPath = function() {};
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500228CanvasKit.SkPath.prototype.addRect = function() {};
Alexander Khovansky3e119332018-11-15 02:01:19 +0300229CanvasKit.SkPath.prototype.arc = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400230CanvasKit.SkPath.prototype.arcTo = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400231CanvasKit.SkPath.prototype.close = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400232CanvasKit.SkPath.prototype.conicTo = function() {};
233CanvasKit.SkPath.prototype.cubicTo = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400234CanvasKit.SkPath.prototype.dash = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400235CanvasKit.SkPath.prototype.lineTo = function() {};
236CanvasKit.SkPath.prototype.moveTo = function() {};
237CanvasKit.SkPath.prototype.op = function() {};
238CanvasKit.SkPath.prototype.quadTo = function() {};
239CanvasKit.SkPath.prototype.rect = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400240CanvasKit.SkPath.prototype.simplify = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400241CanvasKit.SkPath.prototype.stroke = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400242CanvasKit.SkPath.prototype.transform = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400243CanvasKit.SkPath.prototype.trim = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400244
Kevin Lubick53965c92018-10-11 08:51:55 -0400245CanvasKit.SkSurface.prototype.flush = function() {};
Kevin Lubick5b90b842018-10-17 07:57:18 -0400246CanvasKit.SkSurface.prototype.dispose = function() {};
Kevin Lubick53965c92018-10-11 08:51:55 -0400247
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400248CanvasKit.SkVertices.prototype.applyBones = function() {};
249
Alexander Khovansky3e119332018-11-15 02:01:19 +0300250CanvasKit.SkImage.prototype.encodeToData = function() {};
251
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400252// Define StrokeOpts object
253var StrokeOpts = {};
254StrokeOpts.prototype.width;
255StrokeOpts.prototype.miter_limit;
256StrokeOpts.prototype.cap;
257StrokeOpts.prototype.join;
258
Kevin Lubick217056c2018-09-20 17:39:31 -0400259// Not sure why this is needed - might be a bug in emsdk that this isn't properly declared.
260function loadWebAssemblyModule() {}