1 /* 2 * Copyright 2021 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 #ifndef SKIA_BINDINGS_H 8 #define SKIA_BINDINGS_H 9 10 #include <emscripten.h> 11 #include <emscripten/bind.h> 12 using namespace emscripten; 13 14 // The following two macros allow for the generation of various support files to create 15 // Canvaskit. The code inside the parentheses should be the Typescript declaration of whatever 16 // the following line or lines of code are describing. There are 3 types of files created, the 17 // ambient namespace files (e.g. core.d.ts; the public and private JS functions exposed by embind), 18 // externs.js (used to tell the Closure compiler not to minify certain names in the interface 19 // code) and the API Summary doc (index.d.ts). Types declared with TS_PRIVATE_EXPORT will 20 // only appear in the first two; TS_EXPORT will show up in all three. 21 // 22 // Because TS_EXPORT will show up in the public API docs, it is required that all TS_EXPORT 23 // declarations are preceded by docs starting with /** that will be copied into the final API 24 // summary doc, otherwise the generation step will fail. 25 // 26 // The declarations will be normal TS, with the exception of having a ClassName:: as a prefix if 27 // we are exposing a method on a class. This lets us properly group methods together. 28 // 29 // As an example: 30 // 31 // TS_PRIVATE_EXPORT("_privateFunction(x: number, y: number): number") 32 // function("_privateFunction", optional_override([](int x, int y)->size_t { 33 // return x * y; 34 // })); 35 // 36 // /** See SkCanvas.h for more on this class */ 37 // class_<SkCanvas>("Canvas") 38 // /** 39 // * Draw the given paint using the current matrix and cli. 40 // * @param p a paint to draw. 41 // */ 42 // TS_EXPORT("Canvas::drawPaint(p: Paint): void") 43 // .function("drawPaint", &SkCanvas::drawPaint) 44 #define TS_PRIVATE_EXPORT(ts_code) 45 #define TS_EXPORT(ts_code) 46 47 #endif // SKIA_BINDINGS_H 48