• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Minimum TypeScript Version: 3.7
2export function CanvasKitInit(opts: CanvasKitInitOptions): Promise<CanvasKit>;
3
4export interface CanvasKitInitOptions {
5    /**
6     * This callback will be invoked when the CanvasKit loader needs to fetch a file (e.g.
7     * the blob of WASM code). The correct url prefix should be applied.
8     * @param file - the name of the file that is about to be loaded.
9     */
10    locateFile(file: string): string;
11}
12
13export interface CanvasKit {
14    // Helpers
15    /**
16     * Constructs a Color with the same API as CSS's rgba(), that is
17     * Internally, Colors are four unpremultiplied 32-bit floats: r, g, b, a.
18     * In order to construct one with more precision or in a wider gamut,
19     * use CanvasKit.Color4f().
20     *
21     * @param r - red value, clamped to [0, 255].
22     * @param g - green value, clamped to [0, 255].
23     * @param b - blue value, clamped to [0, 255].
24     * @param a - alpha value, from 0 to 1.0. By default is 1.0 (opaque).
25     */
26    Color(r: number, g: number, b: number, a?: number): Color;
27
28    /**
29     * Construct a 4-float color. Float values are typically between 0.0 and 1.0.
30     * @param r - red value.
31     * @param g - green value.
32     * @param b - blue value.
33     * @param a - alpha value. By default is 1.0 (opaque).
34     */
35    Color4f(r: number, g: number, b: number, a?: number): Color;
36
37    /**
38     * Constructs a Color as a 32 bit unsigned integer, with 8 bits assigned to each channel.
39     * Channels are expected to be between 0 and 255 and will be clamped as such.
40     * If a is omitted, it will be 255 (opaque).
41     *
42     * This is not the preferred way to use colors in Skia APIs, use Color or Color4f.
43     * @param r - red value, clamped to [0, 255].
44     * @param g - green value, clamped to [0, 255].
45     * @param b - blue value, clamped to [0, 255].
46     * @param a - alpha value, from 0 to 1.0. By default is 1.0 (opaque).
47     */
48    ColorAsInt(r: number, g: number, b: number, a?: number): ColorInt;
49
50    /**
51     * Returns a css style [r, g, b, a] where r, g, b are returned as
52     * ints in the range [0, 255] and where a is scaled between 0 and 1.0.
53     * [Deprecated] - this is trivial now that Color is 4 floats.
54     */
55    getColorComponents(c: Color): number[];
56
57    /**
58     * Takes in a CSS color value and returns a CanvasKit.Color
59     * (which is an array of 4 floats in RGBA order). An optional colorMap
60     * may be provided which maps custom strings to values.
61     * In the CanvasKit canvas2d shim layer, we provide this map for processing
62     * canvas2d calls, but not here for code size reasons.
63     */
64    parseColorString(color: string, colorMap?: object): Color;
65
66    /**
67     * Returns a copy of the passed in color with a new alpha value applied.
68     * [Deprecated] - this is trivial now that Color is 4 floats.
69     */
70    multiplyByAlpha(c: Color, alpha: number): Color;
71
72    /**
73     * Computes color values for one-pass tonal alpha.
74     * Note, if malloced colors are passed in, the memory pointed at by the MallocObj
75     * will be overwritten with the computed tonal colors (and thus the return val can be
76     * ignored).
77     * @param colors
78     */
79    computeTonalColors(colors: TonalColorsInput): TonalColorsOutput;
80
81    /**
82     * Returns a rectangle with the given paramaters. See Rect.h for more.
83     * @param left - The x coordinate of the upper-left corner.
84     * @param top  - The y coordinate of the upper-left corner.
85     * @param right - The x coordinate of the lower-right corner.
86     * @param bottom - The y coordinate of the lower-right corner.
87     */
88    LTRBRect(left: number, top: number, right: number, bottom: number): Rect;
89
90    /**
91     * Returns a rectangle with the given paramaters. See Rect.h for more.
92     * @param x - The x coordinate of the upper-left corner.
93     * @param y  - The y coordinate of the upper-left corner.
94     * @param width - The width of the rectangle.
95     * @param height - The height of the rectangle.
96     */
97    XYWHRect(x: number, y: number, width: number, height: number): Rect;
98
99    /**
100     * Returns a rectangle with the given integer paramaters. See Rect.h for more.
101     * @param left - The x coordinate of the upper-left corner.
102     * @param top  - The y coordinate of the upper-left corner.
103     * @param right - The x coordinate of the lower-right corner.
104     * @param bottom - The y coordinate of the lower-right corner.
105     */
106    LTRBiRect(left: number, top: number, right: number, bottom: number): IRect;
107
108    /**
109     * Returns a rectangle with the given paramaters. See Rect.h for more.
110     * @param x - The x coordinate of the upper-left corner.
111     * @param y  - The y coordinate of the upper-left corner.
112     * @param width - The width of the rectangle.
113     * @param height - The height of the rectangle.
114     */
115    XYWHiRect(x: number, y: number, width: number, height: number): IRect;
116
117    /**
118     * Returns a rectangle with rounded corners consisting of the given rectangle and
119     * the same radiusX and radiusY for all four corners.
120     * @param rect - The base rectangle.
121     * @param rx - The radius of the corners in the x direction.
122     * @param ry - The radius of the corners in the y direction.
123     */
124    RRectXY(rect: InputRect, rx: number, ry: number): RRect;
125
126    /**
127     * Generate bounding box for shadows relative to path. Includes both the ambient and spot
128     * shadow bounds. This pairs with Canvas.drawShadow().
129     * See SkShadowUtils.h for more details.
130     * @param ctm - Current transformation matrix to device space.
131     * @param path - The occluder used to generate the shadows.
132     * @param zPlaneParams - Values for the plane function which returns the Z offset of the
133     *                       occluder from the canvas based on local x and y values (the current
134     *                       matrix is not applied).
135     * @param lightPos - The 3D position of the light relative to the canvas plane. This is
136     *                   independent of the canvas's current matrix.
137     * @param lightRadius - The radius of the disc light.
138     * @param flags - See SkShadowFlags.h; 0 means use default options.
139     * @param dstRect - if provided, the bounds will be copied into this rect instead of allocating
140     *                  a new one.
141     * @returns The bounding rectangle or null if it could not be computed.
142     */
143    getShadowLocalBounds(ctm: InputMatrix, path: Path, zPlaneParams: InputVector3,
144                         lightPos: InputVector3, lightRadius: number, flags: number,
145                         dstRect?: Rect): Rect | null;
146
147    /**
148     * Malloc returns a TypedArray backed by the C++ memory of the
149     * given length. It should only be used by advanced users who
150     * can manage memory and initialize values properly. When used
151     * correctly, it can save copying of data between JS and C++.
152     * When used incorrectly, it can lead to memory leaks.
153     * Any memory allocated by CanvasKit.Malloc needs to be released with CanvasKit.Free.
154     *
155     * const mObj = CanvasKit.Malloc(Float32Array, 20);
156     * Get a TypedArray view around the malloc'd memory (this does not copy anything).
157     * const ta = mObj.toTypedArray();
158     * // store data into ta
159     * const cf = CanvasKit.ColorFilter.MakeMatrix(ta); // mObj could also be used.
160     *
161     * // eventually...
162     * CanvasKit.Free(mObj);
163     *
164     * @param typedArray - constructor for the typedArray.
165     * @param len - number of *elements* to store.
166     */
167    Malloc(typedArray: TypedArrayConstructor, len: number): MallocObj;
168
169    /**
170     * As Malloc but for GlyphIDs. This helper exists to make sure the JS side and the C++ side
171     * stay in agreement with how wide GlyphIDs are.
172     * @param len - number of GlyphIDs to make space for.
173     */
174    MallocGlyphIDs(len: number): MallocObj;
175
176    /**
177     * Free frees the memory returned by Malloc.
178     * Any memory allocated by CanvasKit.Malloc needs to be released with CanvasKit.Free.
179     */
180    Free(m: MallocObj): void;
181
182    // Surface related functions
183    /**
184     * Creates a Surface on a given canvas. If both GPU and CPU modes have been compiled in, this
185     * will first try to create a GPU surface and then fallback to a CPU one if that fails. If just
186     * the CPU mode has been compiled in, a CPU surface will be created.
187     * @param canvas - either the canvas element itself or a string with the DOM id of it.
188     */
189    MakeCanvasSurface(canvas: HTMLCanvasElement | string): Surface | null;
190
191    /**
192     * Creates a Raster (CPU) Surface that will draw into the provided Malloc'd buffer. This allows
193     * clients to efficiently be able to read the current pixels w/o having to copy.
194     * The length of pixels must be at least height * bytesPerRow bytes big.
195     * @param ii
196     * @param pixels
197     * @param bytesPerRow - How many bytes are per row. This is at least width * bytesPerColorType. For example,
198     *                      an 8888 ColorType has 4 bytes per pixel, so a 5 pixel wide 8888 surface needs at least
199     *                      5 * 4 = 20 bytesPerRow. Some clients may have more than the usual to make the data line
200     *                      up with a particular multiple.
201     */
202    MakeRasterDirectSurface(ii: ImageInfo, pixels: MallocObj, bytesPerRow: number): Surface | null;
203
204    /**
205     * Creates a CPU backed (aka raster) surface.
206     * @param canvas - either the canvas element itself or a string with the DOM id of it.
207     */
208    MakeSWCanvasSurface(canvas: HTMLCanvasElement | string): Surface | null;
209
210    /**
211     * A helper for creating a WebGL backed (aka GPU) surface and falling back to a CPU surface if
212     * the GPU one cannot be created. This works for both WebGL 1 and WebGL 2.
213     * @param canvas - Either the canvas element itself or a string with the DOM id of it.
214     * @param colorSpace - One of the supported color spaces. Default is SRGB.
215     * @param opts - Options that will get passed to the creation of the WebGL context.
216     */
217    MakeWebGLCanvasSurface(canvas: HTMLCanvasElement | string, colorSpace?: ColorSpace,
218                           opts?: WebGLOptions): Surface | null;
219
220    /**
221     * Returns a CPU backed surface with the given dimensions, an SRGB colorspace, Unpremul
222     * alphaType and 8888 color type. The pixels belonging to this surface  will be in memory and
223     * not visible.
224     * @param width - number of pixels of the width of the drawable area.
225     * @param height - number of pixels of the height of the drawable area.
226     */
227    MakeSurface(width: number, height: number): Surface | null;
228
229    /**
230     * Creates a WebGL Context from the given canvas with the given options. If options are omitted,
231     * sensible defaults will be used.
232     * @param canvas
233     * @param opts
234     */
235    GetWebGLContext(canvas: HTMLCanvasElement, opts?: WebGLOptions): WebGLContextHandle;
236
237    /**
238     * Creates a GrDirectContext from the given WebGL Context.
239     * @param ctx
240     */
241    MakeGrContext(ctx: WebGLContextHandle): GrDirectContext;
242
243    /**
244     * Creates a Surface that will be drawn to the given GrDirectContext (and show up on screen).
245     * @param ctx
246     * @param width - number of pixels of the width of the visible area.
247     * @param height - number of pixels of the height of the visible area.
248     * @param colorSpace
249     */
250    MakeOnScreenGLSurface(ctx: GrDirectContext, width: number, height: number,
251                          colorSpace: ColorSpace): Surface | null;
252
253    /**
254     * Returns a (non-visible) Surface on the GPU. It has the given dimensions and uses 8888
255     * color depth and premultiplied alpha. See Surface.h for more details.
256     * @param ctx
257     * @param width
258     * @param height
259     */
260    MakeRenderTarget(ctx: GrDirectContext, width: number, height: number): Surface | null;
261
262    /**
263     * Returns a (non-visible) Surface on the GPU. It has the settings provided by image info.
264     * See Surface.h for more details.
265     * @param ctx
266     * @param info
267     */
268    MakeRenderTarget(ctx: GrDirectContext, info: ImageInfo): Surface | null;
269
270    /**
271     * Returns the current WebGLContext that the wasm code is configured to draw to. It is
272     * recommended to capture this value after creating a new WebGL surface if there are multiple
273     * surfaces on the screen.
274     */
275    currentContext(): WebGLContextHandle;
276
277    /**
278     * Sets the WebGLContext that the wasm code will draw to.
279     *
280     * When a WebGL call is made on the C++ side, it is routed to the JS side to target a specific
281     * WebGL context. WebGL calls are methods on a WebGL context, so CanvasKit needs to know which
282     * context to send the calls to.
283     * @param ctx
284     */
285    setCurrentContext(ctx: WebGLContextHandle): void;
286
287    /**
288     * Deletes the associated WebGLContext. Function not available on the CPU version.
289     * @param ctx
290     */
291    deleteContext(ctx: WebGLContextHandle): void;
292
293    /**
294     * Returns the max size of the global cache for bitmaps used by CanvasKit.
295     */
296    getDecodeCacheLimitBytes(): number;
297    /**
298     * Returns the current size of the global cache for bitmaps used by CanvasKit.
299     */
300    getDecodeCacheUsedBytes(): number;
301
302    /**
303     * Sets the max size of the global cache for bitmaps used by CanvasKit.
304     * @param size - number of bytes that can be used to cache bitmaps.
305     */
306    setDecodeCacheLimitBytes(size: number): void;
307
308    /**
309     * Decodes the given bytes into an animated image. Returns null if the bytes were invalid.
310     * The passed in bytes will be copied into the WASM heap, so the caller can dispose of them.
311     * @param bytes
312     */
313    MakeAnimatedImageFromEncoded(bytes: Uint8Array | ArrayBuffer): AnimatedImage | null;
314
315    /**
316     * Returns an emulated Canvas2D of the given size.
317     * @param width
318     * @param height
319     */
320    MakeCanvas(width: number, height: number): EmulatedCanvas2D;
321
322    /**
323     * Returns an image with the given pixel data and format.
324     * Note that we will always make a copy of the pixel data, because of inconsistencies in
325     * behavior between GPU and CPU (i.e. the pixel data will be turned into a GPU texture and
326     * not modifiable after creation).
327     *
328     * @param info
329     * @param bytes - bytes representing the pixel data.
330     * @param bytesPerRow
331     */
332    MakeImage(info: ImageInfo, bytes: number[] | Uint8Array | Uint8ClampedArray,
333              bytesPerRow: number): Image | null;
334
335    /**
336     * Return an Image backed by the encoded data, but attempt to defer decoding until the image
337     * is actually used/drawn. This deferral allows the system to cache the result, either on the
338     * CPU or on the GPU, depending on where the image is drawn.
339     * This decoding uses the codecs that have been compiled into CanvasKit. If the bytes are
340     * invalid (or an unrecognized codec), null will be returned. See Image.h for more details.
341     * @param bytes
342     */
343    MakeImageFromEncoded(bytes: Uint8Array | ArrayBuffer): Image | null;
344
345    /**
346     * Returns an Image with the data from the provided CanvasImageSource (e.g. <img>). This will
347     * use the browser's built in codecs, in that src will be drawn to a canvas and then readback
348     * and placed into an Image.
349     * @param src
350     */
351    MakeImageFromCanvasImageSource(src: CanvasImageSource): Image;
352
353    /**
354     * Returns an SkPicture which has been serialized previously to the given bytes.
355     * @param bytes
356     */
357    MakePicture(bytes: Uint8Array | ArrayBuffer): SkPicture | null;
358
359    /**
360     * Returns an Vertices based on the given positions and optional parameters.
361     * See SkVertices.h (especially the Builder) for more details.
362     * @param mode
363     * @param positions
364     * @param textureCoordinates
365     * @param colors - either a list of int colors or a flattened color array.
366     * @param indices
367     * @param isVolatile
368     */
369    MakeVertices(mode: VertexMode, positions: InputFlattenedPointArray,
370                 textureCoordinates?: InputFlattenedPointArray | null,
371                 colors?: Float32Array | ColorIntArray | null, indices?: number[] | null,
372                 isVolatile?: boolean): Vertices;
373
374    /**
375     * Returns a Skottie animation built from the provided json string.
376     * Requires that Skottie be compiled into CanvasKit.
377     * @param json
378     */
379    MakeAnimation(json: string): SkottieAnimation;
380
381    /**
382     * Returns a managed Skottie animation built from the provided json string and assets.
383     * Requires that Skottie be compiled into CanvasKit.
384     * @param json
385     * @param assets - a dictionary of named blobs: { key: ArrayBuffer, ... }
386     * @param filterPrefix - an optional string acting as a name filter for selecting "interesting"
387     *                       Lottie properties (surfaced in the embedded player controls)
388     * @param soundMap - an optional mapping of sound identifiers (strings) to AudioPlayers.
389     *                   Only needed if the animation supports sound.
390     */
391    MakeManagedAnimation(json: string, assets?: Record<string, ArrayBuffer>,
392                         filterPrefix?: string, soundMap?: SoundMap): ManagedSkottieAnimation;
393
394    /**
395     * Returns a Particles effect built from the provided json string and assets.
396     * Requires that Particles be compiled into CanvasKit
397     * @param json
398     * @param assets
399     */
400    MakeParticles(json: string, assets?: Record<string, ArrayBuffer>): Particles;
401
402    // Constructors, i.e. things made with `new CanvasKit.Foo()`;
403    readonly ImageData: ImageDataConstructor;
404    readonly ParagraphStyle: ParagraphStyleConstructor;
405    readonly ContourMeasureIter: ContourMeasureIterConstructor;
406    readonly Font: FontConstructor;
407    readonly Paint: DefaultConstructor<Paint>;
408    readonly Path: PathConstructorAndFactory;
409    readonly PictureRecorder: DefaultConstructor<PictureRecorder>;
410    readonly TextStyle: TextStyleConstructor;
411
412    // Factories, i.e. things made with CanvasKit.Foo.MakeTurboEncapsulator()
413    readonly ParagraphBuilder: ParagraphBuilderFactory;
414    readonly ColorFilter: ColorFilterFactory;
415    readonly FontMgr: FontMgrFactory;
416    readonly ImageFilter: ImageFilterFactory;
417    readonly MaskFilter: MaskFilterFactory;
418    readonly PathEffect: PathEffectFactory;
419    readonly RuntimeEffect: RuntimeEffectFactory;
420    readonly Shader: ShaderFactory;
421    readonly TextBlob: TextBlobFactory;
422    readonly TypefaceFontProvider: TypefaceFontProviderFactory;
423
424    // Misc
425    readonly ColorMatrix: ColorMatrixHelpers;
426    readonly Matrix: Matrix3x3Helpers;
427    readonly M44: Matrix4x4Helpers;
428    readonly Vector: VectorHelpers;
429
430    // Core Enums
431    readonly AlphaType: AlphaTypeEnumValues;
432    readonly BlendMode: BlendModeEnumValues;
433    readonly BlurStyle: BlurStyleEnumValues;
434    readonly ClipOp: ClipOpEnumValues;
435    readonly ColorType: ColorTypeEnumValues;
436    readonly FillType: FillTypeEnumValues;
437    readonly FilterMode: FilterModeEnumValues;
438    readonly FilterQuality: FilterQualityEnumValues;
439    readonly FontEdging: FontEdgingEnumValues;
440    readonly FontHinting: FontHintingEnumValues;
441    readonly GlyphRunFlags: GlyphRunFlagValues;
442    readonly ImageFormat: ImageFormatEnumValues;
443    readonly MipmapMode: MipmapModeEnumValues;
444    readonly PaintStyle: PaintStyleEnumValues;
445    readonly PathOp: PathOpEnumValues;
446    readonly PointMode: PointModeEnumValues;
447    readonly ColorSpace: ColorSpaceEnumValues;
448    readonly StrokeCap: StrokeCapEnumValues;
449    readonly StrokeJoin: StrokeJoinEnumValues;
450    readonly TileMode: TileModeEnumValues;
451    readonly VertexMode: VertexModeEnumValues;
452
453    // Core Constants
454    readonly TRANSPARENT: Color;
455    readonly BLACK: Color;
456    readonly WHITE: Color;
457    readonly RED: Color;
458    readonly GREEN: Color;
459    readonly BLUE: Color;
460    readonly YELLOW: Color;
461    readonly CYAN: Color;
462    readonly MAGENTA: Color;
463
464    readonly MOVE_VERB: number;
465    readonly LINE_VERB: number;
466    readonly QUAD_VERB: number;
467    readonly CONIC_VERB: number;
468    readonly CUBIC_VERB: number;
469    readonly CLOSE_VERB: number;
470
471    readonly SaveLayerInitWithPrevious: SaveLayerFlag;
472    readonly SaveLayerF16ColorType: SaveLayerFlag;
473
474    /**
475     * Use this shadow flag to indicate the occluding object is not opaque. Knowing that the
476     * occluder is opaque allows us to cull shadow geometry behind it and improve performance.
477     */
478    readonly ShadowTransparentOccluder: number;
479    /**
480     * Use this shadow flag to not use analytic shadows.
481     */
482    readonly ShadowGeometricOnly: number;
483    /**
484     * Use this shadow flag to indicate the light position represents a direction and light radius
485     * is blur radius at elevation 1.
486     */
487    readonly ShadowDirectionalLight: number;
488
489    readonly gpu?: boolean; // true if GPU code was compiled in
490    readonly managed_skottie?: boolean; // true if advanced (managed) Skottie code was compiled in
491    readonly particles?: boolean; // true if Particles code was compiled in
492    readonly rt_effect?: boolean; // true if RuntimeEffect was compiled in
493    readonly skottie?: boolean; // true if base Skottie code was compiled in
494
495    // Paragraph Enums
496    readonly Affinity: AffinityEnumValues;
497    readonly DecorationStyle: DecorationStyleEnumValues;
498    readonly FontSlant: FontSlantEnumValues;
499    readonly FontWeight: FontWeightEnumValues;
500    readonly FontWidth: FontWidthEnumValues;
501    readonly PlaceholderAlignment: PlaceholderAlignmentEnumValues;
502    readonly RectHeightStyle: RectHeightStyleEnumValues;
503    readonly RectWidthStyle: RectWidthStyleEnumValues;
504    readonly TextAlign: TextAlignEnumValues;
505    readonly TextBaseline: TextBaselineEnumValues;
506    readonly TextDirection: TextDirectionEnumValues;
507    readonly TextHeightBehavior: TextHeightBehaviorEnumValues;
508
509    // Paragraph Constants
510    readonly NoDecoration: number;
511    readonly UnderlineDecoration: number;
512    readonly OverlineDecoration: number;
513    readonly LineThroughDecoration: number;
514}
515
516export interface Camera {
517    /** a 3d point locating the camera. */
518    eye: Vector3;
519    /** center of attention - the 3d point the camera is looking at. */
520    coa: Vector3;
521    /**
522     * A unit vector pointing the cameras up direction. Note that using only eye and coa
523     * would leave the roll of the camera unspecified.
524     */
525    up: Vector3;
526    /** near clipping plane distance */
527    near: number;
528    /** far clipping plane distance */
529    far: number;
530    /** field of view in radians */
531    angle: AngleInRadians;
532}
533
534/**
535 * CanvasKit is built with Emscripten and Embind. Embind adds the following methods to all objects
536 * that are exposed with it.
537 */
538export interface EmbindObject<T extends EmbindObject<T>> {
539    clone(): T;
540    delete(): void;
541    deleteAfter(): void;
542    isAliasOf(other: any): boolean;
543    isDeleted(): boolean;
544}
545
546/**
547 * Represents the set of enum values.
548 */
549export interface EmbindEnum {
550    readonly values: number[];
551}
552
553/**
554 * Represents a single member of an enum.
555 */
556export interface EmbindEnumEntity {
557    readonly value: number;
558}
559
560export interface EmulatedCanvas2D {
561    /**
562     * Cleans up all resources associated with this emulated canvas.
563     */
564    dispose(): void;
565    /**
566     * Decodes an image with the given bytes.
567     * @param bytes
568     */
569    decodeImage(bytes: ArrayBuffer | Uint8Array): Image;
570
571    /**
572     * Returns an emulated canvas2d context if type == '2d', null otherwise.
573     * @param type
574     */
575    getContext(type: string): EmulatedCanvas2DContext | null;
576
577    /**
578     * Loads the given font with the given descriptors. Emulates new FontFace().
579     * @param bytes
580     * @param descriptors
581     */
582    loadFont(bytes: ArrayBuffer | Uint8Array, descriptors: object): void;
583
584    /**
585     * Returns an new emulated Path2D object.
586     * @param str - an SVG string representing a path.
587     */
588    makePath2D(str?: string): EmulatedPath2D;
589
590    /**
591     * Returns the current canvas as a base64 encoded image string.
592     * @param codec - image/png by default; image/jpeg also supported.
593     * @param quality
594     */
595    toDataURL(codec?: string, quality?: number): string;
596}
597
598/** Part of the Canvas2D emulation code */
599export type EmulatedCanvas2DContext = CanvasRenderingContext2D;
600export type EmulatedImageData = ImageData;
601export type EmulatedPath2D = Path2D;
602
603export interface FontStyle {
604    weight?: FontWeight;
605    width?: FontWidth;
606    slant?: FontSlant;
607}
608
609/**
610 * See GrDirectContext.h for more on this class.
611 */
612export interface GrDirectContext extends EmbindObject<GrDirectContext> {
613    getResourceCacheLimitBytes(): number;
614    getResourceCacheUsageBytes(): number;
615    releaseResourcesAndAbandonContext(): void;
616    setResourceCacheLimitBytes(bytes: number): void;
617}
618
619/**
620 * See Metrics.h for more on this struct.
621 */
622export interface LineMetrics {
623    /** The index in the text buffer the line begins. */
624    startIndex: number;
625    /** The index in the text buffer the line ends. */
626    endIndex: number;
627    endExcludingWhitespaces: number;
628    endIncludingNewline: number;
629    /** True if the line ends in a hard break (e.g. newline) */
630    isHardBreak: boolean;
631    /**
632     * The final computed ascent for the line. This can be impacted by
633     * the strut, height, scaling, as well as outlying runs that are very tall.
634     */
635    ascent: number;
636    /**
637     * The final computed descent for the line. This can be impacted by
638     * the strut, height, scaling, as well as outlying runs that are very tall.
639     */
640    descent: number;
641    /** round(ascent + descent) */
642    height: number;
643    /** width of the line */
644    width: number;
645    /** The left edge of the line. The right edge can be obtained with `left + width` */
646    left: number;
647    /** The y position of the baseline for this line from the top of the paragraph. */
648    baseline: number;
649    /** Zero indexed line number. */
650    lineNumber: number;
651}
652
653export interface Range {
654    first: number;
655    last:  number;
656}
657
658/**
659 * Information for a run of shaped text. See Paragraph.getShapedLines()
660 *
661 * Notes:
662 * positions is documented as Float32, but it holds twice as many as you expect, and they
663 * are treated logically as pairs of floats: {x0, y0}, {x1, y1}, ... for each glyph.
664 *
665 * positions and offsets arrays have 1 extra slot (actually 2 for positions)
666 * to describe the location "after" the last glyph in the glyphs array.
667 */
668export interface GlyphRun {
669    typeface: Typeface;     // currently set to null (temporary)
670    size: number;
671    fakeBold: Boolean;
672    fakeItalic: Boolean;
673
674    glyphs: Uint16Array;
675    positions: Float32Array;    // alternating x0, y0, x1, y1, ...
676    offsets: Uint32Array;
677    flags: number;              // see GlyphRunFlags
678}
679
680/**
681 * Information for a paragraph of text. See Paragraph.getShapedLines()
682 */
683 export interface ShapedLine {
684    textRange: Range;   // first and last character offsets for the line (derived from runs[])
685    top: number;        // top y-coordinate for the line
686    bottom: number;     // bottom y-coordinate for the line
687    baseline: number;   // baseline y-coordinate for the line
688    runs: GlyphRun[];   // array of GlyphRun objects for the line
689}
690
691/**
692 * Input to ShapeText(..., FontBlock[], ...);
693 */
694export interface FontBlock {
695    length: number;     // number of text codepoints this block is applied to
696
697    typeface: Typeface;
698    size: number;
699    fakeBold: Boolean;
700    fakeItalic: Boolean;
701}
702
703/**
704 * This object is a wrapper around a pointer to some memory on the WASM heap. The type of the
705 * pointer was determined at creation time.
706 */
707export interface MallocObj {
708    /**
709     * The number of objects this pointer refers to.
710     */
711    readonly length: number;
712    /**
713     * The "pointer" into the WASM memory. Should be fixed over the lifetime of the object.
714     */
715    readonly byteOffset: number;
716    /**
717     * Return a read/write view into a subset of the memory. Do not cache the TypedArray this
718     * returns, it may be invalidated if the WASM heap is resized. This is the same as calling
719     * .toTypedArray().subarray() except the returned TypedArray can also be passed into an API
720     * and not cause an additional copy.
721     */
722    subarray(start: number, end: number): TypedArray;
723    /**
724     * Return a read/write view of the memory. Do not cache the TypedArray this returns, it may be
725     * invalidated if the WASM heap is resized. If this TypedArray is passed into a CanvasKit API,
726     * it will not be copied again, only the pointer will be re-used.
727     */
728    toTypedArray(): TypedArray;
729}
730
731/**
732 * This object maintains a single audio layer during skottie playback
733 */
734export interface AudioPlayer {
735    /**
736     * Playback control callback, emitted for each corresponding Animation::seek().
737     *
738     * Will seek to time t (seconds) relative to the layer's timeline origin.
739     * Negative t values are used to signal off state (stop playback outside layer span).
740     */
741    seek(t: number): void;
742}
743
744/**
745 * Mapping of sound names (strings) to AudioPlayers
746 */
747export interface SoundMap {
748    /**
749     * Returns AudioPlayer for a certain audio layer
750     * @param key string identifier, name of audio file the desired AudioPlayer manages
751     */
752    getPlayer(key: string): AudioPlayer;
753}
754
755/**
756 * Named color property.
757 */
758export interface ColorProperty {
759    /**
760     * Property identifier, usually the node name.
761     */
762    key: string;
763    /**
764     * Property value (RGBA, 255-based).
765     */
766    value: ColorInt;
767}
768
769/**
770 * Named opacity property.
771 */
772export interface OpacityProperty {
773    /**
774     * Property identifier, usually the node name.
775     */
776    key: string;
777    /**
778     * Property value (0..100).
779     */
780    value: number;
781}
782
783/**
784 * Text property value.
785 */
786export interface TextValue {
787    /**
788     * The text string payload.
789     */
790    text: string;
791    /**
792     * Font size.
793     */
794    size: number;
795}
796
797/**
798 * Named text property.
799 */
800export interface TextProperty {
801    /**
802     * Property identifier, usually the node name.
803     */
804    key: string;
805    /**
806     * Property value.
807     */
808    value: TextValue;
809}
810
811export interface ManagedSkottieAnimation extends SkottieAnimation {
812    setColor(key: string, color: InputColor): boolean;
813    setOpacity(key: string, opacity: number): boolean;
814    setText(key: string, text: string, size: number): boolean;
815    getMarkers(): object[];
816    getColorProps(): ColorProperty[];
817    getOpacityProps(): OpacityProperty[];
818    getTextProps(): TextProperty[];
819}
820
821/**
822 * See Paragraph.h for more information on this class. This is only available if Paragraph has
823 * been compiled in.
824 */
825export interface Paragraph extends EmbindObject<Paragraph> {
826    didExceedMaxLines(): boolean;
827    getAlphabeticBaseline(): number;
828
829    /**
830     * Returns the index of the glyph that corresponds to the provided coordinate,
831     * with the top left corner as the origin, and +y direction as down.
832     */
833    getGlyphPositionAtCoordinate(dx: number, dy: number): PositionWithAffinity;
834
835    getHeight(): number;
836    getIdeographicBaseline(): number;
837    getLineMetrics(): LineMetrics[];
838    getLongestLine(): number;
839    getMaxIntrinsicWidth(): number;
840    getMaxWidth(): number;
841    getMinIntrinsicWidth(): number;
842    getRectsForPlaceholders(): FlattenedRectangleArray;
843
844    /**
845     * Returns bounding boxes that enclose all text in the range of glpyh indexes [start, end).
846     * @param start
847     * @param end
848     * @param hStyle
849     * @param wStyle
850     */
851    getRectsForRange(start: number, end: number, hStyle: RectHeightStyle,
852                     wStyle: RectWidthStyle): FlattenedRectangleArray;
853
854    /**
855     * Finds the first and last glyphs that define a word containing the glyph at index offset.
856     * @param offset
857     */
858    getWordBoundary(offset: number): URange;
859
860    /**
861     * Returns an array of ShapedLine objects, describing the paragraph.
862     */
863    getShapedLines(): ShapedLine[];
864
865    /**
866     * Lays out the text in the paragraph so it is wrapped to the given width.
867     * @param width
868     */
869    layout(width: number): void;
870}
871
872export interface ParagraphBuilder extends EmbindObject<ParagraphBuilder> {
873    /**
874     * Pushes the information required to leave an open space.
875     * @param width
876     * @param height
877     * @param alignment
878     * @param baseline
879     * @param offset
880     */
881    addPlaceholder(width?: number, height?: number, alignment?: PlaceholderAlignment,
882                   baseline?: TextBaseline, offset?: number): void;
883
884    /**
885     * Adds text to the builder. Forms the proper runs to use the upper-most style
886     * on the style_stack.
887     * @param str
888     */
889    addText(str: string): void;
890
891    /**
892     * Returns a Paragraph object that can be used to be layout and paint the text to an
893     * Canvas.
894     */
895    build(): Paragraph;
896
897    /**
898     * Remove a style from the stack. Useful to apply different styles to chunks
899     * of text such as bolding.
900     */
901    pop(): void;
902
903    /**
904     * Push a style to the stack. The corresponding text added with addText will
905     * use the top-most style.
906     * @param text
907     */
908    pushStyle(text: TextStyle): void;
909
910    /**
911     * Pushes a TextStyle using paints instead of colors for foreground and background.
912     * @param textStyle
913     * @param fg
914     * @param bg
915     */
916    pushPaintStyle(textStyle: TextStyle, fg: Paint, bg: Paint): void;
917}
918
919export interface ParagraphStyle {
920    disableHinting?: boolean;
921    ellipsis?: string;
922    heightMultiplier?: number;
923    maxLines?: number;
924    strutStyle?: StrutStyle;
925    textAlign?: TextAlign;
926    textDirection?: TextDirection;
927    textHeightBehavior?: TextHeightBehavior;
928    textStyle?: TextStyle;
929}
930
931export interface PositionWithAffinity {
932    pos: number;
933    affinity: Affinity;
934}
935
936/**
937 * See SkParticleEffect.h for more details.
938 */
939export interface Particles extends EmbindObject<Particles> {
940    /**
941     * Draws the current state of the particles on the given canvas.
942     * @param canvas
943     */
944    draw(canvas: Canvas): void;
945
946    /**
947     * Returns a Float32Array bound to the WASM memory of these uniforms. Changing these
948     * floats will change the corresponding uniforms instantly.
949     */
950    uniforms(): Float32Array;
951
952    /**
953     * Returns the nth uniform from the effect.
954     * @param index
955     */
956    getUniform(index: number): SkSLUniform;
957
958    /**
959     * Returns the number of uniforms on the effect.
960     */
961    getUniformCount(): number;
962
963    /**
964     * Returns the total number of floats across all uniforms on the effect. This is the length
965     * of the array returned by `uniforms()`. For example, an effect with a single float3 uniform,
966     * would return 1 from `getUniformCount()`, but 3 from `getUniformFloatCount()`.
967     */
968    getUniformFloatCount(): number;
969
970    /**
971     * Returns the name of the nth effect uniform.
972     * @param index
973     */
974    getUniformName(index: number): string;
975
976    /**
977     * Sets the base position of the effect.
978     * @param point
979     */
980    setPosition(point: InputPoint): void;
981
982    /**
983     * Sets the base rate of the effect.
984     * @param rate
985     */
986    setRate(rate: number): void;
987
988    /**
989     * Starts playing the effect.
990     * @param now
991     * @param looping
992     */
993    start(now: number, looping: boolean): void;
994
995    /**
996     * Updates the effect using the new time.
997     * @param now
998     */
999    update(now: number): void;
1000}
1001
1002export interface SkSLUniform {
1003    columns: number;
1004    rows: number;
1005    /** The index into the uniforms array that this uniform begins. */
1006    slot: number;
1007}
1008
1009/**
1010 * See SkAnimatedImage.h for more information on this class.
1011 */
1012export interface AnimatedImage extends EmbindObject<AnimatedImage> {
1013    /**
1014     * Decodes the next frame. Returns -1 when the animation is on the last frame.
1015     */
1016    decodeNextFrame(): number;
1017
1018    /**
1019     * Return the total number of frames in the animation.
1020     */
1021    getFrameCount(): number;
1022
1023    /**
1024     * Return the repetition count for this animation.
1025     */
1026    getRepetitionCount(): number;
1027
1028    /**
1029     * Returns the possibly scaled height of the image.
1030     */
1031    height(): number;
1032
1033    /**
1034     * Returns a still image of the current frame or null if there is no current frame.
1035     */
1036    makeImageAtCurrentFrame(): Image | null;
1037
1038    /**
1039     * Reset the animation to the beginning.
1040     */
1041    reset(): void;
1042
1043    /**
1044     * Returns the possibly scaled width of the image.
1045     */
1046    width(): number;
1047}
1048
1049/**
1050 * See SkCanvas.h for more information on this class.
1051 */
1052export interface Canvas extends EmbindObject<Canvas> {
1053    /**
1054     * Fills the current clip with the given color using Src BlendMode.
1055     * This has the effect of replacing all pixels contained by clip with color.
1056     * @param color
1057     */
1058    clear(color: InputColor): void;
1059
1060    /**
1061     * Replaces clip with the intersection or difference of the current clip and path,
1062     * with an aliased or anti-aliased clip edge.
1063     * @param path
1064     * @param op
1065     * @param doAntiAlias
1066     */
1067    clipPath(path: Path, op: ClipOp, doAntiAlias: boolean): void;
1068
1069    /**
1070     * Replaces clip with the intersection or difference of the current clip and rect,
1071     * with an aliased or anti-aliased clip edge.
1072     * @param rect
1073     * @param op
1074     * @param doAntiAlias
1075     */
1076    clipRect(rect: InputRect, op: ClipOp, doAntiAlias: boolean): void;
1077
1078    /**
1079     * Replaces clip with the intersection or difference of the current clip and rrect,
1080     * with an aliased or anti-aliased clip edge.
1081     * @param rrect
1082     * @param op
1083     * @param doAntiAlias
1084     */
1085    clipRRect(rrect: InputRRect, op: ClipOp, doAntiAlias: boolean): void;
1086
1087    /**
1088     * Replaces current matrix with m premultiplied with the existing matrix.
1089     * @param m
1090     */
1091    concat(m: InputMatrix): void;
1092
1093    /**
1094     * Draws arc using clip, Matrix, and Paint paint.
1095     *
1096     * Arc is part of oval bounded by oval, sweeping from startAngle to startAngle plus
1097     * sweepAngle. startAngle and sweepAngle are in degrees.
1098     * @param oval - bounds of oval containing arc to draw
1099     * @param startAngle - angle in degrees where arc begins
1100     * @param sweepAngle - sweep angle in degrees; positive is clockwise
1101     * @param useCenter - if true, include the center of the oval
1102     * @param paint
1103     */
1104    drawArc(oval: InputRect, startAngle: AngleInDegrees, sweepAngle: AngleInDegrees,
1105            useCenter: boolean, paint: Paint): void;
1106
1107    /**
1108     * Draws a set of sprites from atlas, using clip, Matrix, and optional Paint paint.
1109     * @param atlas - Image containing sprites
1110     * @param srcRects - Rect locations of sprites in atlas
1111     * @param dstXforms - RSXform mappings for sprites in atlas
1112     * @param paint
1113     * @param blendMode - BlendMode combining colors and sprites
1114     * @param colors - If provided, will be blended with sprite using blendMode.
1115     * @param sampling - Specifies sampling options. If null, bilinear is used.
1116     */
1117    drawAtlas(atlas: Image, srcRects: InputFlattenedRectangleArray,
1118              dstXforms: InputFlattenedRSXFormArray, paint: Paint,
1119              blendMode?: BlendMode | null, colors?: ColorIntArray | null,
1120              sampling?: CubicResampler | FilterOptions): void;
1121
1122    /**
1123     * Draws a circle at (cx, cy) with the given radius.
1124     * @param cx
1125     * @param cy
1126     * @param radius
1127     * @param paint
1128     */
1129    drawCircle(cx: number, cy: number, radius: number, paint: Paint): void;
1130
1131    /**
1132     * Fills clip with the given color.
1133     * @param color
1134     * @param blendMode - defaults to SrcOver.
1135     */
1136    drawColor(color: InputColor, blendMode?: BlendMode): void;
1137
1138    /**
1139     * Fills clip with the given color.
1140     * @param r - red value (typically from 0 to 1.0).
1141     * @param g - green value (typically from 0 to 1.0).
1142     * @param b - blue value (typically from 0 to 1.0).
1143     * @param a - alpha value, range 0 to 1.0 (1.0 is opaque).
1144     * @param blendMode - defaults to SrcOver.
1145     */
1146    drawColorComponents(r: number, g: number, b: number, a: number, blendMode?: BlendMode): void;
1147
1148    /**
1149     * Fills clip with the given color.
1150     * @param color
1151     * @param blendMode - defaults to SrcOver.
1152     */
1153    drawColorInt(color: ColorInt, blendMode?: BlendMode): void;
1154
1155    /**
1156     * Draws RRect outer and inner using clip, Matrix, and Paint paint.
1157     * outer must contain inner or the drawing is undefined.
1158     * @param outer
1159     * @param inner
1160     * @param paint
1161     */
1162    drawDRRect(outer: InputRRect, inner: InputRRect, paint: Paint): void;
1163
1164    /**
1165     * Draws a run of glyphs, at corresponding positions, in a given font.
1166     * @param glyphs the array of glyph IDs (Uint16TypedArray)
1167     * @param positions the array of x,y floats to position each glyph
1168     * @param x x-coordinate of the origin of the entire run
1169     * @param y y-coordinate of the origin of the entire run
1170     * @param font the font that contains the glyphs
1171     * @param paint
1172     */
1173    drawGlyphs(glyphs: InputGlyphIDArray,
1174               positions: InputFlattenedPointArray,
1175               x: number, y: number,
1176               font: Font, paint: Paint): void;
1177
1178    /**
1179     * Draws the given image with its top-left corner at (left, top) using the current clip,
1180     * the current matrix, and optionally-provided paint.
1181     * @param img
1182     * @param left
1183     * @param top
1184     * @param paint
1185     */
1186    drawImage(img: Image, left: number, top: number, paint?: Paint): void;
1187
1188    /**
1189     * Draws the given image with its top-left corner at (left, top) using the current clip,
1190     * the current matrix. It will use the cubic sampling options B and C if necessary.
1191     * @param img
1192     * @param left
1193     * @param top
1194     * @param B - See CubicResampler in SkSamplingOptions.h for more information
1195     * @param C - See CubicResampler in SkSamplingOptions.h for more information
1196     * @param paint
1197     */
1198    drawImageCubic(img: Image, left: number, top: number, B: number, C: number,
1199                   paint: Paint | null): void;
1200
1201    /**
1202     * Draws the given image with its top-left corner at (left, top) using the current clip,
1203     * the current matrix. It will use the provided sampling options if necessary.
1204     * @param img
1205     * @param left
1206     * @param top
1207     * @param fm - The filter mode.
1208     * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps
1209     *             calculated with makeCopyWithDefaultMipmaps;
1210     * @param paint
1211     */
1212    drawImageOptions(img: Image, left: number, top: number, fm: FilterMode,
1213                     mm: MipmapMode, paint: Paint | null): void;
1214
1215    /**
1216     * Draws the current frame of the given animated image with its top-left corner at
1217     * (left, top) using the current clip, the current matrix, and optionally-provided paint.
1218     * @param aImg
1219     * @param left
1220     * @param top
1221     * @param paint
1222     */
1223    drawImageAtCurrentFrame(aImg: AnimatedImage, left: number, top: number,
1224                            paint?: Paint): void;
1225
1226    /**
1227     *  Draws the provided image stretched proportionally to fit into dst rectangle.
1228     *  The center rectangle divides the image into nine sections: four sides, four corners, and
1229     *  the center.
1230     * @param img
1231     * @param center
1232     * @param dest
1233     * @param filter - what technique to use when sampling the image
1234     * @param paint
1235     */
1236    drawImageNine(img: Image, center: InputIRect, dest: InputRect, filter: FilterMode,
1237                  paint?: Paint): void;
1238
1239    /**
1240     * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.
1241     * @param img
1242     * @param src
1243     * @param dest
1244     * @param paint
1245     * @param fastSample - if false, will filter strictly within src.
1246     */
1247    drawImageRect(img: Image, src: InputRect, dest: InputRect, paint: Paint,
1248                  fastSample?: boolean): void;
1249
1250    /**
1251     * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.
1252     * It will use the cubic sampling options B and C if necessary.
1253     * @param img
1254     * @param src
1255     * @param dest
1256     * @param B - See CubicResampler in SkSamplingOptions.h for more information
1257     * @param C - See CubicResampler in SkSamplingOptions.h for more information
1258     * @param paint
1259     */
1260    drawImageRectCubic(img: Image, src: InputRect, dest: InputRect,
1261                       B: number, C: number, paint?: Paint): void;
1262
1263    /**
1264     * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.
1265     * It will use the provided sampling options if necessary.
1266     * @param img
1267     * @param src
1268     * @param dest
1269     * @param fm - The filter mode.
1270     * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps
1271     *             calculated with makeCopyWithDefaultMipmaps;
1272     * @param paint
1273     */
1274    drawImageRectOptions(img: Image, src: InputRect, dest: InputRect, fm: FilterMode,
1275                         mm: MipmapMode, paint?: Paint): void;
1276
1277    /**
1278     * Draws line segment from (x0, y0) to (x1, y1) using the current clip, current matrix,
1279     * and the provided paint.
1280     * @param x0
1281     * @param y0
1282     * @param x1
1283     * @param y1
1284     * @param paint
1285     */
1286    drawLine(x0: number, y0: number, x1: number, y1: number, paint: Paint): void;
1287
1288    /**
1289     * Draws an oval bounded by the given rectangle using the current clip, current matrix,
1290     * and the provided paint.
1291     * @param oval
1292     * @param paint
1293     */
1294    drawOval(oval: InputRect, paint: Paint): void;
1295
1296    /**
1297     * Fills clip with the given paint.
1298     * @param paint
1299     */
1300    drawPaint(paint: Paint): void;
1301
1302    /**
1303     * Draws the given Paragraph at the provided coordinates.
1304     * Requires the Paragraph code to be compiled in.
1305     * @param p
1306     * @param x
1307     * @param y
1308     */
1309    drawParagraph(p: Paragraph, x: number, y: number): void;
1310
1311    /**
1312     * Draws the given path using the current clip, current matrix, and the provided paint.
1313     * @param path
1314     * @param paint
1315     */
1316    drawPath(path: Path, paint: Paint): void;
1317
1318    /**
1319     * Draws a cubic patch defined by 12 control points [top, right, bottom, left] with optional
1320     * colors and shader-coordinates [4] specifed for each corner [top-left, top-right, bottom-right, bottom-left]
1321     * @param cubics 12 points : 4 connected cubics specifying the boundary of the patch
1322     * @param colors optional colors interpolated across the patch
1323     * @param texs optional shader coordinates interpolated across the patch
1324     * @param mode Specifies how shader and colors blend (if both are specified)
1325     * @param paint
1326     */
1327    drawPatch(cubics: InputFlattenedPointArray,
1328              colors?: ColorIntArray | Color[] | null,
1329              texs?: InputFlattenedPointArray | null,
1330              mode?: BlendMode | null,
1331              paint?: Paint): void;
1332
1333    /**
1334     * Draws the given picture using the current clip, current matrix, and the provided paint.
1335     * @param skp
1336     */
1337    drawPicture(skp: SkPicture): void;
1338
1339    /**
1340     * Draws the given points using the current clip, current matrix, and the provided paint.
1341     *
1342     * See Canvas.h for more on the mode and its interaction with paint.
1343     * @param mode
1344     * @param points
1345     * @param paint
1346     */
1347    drawPoints(mode: PointMode, points: InputFlattenedPointArray, paint: Paint): void;
1348
1349    /**
1350     * Draws the given rectangle using the current clip, current matrix, and the provided paint.
1351     * @param rect
1352     * @param paint
1353     */
1354    drawRect(rect: InputRect, paint: Paint): void;
1355
1356    /**
1357     * Draws the given rectangle using the current clip, current matrix, and the provided paint.
1358     * @param left
1359     * @param top
1360     * @param right
1361     * @param bottom
1362     * @param paint
1363     */
1364    drawRect4f(left: number, top: number, right: number, bottom: number, paint: Paint): void;
1365
1366    /**
1367     * Draws the given rectangle with rounded corners using the current clip, current matrix,
1368     * and the provided paint.
1369     * @param rrect
1370     * @param paint
1371     */
1372    drawRRect(rrect: InputRRect, paint: Paint): void;
1373
1374    /**
1375     * Draw an offset spot shadow and outlining ambient shadow for the given path using a disc
1376     * light. See SkShadowUtils.h for more details
1377     * @param path - The occluder used to generate the shadows.
1378     * @param zPlaneParams - Values for the plane function which returns the Z offset of the
1379     *                       occluder from the canvas based on local x and y values (the current
1380     *                       matrix is not applied).
1381     * @param lightPos - The 3D position of the light relative to the canvas plane. This is
1382     *                   independent of the canvas's current matrix.
1383     * @param lightRadius - The radius of the disc light.
1384     * @param ambientColor - The color of the ambient shadow.
1385     * @param spotColor -  The color of the spot shadow.
1386     * @param flags - See SkShadowFlags.h; 0 means use default options.
1387     */
1388    drawShadow(path: Path, zPlaneParams: InputVector3, lightPos: InputVector3, lightRadius: number,
1389               ambientColor: InputColor, spotColor: InputColor, flags: number): void;
1390
1391    /**
1392     * Draw the given text at the location (x, y) using the provided paint and font. The text will
1393     * be drawn as is; no shaping, left-to-right, etc.
1394     * @param str
1395     * @param x
1396     * @param y
1397     * @param paint
1398     * @param font
1399     */
1400    drawText(str: string, x: number, y: number, paint: Paint, font: Font): void;
1401
1402    /**
1403     * Draws the given TextBlob at (x, y) using the current clip, current matrix, and the
1404     * provided paint. Reminder that the fonts used to draw TextBlob are part of the blob.
1405     * @param blob
1406     * @param x
1407     * @param y
1408     * @param paint
1409     */
1410    drawTextBlob(blob: TextBlob, x: number, y: number, paint: Paint): void;
1411
1412    /**
1413     * Draws the given vertices (a triangle mesh) using the current clip, current matrix, and the
1414     * provided paint.
1415     *  If paint contains an Shader and vertices does not contain texCoords, the shader
1416     *  is mapped using the vertices' positions.
1417     *  If vertices colors are defined in vertices, and Paint paint contains Shader,
1418     *  BlendMode mode combines vertices colors with Shader.
1419     * @param verts
1420     * @param mode
1421     * @param paint
1422     */
1423    drawVertices(verts: Vertices, mode: BlendMode, paint: Paint): void;
1424
1425    /**
1426     * Returns the 4x4 matrix matching the given marker or null if there was none.
1427     * See also markCTM.
1428     * @param marker
1429     */
1430    findMarkedCTM(marker: string): Matrix4x4 | null;
1431
1432    /**
1433     * Returns the current transform from local coordinates to the 'device', which for most
1434     * purposes means pixels.
1435     */
1436    getLocalToDevice(): Matrix4x4;
1437
1438    /**
1439     * Returns the number of saved states, each containing: Matrix and clip.
1440     * Equals the number of save() calls less the number of restore() calls plus one.
1441     * The save count of a new canvas is one.
1442     */
1443    getSaveCount(): number;
1444
1445    /**
1446     * Legacy version of getLocalToDevice(), which strips away any Z information, and
1447     * just returns a 3x3 version.
1448     */
1449    getTotalMatrix(): number[];
1450
1451    /**
1452     * Creates Surface matching info and props, and associates it with Canvas.
1453     * Returns null if no match found.
1454     * @param info
1455     */
1456    makeSurface(info: ImageInfo): Surface | null;
1457
1458    /**
1459     * Record a marker (provided by caller) for the current CTM. This does not change anything
1460     * about the ctm or clip, but does "name" this matrix value, so it can be referenced by
1461     * custom effects (who access it by specifying the same name).
1462     * See also findMarkedCTM.
1463     * @param marker
1464     */
1465    markCTM(marker: string): void;
1466
1467    /**
1468     * Returns a TypedArray containing the pixels reading starting at (srcX, srcY) and does not
1469     * exceed the size indicated by imageInfo. See SkCanvas.h for more on the caveats.
1470     *
1471     * If dest is not provided, we allocate memory equal to the provided height * the provided
1472     * bytesPerRow to fill the data with.
1473     *
1474     * This is generally a very expensive call for the GPU backend.
1475     *
1476     * @param srcX
1477     * @param srcY
1478     * @param imageInfo - describes the destination format of the pixels.
1479     * @param dest - If provided, the pixels will be copied into the allocated buffer allowing
1480     *        access to the pixels without allocating a new TypedArray.
1481     * @param bytesPerRow - number of bytes per row. Must be provided if dest is set. This
1482     *        depends on destination ColorType. For example, it must be at least 4 * width for
1483     *        the 8888 color type.
1484     * @returns a TypedArray appropriate for the specified ColorType. Note that 16 bit floats are
1485     *          not supported in JS, so that colorType corresponds to raw bytes Uint8Array.
1486     */
1487    readPixels(srcX: number, srcY: number, imageInfo: ImageInfo, dest?: MallocObj,
1488               bytesPerRow?: number): Uint8Array | Float32Array | null;
1489
1490    /**
1491     * Removes changes to the current matrix and clip since Canvas state was
1492     * last saved. The state is removed from the stack.
1493     * Does nothing if the stack is empty.
1494     */
1495    restore(): void;
1496
1497    /**
1498     * Restores state to a previous stack value.
1499     * @param saveCount
1500     */
1501    restoreToCount(saveCount: number): void;
1502
1503    /**
1504     * Rotates the current matrix by the number of degrees.
1505     * @param rot - angle of rotation in degrees.
1506     * @param rx
1507     * @param ry
1508     */
1509    rotate(rot: AngleInDegrees, rx: number, ry: number): void;
1510
1511    /**
1512     * Saves the current matrix and clip and returns current height of the stack.
1513     */
1514    save(): number;
1515
1516    /**
1517     * Saves Matrix and clip, and allocates a SkBitmap for subsequent drawing.
1518     * Calling restore() discards changes to Matrix and clip, and draws the SkBitmap.
1519     * It returns the height of the stack.
1520     * See Canvas.h for more.
1521     * @param paint
1522     * @param bounds
1523     * @param backdrop
1524     * @param flags
1525     */
1526    saveLayer(paint?: Paint, bounds?: InputRect | null, backdrop?: ImageFilter | null,
1527              flags?: SaveLayerFlag): number;
1528
1529    /**
1530     * Scales the current matrix by sx on the x-axis and sy on the y-axis.
1531     * @param sx
1532     * @param sy
1533     */
1534    scale(sx: number, sy: number): void;
1535
1536    /**
1537     *  Skews Matrix by sx on the x-axis and sy on the y-axis. A positive value of sx
1538     *  skews the drawing right as y-axis values increase; a positive value of sy skews
1539     *  the drawing down as x-axis values increase.
1540     * @param sx
1541     * @param sy
1542     */
1543    skew(sx: number, sy: number): void;
1544
1545    /**
1546     * Translates Matrix by dx along the x-axis and dy along the y-axis.
1547     * @param dx
1548     * @param dy
1549     */
1550    translate(dx: number, dy: number): void;
1551
1552    /**
1553     * Writes the given rectangle of pixels to the provided coordinates. The source pixels
1554     * will be converted to the canvas's alphaType and colorType if they do not match.
1555     * @param pixels
1556     * @param srcWidth
1557     * @param srcHeight
1558     * @param destX
1559     * @param destY
1560     * @param alphaType - defaults to Unpremul
1561     * @param colorType - defaults to RGBA_8888
1562     * @param colorSpace - defaults to SRGB
1563     */
1564    writePixels(pixels: Uint8Array | number[], srcWidth: number, srcHeight: number,
1565                destX: number, destY: number, alphaType?: AlphaType, colorType?: ColorType,
1566                colorSpace?: ColorSpace): boolean;
1567}
1568
1569/**
1570 * See SkColorFilter.h for more on this class. The objects are opaque.
1571 */
1572export type ColorFilter = EmbindObject<ColorFilter>;
1573
1574export interface ContourMeasureIter extends EmbindObject<ContourMeasureIter> {
1575    /**
1576     *  Iterates through contours in path, returning a contour-measure object for each contour
1577     *  in the path. Returns null when it is done.
1578     *
1579     *  See SkContourMeasure.h for more details.
1580     */
1581    next(): ContourMeasure | null;
1582}
1583
1584export interface ContourMeasure extends EmbindObject<ContourMeasure> {
1585    /**
1586     * Returns the given position and tangent line for the distance on the given contour.
1587     * The return value is 4 floats in this order: posX, posY, vecX, vecY.
1588     * @param distance - will be pinned between 0 and length().
1589     * @param output - if provided, the four floats of the PosTan will be copied into this array
1590     *                 instead of allocating a new one.
1591     */
1592    getPosTan(distance: number, output?: PosTan): PosTan;
1593
1594    /**
1595     * Returns an Path representing the segement of this contour.
1596     * @param startD - will be pinned between 0 and length()
1597     * @param stopD - will be pinned between 0 and length()
1598     * @param startWithMoveTo
1599     */
1600    getSegment(startD: number, stopD: number, startWithMoveTo: boolean): Path;
1601
1602    /**
1603     * Returns true if the contour is closed.
1604     */
1605    isClosed(): boolean;
1606
1607    /**
1608     * Returns the length of this contour.
1609     */
1610    length(): number;
1611}
1612
1613export interface FontMetrics {
1614    ascent: number;     // suggested space above the baseline. < 0
1615    descent: number;    // suggested space below the baseline. > 0
1616    leading: number;    // suggested spacing between descent of previous line and ascent of next line.
1617    bounds?: Rect;      // smallest rect containing all glyphs (relative to 0,0)
1618}
1619
1620/**
1621 * See SkFont.h for more on this class.
1622 */
1623export interface Font extends EmbindObject<Font> {
1624    /**
1625     * Returns the FontMetrics for this font.
1626     */
1627    getMetrics(): FontMetrics;
1628
1629    /**
1630     * Retrieves the bounds for each glyph in glyphs.
1631     * If paint is not null, its stroking, PathEffect, and MaskFilter fields are respected.
1632     * These are returned as flattened rectangles.  For each glyph, there will be 4 floats for
1633     * left, top, right, bottom (relative to 0, 0) for that glyph.
1634     * @param glyphs
1635     * @param paint
1636     * @param output - if provided, the results will be copied into this array.
1637     */
1638    getGlyphBounds(glyphs: InputGlyphIDArray, paint?: Paint | null,
1639                   output?: Float32Array): Float32Array;
1640
1641    /**
1642     * Retrieves the glyph ids for each code point in the provided string. Note that glyph IDs
1643     * are font-dependent; different fonts may have different ids for the same code point.
1644     * @param str
1645     * @param numCodePoints - the number of code points in the string. Defaults to str.length.
1646     * @param output - if provided, the results will be copied into this array.
1647     */
1648    getGlyphIDs(str: string, numCodePoints?: number,
1649                output?: TypedArray): GlyphIDArray;
1650
1651    /**
1652     * Retrieves the advanceX measurements for each glyph.
1653     * If paint is not null, its stroking, PathEffect, and MaskFilter fields are respected.
1654     * One width per glyph is returned in the returned array.
1655     * @param glyphs
1656     * @param paint
1657     * @param output - if provided, the results will be copied into this array.
1658     */
1659    getGlyphWidths(glyphs: InputGlyphIDArray, paint?: Paint | null,
1660                   output?: Float32Array): Float32Array;
1661
1662    /**
1663     * Returns text scale on x-axis. Default value is 1.
1664     */
1665    getScaleX(): number;
1666
1667    /**
1668     * Returns text size in points.
1669     */
1670    getSize(): number;
1671
1672    /**
1673     * Returns text skew on x-axis. Default value is zero.
1674     */
1675    getSkewX(): number;
1676
1677    /**
1678     * Returns embolden effect for this font. Default value is false.
1679     */
1680    isEmbolden(): boolean;
1681
1682     /**
1683     * Returns the Typeface set for this font.
1684     */
1685    getTypeface(): Typeface | null;
1686
1687    /**
1688     * Requests, but does not require, that edge pixels draw opaque or with partial transparency.
1689     * @param edging
1690     */
1691    setEdging(edging: FontEdging): void;
1692
1693    /**
1694     * Requests, but does not require, to use bitmaps in fonts instead of outlines.
1695     * @param embeddedBitmaps
1696     */
1697    setEmbeddedBitmaps(embeddedBitmaps: boolean): void;
1698
1699    /**
1700     * Sets level of glyph outline adjustment.
1701     * @param hinting
1702     */
1703    setHinting(hinting: FontHinting): void;
1704
1705    /**
1706     * Requests, but does not require, linearly scalable font and glyph metrics.
1707     *
1708     * For outline fonts 'true' means font and glyph metrics should ignore hinting and rounding.
1709     * Note that some bitmap formats may not be able to scale linearly and will ignore this flag.
1710     * @param linearMetrics
1711     */
1712    setLinearMetrics(linearMetrics: boolean): void;
1713
1714    /**
1715     * Sets the text scale on the x-axis.
1716     * @param sx
1717     */
1718    setScaleX(sx: number): void;
1719
1720    /**
1721     * Sets the text size in points on this font.
1722     * @param points
1723     */
1724    setSize(points: number): void;
1725
1726    /**
1727     * Sets the text-skew on the x axis for this font.
1728     * @param sx
1729     */
1730    setSkewX(sx: number): void;
1731
1732    /**
1733     * Set embolden effect for this font.
1734     * @param embolden
1735     */
1736    setEmbolden(embolden: boolean): void;
1737
1738    /**
1739     * Requests, but does not require, that glyphs respect sub-pixel positioning.
1740     * @param subpixel
1741     */
1742    setSubpixel(subpixel: boolean): void;
1743
1744    /**
1745     * Sets the typeface to use with this font. null means to clear the typeface and use the
1746     * default one.
1747     * @param face
1748     */
1749    setTypeface(face: Typeface | null): void;
1750}
1751
1752/**
1753 * See SkFontMgr.h for more details
1754 */
1755export interface FontMgr extends EmbindObject<FontMgr> {
1756    /**
1757     * Return the number of font families loaded in this manager. Useful for debugging.
1758     */
1759    countFamilies(): number;
1760
1761    /**
1762     * Return the nth family name. Useful for debugging.
1763     * @param index
1764     */
1765    getFamilyName(index: number): string;
1766
1767    /**
1768     * Create a typeface for the specified bytes and return it.
1769     * @param fontData
1770     */
1771    makeTypefaceFromData(fontData: ArrayBuffer): Typeface;
1772}
1773
1774/**
1775 * See SkImage.h for more information on this class.
1776 */
1777export interface Image extends EmbindObject<Image> {
1778    /**
1779     * Encodes this image's pixels to the specified format and returns them. Must be built with
1780     * the specified codec. If the options are unspecified, sensible defaults will be
1781     * chosen.
1782     * @param fmt - PNG is the default value.
1783     * @param quality - a value from 0 to 100; 100 is the least lossy. May be ignored.
1784     */
1785    encodeToBytes(fmt?: EncodedImageFormat, quality?: number): Uint8Array | null;
1786
1787    /**
1788     * Returns the color space associated with this object.
1789     * It is the user's responsibility to call delete() on this after it has been used.
1790     */
1791    getColorSpace(): ColorSpace;
1792
1793    /**
1794     * Returns the width, height, colorType and alphaType associated with this image.
1795     * Colorspace is separate so as to not accidentally leak that memory.
1796     */
1797    getImageInfo(): PartialImageInfo;
1798
1799    /**
1800     * Return the height in pixels of the image.
1801     */
1802    height(): number;
1803
1804    /**
1805     * Returns an Image with the same "base" pixels as the this image, but with mipmap levels
1806     * automatically generated and attached.
1807     */
1808    makeCopyWithDefaultMipmaps(): Image;
1809
1810    /**
1811     * Returns this image as a shader with the specified tiling. It will use cubic sampling.
1812     * @param tx - tile mode in the x direction.
1813     * @param ty - tile mode in the y direction.
1814     * @param B - See CubicResampler in SkSamplingOptions.h for more information
1815     * @param C - See CubicResampler in SkSamplingOptions.h for more information
1816     * @param localMatrix
1817     */
1818    makeShaderCubic(tx: TileMode, ty: TileMode, B: number, C: number,
1819                    localMatrix?: InputMatrix): Shader;
1820
1821    /**
1822     * Returns this image as a shader with the specified tiling. It will use cubic sampling.
1823     * @param tx - tile mode in the x direction.
1824     * @param ty - tile mode in the y direction.
1825     * @param fm - The filter mode.
1826     * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps
1827     *             calculated with makeCopyWithDefaultMipmaps;
1828     * @param localMatrix
1829     */
1830    makeShaderOptions(tx: TileMode, ty: TileMode, fm: FilterMode, mm: MipmapMode,
1831                    localMatrix?: InputMatrix): Shader;
1832
1833    /**
1834     * Returns a TypedArray containing the pixels reading starting at (srcX, srcY) and does not
1835     * exceed the size indicated by imageInfo. See SkImage.h for more on the caveats.
1836     *
1837     * If dest is not provided, we allocate memory equal to the provided height * the provided
1838     * bytesPerRow to fill the data with.
1839     *
1840     * @param srcX
1841     * @param srcY
1842     * @param imageInfo - describes the destination format of the pixels.
1843     * @param dest - If provided, the pixels will be copied into the allocated buffer allowing
1844     *        access to the pixels without allocating a new TypedArray.
1845     * @param bytesPerRow - number of bytes per row. Must be provided if dest is set. This
1846     *        depends on destination ColorType. For example, it must be at least 4 * width for
1847     *        the 8888 color type.
1848     * @returns a TypedArray appropriate for the specified ColorType. Note that 16 bit floats are
1849     *          not supported in JS, so that colorType corresponds to raw bytes Uint8Array.
1850     */
1851    readPixels(srcX: number, srcY: number, imageInfo: ImageInfo, dest?: MallocObj,
1852               bytesPerRow?: number): Uint8Array | Float32Array | null;
1853
1854    /**
1855     * Return the width in pixels of the image.
1856     */
1857    width(): number;
1858}
1859
1860/**
1861 * See ImageFilter.h for more on this class. The objects are opaque.
1862 */
1863export type ImageFilter = EmbindObject<ImageFilter>;
1864
1865export interface ImageInfo {
1866    alphaType: AlphaType;
1867    colorSpace: ColorSpace;
1868    colorType: ColorType;
1869    height: number;
1870    width: number;
1871}
1872
1873export interface PartialImageInfo {
1874    alphaType: AlphaType;
1875    colorType: ColorType;
1876    height: number;
1877    width: number;
1878}
1879
1880/*
1881 *  Specifies sampling with bicubic coefficients
1882 */
1883export interface CubicResampler {
1884    B: number;  // 0..1
1885    C: number;  // 0..1
1886}
1887
1888/**
1889 * Specifies sampling using filter and mipmap options
1890 */
1891export interface FilterOptions {
1892    filter: FilterMode;
1893    mipmap?: MipmapMode;    // defaults to None if not specified
1894}
1895
1896/**
1897 * See SkMaskFilter.h for more on this class. The objects are opaque.
1898 */
1899export type MaskFilter = EmbindObject<MaskFilter>;
1900
1901/**
1902 * See SkPaint.h for more information on this class.
1903 */
1904export interface Paint extends EmbindObject<Paint> {
1905    /**
1906     * Returns a copy of this paint.
1907     */
1908    copy(): Paint;
1909
1910    /**
1911     * Returns the blend mode, that is, the mode used to combine source color
1912     * with destination color.
1913     */
1914    getBlendMode(): BlendMode;
1915
1916    /**
1917     * Retrieves the alpha and RGB unpremultiplied. RGB are extended sRGB values
1918     * (sRGB gamut, and encoded with the sRGB transfer function).
1919     */
1920    getColor(): Color;
1921
1922    /**
1923     * Returns the geometry drawn at the beginning and end of strokes.
1924     */
1925    getStrokeCap(): StrokeCap;
1926
1927    /**
1928     * Returns the geometry drawn at the corners of strokes.
1929     */
1930    getStrokeJoin(): StrokeJoin;
1931
1932    /**
1933     *  Returns the limit at which a sharp corner is drawn beveled.
1934     */
1935    getStrokeMiter(): number;
1936
1937    /**
1938     * Returns the thickness of the pen used to outline the shape.
1939     */
1940    getStrokeWidth(): number;
1941
1942    /**
1943     * Replaces alpha, leaving RGBA unchanged. 0 means fully transparent, 1.0 means opaque.
1944     * @param alpha
1945     */
1946    setAlphaf(alpha: number): void;
1947
1948    /**
1949     * Requests, but does not require, that edge pixels draw opaque or with
1950     * partial transparency.
1951     * @param aa
1952     */
1953    setAntiAlias(aa: boolean): void;
1954
1955    /**
1956     * Sets the blend mode that is, the mode used to combine source color
1957     * with destination color.
1958     * @param mode
1959     */
1960    setBlendMode(mode: BlendMode): void;
1961
1962    /**
1963     * Sets alpha and RGB used when stroking and filling. The color is four floating
1964     * point values, unpremultiplied. The color values are interpreted as being in
1965     * the provided colorSpace.
1966     * @param color
1967     * @param colorSpace - defaults to sRGB
1968     */
1969    setColor(color: InputColor, colorSpace?: ColorSpace): void;
1970
1971    /**
1972     * Sets alpha and RGB used when stroking and filling. The color is four floating
1973     * point values, unpremultiplied. The color values are interpreted as being in
1974     * the provided colorSpace.
1975     * @param r
1976     * @param g
1977     * @param b
1978     * @param a
1979     * @param colorSpace - defaults to sRGB
1980     */
1981    setColorComponents(r: number, g: number, b: number, a: number, colorSpace?: ColorSpace): void;
1982
1983    /**
1984     * Sets the current color filter, replacing the existing one if there was one.
1985     * @param filter
1986     */
1987    setColorFilter(filter: ColorFilter): void;
1988
1989    /**
1990     * Sets the color used when stroking and filling. The color values are interpreted as being in
1991     * the provided colorSpace.
1992     * @param color
1993     * @param colorSpace - defaults to sRGB.
1994     */
1995    setColorInt(color: ColorInt, colorSpace?: ColorSpace): void;
1996
1997    /**
1998     * Sets the current image filter, replacing the existing one if there was one.
1999     * @param filter
2000     */
2001    setImageFilter(filter: ImageFilter): void;
2002
2003    /**
2004     * Sets the current mask filter, replacing the existing one if there was one.
2005     * @param filter
2006     */
2007    setMaskFilter(filter: MaskFilter): void;
2008
2009    /**
2010     * Sets the current path effect, replacing the existing one if there was one.
2011     * @param effect
2012     */
2013    setPathEffect(effect: PathEffect): void;
2014
2015    /**
2016     * Sets the current shader, replacing the existing one if there was one.
2017     * @param shader
2018     */
2019    setShader(shader: Shader): void;
2020
2021    /**
2022     * Sets the geometry drawn at the beginning and end of strokes.
2023     * @param cap
2024     */
2025    setStrokeCap(cap: StrokeCap): void;
2026
2027    /**
2028     * Sets the geometry drawn at the corners of strokes.
2029     * @param join
2030     */
2031    setStrokeJoin(join: StrokeJoin): void;
2032
2033    /**
2034     * Sets the limit at which a sharp corner is drawn beveled.
2035     * @param limit
2036     */
2037    setStrokeMiter(limit: number): void;
2038
2039    /**
2040     * Sets the thickness of the pen used to outline the shape.
2041     * @param width
2042     */
2043    setStrokeWidth(width: number): void;
2044
2045    /**
2046     * Sets whether the geometry is filled or stroked.
2047     * @param style
2048     */
2049    setStyle(style: PaintStyle): void;
2050}
2051
2052/**
2053 * See SkPath.h for more information on this class.
2054 */
2055export interface Path extends EmbindObject<Path> {
2056    /**
2057     * Appends arc to Path, as the start of new contour. Arc added is part of ellipse
2058     * bounded by oval, from startAngle through sweepAngle. Both startAngle and
2059     * sweepAngle are measured in degrees, where zero degrees is aligned with the
2060     * positive x-axis, and positive sweeps extends arc clockwise.
2061     * Returns the modified path for easier chaining.
2062     * @param oval
2063     * @param startAngle
2064     * @param sweepAngle
2065     */
2066    addArc(oval: InputRect, startAngle: AngleInDegrees, sweepAngle: AngleInDegrees): Path;
2067
2068    /**
2069     * Adds oval to Path, appending kMove_Verb, four kConic_Verb, and kClose_Verb.
2070     * Oval is upright ellipse bounded by Rect oval with radii equal to half oval width
2071     * and half oval height. Oval begins at start and continues clockwise by default.
2072     * Returns the modified path for easier chaining.
2073     * @param oval
2074     * @param isCCW - if the path should be drawn counter-clockwise or not
2075     * @param startIndex - index of initial point of ellipse
2076     */
2077    addOval(oval: InputRect, isCCW?: boolean, startIndex?: number): Path;
2078
2079    /**
2080     * Takes 1, 2, 7, or 10 required args, where the first arg is always the path.
2081     * The last arg is an optional boolean and chooses between add or extend mode.
2082     * The options for the remaining args are:
2083     *   - an array of 6 or 9 parameters (perspective is optional)
2084     *   - the 9 parameters of a full matrix or
2085     *     the 6 non-perspective params of a matrix.
2086     * Returns the modified path for easier chaining (or null if params were incorrect).
2087     * @param args
2088     */
2089    addPath(...args: any[]): Path | null;
2090
2091    /**
2092     * Adds contour created from array of n points, adding (count - 1) line segments.
2093     * Contour added starts at pts[0], then adds a line for every additional point
2094     * in pts array. If close is true, appends kClose_Verb to Path, connecting
2095     * pts[count - 1] and pts[0].
2096     * Returns the modified path for easier chaining.
2097     * @param points
2098     * @param close - if true, will add a line connecting last point to the first point.
2099     */
2100    addPoly(points: InputFlattenedPointArray, close: boolean): Path;
2101
2102    /**
2103     * Adds Rect to Path, appending kMove_Verb, three kLine_Verb, and kClose_Verb,
2104     * starting with top-left corner of Rect; followed by top-right, bottom-right,
2105     * and bottom-left if isCCW is false; or followed by bottom-left,
2106     * bottom-right, and top-right if isCCW is true.
2107     * Returns the modified path for easier chaining.
2108     * @param rect
2109     * @param isCCW
2110     */
2111    addRect(rect: InputRect, isCCW?: boolean): Path;
2112
2113    /**
2114     * Adds rrect to Path, creating a new closed contour.
2115     * Returns the modified path for easier chaining.
2116     * @param rrect
2117     * @param isCCW
2118     */
2119    addRRect(rrect: InputRRect, isCCW?: boolean): Path;
2120
2121    /**
2122     * Adds the given verbs and associated points/weights to the path. The process
2123     * reads the first verb from verbs and then the appropriate number of points from the
2124     * FlattenedPointArray (e.g. 2 points for moveTo, 4 points for quadTo, etc). If the verb is
2125     * a conic, a weight will be read from the WeightList.
2126     * Returns the modified path for easier chaining
2127     * @param verbs - the verbs that create this path, in the order of being drawn.
2128     * @param points - represents n points with 2n floats.
2129     * @param weights - used if any of the verbs are conics, can be omitted otherwise.
2130     */
2131    addVerbsPointsWeights(verbs: VerbList, points: InputFlattenedPointArray,
2132                          weights?: WeightList): Path;
2133
2134    /**
2135     * Adds an arc to this path, emulating the Canvas2D behavior.
2136     * Returns the modified path for easier chaining.
2137     * @param x
2138     * @param y
2139     * @param radius
2140     * @param startAngle
2141     * @param endAngle
2142     * @param isCCW
2143     */
2144    arc(x: number, y: number, radius: number, startAngle: AngleInRadians, endAngle: AngleInRadians,
2145        isCCW?: boolean): Path;
2146
2147    /**
2148     * Appends arc to Path. Arc added is part of ellipse
2149     * bounded by oval, from startAngle through sweepAngle. Both startAngle and
2150     * sweepAngle are measured in degrees, where zero degrees is aligned with the
2151     * positive x-axis, and positive sweeps extends arc clockwise.
2152     * Returns the modified path for easier chaining.
2153     * @param oval
2154     * @param startAngle
2155     * @param endAngle
2156     * @param forceMoveTo
2157     */
2158    arcToOval(oval: InputRect, startAngle: AngleInDegrees, endAngle: AngleInDegrees,
2159              forceMoveTo: boolean): Path;
2160
2161    /**
2162     * Appends arc to Path. Arc is implemented by one or more conics weighted to
2163     * describe part of oval with radii (rx, ry) rotated by xAxisRotate degrees. Arc
2164     * curves from last Path Point to (x, y), choosing one of four possible routes:
2165     * clockwise or counterclockwise, and smaller or larger. See SkPath.h for more details.
2166     * Returns the modified path for easier chaining.
2167     * @param rx
2168     * @param ry
2169     * @param xAxisRotate
2170     * @param useSmallArc
2171     * @param isCCW
2172     * @param x
2173     * @param y
2174     */
2175    arcToRotated(rx: number, ry: number, xAxisRotate: AngleInDegrees, useSmallArc: boolean,
2176                 isCCW: boolean, x: number, y: number): Path;
2177
2178    /**
2179     * Appends arc to Path, after appending line if needed. Arc is implemented by conic
2180     * weighted to describe part of circle. Arc is contained by tangent from
2181     * last Path point to (x1, y1), and tangent from (x1, y1) to (x2, y2). Arc
2182     * is part of circle sized to radius, positioned so it touches both tangent lines.
2183     * Returns the modified path for easier chaining.
2184     * @param x1
2185     * @param y1
2186     * @param x2
2187     * @param y2
2188     * @param radius
2189     */
2190    arcToTangent(x1: number, y1: number, x2: number, y2: number, radius: number): Path;
2191
2192    /**
2193     * Appends CLOSE_VERB to Path. A closed contour connects the first and last point
2194     * with a line, forming a continuous loop.
2195     * Returns the modified path for easier chaining.
2196     */
2197    close(): Path;
2198
2199    /**
2200     * Returns minimum and maximum axes values of the lines and curves in Path.
2201     * Returns (0, 0, 0, 0) if Path contains no points.
2202     * Returned bounds width and height may be larger or smaller than area affected
2203     * when Path is drawn.
2204     *
2205     * Behaves identically to getBounds() when Path contains
2206     * only lines. If Path contains curves, computed bounds includes
2207     * the maximum extent of the quad, conic, or cubic; is slower than getBounds();
2208     * and unlike getBounds(), does not cache the result.
2209     * @param outputArray - if provided, the bounding box will be copied into this array instead of
2210     *                      allocating a new one.
2211     */
2212    computeTightBounds(outputArray?: Rect): Rect;
2213
2214    /**
2215     * Adds conic from last point towards (x1, y1), to (x2, y2), weighted by w.
2216     * If Path is empty, or path is closed, the last point is set to (0, 0)
2217     * before adding conic.
2218     * Returns the modified path for easier chaining.
2219     * @param x1
2220     * @param y1
2221     * @param x2
2222     * @param y2
2223     * @param w
2224     */
2225    conicTo(x1: number, y1: number, x2: number, y2: number, w: number): Path;
2226
2227    /**
2228     * Returns true if the point (x, y) is contained by Path, taking into
2229     * account FillType.
2230     * @param x
2231     * @param y
2232     */
2233    contains(x: number, y: number): boolean;
2234
2235    /**
2236     * Returns a copy of this Path.
2237     */
2238    copy(): Path;
2239
2240    /**
2241     * Returns the number of points in this path. Initially zero.
2242     */
2243    countPoints(): number;
2244
2245    /**
2246     *  Adds cubic from last point towards (x1, y1), then towards (x2, y2), ending at
2247     * (x3, y3). If Path is empty, or path is closed, the last point is set to
2248     * (0, 0) before adding cubic.
2249     * @param cpx1
2250     * @param cpy1
2251     * @param cpx2
2252     * @param cpy2
2253     * @param x
2254     * @param y
2255     */
2256    cubicTo(cpx1: number, cpy1: number, cpx2: number, cpy2: number, x: number, y: number): Path;
2257
2258    /**
2259     * Changes this path to be the dashed version of itself. This is the same effect as creating
2260     * a DashPathEffect and calling filterPath on this path.
2261     * @param on
2262     * @param off
2263     * @param phase
2264     */
2265    dash(on: number, off: number, phase: number): boolean;
2266
2267    /**
2268     * Returns true if other path is equal to this path.
2269     * @param other
2270     */
2271    equals(other: Path): boolean;
2272
2273    /**
2274     * Returns minimum and maximum axes values of Point array.
2275     * Returns (0, 0, 0, 0) if Path contains no points. Returned bounds width and height may
2276     * be larger or smaller than area affected when Path is drawn.
2277     * @param outputArray - if provided, the bounding box will be copied into this array instead of
2278     *                      allocating a new one.
2279     */
2280    getBounds(outputArray?: Rect): Rect;
2281
2282    /**
2283     * Return the FillType for this path.
2284     */
2285    getFillType(): FillType;
2286
2287    /**
2288     * Returns the Point at index in Point array. Valid range for index is
2289     * 0 to countPoints() - 1.
2290     * @param index
2291     * @param outputArray - if provided, the point will be copied into this array instead of
2292     *                      allocating a new one.
2293     */
2294    getPoint(index: number, outputArray?: Point): Point;
2295
2296    /**
2297     * Returns true if there are no verbs in the path.
2298     */
2299    isEmpty(): boolean;
2300
2301    /**
2302     * Returns true if the path is volatile; it will not be altered or discarded
2303     * by the caller after it is drawn. Path by default have volatile set false, allowing
2304     * Surface to attach a cache of data which speeds repeated drawing. If true, Surface
2305     * may not speed repeated drawing.
2306     */
2307    isVolatile(): boolean;
2308
2309    /**
2310     * Adds line from last point to (x, y). If Path is empty, or last path is closed,
2311     * last point is set to (0, 0) before adding line.
2312     * Returns the modified path for easier chaining.
2313     * @param x
2314     * @param y
2315     */
2316    lineTo(x: number, y: number): Path;
2317
2318    /**
2319     * Adds begininning of contour at the given point.
2320     * Returns the modified path for easier chaining.
2321     * @param x
2322     * @param y
2323     */
2324    moveTo(x: number, y: number): Path;
2325
2326    /**
2327     * Translates all the points in the path by dx, dy.
2328     * Returns the modified path for easier chaining.
2329     * @param dx
2330     * @param dy
2331     */
2332    offset(dx: number, dy: number): Path;
2333
2334    /**
2335     * Combines this path with the other path using the given PathOp. Returns false if the operation
2336     * fails.
2337     * @param other
2338     * @param op
2339     */
2340    op(other: Path, op: PathOp): boolean;
2341
2342    /**
2343     * Adds quad from last point towards (x1, y1), to (x2, y2).
2344     * If Path is empty, or path is closed, last point is set to (0, 0) before adding quad.
2345     * Returns the modified path for easier chaining.
2346     * @param x1
2347     * @param y1
2348     * @param x2
2349     * @param y2
2350     */
2351    quadTo(x1: number, y1: number, x2: number, y2: number): Path;
2352
2353    /**
2354     * Relative version of arcToRotated.
2355     * @param rx
2356     * @param ry
2357     * @param xAxisRotate
2358     * @param useSmallArc
2359     * @param isCCW
2360     * @param dx
2361     * @param dy
2362     */
2363    rArcTo(rx: number, ry: number, xAxisRotate: AngleInDegrees, useSmallArc: boolean,
2364           isCCW: boolean, dx: number, dy: number): Path;
2365
2366    /**
2367     * Relative version of conicTo.
2368     * @param dx1
2369     * @param dy1
2370     * @param dx2
2371     * @param dy2
2372     * @param w
2373     */
2374    rConicTo(dx1: number, dy1: number, dx2: number, dy2: number, w: number): Path;
2375
2376    /**
2377     * Relative version of cubicTo.
2378     * @param cpx1
2379     * @param cpy1
2380     * @param cpx2
2381     * @param cpy2
2382     * @param x
2383     * @param y
2384     */
2385    rCubicTo(cpx1: number, cpy1: number, cpx2: number, cpy2: number, x: number, y: number): Path;
2386
2387    /**
2388     * Sets Path to its initial state.
2389     * Removes verb array, point array, and weights, and sets FillType to Winding.
2390     * Internal storage associated with Path is released
2391     */
2392    reset(): void;
2393
2394    /**
2395     * Sets Path to its initial state.
2396     * Removes verb array, point array, and weights, and sets FillType to Winding.
2397     * Internal storage associated with Path is *not* released.
2398     * Use rewind() instead of reset() if Path storage will be reused and performance
2399     * is critical.
2400     */
2401    rewind(): void;
2402
2403    /**
2404     * Relative version of lineTo.
2405     * @param x
2406     * @param y
2407     */
2408    rLineTo(x: number, y: number): Path;
2409
2410    /**
2411     * Relative version of moveTo.
2412     * @param x
2413     * @param y
2414     */
2415    rMoveTo(x: number, y: number): Path;
2416
2417    /**
2418     * Relative version of quadTo.
2419     * @param x1
2420     * @param y1
2421     * @param x2
2422     * @param y2
2423     */
2424    rQuadTo(x1: number, y1: number, x2: number, y2: number): Path;
2425
2426    /**
2427     * Sets FillType, the rule used to fill Path.
2428     * @param fill
2429     */
2430    setFillType(fill: FillType): void;
2431
2432    /**
2433     * Specifies whether Path is volatile; whether it will be altered or discarded
2434     * by the caller after it is drawn. Path by default have volatile set false.
2435     *
2436     * Mark animating or temporary paths as volatile to improve performance.
2437     * Mark unchanging Path non-volatile to improve repeated rendering.
2438     * @param volatile
2439     */
2440    setIsVolatile(volatile: boolean): void;
2441
2442    /**
2443     * Set this path to a set of non-overlapping contours that describe the
2444     * same area as the original path.
2445     * The curve order is reduced where possible so that cubics may
2446     * be turned into quadratics, and quadratics maybe turned into lines.
2447     *
2448     * Returns true if operation was able to produce a result.
2449     */
2450    simplify(): boolean;
2451
2452    /**
2453     * Turns this path into the filled equivalent of the stroked path. Returns null if the operation
2454     * fails (e.g. the path is a hairline).
2455     * @param opts - describe how stroked path should look.
2456     */
2457    stroke(opts?: StrokeOpts): Path | null;
2458
2459    /**
2460     * Serializes the contents of this path as a series of commands.
2461     */
2462    toCmds(): PathCommand[];
2463
2464    /**
2465     * Returns this path as an SVG string.
2466     */
2467    toSVGString(): string;
2468
2469    /**
2470     * Takes a 3x3 matrix as either an array or as 9 individual params.
2471     * @param args
2472     */
2473    transform(...args: any[]): Path;
2474
2475    /**
2476     * Take start and stop "t" values (values between 0...1), and modify this path such that
2477     * it is a subset of the original path.
2478     * The trim values apply to the entire path, so if it contains several contours, all of them
2479     * are including in the calculation.
2480     * Null is returned if either input value is NaN.
2481     * @param startT - a value in the range [0.0, 1.0]. 0.0 is the beginning of the path.
2482     * @param stopT  - a value in the range [0.0, 1.0]. 1.0 is the end of the path.
2483     * @param isComplement
2484     */
2485    trim(startT: number, stopT: number, isComplement: boolean): Path | null;
2486}
2487
2488/**
2489 * See SkPathEffect.h for more on this class. The objects are opaque.
2490 */
2491export type PathEffect = EmbindObject<PathEffect>;
2492
2493/**
2494 * See SkPicture.h for more information on this class.
2495 *
2496 * Of note, SkPicture is *not* what is colloquially thought of as a "picture" (what we
2497 * call a bitmap). An SkPicture is a series of draw commands.
2498 */
2499export interface SkPicture extends EmbindObject<SkPicture> {
2500    /**
2501     * Returns the serialized format of this SkPicture. The format may change at anytime and
2502     * no promises are made for backwards or forward compatibility.
2503     */
2504    serialize(): Uint8Array | null;
2505}
2506
2507export interface PictureRecorder extends EmbindObject<PictureRecorder> {
2508    /**
2509     * Returns a canvas on which to draw. When done drawing, call finishRecordingAsPicture()
2510     *
2511     * @param bounds - a rect to cull the results.
2512     */
2513    beginRecording(bounds: InputRect): Canvas;
2514
2515    /**
2516     * Returns the captured draw commands as a picture and invalidates the canvas returned earlier.
2517     */
2518    finishRecordingAsPicture(): SkPicture;
2519}
2520
2521/**
2522 * See SkRuntimeEffect.h for more details.
2523 */
2524export interface RuntimeEffect extends EmbindObject<RuntimeEffect> {
2525    /**
2526     * Returns a shader executed using the given uniform data.
2527     * @param uniforms
2528     * @param isOpaque
2529     * @param localMatrix
2530     */
2531    makeShader(uniforms: Float32Array | number[], isOpaque?: boolean,
2532               localMatrix?: InputMatrix): Shader;
2533
2534    /**
2535     * Returns a shader executed using the given uniform data and the children as inputs.
2536     * @param uniforms
2537     * @param isOpaque
2538     * @param children
2539     * @param localMatrix
2540     */
2541    makeShaderWithChildren(uniforms: Float32Array | number[], isOpaque?: boolean,
2542                           children?: Shader[], localMatrix?: InputMatrix): Shader;
2543
2544    /**
2545     * Returns the nth uniform from the effect.
2546     * @param index
2547     */
2548    getUniform(index: number): SkSLUniform;
2549
2550    /**
2551     * Returns the number of uniforms on the effect.
2552     */
2553    getUniformCount(): number;
2554
2555    /**
2556     * Returns the total number of floats across all uniforms on the effect. This is the length
2557     * of the uniforms array expected by makeShader. For example, an effect with a single float3
2558     * uniform, would return 1 from `getUniformCount()`, but 3 from `getUniformFloatCount()`.
2559     */
2560    getUniformFloatCount(): number;
2561
2562    /**
2563     * Returns the name of the nth effect uniform.
2564     * @param index
2565     */
2566    getUniformName(index: number): string;
2567}
2568
2569/**
2570 * See SkShader.h for more on this class. The objects are opaque.
2571 */
2572export type Shader = EmbindObject<Shader>;
2573
2574export interface Surface extends EmbindObject<Surface> {
2575    /**
2576     * Clean up the surface and any extra memory.
2577     * [Deprecated]: In the future, calls to delete() will be sufficient to clean up the memory.
2578     */
2579    dispose(): void;
2580
2581    /**
2582     * Make sure any queued draws are sent to the screen or the GPU.
2583     */
2584    flush(): void;
2585
2586    /**
2587     * Return a canvas that is backed by this surface. Any draws to the canvas will (eventually)
2588     * show up on the surface. The returned canvas is owned by the surface and does NOT need to
2589     * be cleaned up by the client.
2590     */
2591    getCanvas(): Canvas;
2592
2593    /**
2594     * Returns the height of this surface in pixels.
2595     */
2596    height(): number;
2597
2598    /**
2599     * Returns the ImageInfo associated with this surface.
2600     */
2601    imageInfo(): ImageInfo;
2602
2603    /**
2604     * Returns current contents of the surface as an Image. This image will be optimized to be
2605     * drawn to another surface of the same type. For example, if this surface is backed by the
2606     * GPU, the returned Image will be backed by a GPU texture.
2607     */
2608    makeImageSnapshot(bounds?: InputIRect): Image;
2609
2610    /**
2611     * Returns a compatible Surface, haring the same raster or GPU properties of the original.
2612     * The pixels are not shared.
2613     * @param info - width, height, etc of the Surface.
2614     */
2615    makeSurface(info: ImageInfo): Surface;
2616
2617    /**
2618     * Returns if this Surface is a GPU-backed surface or not.
2619     */
2620    reportBackendTypeIsGPU(): boolean;
2621
2622    /**
2623     * If this surface is GPU-backed, return the sample count of the surface.
2624     */
2625    sampleCnt(): number;
2626
2627    /**
2628     * Returns the width of this surface in pixels.
2629     */
2630    width(): number;
2631}
2632
2633/**
2634 * See SkTextBlob.h for more on this class. The objects are opaque.
2635 */
2636export type TextBlob = EmbindObject<TextBlob>;
2637
2638/**
2639 * See SkTypeface.h for more on this class. The objects are opaque.
2640 */
2641export type Typeface = EmbindObject<Typeface>;
2642
2643/**
2644 * See SkVertices.h for more on this class.
2645 */
2646export interface Vertices extends EmbindObject<Vertices> {
2647    /**
2648     * Return the bounding area for the vertices.
2649     * @param outputArray - if provided, the bounding box will be copied into this array instead of
2650     *                      allocating a new one.
2651     */
2652    bounds(outputArray?: Rect): Rect;
2653
2654    /**
2655     * Return a unique ID for this vertices object.
2656     */
2657    uniqueID(): number;
2658}
2659
2660export interface SkottieAnimation extends EmbindObject<SkottieAnimation> {
2661    /**
2662     * Returns the animation duration in seconds.
2663     */
2664    duration(): number;
2665    /**
2666     * Returns the animation frame rate (frames / second).
2667     */
2668    fps(): number;
2669
2670    /**
2671     * Draws current animation frame. Must call seek or seekFrame first.
2672     * @param canvas
2673     * @param dstRect
2674     */
2675    render(canvas: Canvas, dstRect?: InputRect): void;
2676
2677    /**
2678     * [deprecated] - use seekFrame
2679     * @param t - value from [0.0, 1.0]; 0 is first frame, 1 is final frame.
2680     * @param damageRect - will copy damage frame into this if provided.
2681     */
2682    seek(t: number, damageRect?: Rect): Rect;
2683
2684    /**
2685     * Update the animation state to match |t|, specified as a frame index
2686     * i.e. relative to duration() * fps().
2687     *
2688     * Returns the rectangle that was affected by this animation.
2689     *
2690     * @param frame - Fractional values are allowed and meaningful - e.g.
2691     *                0.0 -> first frame
2692     *                1.0 -> second frame
2693     *                0.5 -> halfway between first and second frame
2694     * @param damageRect - will copy damage frame into this if provided.
2695     */
2696    seekFrame(frame: number, damageRect?: Rect): Rect;
2697
2698    /**
2699     * Return the size of this animation.
2700     * @param outputSize - If provided, the size will be copied into here as width, height.
2701     */
2702    size(outputSize?: Point): Point;
2703    version(): string;
2704}
2705
2706/**
2707 * Options used for Path.stroke(). If an option is omitted, a sensible default will be used.
2708 */
2709export interface StrokeOpts {
2710    /** The width of the stroked lines. */
2711    width?: number;
2712    miter_limit?: number;
2713    /**
2714     * if > 1, increase precision, else if (0 < resScale < 1) reduce precision to
2715     * favor speed and size
2716     */
2717    precision?: number;
2718    join?: StrokeJoin;
2719    cap?: StrokeCap;
2720}
2721
2722export interface StrutStyle {
2723    strutEnabled?: boolean;
2724    fontFamilies?: string[];
2725    fontStyle?: FontStyle;
2726    fontSize?: number;
2727    heightMultiplier?: number;
2728    halfLeading?: boolean;
2729    leading?: number;
2730    forceStrutHeight?: boolean;
2731}
2732
2733export interface TextFontFeatures {
2734    name: string;
2735    value: number;
2736}
2737
2738export interface TextShadow {
2739    color?: InputColor;
2740    /**
2741     * 2d array for x and y offset. Defaults to [0, 0]
2742     */
2743    offset?: number[];
2744    blurRadius?: number;
2745}
2746
2747export interface TextStyle {
2748    backgroundColor?: InputColor;
2749    color?: InputColor;
2750    decoration?: number;
2751    decorationColor?: InputColor;
2752    decorationThickness?: number;
2753    decrationStyle?: DecorationStyle;
2754    fontFamilies?: string[];
2755    fontFeatures?: TextFontFeatures[];
2756    fontSize?: number;
2757    fontStyle?: FontStyle;
2758    foregroundColor?: InputColor;
2759    heightMultiplier?: number;
2760    halfLeading?: boolean;
2761    letterSpacing?: number;
2762    locale?: string;
2763    shadows?: TextShadow[];
2764    textBaseline?: TextBaseline;
2765    wordSpacing?: number;
2766}
2767
2768export interface TonalColorsInput {
2769    ambient: InputColor;
2770    spot: InputColor;
2771}
2772
2773export interface TonalColorsOutput {
2774    ambient: Color;
2775    spot: Color;
2776}
2777
2778export interface TypefaceFontProvider extends EmbindObject<TypefaceFontProvider> {
2779    /**
2780     * Registers a given typeface with the given family name (ignoring whatever name the
2781     * typface has for itself).
2782     * @param bytes - the raw bytes for a typeface.
2783     * @param family
2784     */
2785    registerFont(bytes: ArrayBuffer | Uint8Array, family: string): void;
2786}
2787
2788export interface URange {
2789    start: number;
2790    end: number;
2791}
2792
2793/**
2794 * Options for configuring a WebGL context. If an option is omitted, a sensible default will
2795 * be used. These are defined by the WebGL standards.
2796 */
2797export interface WebGLOptions {
2798    alpha?: number;
2799    antialias?: number;
2800    depth?: number;
2801    enableExtensionsByDefault?: number;
2802    explicitSwapControl?: number;
2803    failIfMajorPerformanceCaveat?: number;
2804    majorVersion?: number;
2805    minorVersion?: number;
2806    preferLowPowerToHighPerformance?: number;
2807    premultipliedAlpha?: number;
2808    preserveDrawingBuffer?: number;
2809    renderViaOffscreenBackBuffer?: number;
2810    stencil?: number;
2811}
2812
2813export interface DefaultConstructor<T> {
2814    new (): T;
2815}
2816
2817export interface ColorMatrixHelpers {
2818    /**
2819     * Returns a new ColorMatrix that is the result of multiplying outer*inner
2820     * @param outer
2821     * @param inner
2822     */
2823    concat(outer: ColorMatrix, inner: ColorMatrix): ColorMatrix;
2824
2825    /**
2826     * Returns an identity ColorMatrix.
2827     */
2828    identity(): ColorMatrix;
2829
2830    /**
2831     * Sets the 4 "special" params that will translate the colors after they are multiplied
2832     * by the 4x4 matrix.
2833     * @param m
2834     * @param dr - delta red
2835     * @param dg - delta green
2836     * @param db - delta blue
2837     * @param da - delta alpha
2838     */
2839    postTranslate(m: ColorMatrix, dr: number, dg: number, db: number, da: number): ColorMatrix;
2840
2841    /**
2842     * Returns a new ColorMatrix that is rotated around a given axis.
2843     * @param axis - 0 for red, 1 for green, 2 for blue
2844     * @param sine - sin(angle)
2845     * @param cosine - cos(angle)
2846     */
2847    rotated(axis: number, sine: number, cosine: number): ColorMatrix;
2848
2849    /**
2850     * Returns a new ColorMatrix that scales the colors as specified.
2851     * @param redScale
2852     * @param greenScale
2853     * @param blueScale
2854     * @param alphaScale
2855     */
2856    scaled(redScale: number, greenScale: number, blueScale: number,
2857           alphaScale: number): ColorMatrix;
2858}
2859
2860/**
2861 * A constructor for making an ImageData that is compatible with the Canvas2D emulation code.
2862 */
2863export interface ImageDataConstructor {
2864    new (width: number, height: number): EmulatedImageData;
2865    new (pixels: Uint8ClampedArray, width: number, height: number): EmulatedImageData;
2866}
2867
2868/**
2869 * TODO(kjlubick) Make this API return Float32Arrays
2870 */
2871export interface Matrix3x3Helpers {
2872    /**
2873     * Returns a new identity 3x3 matrix.
2874     */
2875    identity(): number[];
2876
2877    /**
2878     * Returns the inverse of the given 3x3 matrix or null if it is not invertible.
2879     * @param m
2880     */
2881    invert(m: Matrix3x3 | number[]): number[] | null;
2882
2883    /**
2884     * Maps the given 2d points according to the given 3x3 matrix.
2885     * @param m
2886     * @param points - the flattened points to map; the results are computed in place on this array.
2887     */
2888    mapPoints(m: Matrix3x3 | number[], points: number[]): number[];
2889
2890    /**
2891     * Multiplies the provided 3x3 matrices together from left to right.
2892     * @param matrices
2893     */
2894    multiply(...matrices: Array<(Matrix3x3 | number[])>): number[];
2895
2896    /**
2897     * Returns a new 3x3 matrix representing a rotation by n radians.
2898     * @param radians
2899     * @param px - the X value to rotate around, defaults to 0.
2900     * @param py - the Y value to rotate around, defaults to 0.
2901     */
2902    rotated(radians: AngleInRadians, px?: number, py?: number): number[];
2903
2904    /**
2905     * Returns a new 3x3 matrix representing a scale in the x and y directions.
2906     * @param sx - the scale in the X direction.
2907     * @param sy - the scale in the Y direction.
2908     * @param px - the X value to scale from, defaults to 0.
2909     * @param py - the Y value to scale from, defaults to 0.
2910     */
2911    scaled(sx: number, sy: number, px?: number, py?: number): number[];
2912
2913    /**
2914     * Returns a new 3x3 matrix representing a scale in the x and y directions.
2915     * @param kx - the kurtosis in the X direction.
2916     * @param ky - the kurtosis in the Y direction.
2917     * @param px - the X value to skew from, defaults to 0.
2918     * @param py - the Y value to skew from, defaults to 0.
2919     */
2920    skewed(kx: number, ky: number, px?: number, py?: number): number[];
2921
2922    /**
2923     * Returns a new 3x3 matrix representing a translation in the x and y directions.
2924     * @param dx
2925     * @param dy
2926     */
2927    translated(dx: number, dy: number): number[];
2928}
2929
2930/**
2931 * See SkM44.h for more details.
2932 */
2933export interface Matrix4x4Helpers {
2934    /**
2935     * Returns a new identity 4x4 matrix.
2936     */
2937    identity(): number[];
2938
2939    /**
2940     * Returns the inverse of the given 4x4 matrix or null if it is not invertible.
2941     * @param matrix
2942     */
2943    invert(matrix: Matrix4x4 | number[]): number[] | null;
2944
2945    /**
2946     * Return a new 4x4 matrix representing a camera at eyeVec, pointed at centerVec.
2947     * @param eyeVec
2948     * @param centerVec
2949     * @param upVec
2950     */
2951    lookat(eyeVec: Vector3, centerVec: Vector3, upVec: Vector3): number[];
2952
2953    /**
2954     * Multiplies the provided 4x4 matrices together from left to right.
2955     * @param matrices
2956     */
2957    multiply(...matrices: Array<(Matrix4x4 | number[])>): number[];
2958
2959    /**
2960     * Returns the inverse of the given 4x4 matrix or throws if it is not invertible.
2961     * @param matrix
2962     */
2963    mustInvert(matrix: Matrix4x4 | number[]): number[];
2964
2965    /**
2966     * Returns a new 4x4 matrix representing a perspective.
2967     * @param near
2968     * @param far
2969     * @param radians
2970     */
2971    perspective(near: number, far: number, radians: AngleInRadians): number[];
2972
2973    /**
2974     * Returns the value at the specified row and column of the given 4x4 matrix.
2975     * @param matrix
2976     * @param row
2977     * @param col
2978     */
2979    rc(matrix: Matrix4x4 | number[], row: number, col: number): number;
2980
2981    /**
2982     * Returns a new 4x4 matrix representing a rotation around the provided vector.
2983     * @param axis
2984     * @param radians
2985     */
2986    rotated(axis: Vector3, radians: AngleInRadians): number[];
2987
2988    /**
2989     * Returns a new 4x4 matrix representing a rotation around the provided vector.
2990     * Rotation is provided redundantly as both sin and cos values.
2991     * This rotate can be used when you already have the cosAngle and sinAngle values
2992     * so you don't have to atan(cos/sin) to call roatated() which expects an angle in radians.
2993     * This does no checking! Behavior for invalid sin or cos values or non-normalized axis vectors
2994     * is incorrect. Prefer rotated().
2995     * @param axis
2996     * @param sinAngle
2997     * @param cosAngle
2998     */
2999    rotatedUnitSinCos(axis: Vector3, sinAngle: number, cosAngle: number): number[];
3000
3001    /**
3002     * Returns a new 4x4 matrix representing a scale by the provided vector.
3003     * @param vec
3004     */
3005    scaled(vec: Vector3): number[];
3006
3007    /**
3008     * Returns a new 4x4 matrix that sets up a 3D perspective view from a given camera.
3009     * @param area - describes the viewport. (0, 0, canvas_width, canvas_height) suggested.
3010     * @param zScale - describes the scale of the z axis. min(width, height)/2 suggested
3011     * @param cam
3012     */
3013    setupCamera(area: InputRect, zScale: number, cam: Camera): number[];
3014
3015    /**
3016     * Returns a new 4x4 matrix representing a translation by the provided vector.
3017     * @param vec
3018     */
3019    translated(vec: Vector3): number[];
3020
3021    /**
3022     * Returns a new 4x4 matrix that is the transpose of this 4x4 matrix.
3023     * @param matrix
3024     */
3025    transpose(matrix: Matrix4x4 | number[]): number[];
3026}
3027
3028export interface ParagraphBuilderFactory {
3029    /**
3030     * Creates a ParagraphBuilder using the fonts available from the given font manager.
3031     * @param style
3032     * @param fontManager
3033     */
3034    Make(style: ParagraphStyle, fontManager: FontMgr): ParagraphBuilder;
3035
3036    /**
3037     * Creates a ParagraphBuilder using the fonts available from the given font provider.
3038     * @param style
3039     * @param fontSrc
3040     */
3041    MakeFromFontProvider(style: ParagraphStyle, fontSrc: TypefaceFontProvider): ParagraphBuilder;
3042
3043    /**
3044     * Return a shaped array of lines
3045     */
3046    ShapeText(text: string, runs: FontBlock[], width?: number): ShapedLine[];
3047}
3048
3049export interface ParagraphStyleConstructor {
3050    /**
3051     * Fills out all optional fields with defaults. The emscripten bindings complain if there
3052     * is a field undefined and it was expecting a float (for example).
3053     * @param ps
3054     */
3055    new(ps: ParagraphStyle): ParagraphStyle;
3056}
3057
3058/**
3059 * See SkColorFilter.h for more.
3060 */
3061export interface ColorFilterFactory {
3062    /**
3063     * Makes a color filter with the given color and blend mode.
3064     * @param color
3065     * @param mode
3066     */
3067    MakeBlend(color: InputColor, mode: BlendMode): ColorFilter;
3068
3069    /**
3070     * Makes a color filter composing two color filters.
3071     * @param outer
3072     * @param inner
3073     */
3074    MakeCompose(outer: ColorFilter, inner: ColorFilter): ColorFilter;
3075
3076    /**
3077     * Makes a color filter that is linearly interpolated between two other color filters.
3078     * @param t - a float in the range of 0.0 to 1.0.
3079     * @param dst
3080     * @param src
3081     */
3082    MakeLerp(t: number, dst: ColorFilter, src: ColorFilter): ColorFilter;
3083
3084    /**
3085     * Makes a color filter that converts between linear colors and sRGB colors.
3086     */
3087    MakeLinearToSRGBGamma(): ColorFilter;
3088
3089    /**
3090     * Creates a color filter using the provided color matrix.
3091     * @param cMatrix
3092     */
3093    MakeMatrix(cMatrix: InputColorMatrix): ColorFilter;
3094
3095    /**
3096     * Makes a color filter that converts between sRGB colors and linear colors.
3097     */
3098    MakeSRGBToLinearGamma(): ColorFilter;
3099}
3100
3101export interface ContourMeasureIterConstructor {
3102    /**
3103     * Creates an ContourMeasureIter with the given path.
3104     * @param path
3105     * @param forceClosed - if path should be forced close before measuring it.
3106     * @param resScale - controls the precision of the measure. values > 1 increase the
3107     *                   precision (and possibly slow down the computation).
3108     */
3109    new (path: Path, forceClosed: boolean, resScale: number): ContourMeasureIter;
3110}
3111
3112/**
3113 * See SkFont.h for more.
3114 */
3115export interface FontConstructor extends DefaultConstructor<Font> {
3116    /**
3117     * Constructs Font with default values with Typeface.
3118     * @param face
3119     * @param size - font size in points. If not specified, uses a default value.
3120     */
3121    new (face: Typeface | null, size?: number): Font;
3122
3123    /**
3124     * Constructs Font with default values with Typeface and size in points,
3125     * horizontal scale, and horizontal skew. Horizontal scale emulates condensed
3126     * and expanded fonts. Horizontal skew emulates oblique fonts.
3127     * @param face
3128     * @param size
3129     * @param scaleX
3130     * @param skewX
3131     */
3132    new (face: Typeface | null, size: number, scaleX: number, skewX: number): Font;
3133}
3134
3135export interface FontMgrFactory {
3136    /**
3137     * Create an FontMgr with the created font data. Returns null if buffers was empty.
3138     * @param buffers
3139     */
3140    FromData(...buffers: ArrayBuffer[]): FontMgr | null;
3141
3142    /**
3143     * Return the default FontMgr. This will generally have 0 or 1 fonts in it, depending on if
3144     * the demo monospace font was compiled in.
3145     */
3146    RefDefault(): FontMgr;
3147}
3148
3149/**
3150 * See effects/ImageFilters.h for more.
3151 */
3152export interface ImageFilterFactory {
3153    /**
3154     * Create a filter that blurs its input by the separate X and Y sigmas. The provided tile mode
3155     * is used when the blur kernel goes outside the input image.
3156     *
3157     * @param sigmaX - The Gaussian sigma value for blurring along the X axis.
3158     * @param sigmaY - The Gaussian sigma value for blurring along the Y axis.
3159     * @param mode
3160     * @param input - if null, it will use the dynamic source image (e.g. a saved layer)
3161     */
3162    MakeBlur(sigmaX: number, sigmaY: number, mode: TileMode,
3163             input: ImageFilter | null): ImageFilter;
3164
3165    /**
3166     * Create a filter that applies the color filter to the input filter results.
3167     * @param cf
3168     * @param input - if null, it will use the dynamic source image (e.g. a saved layer)
3169     */
3170    MakeColorFilter(cf: ColorFilter, input: ImageFilter | null): ImageFilter;
3171
3172    /**
3173     * Create a filter that composes 'inner' with 'outer', such that the results of 'inner' are
3174     * treated as the source bitmap passed to 'outer'.
3175     * If either param is null, the other param will be returned.
3176     * @param outer
3177     * @param inner - if null, it will use the dynamic source image (e.g. a saved layer)
3178     */
3179    MakeCompose(outer: ImageFilter | null, inner: ImageFilter | null): ImageFilter;
3180
3181    /**
3182     * Create a filter that transforms the input image by 'matrix'. This matrix transforms the
3183     * local space, which means it effectively happens prior to any transformation coming from the
3184     * Canvas initiating the filtering.
3185     * @param matr
3186     * @param fq
3187     * @param input - if null, it will use the dynamic source image (e.g. a saved layer)
3188     */
3189    MakeMatrixTransform(matr: InputMatrix, fq: FilterQuality,
3190                        input: ImageFilter | null): ImageFilter;
3191}
3192
3193/**
3194 * See SkMaskFilter.h for more details.
3195 */
3196export interface MaskFilterFactory {
3197    /**
3198     * Create a blur maskfilter
3199     * @param style
3200     * @param sigma - Standard deviation of the Gaussian blur to apply. Must be > 0.
3201     * @param respectCTM - if true the blur's sigma is modified by the CTM.
3202     */
3203    MakeBlur(style: BlurStyle, sigma: number, respectCTM: boolean): MaskFilter;
3204}
3205
3206/**
3207 * Contains the ways to create an Path.
3208 */
3209export interface PathConstructorAndFactory extends DefaultConstructor<Path> {
3210    /**
3211     * Creates a new path from the given list of path commands. If this fails, null will be
3212     * returned instead.
3213     * @param cmds
3214     */
3215    MakeFromCmds(cmds: PathCommand[]): Path | null;
3216
3217    /**
3218     * Creates a new path by combining the given paths according to op. If this fails, null will
3219     * be returned instead.
3220     * @param one
3221     * @param two
3222     * @param op
3223     */
3224    MakeFromOp(one: Path, two: Path, op: PathOp): Path | null;
3225
3226    /**
3227     * Creates a new path from the provided SVG string. If this fails, null will be
3228     * returned instead.
3229     * @param str
3230     */
3231    MakeFromSVGString(str: string): Path | null;
3232
3233    /**
3234     * Creates a new path using the provided verbs and associated points and weights. The process
3235     * reads the first verb from verbs and then the appropriate number of points from the
3236     * FlattenedPointArray (e.g. 2 points for moveTo, 4 points for quadTo, etc). If the verb is
3237     * a conic, a weight will be read from the WeightList.
3238     * If the data is malformed (e.g. not enough points), the resulting path will be incomplete.
3239     * @param verbs - the verbs that create this path, in the order of being drawn.
3240     * @param points - represents n points with 2n floats.
3241     * @param weights - used if any of the verbs are conics, can be omitted otherwise.
3242     */
3243    MakeFromVerbsPointsWeights(verbs: VerbList, points: InputFlattenedPointArray,
3244                               weights?: WeightList): Path;
3245}
3246
3247/**
3248 * See SkPathEffect.h for more details.
3249 */
3250export interface PathEffectFactory {
3251    /**
3252     * Returns a PathEffect that can turn sharp corners into rounded corners.
3253     * @param radius - if <=0, returns null
3254     */
3255    MakeCorner(radius: number): PathEffect | null;
3256
3257    /**
3258     * Returns a PathEffect that add dashes to the path.
3259     *
3260     * See SkDashPathEffect.h for more details.
3261     *
3262     * @param intervals - even number of entries with even indicies specifying the length of
3263     *                    the "on" intervals, and the odd indices specifying the length of "off".
3264     * @param phase - offset length into the intervals array. Defaults to 0.
3265     */
3266    MakeDash(intervals: number[], phase?: number): PathEffect;
3267
3268    /**
3269     * Returns a PathEffect that breaks path into segments of segLength length, and randomly move
3270     * the endpoints away from the original path by a maximum of deviation.
3271     * @param segLength - length of the subsegments.
3272     * @param dev - limit of the movement of the endpoints.
3273     * @param seedAssist - modifies the randomness. See SkDiscretePathEffect.h for more.
3274     */
3275    MakeDiscrete(segLength: number, dev: number, seedAssist: number): PathEffect;
3276}
3277
3278/**
3279 * See RuntimeEffect.h for more details.
3280 */
3281export interface RuntimeEffectFactory {
3282    /**
3283     * Compiles a RuntimeEffect from the given shader code.
3284     * @param sksl - Source code for a shader written in SkSL
3285     * @param callback - will be called with any compilation error. If not provided, errors will
3286     *                   be printed to console.log().
3287     */
3288    Make(sksl: string, callback?: (err: string) => void): RuntimeEffect | null;
3289}
3290
3291/**
3292 * For more information, see SkShaders.h.
3293 */
3294export interface ShaderFactory {
3295    /**
3296     * Returns a shader that combines the given shaders with a BlendMode.
3297     * @param mode
3298     * @param one
3299     * @param two
3300     */
3301    MakeBlend(mode: BlendMode, one: Shader, two: Shader): Shader;
3302
3303    /**
3304     * Returns a shader with a given color and colorspace.
3305     * @param color
3306     * @param space
3307     */
3308    MakeColor(color: InputColor, space: ColorSpace): Shader;
3309
3310    /**
3311     * Returns a shader with Perlin Fractal Noise.
3312     * See SkPerlinNoiseShader.h for more details
3313     * @param baseFreqX - base frequency in the X direction; range [0.0, 1.0]
3314     * @param baseFreqY - base frequency in the Y direction; range [0.0, 1.0]
3315     * @param octaves
3316     * @param seed
3317     * @param tileW - if this and tileH are non-zero, the frequencies will be modified so that the
3318     *                noise will be tileable for the given size.
3319     * @param tileH - if this and tileW are non-zero, the frequencies will be modified so that the
3320     *                noise will be tileable for the given size.
3321     */
3322    MakeFractalNoise(baseFreqX: number, baseFreqY: number, octaves: number, seed: number,
3323                     tileW: number, tileH: number): Shader;
3324
3325    /**
3326     * Returns a shader is a linear interpolation combines the given shaders with a BlendMode.
3327     * @param t - range of [0.0, 1.0], indicating how far we should be between one and two.
3328     * @param one
3329     * @param two
3330     */
3331    MakeLerp(t: number, one: Shader, two: Shader): Shader;
3332
3333    /**
3334     * Returns a shader that generates a linear gradient between the two specified points.
3335     * See SkGradientShader.h for more.
3336     * @param start
3337     * @param end
3338     * @param colors - colors to be distributed between start and end.
3339     * @param pos - May be null. The relative positions of colors. If supplied must be same length
3340     *              as colors.
3341     * @param mode
3342     * @param localMatrix
3343     * @param flags - By default gradients will interpolate their colors in unpremul space
3344     *                and then premultiply each of the results. By setting this to 1, the
3345     *                gradients will premultiply their colors first, and then interpolate
3346     *                between them.
3347     * @param colorSpace
3348     */
3349    MakeLinearGradient(start: InputPoint, end: InputPoint, colors: InputFlexibleColorArray,
3350                       pos: number[] | null, mode: TileMode, localMatrix?: InputMatrix,
3351                       flags?: number, colorSpace?: ColorSpace): Shader;
3352
3353    /**
3354     * Returns a shader that generates a radial gradient given the center and radius.
3355     * See SkGradientShader.h for more.
3356     * @param center
3357     * @param radius
3358     * @param colors - colors to be distributed between the center and edge.
3359     * @param pos - May be null. The relative positions of colors. If supplied must be same length
3360     *              as colors. Range [0.0, 1.0]
3361     * @param mode
3362     * @param localMatrix
3363     * @param flags - 0 to interpolate colors in unpremul, 1 to interpolate colors in premul.
3364     * @param colorSpace
3365     */
3366    MakeRadialGradient(center: InputPoint, radius: number, colors: InputFlexibleColorArray,
3367                       pos: number[] | null, mode: TileMode, localMatrix?: InputMatrix,
3368                       flags?: number, colorSpace?: ColorSpace): Shader;
3369
3370    /**
3371     * Returns a shader that generates a sweep gradient given a center.
3372     * See SkGradientShader.h for more.
3373     * @param cx
3374     * @param cy
3375     * @param colors - colors to be distributed around the center, within the provided angles.
3376     * @param pos - May be null. The relative positions of colors. If supplied must be same length
3377     *              as colors. Range [0.0, 1.0]
3378     * @param mode
3379     * @param localMatrix
3380     * @param flags - 0 to interpolate colors in unpremul, 1 to interpolate colors in premul.
3381     * @param startAngle - angle corresponding to 0.0. Defaults to 0 degrees.
3382     * @param endAngle - angle corresponding to 1.0. Defaults to 360 degrees.
3383     * @param colorSpace
3384     */
3385    MakeSweepGradient(cx: number, cy: number, colors: InputFlexibleColorArray,
3386                      pos: number[] | null, mode: TileMode, localMatrix?: InputMatrix | null,
3387                      flags?: number, startAngle?: AngleInDegrees, endAngle?: AngleInDegrees,
3388                      colorSpace?: ColorSpace): Shader;
3389
3390    /**
3391     * Returns a shader with Perlin Turbulence.
3392     * See SkPerlinNoiseShader.h for more details
3393     * @param baseFreqX - base frequency in the X direction; range [0.0, 1.0]
3394     * @param baseFreqY - base frequency in the Y direction; range [0.0, 1.0]
3395     * @param octaves
3396     * @param seed
3397     * @param tileW - if this and tileH are non-zero, the frequencies will be modified so that the
3398     *                noise will be tileable for the given size.
3399     * @param tileH - if this and tileW are non-zero, the frequencies will be modified so that the
3400     *                noise will be tileable for the given size.
3401     */
3402    MakeTurbulence(baseFreqX: number, baseFreqY: number, octaves: number, seed: number,
3403                   tileW: number, tileH: number): Shader;
3404
3405    /**
3406     * Returns a shader that generates a conical gradient given two circles.
3407     * See SkGradientShader.h for more.
3408     * @param start
3409     * @param startRadius
3410     * @param end
3411     * @param endRadius
3412     * @param colors
3413     * @param pos
3414     * @param mode
3415     * @param localMatrix
3416     * @param flags
3417     * @param colorSpace
3418     */
3419    MakeTwoPointConicalGradient(start: InputPoint, startRadius: number, end: InputPoint,
3420                                endRadius: number, colors: InputFlexibleColorArray,
3421                                pos: number[] | null, mode: TileMode, localMatrix?: InputMatrix,
3422                                flags?: number, colorSpace?: ColorSpace): Shader;
3423}
3424
3425/**
3426 * See SkTextBlob.h for more details.
3427 */
3428export interface TextBlobFactory {
3429    /**
3430     * Return a TextBlob with a single run of text.
3431     *
3432     * It does not perform typeface fallback for characters not found in the Typeface.
3433     * It does not perform kerning or other complex shaping; glyphs are positioned based on their
3434     * default advances.
3435     * @param glyphs - if using Malloc'd array, be sure to use CanvasKit.MallocGlyphIDs().
3436     * @param font
3437     */
3438    MakeFromGlyphs(glyphs: InputGlyphIDArray, font: Font): TextBlob;
3439
3440    /**
3441     * Returns a TextBlob built from a single run of text with rotation, scale, and translations.
3442     *
3443     * It uses the default character-to-glyph mapping from the typeface in the font.
3444     * @param str
3445     * @param rsxforms
3446     * @param font
3447     */
3448    MakeFromRSXform(str: string, rsxforms: InputFlattenedRSXFormArray, font: Font): TextBlob;
3449
3450    /**
3451     * Returns a TextBlob built from a single run of text with rotation, scale, and translations.
3452     *
3453     * @param glyphs - if using Malloc'd array, be sure to use CanvasKit.MallocGlyphIDs().
3454     * @param rsxforms
3455     * @param font
3456     */
3457    MakeFromRSXformGlyphs(glyphs: InputGlyphIDArray, rsxforms: InputFlattenedRSXFormArray,
3458                          font: Font): TextBlob;
3459
3460    /**
3461     * Return a TextBlob with a single run of text.
3462     *
3463     * It uses the default character-to-glyph mapping from the typeface in the font.
3464     * It does not perform typeface fallback for characters not found in the Typeface.
3465     * It does not perform kerning or other complex shaping; glyphs are positioned based on their
3466     * default advances.
3467     * @param str
3468     * @param font
3469     */
3470    MakeFromText(str: string, font: Font): TextBlob;
3471
3472    /**
3473     * Returns a TextBlob that has the glyphs following the contours of the given path.
3474     *
3475     * It is a convenience wrapper around MakeFromRSXform and ContourMeasureIter.
3476     * @param str
3477     * @param path
3478     * @param font
3479     * @param initialOffset - the length in pixels to start along the path.
3480     */
3481    MakeOnPath(str: string, path: Path, font: Font, initialOffset?: number): TextBlob;
3482}
3483
3484export interface TextStyleConstructor {
3485    /**
3486     * Fills out all optional fields with defaults. The emscripten bindings complain if there
3487     * is a field undefined and it was expecting a float (for example).
3488     * @param ts
3489     */
3490    new(ts: TextStyle): TextStyle;
3491}
3492
3493export interface TypefaceFontProviderFactory {
3494    /**
3495     * Return an empty TypefaceFontProvider
3496     */
3497    Make(): TypefaceFontProvider;
3498}
3499
3500/**
3501 * Functions for manipulating vectors. It is Loosely based off of SkV3 in SkM44.h but Skia
3502 * also has SkVec2 and Skv4. This combines them and works on vectors of any length.
3503 */
3504export interface VectorHelpers {
3505    /**
3506     * Adds 2 vectors together, term by term, returning a new Vector.
3507     * @param a
3508     * @param b
3509     */
3510    add(a: VectorN, b: VectorN): VectorN;
3511
3512    /**
3513     * Returns the cross product of the two vectors. Only works for length 3.
3514     * @param a
3515     * @param b
3516     */
3517    cross(a: Vector3, b: Vector3): Vector3;
3518
3519    /**
3520     * Returns the length(sub(a, b))
3521     * @param a
3522     * @param b
3523     */
3524    dist(a: VectorN, b: VectorN): number;
3525
3526    /**
3527     * Returns the dot product of the two vectors.
3528     * @param a
3529     * @param b
3530     */
3531    dot(a: VectorN, b: VectorN): number;
3532
3533    /**
3534     * Returns the length of this vector, which is always positive.
3535     * @param v
3536     */
3537    length(v: VectorN): number;
3538
3539    /**
3540     * Returns the length squared of this vector.
3541     * @param v
3542     */
3543    lengthSquared(v: VectorN): number;
3544
3545    /**
3546     * Returns a new vector which is v multiplied by the scalar s.
3547     * @param v
3548     * @param s
3549     */
3550    mulScalar(v: VectorN, s: number): VectorN;
3551
3552    /**
3553     * Returns a normalized vector.
3554     * @param v
3555     */
3556    normalize(v: VectorN): VectorN;
3557
3558    /**
3559     * Subtracts vector b from vector a (termwise).
3560     * @param a
3561     * @param b
3562     */
3563    sub(a: VectorN, b: VectorN): VectorN;
3564}
3565
3566/**
3567 * A PosTan is a Float32Array of length 4, representing a position and a tangent vector. In order,
3568 * the values are [px, py, tx, ty].
3569 */
3570export type PosTan = Float32Array;
3571/**
3572 * An Color is represented by 4 floats, typically with values between 0 and 1.0. In order,
3573 * the floats correspond to red, green, blue, alpha.
3574 */
3575export type Color = Float32Array;
3576export type ColorInt = number; // deprecated, prefer Color
3577/**
3578 * An ColorMatrix is a 4x4 color matrix that transforms the 4 color channels
3579 * with a 1x4 matrix that post-translates those 4 channels.
3580 * For example, the following is the layout with the scale (S) and post-transform
3581 * (PT) items indicated.
3582 * RS,  0,  0,  0 | RPT
3583 *  0, GS,  0,  0 | GPT
3584 *  0,  0, BS,  0 | BPT
3585 *  0,  0,  0, AS | APT
3586 */
3587export type ColorMatrix = Float32Array;
3588/**
3589 * An IRect is represented by 4 ints. In order, the ints correspond to left, top,
3590 * right, bottom. See Rect.h for more
3591 */
3592export type IRect = Int32Array;
3593/**
3594 * An Point is represented by 2 floats: (x, y).
3595 */
3596export type Point = Float32Array;
3597/**
3598 * An Rect is represented by 4 floats. In order, the floats correspond to left, top,
3599 * right, bottom. See Rect.h for more
3600 */
3601export type Rect = Float32Array;
3602/**
3603 * An RRect (rectangle with rounded corners) is represented by 12 floats. In order, the floats
3604 * correspond to left, top, right, bottom and then in pairs, the radiusX, radiusY for upper-left,
3605 * upper-right, lower-right, lower-left. See RRect.h for more.
3606 */
3607export type RRect = Float32Array;
3608
3609export type WebGLContextHandle = number;
3610export type AngleInDegrees = number;
3611export type AngleInRadians = number;
3612export type SaveLayerFlag = number;
3613
3614export type TypedArrayConstructor = Float32ArrayConstructor | Int32ArrayConstructor |
3615    Int16ArrayConstructor | Int8ArrayConstructor | Uint32ArrayConstructor |
3616    Uint16ArrayConstructor | Uint8ArrayConstructor;
3617export type TypedArray = Float32Array | Int32Array | Int16Array | Int8Array | Uint32Array |
3618    Uint16Array | Uint8Array;
3619
3620export type ColorIntArray = MallocObj | Uint32Array | number[];
3621/**
3622 * FlattenedPointArray represents n points by 2*n float values. In order, the values should
3623 * be the x, y for each point.
3624 */
3625export type FlattenedPointArray = Float32Array;
3626/**
3627 * FlattenedRectangleArray represents n rectangles by 4*n float values. In order, the values should
3628 * be the top, left, right, bottom point for each rectangle.
3629 */
3630export type FlattenedRectangleArray = Float32Array;
3631
3632export type GlyphIDArray = Uint16Array;
3633/**
3634 * PathCommand contains a verb and then any arguments needed to fulfill that path verb.
3635 * Examples:
3636 *   [CanvasKit.MOVE_VERB, 0, 10]
3637 *   [CanvasKit.LINE_VERB, 30, 40]
3638 * TODO(kjlubick) Make this not be a 2-d array and support typed arrays.
3639 */
3640export type PathCommand = number[];
3641/**
3642 * VerbList holds verb constants like CanvasKit.MOVE_VERB, CanvasKit.CUBIC_VERB.
3643 */
3644export type VerbList = MallocObj | Uint8Array | number[];
3645/**
3646 * WeightList holds weights for conics when making paths.
3647 */
3648export type WeightList = MallocObj | Float32Array | number[];
3649
3650export type Matrix4x4 = Float32Array;
3651export type Matrix3x3 = Float32Array;
3652export type Matrix3x2 = Float32Array;
3653/**
3654 * Vector3 represents an x, y, z coordinate or vector. It has length 3.
3655 */
3656export type Vector3 = number[];
3657
3658/**
3659 * VectorN represents a vector of length n.
3660 */
3661export type VectorN = number[];
3662
3663/**
3664 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as colors.
3665 * Length 4.
3666 */
3667export type InputColor = MallocObj | Color | number[];
3668/**
3669 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as color matrices.
3670 * Length 20.
3671 */
3672export type InputColorMatrix = MallocObj | ColorMatrix | number[];
3673/**
3674 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as glyph IDs.
3675 * Length n for n glyph IDs.
3676 */
3677export type InputGlyphIDArray = MallocObj | GlyphIDArray | number[];
3678/**
3679 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as flattened points.
3680 * Length 2 * n for n points.
3681 */
3682export type InputFlattenedPointArray = MallocObj | FlattenedPointArray | number[];
3683/**
3684 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as flattened rectangles.
3685 * Length 4 * n for n rectangles.
3686 */
3687export type InputFlattenedRectangleArray = MallocObj | FlattenedRectangleArray | number[];
3688/**
3689 * Some APIs accept a flattened array of colors in one of two ways - groups of 4 float values for
3690 * r, g, b, a or just integers that have 8 bits for each these. CanvasKit will detect which one
3691 * it is and act accordingly. Additionally, this can be an array of Float32Arrays of length 4
3692 * (e.g. Color). This is convenient for things like gradients when matching up colors to stops.
3693 */
3694export type InputFlexibleColorArray = Float32Array | Uint32Array | Float32Array[];
3695/**
3696 * CanvasKit APIs accept a Float32Array or a normal array (of length 2) as a Point.
3697 */
3698export type InputPoint = Point | number[];
3699/**
3700 * CanvasKit APIs accept all of these matrix types. Under the hood, we generally use 4x4 matrices.
3701 */
3702export type InputMatrix = MallocObj | Matrix4x4 | Matrix3x3 | Matrix3x2 | DOMMatrix | number[];
3703/**
3704 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as rectangles.
3705 * Length 4.
3706 */
3707export type InputRect = MallocObj | Rect | number[];
3708/**
3709 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as (int) rectangles.
3710 * Length 4.
3711 */
3712export type InputIRect = MallocObj | IRect | number[];
3713/**
3714 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as rectangles with
3715 * rounded corners. Length 12.
3716 */
3717export type InputRRect = MallocObj | RRect | number[];
3718/**
3719 * This represents n RSXforms by 4*n float values. In order, the values should
3720 * be scos, ssin, tx, ty for each RSXForm. See RSXForm.h for more details.
3721 */
3722export type InputFlattenedRSXFormArray = MallocObj | Float32Array | number[];
3723/**
3724 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as a vector of 3 floats.
3725 * For example, this is the x, y, z coordinates.
3726 */
3727export type InputVector3 = MallocObj | Vector3 | Float32Array;
3728
3729export type AlphaType = EmbindEnumEntity;
3730export type BlendMode = EmbindEnumEntity;
3731export type BlurStyle = EmbindEnumEntity;
3732export type ClipOp = EmbindEnumEntity;
3733export type ColorSpace = EmbindObject<ColorSpace>;
3734export type ColorType = EmbindEnumEntity;
3735export type EncodedImageFormat = EmbindEnumEntity;
3736export type FillType = EmbindEnumEntity;
3737export type FilterMode = EmbindEnumEntity;
3738export type FilterQuality = EmbindEnumEntity;
3739export type FontEdging = EmbindEnumEntity;
3740export type FontHinting = EmbindEnumEntity;
3741export type MipmapMode = EmbindEnumEntity;
3742export type PaintStyle = EmbindEnumEntity;
3743export type PathOp = EmbindEnumEntity;
3744export type PointMode = EmbindEnumEntity;
3745export type StrokeCap = EmbindEnumEntity;
3746export type StrokeJoin = EmbindEnumEntity;
3747export type TileMode = EmbindEnumEntity;
3748export type VertexMode = EmbindEnumEntity;
3749
3750export type Affinity = EmbindEnumEntity;
3751export type DecorationStyle = EmbindEnumEntity;
3752export type FontSlant = EmbindEnumEntity;
3753export type FontWeight = EmbindEnumEntity;
3754export type FontWidth = EmbindEnumEntity;
3755export type PlaceholderAlignment = EmbindEnumEntity;
3756export type RectHeightStyle = EmbindEnumEntity;
3757export type RectWidthStyle = EmbindEnumEntity;
3758export type TextAlign = EmbindEnumEntity;
3759export type TextBaseline = EmbindEnumEntity;
3760export type TextDirection = EmbindEnumEntity;
3761export type TextHeightBehavior = EmbindEnumEntity;
3762
3763export interface AffinityEnumValues extends EmbindEnum {
3764    Upstream: Affinity;
3765    Downstream: Affinity;
3766}
3767
3768export interface AlphaTypeEnumValues extends EmbindEnum {
3769    Opaque: AlphaType;
3770    Premul: AlphaType;
3771    Unpremul: AlphaType;
3772}
3773
3774export interface BlendModeEnumValues extends EmbindEnum {
3775    Clear: BlendMode;
3776    Src: BlendMode;
3777    Dst: BlendMode;
3778    SrcOver: BlendMode;
3779    DstOver: BlendMode;
3780    SrcIn: BlendMode;
3781    DstIn: BlendMode;
3782    SrcOut: BlendMode;
3783    DstOut: BlendMode;
3784    SrcATop: BlendMode;
3785    DstATop: BlendMode;
3786    Xor: BlendMode;
3787    Plus: BlendMode;
3788    Modulate: BlendMode;
3789    Screen: BlendMode;
3790    Overlay: BlendMode;
3791    Darken: BlendMode;
3792    Lighten: BlendMode;
3793    ColorDodge: BlendMode;
3794    ColorBurn: BlendMode;
3795    HardLight: BlendMode;
3796    SoftLight: BlendMode;
3797    Difference: BlendMode;
3798    Exclusion: BlendMode;
3799    Multiply: BlendMode;
3800    Hue: BlendMode;
3801    Saturation: BlendMode;
3802    Color: BlendMode;
3803    Luminosity: BlendMode;
3804}
3805
3806export interface BlurStyleEnumValues extends EmbindEnum {
3807    Normal: BlurStyle;
3808    Solid: BlurStyle;
3809    Outer: BlurStyle;
3810    Inner: BlurStyle;
3811}
3812
3813export interface ClipOpEnumValues extends EmbindEnum {
3814    Difference: ClipOp;
3815    Intersect: ClipOp;
3816}
3817
3818/**
3819 * The currently supported color spaces. These are all singleton values.
3820 */
3821export interface ColorSpaceEnumValues { // not a typical enum, but effectively like one.
3822    // These are all singleton values - don't call delete on them.
3823    readonly SRGB: ColorSpace;
3824    readonly DISPLAY_P3: ColorSpace;
3825    readonly ADOBE_RGB: ColorSpace;
3826
3827    /**
3828     * Returns true if the two color spaces are equal.
3829     * @param a
3830     * @param b
3831     */
3832    Equals(a: ColorSpace, b: ColorSpace): boolean;
3833}
3834
3835export interface ColorTypeEnumValues extends EmbindEnum {
3836    Alpha_8: ColorType;
3837    RGB_565: ColorType;
3838    RGBA_8888: ColorType;
3839    BGRA_8888: ColorType;
3840    RGBA_1010102: ColorType;
3841    RGB_101010x: ColorType;
3842    Gray_8: ColorType;
3843    RGBA_F16: ColorType;
3844    RGBA_F32: ColorType;
3845}
3846
3847export interface DecorationStyleEnumValues extends EmbindEnum {
3848    Solid: DecorationStyle;
3849    Double: DecorationStyle;
3850    Dotted: DecorationStyle;
3851    Dashed: DecorationStyle;
3852    Wavy: DecorationStyle;
3853}
3854
3855export interface FillTypeEnumValues extends EmbindEnum {
3856    Winding: FillType;
3857    EvenOdd: FillType;
3858}
3859
3860export interface FilterModeEnumValues extends EmbindEnum {
3861    Linear: FilterMode;
3862    Nearest: FilterMode;
3863}
3864
3865export interface FilterQualityEnumValues extends EmbindEnum {
3866    None: FilterQuality;
3867    Low: FilterQuality;
3868    Medium: FilterQuality;
3869    High: FilterQuality;
3870}
3871
3872export interface FontEdgingEnumValues extends EmbindEnum {
3873    Alias: FontEdging;
3874    AntiAlias: FontEdging;
3875    SubpixelAntiAlias: FontEdging;
3876}
3877
3878export interface FontHintingEnumValues extends EmbindEnum {
3879    None: FontHinting;
3880    Slight: FontHinting;
3881    Normal: FontHinting;
3882    Full: FontHinting;
3883}
3884
3885export interface FontSlantEnumValues extends EmbindEnum {
3886    Upright: FontSlant;
3887    Italic: FontSlant;
3888    Oblique: FontSlant;
3889}
3890
3891export interface FontWeightEnumValues extends EmbindEnum {
3892    Invisible: FontWeight;
3893    Thin: FontWeight;
3894    ExtraLight: FontWeight;
3895    Light: FontWeight;
3896    Normal: FontWeight;
3897    Medium: FontWeight;
3898    SemiBold: FontWeight;
3899    Bold: FontWeight;
3900    ExtraBold: FontWeight;
3901    Black: FontWeight;
3902    ExtraBlack: FontWeight;
3903}
3904
3905export interface FontWidthEnumValues extends EmbindEnum {
3906    UltraCondensed: FontWidth;
3907    ExtraCondensed: FontWidth;
3908    Condensed: FontWidth;
3909    SemiCondensed: FontWidth;
3910    Normal: FontWidth;
3911    SemiExpanded: FontWidth;
3912    Expanded: FontWidth;
3913    ExtraExpanded: FontWidth;
3914    UltraExpanded: FontWidth;
3915}
3916
3917/*
3918 *  These values can be OR'd together
3919 */
3920export interface GlyphRunFlagValues {
3921    IsWhiteSpace: number;
3922}
3923
3924export interface ImageFormatEnumValues extends EmbindEnum {
3925    // TODO(kjlubick) When these are compiled in depending on the availability of the codecs,
3926    //   be sure to make these nullable.
3927    PNG: EncodedImageFormat;
3928    JPEG: EncodedImageFormat;
3929    WEBP: EncodedImageFormat;
3930}
3931
3932export interface MipmapModeEnumValues extends EmbindEnum {
3933    None: MipmapMode;
3934    Nearest: MipmapMode;
3935    Linear: MipmapMode;
3936}
3937
3938export interface PaintStyleEnumValues extends EmbindEnum {
3939    Fill: PaintStyle;
3940    Stroke: PaintStyle;
3941}
3942
3943export interface PathOpEnumValues extends EmbindEnum {
3944    Difference: PathOp;
3945    Intersect: PathOp;
3946    Union: PathOp;
3947    XOR: PathOp;
3948    ReverseDifference: PathOp;
3949}
3950
3951export interface PlaceholderAlignmentEnumValues extends EmbindEnum {
3952    Baseline: PlaceholderAlignment;
3953    AboveBaseline: PlaceholderAlignment;
3954    BelowBaseline: PlaceholderAlignment;
3955    Top: PlaceholderAlignment;
3956    Bottom: PlaceholderAlignment;
3957    Middle: PlaceholderAlignment;
3958}
3959
3960export interface PointModeEnumValues extends EmbindEnum {
3961    Points: PointMode;
3962    Lines: PointMode;
3963    Polygon: PointMode;
3964}
3965
3966export interface RectHeightStyleEnumValues extends EmbindEnum {
3967    Tight: RectHeightStyle;
3968    Max: RectHeightStyle;
3969    IncludeLineSpacingMiddle: RectHeightStyle;
3970    IncludeLineSpacingTop: RectHeightStyle;
3971    IncludeLineSpacingBottom: RectHeightStyle;
3972    Strut: RectHeightStyle;
3973}
3974
3975export interface RectWidthStyleEnumValues extends EmbindEnum {
3976    Tight: RectWidthStyle;
3977    Max: RectWidthStyle;
3978}
3979
3980export interface StrokeCapEnumValues extends EmbindEnum {
3981    Butt: StrokeCap;
3982    Round: StrokeCap;
3983    Square: StrokeCap;
3984}
3985
3986export interface StrokeJoinEnumValues extends EmbindEnum {
3987    Bevel: StrokeJoin;
3988    Miter: StrokeJoin;
3989    Round: StrokeJoin;
3990}
3991
3992export interface TextAlignEnumValues extends EmbindEnum {
3993    Left: TextAlign;
3994    Right: TextAlign;
3995    Center: TextAlign;
3996    Justify: TextAlign;
3997    Start: TextAlign;
3998    End: TextAlign;
3999}
4000
4001export interface TextBaselineEnumValues extends EmbindEnum {
4002    Alphabetic: TextBaseline;
4003    Ideographic: TextBaseline;
4004}
4005
4006export interface TextDirectionEnumValues extends EmbindEnum {
4007    LTR: TextDirection;
4008    RTL: TextDirection;
4009}
4010
4011export interface TextHeightBehaviorEnumValues extends EmbindEnum {
4012    All: TextHeightBehavior;
4013    DisableFirstAscent: TextHeightBehavior;
4014    DisableLastDescent: TextHeightBehavior;
4015    DisableAll: TextHeightBehavior;
4016}
4017
4018export interface TileModeEnumValues extends EmbindEnum {
4019    Clamp: TileMode;
4020    Decal: TileMode;
4021    Mirror: TileMode;
4022    Repeat: TileMode;
4023}
4024
4025export interface VertexModeEnumValues extends EmbindEnum {
4026    Triangles: VertexMode;
4027    TrianglesStrip: VertexMode;
4028    TriangleFan: VertexMode;
4029}
4030