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