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: { |
| 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 Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 100 | _dash: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 101 | _lineTo: function() {}, |
| 102 | _moveTo: function() {}, |
| 103 | _op: function() {}, |
| 104 | _quadTo: function() {}, |
| 105 | _rect: function() {}, |
| 106 | _simplify: function() {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 107 | _stroke: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 108 | _transform: function() {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 109 | _trim: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 110 | 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 Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 151 | 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 Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 161 | // 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 Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 179 | /** Represents the heap of the WASM code |
| 180 | * @type {ArrayBuffer} |
| 181 | */ |
| 182 | buffer: {}, |
| 183 | /** |
| 184 | * @type {Float32Array} |
| 185 | */ |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 186 | HEAPF32: {}, |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 187 | /** |
| 188 | * @type {Uint8Array} |
| 189 | */ |
| 190 | HEAPU8: {}, |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 191 | /** |
| 192 | * @type {Uint16Array} |
| 193 | */ |
| 194 | HEAPU16: {}, |
| 195 | /** |
| 196 | * @type {Int32Array} |
| 197 | */ |
| 198 | HEAP32: {}, |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 199 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 200 | _malloc: function() {}, |
| 201 | _free: function() {}, |
| 202 | onRuntimeInitialized: function() {}, |
| 203 | }; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 204 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 205 | // 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 Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 208 | CanvasKit.SkPath.prototype.addPath = function() {}; |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 209 | CanvasKit.SkPath.prototype.arcTo = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 210 | CanvasKit.SkPath.prototype.close = function() {}; |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 211 | CanvasKit.SkPath.prototype.conicTo = function() {}; |
| 212 | CanvasKit.SkPath.prototype.cubicTo = function() {}; |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 213 | CanvasKit.SkPath.prototype.dash = function() {}; |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 214 | CanvasKit.SkPath.prototype.lineTo = function() {}; |
| 215 | CanvasKit.SkPath.prototype.moveTo = function() {}; |
| 216 | CanvasKit.SkPath.prototype.op = function() {}; |
| 217 | CanvasKit.SkPath.prototype.quadTo = function() {}; |
| 218 | CanvasKit.SkPath.prototype.rect = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 219 | CanvasKit.SkPath.prototype.simplify = function() {}; |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 220 | CanvasKit.SkPath.prototype.stroke = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 221 | CanvasKit.SkPath.prototype.transform = function() {}; |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 222 | CanvasKit.SkPath.prototype.trim = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 223 | |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 224 | CanvasKit.SkSurface.prototype.flush = function() {}; |
Kevin Lubick | 5b90b84 | 2018-10-17 07:57:18 -0400 | [diff] [blame] | 225 | CanvasKit.SkSurface.prototype.dispose = function() {}; |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 226 | |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 227 | CanvasKit.SkVertices.prototype.applyBones = function() {}; |
| 228 | |
| 229 | // Define StrokeOpts object |
| 230 | var StrokeOpts = {}; |
| 231 | StrokeOpts.prototype.width; |
| 232 | StrokeOpts.prototype.miter_limit; |
| 233 | StrokeOpts.prototype.cap; |
| 234 | StrokeOpts.prototype.join; |
| 235 | |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 236 | // Not sure why this is needed - might be a bug in emsdk that this isn't properly declared. |
| 237 | function loadWebAssemblyModule() {} |