Skip to content

Add WebGL addon to web termal#36763

Merged
avatus merged 1 commit intomasterfrom
avatus/webgl
Jan 18, 2024
Merged

Add WebGL addon to web termal#36763
avatus merged 1 commit intomasterfrom
avatus/webgl

Conversation

@avatus
Copy link
Copy Markdown
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
Copy Markdown

@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

@github-actions github-actions Bot requested review from gzdunek and ravicious January 16, 2024 21:06
@avatus avatus enabled auto-merge January 16, 2024 21:27
@zmb3 zmb3 requested a review from marcoandredinis January 16, 2024 21:34
@avatus avatus requested review from ryanclark and removed request for gzdunek and ravicious January 17, 2024 00:03
this.term.loadAddon(this._webLinksAddon);
// handle context loss and load webgl addon
this._webglAddon.onContextLoss(() => {
this._webglAddon.dispose();
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

I can confirm that this works for me 👍
image

@avatus
Copy link
Copy Markdown
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
Copy Markdown
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.


this.term.loadAddon(this._fitAddon);
this.term.loadAddon(this._webLinksAddon);
// this.term.loadAddon(this._webLinksAddon);
Copy link
Copy Markdown
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
Copy Markdown
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

}

fallbackToCanvas() {
console.log('WebGL context lost. Falling back to canvas');
Copy link
Copy Markdown
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
Copy link
Copy Markdown
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?

Copy link
Copy Markdown
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
Copy link
Copy Markdown
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
Copy Markdown
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
@public-teleport-github-review-bot public-teleport-github-review-bot Bot removed the request for review from rudream January 18, 2024 20:24
@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
@avatus avatus deleted the avatus/webgl branch January 18, 2024 20:49
@public-teleport-github-review-bot
Copy link
Copy Markdown

@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