skia2/experimental/wasm-skp-debugger/gpu.js
Kevin Lubick c7755d9470 [canvaskit] Bump GPU resource cache to 256MB
Wrong file was previously edited.

Change-Id: I2e78d102ca85a22268481d1958b983e41d72ee3e
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/206271
Reviewed-by: Florin Malita <fmalita@chromium.org>
2019-04-05 18:06:18 +00:00

75 lines
2.9 KiB
JavaScript

// Adds compile-time JS functions to augment the DebuggerView interface.
// Specifically, anything that should only be on the GPU version of DebuggerView.
(function(DebuggerView){
function makeWebGLContext(canvas, attrs) {
// These defaults come from the emscripten _emscripten_webgl_create_context
// TODO(nifong): All these settings appear to be ignored. investigate.
var contextAttributes = {
alpha: 1,
depth: 1,
stencil: 0,
antialias: 1,
premultipliedAlpha: 1,
// for the zoom to be able to access the pixels. Incurs performance penalty
preserveDrawingBuffer: 1,
preferLowPowerToHighPerformance: 0,
failIfMajorPerformanceCaveat: 0,
majorVersion: 1,
minorVersion: 0,
enableExtensionsByDefault: 1,
explicitSwapControl: 0,
renderViaOffscreenBackBuffer: 0,
};
if (!canvas) {
console.log('null canvas passed into makeWebGLContext');
return 0;
}
// This check is from the emscripten version
if (contextAttributes['explicitSwapControl']) {
console.log('explicitSwapControl is not supported');
return 0;
}
// GL is an enscripten provided helper
// See https://github.com/emscripten-core/emscripten/blob/incoming/src/library_webgl.js
var context = GL.createContext(canvas, contextAttributes);
if (!context) {
console.log('Could not get a WebGL context from the canvas element.');
}
console.log('Made Web Gl Canvas Surface');
return context
}
DebuggerView.GetWebGLContext = function(canvas, attrs) {
return makeWebGLContext(canvas, attrs);
};
// canvas - a canvas element to use for this surface.
DebuggerView.MakeWebGLCanvasSurface = function(canvas) {
// we are ok with all the defaults
var ctx = DebuggerView.GetWebGLContext(canvas);
if (!ctx || ctx < 0) {
throw 'failed to create webgl context: err ' + ctx;
}
var grcontext = this.MakeGrContext(ctx);
if (!grcontext) {
throw (
'failed to create grcontext. Open GL driver may not support all needed functions: err '
+ grcontext);
}
// Maybe better to use clientWidth/height. See:
// https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html
var surface = this.MakeOnScreenGLSurface(grcontext, canvas.width, canvas.height);
if (!surface) {
// Don't fall back silently in the debugger, the user explicitly controls which backend he
// wants via the UI. Calling function may catch this and show the user an error.
throw ('Failed to create OpenGL surface. GPU Backend unavailable.');
}
return surface;
};
// Default to trying WebGL first.
DebuggerView.MakeCanvasSurface = DebuggerView.MakeWebGLCanvasSurface;
}(Module)); // When this file is loaded in, the high level object is "Module";