blob: 348ea2966dacacbabc6bb5966f7d51181f394de0 [file] [log] [blame]
Kevin Lubick5b90b842018-10-17 07:57:18 -04001// Adds compile-time JS functions to augment the CanvasKit interface.
2// Specifically, anything that should only be on the GPU version of canvaskit.
3(function(CanvasKit){
4 CanvasKit._extraInitializations = CanvasKit._extraInitializations || [];
5 CanvasKit._extraInitializations.push(function() {
Kevin Lubickb07204a2018-11-20 14:07:42 -05006 CanvasKit.MakeWebGLCanvasSurface = function(htmlID) {
Kevin Lubick5b90b842018-10-17 07:57:18 -04007 var canvas = document.getElementById(htmlID);
8 if (!canvas) {
9 throw 'Canvas with id ' + htmlID + ' was not found';
10 }
11 // Maybe better to use clientWidth/height. See:
12 // https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html
Kevin Lubickb07204a2018-11-20 14:07:42 -050013 var surface = this._getWebGLSurface(htmlID, canvas.width, canvas.height);
14 if (!surface) {
15 console.log('falling back from GPU implementation to a SW based one');
16 return CanvasKit.MakeSWCanvasSurface(htmlID);
17 }
18 return surface;
Kevin Lubick5b90b842018-10-17 07:57:18 -040019 };
Kevin Lubickb07204a2018-11-20 14:07:42 -050020 // Default to trying WebGL first.
21 CanvasKit.MakeCanvasSurface = CanvasKit.MakeWebGLCanvasSurface;
Kevin Lubick5b90b842018-10-17 07:57:18 -040022 });
23}(Module)); // When this file is loaded in, the high level object is "Module";