@@ -15,12 +15,13 @@ import { ReadonlyColorSet } from 'browser/Types';
1515import { CellData } from 'common/buffer/CellData' ;
1616import { WHITESPACE_CELL_CODE } from 'common/buffer/Constants' ;
1717import { IBufferService , IDecorationService , IOptionsService } from 'common/services/Services' ;
18- import { ICellData } from 'common/Types' ;
18+ import { ICellData , IDisposable } from 'common/Types' ;
1919import { Terminal } from 'xterm' ;
2020import { IRenderLayer } from './Types' ;
2121import { CellColorResolver } from 'browser/renderer/shared/CellColorResolver' ;
2222import { Disposable , toDisposable } from 'common/Lifecycle' ;
2323import { isSafari } from 'common/Platform' ;
24+ import { EventEmitter , forwardEvent } from 'common/EventEmitter' ;
2425
2526export abstract class BaseRenderLayer extends Disposable implements IRenderLayer {
2627 private _canvas : HTMLCanvasElement ;
@@ -34,12 +35,16 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
3435
3536 protected _selectionModel : ISelectionRenderModel = createSelectionRenderModel ( ) ;
3637 private _cellColorResolver : CellColorResolver ;
37- private _bitmapGenerator ?: BitmapGenerator ;
38+ private _bitmapGenerator : ( BitmapGenerator | undefined ) [ ] = [ ] ;
3839
3940 protected _charAtlas ! : ITextureAtlas ;
41+ private _charAtlasDisposable ?: IDisposable ;
4042
4143 public get canvas ( ) : HTMLCanvasElement { return this . _canvas ; }
42- public get cacheCanvas ( ) : HTMLCanvasElement { return this . _charAtlas ?. cacheCanvas ! ; }
44+ public get cacheCanvas ( ) : HTMLCanvasElement { return this . _charAtlas ?. pages [ 0 ] . canvas ! ; }
45+
46+ private readonly _onAddTextureAtlasCanvas = this . register ( new EventEmitter < HTMLCanvasElement > ( ) ) ;
47+ public readonly onAddTextureAtlasCanvas = this . _onAddTextureAtlasCanvas . event ;
4348
4449 constructor (
4550 private readonly _terminal : Terminal ,
@@ -116,9 +121,13 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
116121 if ( this . _deviceCharWidth <= 0 && this . _deviceCharHeight <= 0 ) {
117122 return ;
118123 }
124+ this . _charAtlasDisposable ?. dispose ( ) ;
119125 this . _charAtlas = acquireTextureAtlas ( this . _terminal , colorSet , this . _deviceCellWidth , this . _deviceCellHeight , this . _deviceCharWidth , this . _deviceCharHeight , this . _coreBrowserService . dpr ) ;
126+ this . _charAtlasDisposable = forwardEvent ( this . _charAtlas . onAddTextureAtlasCanvas , this . _onAddTextureAtlasCanvas ) ;
120127 this . _charAtlas . warmUp ( ) ;
121- this . _bitmapGenerator = new BitmapGenerator ( this . _charAtlas . cacheCanvas ) ;
128+ for ( let i = 0 ; i < this . _charAtlas . pages . length ; i ++ ) {
129+ this . _bitmapGenerator [ i ] = new BitmapGenerator ( this . _charAtlas . pages [ i ] . canvas ) ;
130+ }
122131 }
123132
124133 public resize ( dim : IRenderDimensions ) : void {
@@ -367,12 +376,15 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
367376 this . _ctx . save ( ) ;
368377 this . _clipRow ( y ) ;
369378 // Draw the image, use the bitmap if it's available
370- if ( this . _charAtlas . hasCanvasChanged ) {
371- this . _bitmapGenerator ?. refresh ( ) ;
372- this . _charAtlas . hasCanvasChanged = false ;
379+ if ( this . _charAtlas . pages [ glyph . texturePage ] . hasCanvasChanged ) {
380+ if ( ! this . _bitmapGenerator [ glyph . texturePage ] ) {
381+ this . _bitmapGenerator [ glyph . texturePage ] = new BitmapGenerator ( this . _charAtlas . pages [ glyph . texturePage ] . canvas ) ;
382+ }
383+ this . _bitmapGenerator [ glyph . texturePage ] ?. refresh ( ) ;
384+ this . _charAtlas . pages [ glyph . texturePage ] . hasCanvasChanged = false ;
373385 }
374386 this . _ctx . drawImage (
375- this . _bitmapGenerator ?. bitmap || this . _charAtlas ! . cacheCanvas ,
387+ this . _bitmapGenerator [ glyph . texturePage ] ?. bitmap || this . _charAtlas ! . pages [ glyph . texturePage ] . canvas ,
376388 glyph . texturePosition . x ,
377389 glyph . texturePosition . y ,
378390 glyph . size . x ,
0 commit comments