Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebGL addon to web termal #36763

Merged
merged 1 commit into from
Jan 18, 2024
Merged

Add WebGL addon to web termal #36763

merged 1 commit into from
Jan 18, 2024

Conversation

avatus
Copy link
Contributor

@avatus avatus commented Jan 16, 2024

This will add the xterm-webgl-addon to the web ui (not Connect) to help properly display underscores (and perhaps other characters that we haven't discovered).

Tested on Ubuntu 24

Without addon (there should be an underscore between "testing" and "thing")
Screenshot from 2024-01-16 15-02-32

With addon
Screenshot from 2024-01-16 15-01-34

changelog: The web terminal now properly displays underscores on Linux

Copy link

@orca-security-us orca-security-us bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Failed Failed Vulnerabilities high 3   medium 1   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca

@@ -78,6 +80,12 @@ export default class TtyTerminal {

this.term.loadAddon(this._fitAddon);
this.term.loadAddon(this._webLinksAddon);
// handle context loss and load webgl addon
this._webglAddon.onContextLoss(() => {
this._webglAddon.dispose();
Copy link
Contributor

@kimlisa kimlisa Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we need to also call this in the destory() func.

i'm not sure i understand what the onContextLoss does, but shouldn't we try to re-instantiate it after disposing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we need it in destroy() for sure. thank you!

onContextLoss is essentially when the browser loses access to the GPU when rendering (if you do some weird driver updates or some kind of switch between GPUs). it's rare. However, the addon itself runs a timeout internally to automatically reinstantiate after a couple seconds and keeps trying.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs say:

An easy, but suboptimal way, to handle this is to..

Is there a more optimal way to handle this scenario?

Copy link
Collaborator

@zmb3 zmb3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a fallback to canvas renderer? Do we need any sort of feature detection in case webgl is not available?

@marcoandredinis
Copy link
Contributor

I can confirm that this works for me 👍
image

@avatus
Copy link
Contributor Author

avatus commented Jan 17, 2024

Do we need a fallback to canvas renderer? Do we need any sort of feature detection in case webgl is not available?

We dont need to, it falls back to the dom renderer by default. Also, the "suboptimal" way I believe is them talking about just disposing and falling back to dom rendering. I checked out vscode and they basically do webgl -> canvas -> dom. I can do the same here

Do we need any sort of feature detection in case webgl is not available?

the WebglAddon constructor will throw if webgl is not supported, so catching that and falling back to canvas/dom is good enough. we don't really need any independent feature detection/state imo

// wont start looking for the context again until the OS has given the browser the context again.
// When the initial context lost event is fired, the webgl addon consumes the event
// and waits for a bit to see if it can get the context back. If it fails repeatedly, it
// will propegate the context loss event itself in which case we fall back to context.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// will propegate the context loss event itself in which case we fall back to context.
// will propagate the context loss event itself in which case we fall back to canvas.

@@ -77,7 +81,28 @@ export default class TtyTerminal {
});

this.term.loadAddon(this._fitAddon);
this.term.loadAddon(this._webLinksAddon);
// this.term.loadAddon(this._webLinksAddon);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more link support? 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my goodness thank you for catching this

@@ -98,6 +123,21 @@ export default class TtyTerminal {
window.addEventListener('resize', this._debouncedResize);
}

fallbackToCanvas() {
console.log('WebGL context lost. Falling back to canvas');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use our logger instead of console here?

@marcoandredinis marcoandredinis removed their request for review January 18, 2024 12:04
} catch (err) {
this.fallbackToCanvas();
}
this.term.loadAddon(this._webglAddon);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing this twice?

try {
// try to create a new WebglAddon. If webgl is not supported, this
// constructor will throw an error and fallback to canvas. We also fallback
// to canvas is the webgl context is lost after a timeout.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// to canvas is the webgl context is lost after a timeout.
// to canvas if the webgl context is lost after a timeout.

Comment on lines 126 to 127
logger.info('WebGL context lost. Falling back to canvas');
this._webglAddon.dispose();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems safer since it's initially undefined

Suggested change
logger.info('WebGL context lost. Falling back to canvas');
this._webglAddon.dispose();
logger.info('WebGL context lost. Falling back to canvas');
this._webglAddon?.dispose();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolutely right. ty

@avatus avatus added this pull request to the merge queue Jan 18, 2024
@kimlisa kimlisa removed this pull request from the merge queue due to a manual request Jan 18, 2024
@avatus avatus enabled auto-merge January 18, 2024 20:29
@avatus avatus added this pull request to the merge queue Jan 18, 2024
Merged via the queue into master with commit 269150e Jan 18, 2024
38 checks passed
@avatus avatus deleted the avatus/webgl branch January 18, 2024 20:49
@public-teleport-github-review-bot

@avatus See the table below for backport results.

Branch Result
branch/v13 Failed
branch/v14 Failed
branch/v15 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants