blob: 4ced26d6562e87406ff1717ba575a254462c1d90 [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: {
88 encodeToData: function() {},
89 },
90
91 SkPath: {
92 // public API (from C++ bindings)
93
94 // private API
95 _addPath: function() {},
96 _arcTo: function() {},
97 _close: function() {},
98 _conicTo: function() {},
99 _cubicTo: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400100 _dash: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400101 _lineTo: function() {},
102 _moveTo: function() {},
103 _op: function() {},
104 _quadTo: function() {},
105 _rect: function() {},
106 _simplify: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400107 _stroke: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400108 _transform: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400109 _trim: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400110 delete: function() {},
111 },
112
113 SkPaint: {
114 // public API (from C++ bindings)
115 /** @return {CanvasKit.SkPaint} */
116 copy: function() {},
117 measureText: function() {},
118 setAntiAlias: function() {},
119 setColor: function() {},
120 setPathEffect: function() {},
121 setShader: function() {},
122 setStrokeWidth: function() {},
123 setStyle: function() {},
124 setTextSize: function() {},
125
126 //private API
127 delete: function() {},
128 },
129
130 SkRect: {
131 fLeft: {},
132 fTop: {},
133 fRight: {},
134 fBottom: {},
135 },
136
137 SkSurface: {
138 // public API (from C++ bindings)
139 /** @return {CanvasKit.SkCanvas} */
140 getCanvas: function() {},
141 /** @return {CanvasKit.SkImage} */
142 makeImageSnapshot: function() {},
143
144 // private API
145 _flush: function() {},
146 _getRasterN32PremulSurface: function() {},
147 _readPixels: function() {},
148 delete: function() {},
149 },
150
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400151 SkVertices: {
152 // public API (from C++ bindings)
153 /** @return {CanvasKit.SkVertices} */
154 applyBones: function() {},
155
156 // private API
157 /** @return {CanvasKit.SkVertices} */
158 _applyBones: function() {},
159 },
160
Kevin Lubick006a6f32018-10-19 14:34:34 -0400161 // Constants and Enums
162 gpu: {},
163 skottie: {},
164 PaintStyle: {
165 FILL: {},
166 STROKE: {},
167 STROKE_AND_FILL: {},
168 },
169
170 FillType: {
171 WINDING: {},
172 EVENODD: {},
173 INVERSE_WINDING: {},
174 INVERSE_EVENODD: {},
175 },
176
177 // Things Enscriptem adds for us
178
Kevin Lubick53965c92018-10-11 08:51:55 -0400179 /** Represents the heap of the WASM code
180 * @type {ArrayBuffer}
181 */
182 buffer: {},
183 /**
184 * @type {Float32Array}
185 */
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400186 HEAPF32: {},
Kevin Lubick53965c92018-10-11 08:51:55 -0400187 /**
188 * @type {Uint8Array}
189 */
190 HEAPU8: {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400191 /**
192 * @type {Uint16Array}
193 */
194 HEAPU16: {},
195 /**
196 * @type {Int32Array}
197 */
198 HEAP32: {},
Kevin Lubick53965c92018-10-11 08:51:55 -0400199
Kevin Lubick006a6f32018-10-19 14:34:34 -0400200 _malloc: function() {},
201 _free: function() {},
202 onRuntimeInitialized: function() {},
203};
Kevin Lubick217056c2018-09-20 17:39:31 -0400204
Kevin Lubick006a6f32018-10-19 14:34:34 -0400205// Public API things that are newly declared in the JS should go here.
206// It's not enough to declare them above, because closure can still erase them
207// unless they go on the prototype.
Kevin Lubick217056c2018-09-20 17:39:31 -0400208CanvasKit.SkPath.prototype.addPath = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400209CanvasKit.SkPath.prototype.arcTo = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400210CanvasKit.SkPath.prototype.close = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400211CanvasKit.SkPath.prototype.conicTo = function() {};
212CanvasKit.SkPath.prototype.cubicTo = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400213CanvasKit.SkPath.prototype.dash = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400214CanvasKit.SkPath.prototype.lineTo = function() {};
215CanvasKit.SkPath.prototype.moveTo = function() {};
216CanvasKit.SkPath.prototype.op = function() {};
217CanvasKit.SkPath.prototype.quadTo = function() {};
218CanvasKit.SkPath.prototype.rect = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400219CanvasKit.SkPath.prototype.simplify = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400220CanvasKit.SkPath.prototype.stroke = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400221CanvasKit.SkPath.prototype.transform = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400222CanvasKit.SkPath.prototype.trim = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400223
Kevin Lubick53965c92018-10-11 08:51:55 -0400224CanvasKit.SkSurface.prototype.flush = function() {};
Kevin Lubick5b90b842018-10-17 07:57:18 -0400225CanvasKit.SkSurface.prototype.dispose = function() {};
Kevin Lubick53965c92018-10-11 08:51:55 -0400226
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400227CanvasKit.SkVertices.prototype.applyBones = function() {};
228
229// Define StrokeOpts object
230var StrokeOpts = {};
231StrokeOpts.prototype.width;
232StrokeOpts.prototype.miter_limit;
233StrokeOpts.prototype.cap;
234StrokeOpts.prototype.join;
235
Kevin Lubick217056c2018-09-20 17:39:31 -0400236// Not sure why this is needed - might be a bug in emsdk that this isn't properly declared.
237function loadWebAssemblyModule() {}