• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * This externs file prevents the Closure JS compiler from minifying away
3 * names of objects created by Emscripten.
4 * Basically, by defining empty objects and functions here, Closure will
5 * know not to rename them.  This is needed because of our pre-js files,
6 * that is, the JS we hand-write to bundle into the output. That JS will be
7 * hit by the closure compiler and thus needs to know about what functions
8 * have special names and should not be minified.
9 *
10 * Emscripten does not support automatically generating an externs file, so we
11 * do it by hand. The general process is to write some JS code, and then put any
12 * calls to CanvasKit or related things in here. Running ./compile.sh and then
13 * looking at the minified results or running the Release trybot should
14 * verify nothing was missed. Optionally, looking directly at the minified
15 * pathkit.js can be useful when developing locally.
16 *
17 * Docs:
18 *   https://github.com/cljsjs/packages/wiki/Creating-Externs
19 *   https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System
20 *
21 * Example externs:
22 *   https://github.com/google/closure-compiler/tree/master/externs
23 */
24
25var CanvasKit = {
26	// public API (i.e. things we declare in the pre-js file)
27	Color: function() {},
28	/** @return {CanvasKit.SkRect} */
29	LTRBRect: function() {},
30	/** @return {CanvasKit.SkRect} */
31	XYWHRect: function() {},
32	/** @return {ImageData} */
33	ImageData: function() {},
34
35	GetWebGLContext: function() {},
36	MakeBlurMaskFilter: function() {},
37	MakeCanvas: function() {},
38	MakeCanvasSurface: function() {},
39	MakeGrContext: function() {},
40	/** @return {CanvasKit.SkImage} */
41	MakeImageFromEncoded: function() {},
42	/** @return {LinearCanvasGradient} */
43	MakeLinearGradientShader: function() {},
44	MakeOnScreenGLSurface: function() {},
45	MakePathFromCmds: function() {},
46	MakePathFromOp: function() {},
47	MakePathFromSVGString: function() {},
48	MakeRadialGradientShader: function() {},
49	MakeRenderTarget: function() {},
50	MakeSWCanvasSurface: function() {},
51	MakeManagedAnimation: function() {},
52	MakeSkDashPathEffect: function() {},
53	MakeSkVertices: function() {},
54	MakeSurface: function() {},
55	/** @return {RadialCanvasGradient} */
56	MakeTwoPointConicalGradientShader: function() {},
57	MakeWebGLCanvasSurface: function() {},
58	currentContext: function() {},
59	getColorComponents: function() {},
60	getSkDataBytes: function() {},
61	multiplyByAlpha: function() {},
62	setCurrentContext: function() {},
63
64	// private API (i.e. things declared in the bindings that we use
65	// in the pre-js file)
66	_MakeImage: function() {},
67	_MakeLinearGradientShader: function() {},
68	_MakePathFromCmds: function() {},
69	_MakeRadialGradientShader: function() {},
70	_MakeManagedAnimation: function() {},
71	_MakeSkDashPathEffect: function() {},
72	_MakeSkVertices: function() {},
73	_MakeTwoPointConicalGradientShader: function() {},
74	_decodeImage: function() {},
75	_drawShapedText: function() {},
76	_getRasterDirectSurface: function() {},
77	_getRasterN32PremulSurface: function() {},
78
79	// The testing object is meant to expose internal functions
80	// for more fine-grained testing, e.g. parseColor
81	_testing: {},
82
83	// Objects and properties on CanvasKit
84
85	GrContext: {
86		// public API (from C++ bindings)
87		getResourceCacheLimitBytes: function() {},
88		getResourceCacheUsageBytes: function() {},
89		setResourceCacheLimitBytes: function() {},
90	},
91
92	RSXFormBuilder: function() {},
93	SkColorBuilder: function() {},
94	SkRectBuilder: function() {},
95
96	ShapedText: {
97		// public API (from C++ bindings)
98		getBounds: function() {},
99	},
100
101	SkCanvas: {
102		// public API (from C++ bindings)
103		clear: function() {},
104		clipPath: function() {},
105		clipRect: function() {},
106		concat: function() {},
107		drawArc: function() {},
108		drawImage: function() {},
109		drawImageRect: function() {},
110		drawLine: function() {},
111		drawOval: function() {},
112		drawPaint: function() {},
113		drawPath: function() {},
114		drawPicture: function() {},
115		drawRect: function() {},
116		drawRoundRect: function() {},
117		drawShadow: function() {},
118		drawText: function() {},
119		drawTextBlob: function() {},
120		drawVertices: function() {},
121		flush: function() {},
122		getTotalMatrix: function() {},
123		makeSurface: function() {},
124		restore: function() {},
125		restoreToCount: function() {},
126		rotate: function() {},
127		save: function() {},
128		saveLayer: function() {},
129		scale: function() {},
130		skew: function() {},
131		translate: function() {},
132
133		// private API
134		_drawAtlas: function() {},
135		_drawSimpleText: function() {},
136		_readPixels: function() {},
137		_writePixels: function() {},
138		delete: function() {},
139	},
140
141	SkFont: {
142		// public API (from C++ bindings)
143		getScaleX: function() {},
144		getSize: function() {},
145		getSkewX: function() {},
146		getTypeface: function() {},
147		measureText: function() {},
148		setScaleX: function() {},
149		setSize: function() {},
150		setSkewX: function() {},
151		setTypeface: function() {},
152		// private API (from C++ bindings)
153		_getWidths: function() {},
154	},
155
156	SkFontMgr: {
157		// public API (from C++ bindings)
158		RefDefault: function() {},
159		countFamilies: function() {},
160
161		// private API
162		_makeTypefaceFromData: function() {},
163	},
164
165	SkImage: {
166		// public API (from C++ bindings)
167		height: function() {},
168		width: function() {},
169		// private API
170		_encodeToData: function() {},
171		_encodeToDataWithFormat: function() {},
172		_makeShader: function() {},
173	},
174
175	SkMatrix: {
176		identity: function() {},
177		invert: function() {},
178		mapPoints: function() {},
179		multiply: function() {},
180		rotated: function() {},
181		scaled: function() {},
182		skewed: function() {},
183		translated: function() {},
184	},
185
186	SkPaint: {
187		// public API (from C++ bindings)
188		/** @return {CanvasKit.SkPaint} */
189		copy: function() {},
190		getBlendMode: function() {},
191		getColor: function() {},
192		getFilterQuality: function() {},
193		getStrokeCap: function() {},
194		getStrokeJoin: function() {},
195		getStrokeMiter: function() {},
196		getStrokeWidth: function() {},
197		setAntiAlias: function() {},
198		setBlendMode: function() {},
199		setColor: function() {},
200		setFilterQuality: function() {},
201		setMaskFilter: function() {},
202		setPathEffect: function() {},
203		setShader: function() {},
204		setStrokeCap: function() {},
205		setStrokeJoin: function() {},
206		setStrokeMiter: function() {},
207		setStrokeWidth: function() {},
208		setStyle: function() {},
209
210		//private API
211		delete: function() {},
212	},
213
214	SkPath: {
215		// public API (from C++ bindings)
216		computeTightBounds: function() {},
217		contains: function() {},
218		/** @return {CanvasKit.SkPath} */
219		copy: function() {},
220		countPoints: function() {},
221		equals: function() {},
222		getBounds: function() {},
223		getFillType: function() {},
224		getPoint: function() {},
225		isEmpty: function() {},
226		isVolatile: function() {},
227		reset: function() {},
228		rewind: function() {},
229		setFillType: function() {},
230		setIsVolatile: function() {},
231		toSVGString: function() {},
232
233		// private API
234		_addArc: function() {},
235		_addPath: function() {},
236		_addRect: function() {},
237		_addRoundRect: function() {},
238		_arc: function() {},
239		_arcTo: function() {},
240		_close: function() {},
241		_conicTo: function() {},
242		_cubicTo: function() {},
243		_dash: function() {},
244		_lineTo: function() {},
245		_moveTo: function() {},
246		_op: function() {},
247		_quadTo: function() {},
248		_rect: function() {},
249		_simplify: function() {},
250		_stroke: function() {},
251		_transform: function() {},
252		_trim: function() {},
253		delete: function() {},
254		dump: function() {},
255		dumpHex: function() {},
256	},
257
258	SkPathMeasure: {
259		getLength: function() {},
260		getPosTan: function() {},
261		isClosed: function() {},
262		nextContour: function() {},
263	},
264
265	SkPicture: {
266		DEBUGONLY_serialize: function() {},
267	},
268
269	SkPictureRecorder: {
270		beginRecording: function() {},
271		finishRecordingAsPicture: function() {},
272	},
273
274	SkRect: {
275		fLeft: {},
276		fTop: {},
277		fRight: {},
278		fBottom: {},
279	},
280
281	SkSurface: {
282		// public API (from C++ bindings)
283		/** @return {CanvasKit.SkCanvas} */
284		getCanvas: function() {},
285		/** @return {CanvasKit.SkImage} */
286		makeImageSnapshot: function() {},
287		makeSurface: function() {},
288		grContext: {},
289
290		// private API
291		_flush: function() {},
292		_getRasterN32PremulSurface: function() {},
293		delete: function() {},
294	},
295
296	SkTextBlob: {
297		// public API (both C++ and JS bindings)
298		MakeFromRSXform: function() {},
299		MakeFromText: function() {},
300		MakeOnPath: function() {},
301		// private API (from C++ bindings)
302		_MakeFromRSXform: function() {},
303		_MakeFromText: function() {},
304	},
305
306	SkVertices: {
307		// public API (from C++ bindings)
308		bounds: function() {},
309		mode: function() {},
310		uniqueID: function() {},
311		vertexCount: function() {},
312
313		// private API
314		/** @return {CanvasKit.SkVertices} */
315		_applyBones: function() {},
316	},
317
318	_SkVerticesBuilder: {
319		// public API (from C++ bindings)
320		boneIndices: function() {},
321		boneWeights: function() {},
322		colors: function() {},
323		detach: function() {},
324		indices: function() {},
325		positions: function() {},
326		texCoords: function() {},
327	},
328
329	// Constants and Enums
330	gpu: {},
331	skottie: {},
332
333	TRANSPARENT: {},
334	RED: {},
335	BLUE: {},
336	YELLOW: {},
337	CYAN: {},
338	BLACK: {},
339	WHITE: {},
340
341	MOVE_VERB: {},
342	LINE_VERB: {},
343	QUAD_VERB: {},
344	CONIC_VERB: {},
345	CUBIC_VERB: {},
346	CLOSE_VERB: {},
347
348	AlphaType: {
349		Opaque: {},
350		Premul: {},
351		Unpremul: {},
352	},
353
354	BlendMode: {
355		Clear: {},
356		Src: {},
357		Dst: {},
358		SrcOver: {},
359		DstOver: {},
360		SrcIn: {},
361		DstIn: {},
362		SrcOut: {},
363		DstOut: {},
364		SrcATop: {},
365		DstATop: {},
366		Xor: {},
367		Plus: {},
368		Modulate: {},
369		Screen: {},
370		Overlay: {},
371		Darken: {},
372		Lighten: {},
373		ColorDodge: {},
374		ColorBurn: {},
375		HardLight: {},
376		SoftLight: {},
377		Difference: {},
378		Exclusion: {},
379		Multiply: {},
380		Hue: {},
381		Saturation: {},
382		Color: {},
383		Luminosity: {},
384	},
385
386	BlurStyle: {
387		Normal: {},
388		Solid: {},
389		Outer: {},
390		Inner: {},
391	},
392
393	ClipOp: {
394		Difference: {},
395		Intersect: {},
396	},
397
398	ColorType: {
399		Alpha_8: {},
400		RGB_565: {},
401		ARGB_4444: {},
402		RGBA_8888: {},
403		RGB_888x: {},
404		BGRA_8888: {},
405		RGBA_1010102: {},
406		RGB_101010x: {},
407		Gray_8: {},
408		RGBA_F16: {},
409		RGBA_F32: {},
410	},
411
412	FillType: {
413		Winding: {},
414		EvenOdd: {},
415		InverseWinding: {},
416		InverseEvenOdd: {},
417	},
418
419	FilterQuality: {
420		None: {},
421		Low: {},
422		Medium: {},
423		High: {},
424	},
425
426	ImageFormat: {
427		PNG: {},
428		JPEG: {},
429	},
430
431	PaintStyle: {
432		Fill: {},
433		Stroke: {},
434		StrokeAndFill: {},
435	},
436
437	PathOp: {
438		Difference: {},
439		Intersect: {},
440		Union: {},
441		XOR: {},
442		ReverseDifference: {},
443	},
444
445	StrokeCap: {
446		Butt: {},
447		Round: {},
448		Square: {},
449	},
450
451	StrokeJoin: {
452		Miter: {},
453		Round: {},
454		Bevel: {},
455	},
456
457	TextEncoding: {
458		UTF8: {},
459		UTF16: {},
460		UTF32: {},
461		GlyphID: {},
462	},
463
464	TileMode: {
465		Clamp: {},
466		Repeat: {},
467		Mirror: {},
468		Decal: {},
469	},
470
471	VertexMode: {
472		Triangles: {},
473		TrianglesStrip: {},
474		TriangleFan: {},
475	},
476
477	// Things Enscriptem adds for us
478
479	/** Represents the heap of the WASM code
480	 * @type {ArrayBuffer}
481	 */
482	buffer: {},
483	/**
484	 * @type {Float32Array}
485	 */
486	HEAPF32: {},
487	/**
488	 * @type {Uint8Array}
489	 */
490	HEAPU8: {},
491	/**
492	 * @type {Uint16Array}
493	 */
494	HEAPU16: {},
495	/**
496	 * @type {Int32Array}
497	 */
498	HEAP32: {},
499	/**
500	 * @type {Uint32Array}
501	 */
502	HEAPU32: {},
503	_malloc: function() {},
504	_free: function() {},
505	onRuntimeInitialized: function() {},
506};
507
508// Public API things that are newly declared in the JS should go here.
509// It's not enough to declare them above, because closure can still erase them
510// unless they go on the prototype.
511CanvasKit.SkPath.prototype.addArc = function() {};
512CanvasKit.SkPath.prototype.addPath = function() {};
513CanvasKit.SkPath.prototype.addRect = function() {};
514CanvasKit.SkPath.prototype.addRoundRect = function() {};
515CanvasKit.SkPath.prototype.arc = function() {};
516CanvasKit.SkPath.prototype.arcTo = function() {};
517CanvasKit.SkPath.prototype.close = function() {};
518CanvasKit.SkPath.prototype.conicTo = function() {};
519CanvasKit.SkPath.prototype.cubicTo = function() {};
520CanvasKit.SkPath.prototype.dash = function() {};
521CanvasKit.SkPath.prototype.lineTo = function() {};
522CanvasKit.SkPath.prototype.moveTo = function() {};
523CanvasKit.SkPath.prototype.op = function() {};
524CanvasKit.SkPath.prototype.quadTo = function() {};
525CanvasKit.SkPath.prototype.rect = function() {};
526CanvasKit.SkPath.prototype.simplify = function() {};
527CanvasKit.SkPath.prototype.stroke = function() {};
528CanvasKit.SkPath.prototype.transform = function() {};
529CanvasKit.SkPath.prototype.trim = function() {};
530
531CanvasKit.SkPicture.prototype.DEBUGONLY_saveAsFile = function() {};
532
533CanvasKit.SkSurface.prototype.dispose = function() {};
534CanvasKit.SkSurface.prototype.flush = function() {};
535CanvasKit.SkSurface.prototype.requestAnimationFrame = function() {};
536CanvasKit.SkSurface.prototype.captureFrameAsSkPicture = function() {};
537
538/** @return {CanvasKit.SkVertices} */
539CanvasKit.SkVertices.prototype.applyBones = function() {};
540
541CanvasKit.SkImage.prototype.encodeToData = function() {};
542CanvasKit.SkImage.prototype.makeShader = function() {};
543
544CanvasKit.SkCanvas.prototype.drawAtlas = function() {};
545CanvasKit.SkCanvas.prototype.drawText = function() {};
546/** @return {Uint8Array} */
547CanvasKit.SkCanvas.prototype.readPixels = function() {};
548CanvasKit.SkCanvas.prototype.writePixels = function() {};
549
550CanvasKit.SkFontMgr.prototype.MakeTypefaceFromData = function() {};
551
552CanvasKit.SkFont.prototype.getWidths = function() {};
553
554CanvasKit.RSXFormBuilder.prototype.build = function() {};
555CanvasKit.RSXFormBuilder.prototype.delete = function() {};
556CanvasKit.RSXFormBuilder.prototype.push = function() {};
557CanvasKit.RSXFormBuilder.prototype.set = function() {};
558
559CanvasKit.SkColorBuilder.prototype.build = function() {};
560CanvasKit.SkColorBuilder.prototype.delete = function() {};
561CanvasKit.SkColorBuilder.prototype.push = function() {};
562CanvasKit.SkColorBuilder.prototype.set = function() {};
563
564// Define StrokeOpts object
565var StrokeOpts = {};
566StrokeOpts.prototype.width;
567StrokeOpts.prototype.miter_limit;
568StrokeOpts.prototype.cap;
569StrokeOpts.prototype.join;
570StrokeOpts.prototype.precision;
571
572// Define everything created in the canvas2d spec here
573var HTMLCanvas = {};
574HTMLCanvas.prototype.decodeImage = function() {};
575HTMLCanvas.prototype.dispose = function() {};
576HTMLCanvas.prototype.getContext = function() {};
577HTMLCanvas.prototype.loadFont = function() {};
578HTMLCanvas.prototype.makePath2D = function() {};
579HTMLCanvas.prototype.toDataURL = function() {};
580
581var CanvasRenderingContext2D = {};
582CanvasRenderingContext2D.prototype.addHitRegion = function() {};
583CanvasRenderingContext2D.prototype.arc = function() {};
584CanvasRenderingContext2D.prototype.arcTo = function() {};
585CanvasRenderingContext2D.prototype.beginPath = function() {};
586CanvasRenderingContext2D.prototype.bezierCurveTo = function() {};
587CanvasRenderingContext2D.prototype.clearHitRegions = function() {};
588CanvasRenderingContext2D.prototype.clearRect = function() {};
589CanvasRenderingContext2D.prototype.clip = function() {};
590CanvasRenderingContext2D.prototype.closePath = function() {};
591CanvasRenderingContext2D.prototype.createImageData = function() {};
592CanvasRenderingContext2D.prototype.createLinearGradient = function() {};
593CanvasRenderingContext2D.prototype.createPattern = function() {};
594CanvasRenderingContext2D.prototype.createRadialGradient = function() {};
595CanvasRenderingContext2D.prototype.drawFocusIfNeeded = function() {};
596CanvasRenderingContext2D.prototype.drawImage = function() {};
597CanvasRenderingContext2D.prototype.ellipse = function() {};
598CanvasRenderingContext2D.prototype.fill = function() {};
599CanvasRenderingContext2D.prototype.fillRect = function() {};
600CanvasRenderingContext2D.prototype.fillText = function() {};
601CanvasRenderingContext2D.prototype.getImageData = function() {};
602CanvasRenderingContext2D.prototype.getLineDash = function() {};
603CanvasRenderingContext2D.prototype.isPointInPath = function() {};
604CanvasRenderingContext2D.prototype.isPointInStroke = function() {};
605CanvasRenderingContext2D.prototype.lineTo = function() {};
606CanvasRenderingContext2D.prototype.measureText = function() {};
607CanvasRenderingContext2D.prototype.moveTo = function() {};
608CanvasRenderingContext2D.prototype.putImageData = function() {};
609CanvasRenderingContext2D.prototype.quadraticCurveTo = function() {};
610CanvasRenderingContext2D.prototype.rect = function() {};
611CanvasRenderingContext2D.prototype.removeHitRegion = function() {};
612CanvasRenderingContext2D.prototype.resetTransform = function() {};
613CanvasRenderingContext2D.prototype.restore = function() {};
614CanvasRenderingContext2D.prototype.rotate = function() {};
615CanvasRenderingContext2D.prototype.save = function() {};
616CanvasRenderingContext2D.prototype.scale = function() {};
617CanvasRenderingContext2D.prototype.scrollPathIntoView = function() {};
618CanvasRenderingContext2D.prototype.setLineDash = function() {};
619CanvasRenderingContext2D.prototype.setTransform = function() {};
620CanvasRenderingContext2D.prototype.stroke = function() {};
621CanvasRenderingContext2D.prototype.strokeRect = function() {};
622CanvasRenderingContext2D.prototype.strokeText = function() {};
623CanvasRenderingContext2D.prototype.transform = function() {};
624CanvasRenderingContext2D.prototype.translate = function() {};
625
626var Path2D = {};
627Path2D.prototype.addPath = function() {};
628Path2D.prototype.arc = function() {};
629Path2D.prototype.arcTo = function() {};
630Path2D.prototype.bezierCurveTo = function() {};
631Path2D.prototype.closePath = function() {};
632Path2D.prototype.ellipse = function() {};
633Path2D.prototype.lineTo = function() {};
634Path2D.prototype.moveTo = function() {};
635Path2D.prototype.quadraticCurveTo = function() {};
636Path2D.prototype.rect = function() {};
637
638var LinearCanvasGradient = {};
639LinearCanvasGradient.prototype.addColorStop = function() {};
640var RadialCanvasGradient = {};
641RadialCanvasGradient.prototype.addColorStop = function() {};
642var CanvasPattern = {};
643CanvasPattern.prototype.setTransform = function() {};
644
645var ImageData = {
646	/**
647	 * @type {Uint8ClampedArray}
648	 */
649	data: {},
650	height: {},
651	width: {},
652};
653
654var DOMMatrix = {
655	a: {},
656	b: {},
657	c: {},
658	d: {},
659	e: {},
660	f: {},
661};
662
663// Not sure why this is needed - might be a bug in emsdk that this isn't properly declared.
664function loadWebAssemblyModule() {};
665