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