public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-xtermjs] xtermjs: try to detect hardware support for webgl2
@ 2023-10-25  9:08 Dominik Csapak
  2023-10-25 17:02 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2023-10-25  9:08 UTC (permalink / raw)
  To: pve-devel

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 addon. 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>
---
tested with and without webgl hardware support on firefox/chrome/chromium

 xterm.js/src/main.js | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/xterm.js/src/main.js b/xterm.js/src/main.js
index 85cc399..1575697 100644
--- a/xterm.js/src/main.js
+++ b/xterm.js/src/main.js
@@ -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;
+}
-- 
2.30.2





^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pve-devel] applied: [PATCH pve-xtermjs] xtermjs: try to detect hardware support for webgl2
  2023-10-25  9:08 [pve-devel] [PATCH pve-xtermjs] xtermjs: try to detect hardware support for webgl2 Dominik Csapak
@ 2023-10-25 17:02 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2023-10-25 17:02 UTC (permalink / raw)
  To: Proxmox VE development discussion, Dominik Csapak

Am 25/10/2023 um 11:08 schrieb Dominik Csapak:
> 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 addon. 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>
> ---
> tested with and without webgl hardware support on firefox/chrome/chromium
> 
>  xterm.js/src/main.js | 22 ++++++++++++++++++++--
>  1 file changed, 20 insertions(+), 2 deletions(-)
> 
>

applied, thanks!




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-25 17:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-25  9:08 [pve-devel] [PATCH pve-xtermjs] xtermjs: try to detect hardware support for webgl2 Dominik Csapak
2023-10-25 17:02 ` [pve-devel] applied: " Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal