@@ -35,6 +35,7 @@ import { TerminalProcessManager } from 'vs/workbench/contrib/terminal/browser/te
3535import type { Terminal as XTermTerminal , IBuffer , ITerminalAddon } from 'xterm' ;
3636import type { SearchAddon , ISearchOptions } from 'xterm-addon-search' ;
3737import type { Unicode11Addon } from 'xterm-addon-unicode11' ;
38+ import type { WebglAddon } from 'xterm-addon-webgl' ;
3839import { CommandTrackerAddon } from 'vs/workbench/contrib/terminal/browser/addons/commandTrackerAddon' ;
3940import { NavigationModeAddon } from 'vs/workbench/contrib/terminal/browser/addons/navigationModeAddon' ;
4041import { XTermCore } from 'vs/workbench/contrib/terminal/browser/xterm-private' ;
@@ -105,6 +106,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
105106 private _widgetManager : TerminalWidgetManager = this . _instantiationService . createInstance ( TerminalWidgetManager ) ;
106107 private _linkManager : TerminalLinkManager | undefined ;
107108 private _environmentInfo : { widget : EnvironmentVariableInfoWidget , disposable : IDisposable } | undefined ;
109+ private _webglAddon : WebglAddon | undefined ;
108110 private _commandTrackerAddon : CommandTrackerAddon | undefined ;
109111 private _navigationModeAddon : INavigationMode & ITerminalAddon | undefined ;
110112
@@ -496,9 +498,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
496498 this . _container . appendChild ( this . _wrapperElement ) ;
497499 xterm . open ( this . _xtermElement ) ;
498500 if ( this . _configHelper . config . rendererType === 'experimentalWebgl' ) {
499- this . _terminalInstanceService . getXtermWebglConstructor ( ) . then ( Addon => {
500- xterm . loadAddon ( new Addon ( ) ) ;
501- } ) ;
501+ this . _enableWebglRenderer ( ) ;
502502 }
503503
504504 if ( ! xterm . element || ! xterm . textarea ) {
@@ -767,7 +767,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
767767 if ( ! this . _xterm ) {
768768 return ;
769769 }
770- this . _xterm . refresh ( 0 , this . _xterm . rows - 1 ) ;
770+ this . _webglAddon ?. clearTextureAtlas ( ) ;
771+ // TODO: Do canvas renderer too?
771772 }
772773
773774 public focus ( force ?: boolean ) : void {
@@ -1227,13 +1228,26 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
12271228 this . _safeSetOption ( 'macOptionClickForcesSelection' , config . macOptionClickForcesSelection ) ;
12281229 this . _safeSetOption ( 'rightClickSelectsWord' , config . rightClickBehavior === 'selectWord' ) ;
12291230 this . _safeSetOption ( 'wordSeparator' , config . wordSeparators ) ;
1230- if ( config . rendererType !== 'experimentalWebgl' ) {
1231+ if ( config . rendererType === 'experimentalWebgl' ) {
1232+ this . _enableWebglRenderer ( ) ;
1233+ } else {
1234+ this . _webglAddon ?. dispose ( ) ;
1235+ this . _webglAddon = undefined ;
12311236 // Never set webgl as it's an addon not a rendererType
12321237 this . _safeSetOption ( 'rendererType' , config . rendererType === 'auto' ? 'canvas' : config . rendererType ) ;
12331238 }
12341239 this . _refreshEnvironmentVariableInfoWidgetState ( this . _processManager . environmentVariableInfo ) ;
12351240 }
12361241
1242+ private async _enableWebglRenderer ( ) : Promise < void > {
1243+ if ( ! this . _xterm || this . _webglAddon ) {
1244+ return ;
1245+ }
1246+ const Addon = await this . _terminalInstanceService . getXtermWebglConstructor ( ) ;
1247+ this . _webglAddon = new Addon ( ) ;
1248+ this . _xterm . loadAddon ( this . _webglAddon ) ;
1249+ }
1250+
12371251 private async _updateUnicodeVersion ( ) : Promise < void > {
12381252 if ( ! this . _xterm ) {
12391253 throw new Error ( 'Cannot update unicode version before xterm has been initialized' ) ;
0 commit comments