Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | var CanvasKit = { |
| 26 | // public API (i.e. things we declare in the pre-js file) |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 27 | Color: function() {}, |
| 28 | /** @return {CanvasKit.SkRect} */ |
| 29 | LTRBRect: function() {}, |
| 30 | MakeCanvas: function() {}, |
| 31 | MakeCanvasSurface: function() {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 32 | MakeImageShader: function() {}, |
| 33 | MakeLinearGradientShader: function() {}, |
| 34 | MakeRadialGradientShader: function() {}, |
Kevin Lubick | 134be1d | 2018-10-30 15:05:04 -0400 | [diff] [blame] | 35 | MakeNimaActor: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 36 | MakeSkDashPathEffect: function() {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 37 | MakeSkVertices: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 38 | MakeSurface: function() {}, |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 39 | currentContext: function() {}, |
Kevin Lubick | 134be1d | 2018-10-30 15:05:04 -0400 | [diff] [blame] | 40 | getSkDataBytes: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 41 | initFonts: function() {}, |
| 42 | setCurrentContext: function() {}, |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 43 | |
| 44 | // private API (i.e. things declared in the bindings that we use |
| 45 | // in the pre-js file) |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 46 | _MakeImageShader: function() {}, |
| 47 | _MakeLinearGradientShader: function() {}, |
Kevin Lubick | 134be1d | 2018-10-30 15:05:04 -0400 | [diff] [blame] | 48 | _MakeNimaActor: function() {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 49 | _MakeRadialGradientShader: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 50 | _MakeSkDashPathEffect: function() {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 51 | _MakeSkVertices: function() {}, |
Kevin Lubick | 134be1d | 2018-10-30 15:05:04 -0400 | [diff] [blame] | 52 | _getRasterN32PremulSurface: function() {}, |
| 53 | _getWebGLSurface: function() {}, |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 54 | |
Kevin Lubick | 1a05fce | 2018-11-20 12:51:16 -0500 | [diff] [blame^] | 55 | // The testing object is meant to expose internal functions |
| 56 | // for more fine-grained testing, e.g. parseColor |
| 57 | _testing: {}, |
| 58 | |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 59 | // Objects and properties on CanvasKit |
| 60 | |
Kevin Lubick | 134be1d | 2018-10-30 15:05:04 -0400 | [diff] [blame] | 61 | 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 Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 73 | 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 Khovansky | 3e11933 | 2018-11-15 02:01:19 +0300 | [diff] [blame] | 92 | // private API |
| 93 | _encodeToData: function() {}, |
| 94 | _encodeToDataWithFormat: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 95 | }, |
| 96 | |
Kevin Lubick | 1a05fce | 2018-11-20 12:51:16 -0500 | [diff] [blame^] | 97 | SkMatrix: { |
| 98 | rotated: function() {}, |
| 99 | }, |
| 100 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 101 | SkPath: { |
| 102 | // public API (from C++ bindings) |
| 103 | |
| 104 | // private API |
Kevin Lubick | 1a05fce | 2018-11-20 12:51:16 -0500 | [diff] [blame^] | 105 | _addArc: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 106 | _addPath: function() {}, |
Kevin Lubick | 1a05fce | 2018-11-20 12:51:16 -0500 | [diff] [blame^] | 107 | _addRect: function() {}, |
Alexander Khovansky | 3e11933 | 2018-11-15 02:01:19 +0300 | [diff] [blame] | 108 | _arc: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 109 | _arcTo: function() {}, |
| 110 | _close: function() {}, |
| 111 | _conicTo: function() {}, |
| 112 | _cubicTo: function() {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 113 | _dash: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 114 | _lineTo: function() {}, |
| 115 | _moveTo: function() {}, |
| 116 | _op: function() {}, |
| 117 | _quadTo: function() {}, |
| 118 | _rect: function() {}, |
| 119 | _simplify: function() {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 120 | _stroke: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 121 | _transform: function() {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 122 | _trim: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 123 | 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 Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 164 | 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 Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 174 | // Constants and Enums |
| 175 | gpu: {}, |
| 176 | skottie: {}, |
| 177 | PaintStyle: { |
Kevin Lubick | 1a05fce | 2018-11-20 12:51:16 -0500 | [diff] [blame^] | 178 | Fill: {}, |
| 179 | Stroke: {}, |
| 180 | StrokeAndFill: {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 181 | }, |
| 182 | |
| 183 | FillType: { |
Kevin Lubick | 1a05fce | 2018-11-20 12:51:16 -0500 | [diff] [blame^] | 184 | Winding: {}, |
| 185 | EvenOdd: {}, |
| 186 | InverseWinding: {}, |
| 187 | InverseEvenOdd: {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 188 | }, |
| 189 | |
Alexander Khovansky | 3e11933 | 2018-11-15 02:01:19 +0300 | [diff] [blame] | 190 | ImageFormat: { |
| 191 | PNG: {}, |
| 192 | JPEG: {}, |
| 193 | }, |
| 194 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 195 | // Things Enscriptem adds for us |
| 196 | |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 197 | /** Represents the heap of the WASM code |
| 198 | * @type {ArrayBuffer} |
| 199 | */ |
| 200 | buffer: {}, |
| 201 | /** |
| 202 | * @type {Float32Array} |
| 203 | */ |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 204 | HEAPF32: {}, |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 205 | /** |
| 206 | * @type {Uint8Array} |
| 207 | */ |
| 208 | HEAPU8: {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 209 | /** |
| 210 | * @type {Uint16Array} |
| 211 | */ |
| 212 | HEAPU16: {}, |
| 213 | /** |
| 214 | * @type {Int32Array} |
| 215 | */ |
| 216 | HEAP32: {}, |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 217 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 218 | _malloc: function() {}, |
| 219 | _free: function() {}, |
| 220 | onRuntimeInitialized: function() {}, |
| 221 | }; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 222 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 223 | // 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 Lubick | 1a05fce | 2018-11-20 12:51:16 -0500 | [diff] [blame^] | 226 | CanvasKit.SkPath.prototype.addArc = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 227 | CanvasKit.SkPath.prototype.addPath = function() {}; |
Kevin Lubick | 1a05fce | 2018-11-20 12:51:16 -0500 | [diff] [blame^] | 228 | CanvasKit.SkPath.prototype.addRect = function() {}; |
Alexander Khovansky | 3e11933 | 2018-11-15 02:01:19 +0300 | [diff] [blame] | 229 | CanvasKit.SkPath.prototype.arc = function() {}; |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 230 | CanvasKit.SkPath.prototype.arcTo = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 231 | CanvasKit.SkPath.prototype.close = function() {}; |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 232 | CanvasKit.SkPath.prototype.conicTo = function() {}; |
| 233 | CanvasKit.SkPath.prototype.cubicTo = function() {}; |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 234 | CanvasKit.SkPath.prototype.dash = function() {}; |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 235 | CanvasKit.SkPath.prototype.lineTo = function() {}; |
| 236 | CanvasKit.SkPath.prototype.moveTo = function() {}; |
| 237 | CanvasKit.SkPath.prototype.op = function() {}; |
| 238 | CanvasKit.SkPath.prototype.quadTo = function() {}; |
| 239 | CanvasKit.SkPath.prototype.rect = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 240 | CanvasKit.SkPath.prototype.simplify = function() {}; |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 241 | CanvasKit.SkPath.prototype.stroke = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 242 | CanvasKit.SkPath.prototype.transform = function() {}; |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 243 | CanvasKit.SkPath.prototype.trim = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 244 | |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 245 | CanvasKit.SkSurface.prototype.flush = function() {}; |
Kevin Lubick | 5b90b84 | 2018-10-17 07:57:18 -0400 | [diff] [blame] | 246 | CanvasKit.SkSurface.prototype.dispose = function() {}; |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 247 | |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 248 | CanvasKit.SkVertices.prototype.applyBones = function() {}; |
| 249 | |
Alexander Khovansky | 3e11933 | 2018-11-15 02:01:19 +0300 | [diff] [blame] | 250 | CanvasKit.SkImage.prototype.encodeToData = function() {}; |
| 251 | |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 252 | // Define StrokeOpts object |
| 253 | var StrokeOpts = {}; |
| 254 | StrokeOpts.prototype.width; |
| 255 | StrokeOpts.prototype.miter_limit; |
| 256 | StrokeOpts.prototype.cap; |
| 257 | StrokeOpts.prototype.join; |
| 258 | |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 259 | // Not sure why this is needed - might be a bug in emsdk that this isn't properly declared. |
| 260 | function loadWebAssemblyModule() {} |