blob: c11b4caac927abaa51c4f30d9b96e5b6b2930a99 [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 Lubick134be1d2018-10-30 15:05:04 -040032 MakeNimaActor: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040033 MakeSkDashPathEffect: function() {},
34 MakeSurface: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040035 currentContext: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040036 getSkDataBytes: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040037 initFonts: function() {},
38 setCurrentContext: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040039
40 // private API (i.e. things declared in the bindings that we use
41 // in the pre-js file)
Kevin Lubick134be1d2018-10-30 15:05:04 -040042 _MakeNimaActor: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040043 _MakeSkDashPathEffect: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040044 _getRasterN32PremulSurface: function() {},
45 _getWebGLSurface: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040046
47 // Objects and properties on CanvasKit
48
Kevin Lubick134be1d2018-10-30 15:05:04 -040049 NimaActor: {
50 // public API (from C++ bindings)
51 duration: function() {},
52 getAnimationNames: function() {},
53 render: function() {},
54 seek: function() {},
55 setAnimationByIndex: function() {},
56 setAnimationByName: function() {},
57
58 // private API
59 },
60
Kevin Lubick006a6f32018-10-19 14:34:34 -040061 SkCanvas: {
62 // public API (from C++ bindings)
63 clear: function() {},
64 drawPaint: function() {},
65 drawPath: function() {},
66 drawText: function() {},
67 flush: function() {},
68 rotate: function() {},
69 save: function() {},
70 scale: function() {},
71 setMatrix: function() {},
72 skew: function() {},
73 translate: function() {},
74
75 // private API
76 delete: function() {},
77 },
78
79 SkImage: {
80 encodeToData: function() {},
81 },
82
83 SkPath: {
84 // public API (from C++ bindings)
85
86 // private API
87 _addPath: function() {},
88 _arcTo: function() {},
89 _close: function() {},
90 _conicTo: function() {},
91 _cubicTo: function() {},
92 _lineTo: function() {},
93 _moveTo: function() {},
94 _op: function() {},
95 _quadTo: function() {},
96 _rect: function() {},
97 _simplify: function() {},
98 _transform: function() {},
99 delete: function() {},
100 },
101
102 SkPaint: {
103 // public API (from C++ bindings)
104 /** @return {CanvasKit.SkPaint} */
105 copy: function() {},
106 measureText: function() {},
107 setAntiAlias: function() {},
108 setColor: function() {},
109 setPathEffect: function() {},
110 setShader: function() {},
111 setStrokeWidth: function() {},
112 setStyle: function() {},
113 setTextSize: function() {},
114
115 //private API
116 delete: function() {},
117 },
118
119 SkRect: {
120 fLeft: {},
121 fTop: {},
122 fRight: {},
123 fBottom: {},
124 },
125
126 SkSurface: {
127 // public API (from C++ bindings)
128 /** @return {CanvasKit.SkCanvas} */
129 getCanvas: function() {},
130 /** @return {CanvasKit.SkImage} */
131 makeImageSnapshot: function() {},
132
133 // private API
134 _flush: function() {},
135 _getRasterN32PremulSurface: function() {},
136 _readPixels: function() {},
137 delete: function() {},
138 },
139
140 // Constants and Enums
141 gpu: {},
142 skottie: {},
143 PaintStyle: {
144 FILL: {},
145 STROKE: {},
146 STROKE_AND_FILL: {},
147 },
148
149 FillType: {
150 WINDING: {},
151 EVENODD: {},
152 INVERSE_WINDING: {},
153 INVERSE_EVENODD: {},
154 },
155
156 // Things Enscriptem adds for us
157
Kevin Lubick53965c92018-10-11 08:51:55 -0400158 /** Represents the heap of the WASM code
159 * @type {ArrayBuffer}
160 */
161 buffer: {},
162 /**
163 * @type {Float32Array}
164 */
Kevin Lubick217056c2018-09-20 17:39:31 -0400165 HEAPF32: {}, // only needed for TypedArray mallocs
Kevin Lubick53965c92018-10-11 08:51:55 -0400166 /**
167 * @type {Uint8Array}
168 */
169 HEAPU8: {},
170
Kevin Lubick006a6f32018-10-19 14:34:34 -0400171 _malloc: function() {},
172 _free: function() {},
173 onRuntimeInitialized: function() {},
174};
Kevin Lubick217056c2018-09-20 17:39:31 -0400175
Kevin Lubick006a6f32018-10-19 14:34:34 -0400176// Public API things that are newly declared in the JS should go here.
177// It's not enough to declare them above, because closure can still erase them
178// unless they go on the prototype.
Kevin Lubick217056c2018-09-20 17:39:31 -0400179CanvasKit.SkPath.prototype.addPath = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400180CanvasKit.SkPath.prototype.arcTo = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400181CanvasKit.SkPath.prototype.close = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400182CanvasKit.SkPath.prototype.conicTo = function() {};
183CanvasKit.SkPath.prototype.cubicTo = function() {};
184CanvasKit.SkPath.prototype.lineTo = function() {};
185CanvasKit.SkPath.prototype.moveTo = function() {};
186CanvasKit.SkPath.prototype.op = function() {};
187CanvasKit.SkPath.prototype.quadTo = function() {};
188CanvasKit.SkPath.prototype.rect = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400189CanvasKit.SkPath.prototype.simplify = function() {};
190CanvasKit.SkPath.prototype.transform = function() {};
191
Kevin Lubick53965c92018-10-11 08:51:55 -0400192CanvasKit.SkSurface.prototype.flush = function() {};
Kevin Lubick5b90b842018-10-17 07:57:18 -0400193CanvasKit.SkSurface.prototype.dispose = function() {};
Kevin Lubick53965c92018-10-11 08:51:55 -0400194
Kevin Lubick217056c2018-09-20 17:39:31 -0400195// Not sure why this is needed - might be a bug in emsdk that this isn't properly declared.
196function loadWebAssemblyModule() {}