fix(terminal): fallback to canvas if webgl renderer incompatible

ref Eugeny/tabby#8884
ref https://bugs.chromium.org/p/chromium/issues/detail?id=1476475
This commit is contained in:
Clem Fern 2023-10-05 22:49:42 +02:00
parent 83c0892546
commit 7d5128a8ce

View file

@ -340,7 +340,26 @@ export class BaseTerminalTabComponent<P extends BaseTerminalProfile> extends Bas
this.configure()
})
const cls: new (..._) => Frontend = {
// Check if the the WebGL renderer is compatible with xterm.js:
// - https://github.com/Eugeny/tabby/issues/8884
// - https://github.com/microsoft/vscode/issues/190195
// - https://github.com/xtermjs/xterm.js/issues/4665
// - https://bugs.chromium.org/p/chromium/issues/detail?id=1476475
//
// Inspired by https://github.com/microsoft/vscode/pull/191795
let enable8884Workarround = false
const checkCanvas = document.createElement('canvas')
const checkGl = checkCanvas.getContext('webgl2')
const debugInfo = checkGl?.getExtension('WEBGL_debug_renderer_info')
if (checkGl && debugInfo) {
const renderer = checkGl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL)
if (renderer.startsWith('ANGLE (Google, Vulkan 1.3.0 (SwiftShader Device (Subzero)')) {
enable8884Workarround = true
}
}
const cls: new (..._) => Frontend = enable8884Workarround ? XTermFrontend : {
xterm: XTermFrontend,
'xterm-webgl': XTermWebGLFrontend,
}[this.config.store.terminal.frontend] ?? XTermFrontend