2018-10-17 11:57:18 +00:00
|
|
|
// Adds compile-time JS functions to augment the CanvasKit interface.
|
|
|
|
// Specifically, anything that should only be on the GPU version of canvaskit.
|
|
|
|
(function(CanvasKit){
|
|
|
|
CanvasKit._extraInitializations = CanvasKit._extraInitializations || [];
|
|
|
|
CanvasKit._extraInitializations.push(function() {
|
2018-11-20 19:07:42 +00:00
|
|
|
CanvasKit.MakeWebGLCanvasSurface = function(htmlID) {
|
2018-10-17 11:57:18 +00:00
|
|
|
var canvas = document.getElementById(htmlID);
|
|
|
|
if (!canvas) {
|
|
|
|
throw 'Canvas with id ' + htmlID + ' was not found';
|
|
|
|
}
|
|
|
|
// Maybe better to use clientWidth/height. See:
|
|
|
|
// https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html
|
2018-11-20 19:07:42 +00:00
|
|
|
var surface = this._getWebGLSurface(htmlID, canvas.width, canvas.height);
|
|
|
|
if (!surface) {
|
2018-11-20 20:55:10 +00:00
|
|
|
SkDebug('falling back from GPU implementation to a SW based one');
|
2018-11-20 19:07:42 +00:00
|
|
|
return CanvasKit.MakeSWCanvasSurface(htmlID);
|
|
|
|
}
|
|
|
|
return surface;
|
2018-10-17 11:57:18 +00:00
|
|
|
};
|
2018-11-20 19:07:42 +00:00
|
|
|
// Default to trying WebGL first.
|
|
|
|
CanvasKit.MakeCanvasSurface = CanvasKit.MakeWebGLCanvasSurface;
|
2018-10-17 11:57:18 +00:00
|
|
|
});
|
|
|
|
}(Module)); // When this file is loaded in, the high level object is "Module";
|