Kevin Lubick | 5b90b84 | 2018-10-17 07:57:18 -0400 | [diff] [blame] | 1 | // 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 Lubick | b07204a | 2018-11-20 14:07:42 -0500 | [diff] [blame^] | 6 | CanvasKit.MakeWebGLCanvasSurface = function(htmlID) { |
Kevin Lubick | 5b90b84 | 2018-10-17 07:57:18 -0400 | [diff] [blame] | 7 | 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 Lubick | b07204a | 2018-11-20 14:07:42 -0500 | [diff] [blame^] | 13 | 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 Lubick | 5b90b84 | 2018-10-17 07:57:18 -0400 | [diff] [blame] | 19 | }; |
Kevin Lubick | b07204a | 2018-11-20 14:07:42 -0500 | [diff] [blame^] | 20 | // Default to trying WebGL first. |
| 21 | CanvasKit.MakeCanvasSurface = CanvasKit.MakeWebGLCanvasSurface; |
Kevin Lubick | 5b90b84 | 2018-10-17 07:57:18 -0400 | [diff] [blame] | 22 | }); |
| 23 | }(Module)); // When this file is loaded in, the high level object is "Module"; |