]> git.proxmox.com Git - pve-xtermjs.git/commitdiff
xtermjs: try to detect hardware support for webgl2
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 25 Oct 2023 09:08:59 +0000 (11:08 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 25 Oct 2023 16:54:12 +0000 (18:54 +0200)
With the new WebGL renderer, chrome/chromium has buggy software
support for emulating this (see [0]), so we have to detect that
manually and prevent loading the add-on. This fixes the issue that on
chrome without HW-support, it would not always render every character.

Firefox does not have support for a software renderer and the
loading/detection throws an exception, falling back to the default
renderer.

0: https://github.com/xtermjs/xterm.js/issues/4574

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
xterm.js/src/main.js

index 85cc39953c928bc2003323777069a49fca5078ab..15756970413f1df711fdfa8cb3dd03fca6cfb2a1 100644 (file)
@@ -154,9 +154,15 @@ function createTerminal() {
     term = new Terminal(getTerminalSettings());
     term.open(terminalContainer);
     term.loadAddon(fitAddon);
+    let loadedWebgl = false;
     try {
-       term.loadAddon(webglAddon);
-    } catch (_e) {
+       if (detectWebgl()) {
+           term.loadAddon(webglAddon);
+           loadedWebgl = true;
+       }
+    } catch (_e) { }
+
+    if (!loadedWebgl) {
        console.warn("webgl-addon loading failed, falling back to regular dom renderer");
     }
 
@@ -384,3 +390,15 @@ function errorTerminal(event) {
     term.dispose();
     updateState(states.disconnected, event.msg, event.code);
 }
+
+// try to detect hardware acceleration, can throw an exception if there is no webgl support
+//
+// for chrome we have to give the parameter, otherwise it'll use its software renderer
+// which is buggy: https://github.com/xtermjs/xterm.js/issues/4574
+//
+// firefox will fail on the getContext anyway if there is not hardware support
+function detectWebgl() {
+    const canvas = document.createElement("canvas");
+    const gl = canvas.getContext("webgl2", { failIfMajorPerformanceCaveat: true });
+    return !!gl;
+}