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() {}, |
| 32 | MakeSkDashPathEffect: function() {}, |
| 33 | MakeSurface: function() {}, |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 34 | currentContext: function() {}, |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 35 | initFonts: function() {}, |
| 36 | setCurrentContext: function() {}, |
| 37 | getSkDataBytes: function() {}, |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 38 | |
| 39 | // private API (i.e. things declared in the bindings that we use |
| 40 | // in the pre-js file) |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 41 | _getWebGLSurface: function() {}, |
| 42 | _getRasterN32PremulSurface: function() {}, |
| 43 | _MakeSkDashPathEffect: function() {}, |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 44 | |
| 45 | // Objects and properties on CanvasKit |
| 46 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 47 | 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 Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 144 | /** Represents the heap of the WASM code |
| 145 | * @type {ArrayBuffer} |
| 146 | */ |
| 147 | buffer: {}, |
| 148 | /** |
| 149 | * @type {Float32Array} |
| 150 | */ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 151 | HEAPF32: {}, // only needed for TypedArray mallocs |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 152 | /** |
| 153 | * @type {Uint8Array} |
| 154 | */ |
| 155 | HEAPU8: {}, |
| 156 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 157 | _malloc: function() {}, |
| 158 | _free: function() {}, |
| 159 | onRuntimeInitialized: function() {}, |
| 160 | }; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 161 | |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 162 | // 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 Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 165 | CanvasKit.SkPath.prototype.addPath = function() {}; |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 166 | CanvasKit.SkPath.prototype.arcTo = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 167 | CanvasKit.SkPath.prototype.close = function() {}; |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 168 | CanvasKit.SkPath.prototype.conicTo = function() {}; |
| 169 | CanvasKit.SkPath.prototype.cubicTo = function() {}; |
| 170 | CanvasKit.SkPath.prototype.lineTo = function() {}; |
| 171 | CanvasKit.SkPath.prototype.moveTo = function() {}; |
| 172 | CanvasKit.SkPath.prototype.op = function() {}; |
| 173 | CanvasKit.SkPath.prototype.quadTo = function() {}; |
| 174 | CanvasKit.SkPath.prototype.rect = function() {}; |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 175 | CanvasKit.SkPath.prototype.simplify = function() {}; |
| 176 | CanvasKit.SkPath.prototype.transform = function() {}; |
| 177 | |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 178 | CanvasKit.SkSurface.prototype.flush = function() {}; |
Kevin Lubick | 5b90b84 | 2018-10-17 07:57:18 -0400 | [diff] [blame] | 179 | CanvasKit.SkSurface.prototype.dispose = function() {}; |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 180 | |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 181 | // Not sure why this is needed - might be a bug in emsdk that this isn't properly declared. |
| 182 | function loadWebAssemblyModule() {} |