skia2/experimental/tskit/bindings/extension.ts
Kevin Lubick 38320680cb [canvaskit] Proof of Concept for Typescript-build structure
This CL demonstrates the following
 - Interface code written in TS
 - Having support for modular builds (e.g. making Paragraph
   optional)
 - Avoiding monolithic interface files
 - Using eslint to enforce style and avoid errors.
 - Working debug and release build (using example.html)

Many of these files would be generated via a tool (that
has not been written yet).

go/ts-canvaskit

Change-Id: Ibe9a214d5897b09920cef01f6e95302f3cf30d5c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/392297
Reviewed-by: Jorge Betancourt <jmbetancourt@google.com>
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
2021-04-09 19:01:49 +00:00

30 lines
1.0 KiB
TypeScript

/// <reference path="load.ts" />
/// <reference path="memory.ts" />
/// <reference path="extension.d.ts" />
/// <reference path="public_api.d.ts" />
// eslint-disable-next-line @typescript-eslint/no-unused-vars
namespace Extension {
// Module is the C++ module with the private (and some public) bindings on it.
declare const Module: extension.Bindings;
declare const CanvasKit: public_api.CanvasKit;
load.afterLoad(() => {
/**
* publicExtension takes the number of rects and returns how
* many of them have the point (5, 5) in them.
* @param myRects
* @ts publicExtension(myRects: InputFlattenedRectArray): void;
*/
CanvasKit.publicExtension = (myRects: public_api.InputFlattenedRectArray) => {
const rPtr = memory.copy1dArray(myRects, 'HEAPF32');
const num = Module._privateExtension(rPtr, myRects.length / 4);
memory.freeIfNecessary(rPtr, myRects);
return num;
};
CanvasKit.withObject = (obj: public_api.CompoundObj) => {
obj.gamma ||= 1.0;
Module._withObject(obj);
};
});
}