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) |
| 27 | Color: function(r, g, b, a) {}, |
| 28 | currentContext: function() {}, |
| 29 | getWebGLSurface: function(htmlID) {}, |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame^] | 30 | getRasterN32PremulSurface: function(htmlID) {}, |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 31 | MakeSkDashPathEffect: function(intervals, phase) {}, |
| 32 | setCurrentContext: function() {}, |
| 33 | LTRBRect: function(l, t, r, b) {}, |
| 34 | |
| 35 | // private API (i.e. things declared in the bindings that we use |
| 36 | // in the pre-js file) |
| 37 | _getWebGLSurface: function(htmlID, w, h) {}, |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame^] | 38 | _getRasterN32PremulSurface: function(w, h) {}, |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 39 | _malloc: function(size) {}, |
| 40 | onRuntimeInitialized: function() {}, |
| 41 | _MakeSkDashPathEffect: function(ptr, len, phase) {}, |
| 42 | |
| 43 | // Objects and properties on CanvasKit |
| 44 | |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame^] | 45 | /** Represents the heap of the WASM code |
| 46 | * @type {ArrayBuffer} |
| 47 | */ |
| 48 | buffer: {}, |
| 49 | /** |
| 50 | * @type {Float32Array} |
| 51 | */ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 52 | HEAPF32: {}, // only needed for TypedArray mallocs |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame^] | 53 | /** |
| 54 | * @type {Uint8Array} |
| 55 | */ |
| 56 | HEAPU8: {}, |
| 57 | |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 58 | |
| 59 | SkPath: { |
| 60 | // public API should go below because closure still will |
| 61 | // remove things declared here and not on the prototype. |
| 62 | |
| 63 | // private API |
| 64 | _addPath: function(path, scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2) {}, |
| 65 | _arcTo: function(x1, y1, x2, y2, radius) {}, |
| 66 | _close: function() {}, |
| 67 | _conicTo: function(x1, y1, x2, y2, w) {}, |
| 68 | _cubicTo: function(cp1x, cp1y, cp2x, cp2y, x, y) {}, |
| 69 | _lineTo: function(x1, y1) {}, |
| 70 | _moveTo: function(x1, y1) {}, |
| 71 | _op: function(otherPath, op) {}, |
| 72 | _quadTo: function(cpx, cpy, x, y) {}, |
| 73 | _rect: function(x, y, w, h) {}, |
| 74 | _simplify: function() {}, |
| 75 | _transform: function(scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2) {}, |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame^] | 76 | }, |
| 77 | |
| 78 | SkSurface: { |
| 79 | // public API should go below because closure still will |
| 80 | // remove things declared here and not on the prototype. |
| 81 | |
| 82 | // private API |
| 83 | _readPixels: function(w, h, ptr) {}, |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
| 87 | // Path public API |
| 88 | CanvasKit.SkPath.prototype.addPath = function() {}; |
| 89 | CanvasKit.SkPath.prototype.arcTo = function(x1, y1, x2, y2, radius) {}; |
| 90 | CanvasKit.SkPath.prototype.close = function() {}; |
| 91 | CanvasKit.SkPath.prototype.conicTo = function(x1, y1, x2, y2, w) {}; |
| 92 | CanvasKit.SkPath.prototype.cubicTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {}; |
| 93 | CanvasKit.SkPath.prototype.lineTo = function(x, y) {}; |
| 94 | CanvasKit.SkPath.prototype.moveTo = function(x, y) {}; |
| 95 | CanvasKit.SkPath.prototype.op = function(otherPath, op) {}; |
| 96 | CanvasKit.SkPath.prototype.quadTo = function(x1, y1, x2, y2) {}; |
| 97 | CanvasKit.SkPath.prototype.rect = function(x, y, w, h) {}; |
| 98 | CanvasKit.SkPath.prototype.simplify = function() {}; |
| 99 | CanvasKit.SkPath.prototype.transform = function() {}; |
| 100 | |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame^] | 101 | CanvasKit.SkSurface.prototype.flush = function() {}; |
| 102 | |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 103 | // Not sure why this is needed - might be a bug in emsdk that this isn't properly declared. |
| 104 | function loadWebAssemblyModule() {} |