Add software backend to gpu build
Bug: skia:8548
Change-Id: If3853711f4b183f3b0437ae2b31525b0e6c88213
Reviewed-on: https://skia-review.googlesource.com/c/172120
Reviewed-by: Kevin Lubick <kjlubick@google.com>
diff --git a/experimental/canvaskit/gpu.js b/experimental/canvaskit/gpu.js
index 3a26842..348ea29 100644
--- a/experimental/canvaskit/gpu.js
+++ b/experimental/canvaskit/gpu.js
@@ -3,22 +3,21 @@
(function(CanvasKit){
CanvasKit._extraInitializations = CanvasKit._extraInitializations || [];
CanvasKit._extraInitializations.push(function() {
- CanvasKit.MakeCanvasSurface = function(htmlID) {
+ CanvasKit.MakeWebGLCanvasSurface = function(htmlID) {
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
- return this._getWebGLSurface(htmlID, canvas.width, canvas.height);
+ var surface = this._getWebGLSurface(htmlID, canvas.width, canvas.height);
+ if (!surface) {
+ console.log('falling back from GPU implementation to a SW based one');
+ return CanvasKit.MakeSWCanvasSurface(htmlID);
+ }
+ return surface;
};
-
- CanvasKit.SkSurface.prototype.flush = function() {
- this._flush();
- }
-
- CanvasKit.SkSurface.prototype.dispose = function() {
- this.delete();
- }
+ // Default to trying WebGL first.
+ CanvasKit.MakeCanvasSurface = CanvasKit.MakeWebGLCanvasSurface;
});
}(Module)); // When this file is loaded in, the high level object is "Module";