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