@@ -56,7 +56,7 @@ function detectWebGLSupport(): boolean {
5656 }
5757}
5858
59- const WebGLSupported = detectWebGLSupport ( ) ;
59+ export const WebGLSupported = detectWebGLSupport ( ) ;
6060let loggedWebGL = false ;
6161
6262type TermWrapOptions = {
@@ -85,6 +85,8 @@ export class TermWrap {
8585 sendDataHandler : ( data : string ) => void ;
8686 onSearchResultsDidChange ?: ( result : { resultIndex : number ; resultCount : number } ) => void ;
8787 private toDispose : TermTypes . IDisposable [ ] = [ ] ;
88+ webglAddon : WebglAddon | null = null ;
89+ webglEnabledAtom : jotai . PrimitiveAtom < boolean > ;
8890 pasteActive : boolean = false ;
8991 lastUpdated : number ;
9092 promptMarkers : TermTypes . IMarker [ ] = [ ] ;
@@ -142,6 +144,7 @@ export class TermWrap {
142144 this . promptMarkers = [ ] ;
143145 this . shellIntegrationStatusAtom = jotai . atom ( null ) as jotai . PrimitiveAtom < ShellIntegrationStatus | null > ;
144146 this . lastCommandAtom = jotai . atom ( null ) as jotai . PrimitiveAtom < string | null > ;
147+ this . webglEnabledAtom = jotai . atom ( false ) as jotai . PrimitiveAtom < boolean > ;
145148 this . terminal = new Terminal ( options ) ;
146149 this . fitAddon = new FitAddon ( ) ;
147150 this . fitAddon . scrollbarWidth = 6 ; // this needs to match scrollbar width in term.scss
@@ -180,17 +183,7 @@ export class TermWrap {
180183 )
181184 ) ;
182185 if ( WebGLSupported && waveOptions . useWebGl ) {
183- const webglAddon = new WebglAddon ( ) ;
184- this . toDispose . push (
185- webglAddon . onContextLoss ( ( ) => {
186- webglAddon . dispose ( ) ;
187- } )
188- ) ;
189- this . terminal . loadAddon ( webglAddon ) ;
190- if ( ! loggedWebGL ) {
191- console . log ( "loaded webgl!" ) ;
192- loggedWebGL = true ;
193- }
186+ this . loadWebGlAddon ( ) ;
194187 }
195188 // Register OSC handlers
196189 this . terminal . parser . registerOscHandler ( 7 , ( data : string ) => {
@@ -307,6 +300,44 @@ export class TermWrap {
307300 this . terminal . options . cursorBlink = cursorBlink ?? false ;
308301 }
309302
303+ loadWebGlAddon ( ) {
304+ const addon = new WebglAddon ( ) ;
305+ this . toDispose . push (
306+ addon . onContextLoss ( ( ) => {
307+ if ( addon === this . webglAddon ) {
308+ this . disableWebGl ( ) ;
309+ }
310+ } )
311+ ) ;
312+ this . terminal . loadAddon ( addon ) ;
313+ this . webglAddon = addon ;
314+ globalStore . set ( this . webglEnabledAtom , true ) ;
315+ if ( ! loggedWebGL ) {
316+ console . log ( "loaded webgl!" ) ;
317+ loggedWebGL = true ;
318+ }
319+ }
320+
321+ isWebGlEnabled ( ) : boolean {
322+ return this . webglAddon != null ;
323+ }
324+
325+ enableWebGl ( ) {
326+ if ( ! WebGLSupported || this . webglAddon != null ) {
327+ return ;
328+ }
329+ this . loadWebGlAddon ( ) ;
330+ }
331+
332+ disableWebGl ( ) {
333+ if ( this . webglAddon == null ) {
334+ return ;
335+ }
336+ this . webglAddon . dispose ( ) ;
337+ this . webglAddon = null ;
338+ globalStore . set ( this . webglEnabledAtom , false ) ;
339+ }
340+
310341 resetCompositionState ( ) {
311342 this . isComposing = false ;
312343 this . composingData = "" ;
0 commit comments