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 | 134be1d | 2018-10-30 15:05:04 -0400 | [diff] [blame^] | 32 | MakeNimaActor: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 33 | MakeSkDashPathEffect: function() {}, |
| 34 | MakeSurface: function() {}, |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 35 | currentContext: function() {}, |
Kevin Lubick | 134be1d | 2018-10-30 15:05:04 -0400 | [diff] [blame^] | 36 | getSkDataBytes: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 37 | initFonts: function() {}, |
| 38 | setCurrentContext: function() {}, |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 39 | |
| 40 | // private API (i.e. things declared in the bindings that we use |
| 41 | // in the pre-js file) |
Kevin Lubick | 134be1d | 2018-10-30 15:05:04 -0400 | [diff] [blame^] | 42 | _MakeNimaActor: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 43 | _MakeSkDashPathEffect: function() {}, |
Kevin Lubick | 134be1d | 2018-10-30 15:05:04 -0400 | [diff] [blame^] | 44 | _getRasterN32PremulSurface: function() {}, |
| 45 | _getWebGLSurface: function() {}, |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 46 | |
| 47 | // Objects and properties on CanvasKit |
| 48 | |
Kevin Lubick | 134be1d | 2018-10-30 15:05:04 -0400 | [diff] [blame^] | 49 | 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 Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 61 | 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 Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 158 | /** Represents the heap of the WASM code |
| 159 | * @type {ArrayBuffer} |
| 160 | */ |
| 161 | buffer: {}, |
| 162 | /** |
| 163 | * @type {Float32Array} |
| 164 | */ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 165 | HEAPF32: {}, // only needed for TypedArray mallocs |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 166 | /** |
| 167 | * @type {Uint8Array} |
| 168 | */ |
| 169 | HEAPU8: {}, |
| 170 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 171 | _malloc: function() {}, |
| 172 | _free: function() {}, |
| 173 | onRuntimeInitialized: function() {}, |
| 174 | }; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 175 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 176 | // 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 Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 179 | CanvasKit.SkPath.prototype.addPath = function() {}; |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 180 | CanvasKit.SkPath.prototype.arcTo = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 181 | CanvasKit.SkPath.prototype.close = function() {}; |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 182 | CanvasKit.SkPath.prototype.conicTo = function() {}; |
| 183 | CanvasKit.SkPath.prototype.cubicTo = function() {}; |
| 184 | CanvasKit.SkPath.prototype.lineTo = function() {}; |
| 185 | CanvasKit.SkPath.prototype.moveTo = function() {}; |
| 186 | CanvasKit.SkPath.prototype.op = function() {}; |
| 187 | CanvasKit.SkPath.prototype.quadTo = function() {}; |
| 188 | CanvasKit.SkPath.prototype.rect = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 189 | CanvasKit.SkPath.prototype.simplify = function() {}; |
| 190 | CanvasKit.SkPath.prototype.transform = function() {}; |
| 191 | |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 192 | CanvasKit.SkSurface.prototype.flush = function() {}; |
Kevin Lubick | 5b90b84 | 2018-10-17 07:57:18 -0400 | [diff] [blame] | 193 | CanvasKit.SkSurface.prototype.dispose = function() {}; |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 194 | |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 195 | // Not sure why this is needed - might be a bug in emsdk that this isn't properly declared. |
| 196 | function loadWebAssemblyModule() {} |