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 | |
| 55 | // Objects and properties on CanvasKit |
| 56 | |
Kevin Lubick | 134be1d | 2018-10-30 15:05:04 -0400 | [diff] [blame] | 57 | 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 Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 69 | 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: { |
Alexander Khovansky | 3e11933 | 2018-11-15 02:01:19 +0300 | [diff] [blame^] | 88 | // private API |
| 89 | _encodeToData: function() {}, |
| 90 | _encodeToDataWithFormat: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 91 | }, |
| 92 | |
| 93 | SkPath: { |
| 94 | // public API (from C++ bindings) |
| 95 | |
| 96 | // private API |
| 97 | _addPath: function() {}, |
Alexander Khovansky | 3e11933 | 2018-11-15 02:01:19 +0300 | [diff] [blame^] | 98 | _arc: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 99 | _arcTo: function() {}, |
| 100 | _close: function() {}, |
| 101 | _conicTo: function() {}, |
| 102 | _cubicTo: function() {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 103 | _dash: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 104 | _lineTo: function() {}, |
| 105 | _moveTo: function() {}, |
| 106 | _op: function() {}, |
| 107 | _quadTo: function() {}, |
| 108 | _rect: function() {}, |
| 109 | _simplify: function() {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 110 | _stroke: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 111 | _transform: function() {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 112 | _trim: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 113 | delete: function() {}, |
| 114 | }, |
| 115 | |
| 116 | SkPaint: { |
| 117 | // public API (from C++ bindings) |
| 118 | /** @return {CanvasKit.SkPaint} */ |
| 119 | copy: function() {}, |
| 120 | measureText: function() {}, |
| 121 | setAntiAlias: function() {}, |
| 122 | setColor: function() {}, |
| 123 | setPathEffect: function() {}, |
| 124 | setShader: function() {}, |
| 125 | setStrokeWidth: function() {}, |
| 126 | setStyle: function() {}, |
| 127 | setTextSize: function() {}, |
| 128 | |
| 129 | //private API |
| 130 | delete: function() {}, |
| 131 | }, |
| 132 | |
| 133 | SkRect: { |
| 134 | fLeft: {}, |
| 135 | fTop: {}, |
| 136 | fRight: {}, |
| 137 | fBottom: {}, |
| 138 | }, |
| 139 | |
| 140 | SkSurface: { |
| 141 | // public API (from C++ bindings) |
| 142 | /** @return {CanvasKit.SkCanvas} */ |
| 143 | getCanvas: function() {}, |
| 144 | /** @return {CanvasKit.SkImage} */ |
| 145 | makeImageSnapshot: function() {}, |
| 146 | |
| 147 | // private API |
| 148 | _flush: function() {}, |
| 149 | _getRasterN32PremulSurface: function() {}, |
| 150 | _readPixels: function() {}, |
| 151 | delete: function() {}, |
| 152 | }, |
| 153 | |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 154 | SkVertices: { |
| 155 | // public API (from C++ bindings) |
| 156 | /** @return {CanvasKit.SkVertices} */ |
| 157 | applyBones: function() {}, |
| 158 | |
| 159 | // private API |
| 160 | /** @return {CanvasKit.SkVertices} */ |
| 161 | _applyBones: function() {}, |
| 162 | }, |
| 163 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 164 | // Constants and Enums |
| 165 | gpu: {}, |
| 166 | skottie: {}, |
| 167 | PaintStyle: { |
| 168 | FILL: {}, |
| 169 | STROKE: {}, |
| 170 | STROKE_AND_FILL: {}, |
| 171 | }, |
| 172 | |
| 173 | FillType: { |
| 174 | WINDING: {}, |
| 175 | EVENODD: {}, |
| 176 | INVERSE_WINDING: {}, |
| 177 | INVERSE_EVENODD: {}, |
| 178 | }, |
| 179 | |
Alexander Khovansky | 3e11933 | 2018-11-15 02:01:19 +0300 | [diff] [blame^] | 180 | ImageFormat: { |
| 181 | PNG: {}, |
| 182 | JPEG: {}, |
| 183 | }, |
| 184 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 185 | // Things Enscriptem adds for us |
| 186 | |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 187 | /** Represents the heap of the WASM code |
| 188 | * @type {ArrayBuffer} |
| 189 | */ |
| 190 | buffer: {}, |
| 191 | /** |
| 192 | * @type {Float32Array} |
| 193 | */ |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 194 | HEAPF32: {}, |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 195 | /** |
| 196 | * @type {Uint8Array} |
| 197 | */ |
| 198 | HEAPU8: {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 199 | /** |
| 200 | * @type {Uint16Array} |
| 201 | */ |
| 202 | HEAPU16: {}, |
| 203 | /** |
| 204 | * @type {Int32Array} |
| 205 | */ |
| 206 | HEAP32: {}, |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 207 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 208 | _malloc: function() {}, |
| 209 | _free: function() {}, |
| 210 | onRuntimeInitialized: function() {}, |
| 211 | }; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 212 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 213 | // Public API things that are newly declared in the JS should go here. |
| 214 | // It's not enough to declare them above, because closure can still erase them |
| 215 | // unless they go on the prototype. |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 216 | CanvasKit.SkPath.prototype.addPath = function() {}; |
Alexander Khovansky | 3e11933 | 2018-11-15 02:01:19 +0300 | [diff] [blame^] | 217 | CanvasKit.SkPath.prototype.arc = function() {}; |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 218 | CanvasKit.SkPath.prototype.arcTo = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 219 | CanvasKit.SkPath.prototype.close = function() {}; |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 220 | CanvasKit.SkPath.prototype.conicTo = function() {}; |
| 221 | CanvasKit.SkPath.prototype.cubicTo = function() {}; |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 222 | CanvasKit.SkPath.prototype.dash = function() {}; |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 223 | CanvasKit.SkPath.prototype.lineTo = function() {}; |
| 224 | CanvasKit.SkPath.prototype.moveTo = function() {}; |
| 225 | CanvasKit.SkPath.prototype.op = function() {}; |
| 226 | CanvasKit.SkPath.prototype.quadTo = function() {}; |
| 227 | CanvasKit.SkPath.prototype.rect = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 228 | CanvasKit.SkPath.prototype.simplify = function() {}; |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 229 | CanvasKit.SkPath.prototype.stroke = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 230 | CanvasKit.SkPath.prototype.transform = function() {}; |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 231 | CanvasKit.SkPath.prototype.trim = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 232 | |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 233 | CanvasKit.SkSurface.prototype.flush = function() {}; |
Kevin Lubick | 5b90b84 | 2018-10-17 07:57:18 -0400 | [diff] [blame] | 234 | CanvasKit.SkSurface.prototype.dispose = function() {}; |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 235 | |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 236 | CanvasKit.SkVertices.prototype.applyBones = function() {}; |
| 237 | |
Alexander Khovansky | 3e11933 | 2018-11-15 02:01:19 +0300 | [diff] [blame^] | 238 | CanvasKit.SkImage.prototype.encodeToData = function() {}; |
| 239 | |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 240 | // Define StrokeOpts object |
| 241 | var StrokeOpts = {}; |
| 242 | StrokeOpts.prototype.width; |
| 243 | StrokeOpts.prototype.miter_limit; |
| 244 | StrokeOpts.prototype.cap; |
| 245 | StrokeOpts.prototype.join; |
| 246 | |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 247 | // Not sure why this is needed - might be a bug in emsdk that this isn't properly declared. |
| 248 | function loadWebAssemblyModule() {} |