Skip to content

Commit f238469

Browse files
authored
Merge pull request #3481 from Tyriar/clear_texture_atlas
Add API to clear canvas renderer texture atlas
2 parents ef6516e + ca46b8c commit f238469

12 files changed

Lines changed: 56 additions & 0 deletions

File tree

src/browser/Terminal.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,10 @@ export class Terminal extends CoreTerminal implements ITerminal {
12921292
this.viewport?.syncScrollArea();
12931293
}
12941294

1295+
public clearTextureAtlas(): void {
1296+
this._renderService?.clearTextureAtlas();
1297+
}
1298+
12951299
private _reportWindowsOptions(type: WindowsOptionsReportType): void {
12961300
if (!this._renderService) {
12971301
return;

src/browser/TestUtils.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ export class MockTerminal implements ITerminal {
195195
public reset(): void {
196196
throw new Error('Method not implemented.');
197197
}
198+
public clearTextureAtlas(): void {
199+
throw new Error('Method not implemented.');
200+
}
198201
public refresh(start: number, end: number): void {
199202
throw new Error('Method not implemented.');
200203
}
@@ -374,6 +377,9 @@ export class MockRenderService implements IRenderService {
374377
public refreshRows(start: number, end: number): void {
375378
throw new Error('Method not implemented.');
376379
}
380+
public clearTextureAtlas(): void {
381+
throw new Error('Method not implemented.');
382+
}
377383
public resize(cols: number, rows: number): void {
378384
throw new Error('Method not implemented.');
379385
}

src/browser/Types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export interface IPublicTerminal extends IDisposable {
7979
write(data: string | Uint8Array, callback?: () => void): void;
8080
paste(data: string): void;
8181
refresh(start: number, end: number): void;
82+
clearTextureAtlas(): void;
8283
reset(): void;
8384
}
8485

src/browser/public/Terminal.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ export class Terminal implements ITerminalApi {
222222
public reset(): void {
223223
this._core.reset();
224224
}
225+
public clearTextureAtlas(): void {
226+
this._core.clearTextureAtlas();
227+
}
225228
public loadAddon(addon: ITerminalAddon): void {
226229
return this._addonManager.loadAddon(this, addon);
227230
}

src/browser/renderer/BaseRenderLayer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ export abstract class BaseRenderLayer implements IRenderLayer {
138138

139139
public abstract reset(): void;
140140

141+
public clearTextureAtlas(): void {
142+
this._charAtlas?.clear();
143+
}
144+
141145
/**
142146
* Fills 1+ cells completely. This uses the existing fillStyle on the context.
143147
* @param x The column to start at.

src/browser/renderer/Renderer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ export class Renderer extends Disposable implements IRenderer {
149149
}
150150
}
151151

152+
public clearTextureAtlas(): void {
153+
for (const layer of this._renderLayers) {
154+
layer.clearTextureAtlas();
155+
}
156+
}
157+
152158
/**
153159
* Recalculates the character and canvas dimensions.
154160
*/

src/browser/renderer/Types.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface IRenderer extends IDisposable {
5252
onOptionsChanged(): void;
5353
clear(): void;
5454
renderRows(start: number, end: number): void;
55+
clearTextureAtlas?(): void;
5556
}
5657

5758
export interface IRenderLayer extends IDisposable {
@@ -100,4 +101,9 @@ export interface IRenderLayer extends IDisposable {
100101
* Clear the state of the render layer.
101102
*/
102103
reset(): void;
104+
105+
/**
106+
* Clears the texture atlas.
107+
*/
108+
clearTextureAtlas(): void;
103109
}

src/browser/renderer/atlas/BaseCharAtlas.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export abstract class BaseCharAtlas implements IDisposable {
2828
*/
2929
private _doWarmUp(): void { }
3030

31+
public clear(): void { }
32+
3133
/**
3234
* Called when we start drawing a new frame.
3335
*

src/browser/renderer/atlas/DynamicCharAtlas.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ export class DynamicCharAtlas extends BaseCharAtlas {
119119
this._drawToCacheCount = 0;
120120
}
121121

122+
public clear(): void {
123+
if (this._cacheMap.size > 0) {
124+
const capacity = this._width * this._height;
125+
this._cacheMap = new LRUMap(capacity);
126+
this._cacheMap.prealloc(capacity);
127+
}
128+
this._cacheCtx.clearRect(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);
129+
this._tmpCtx.clearRect(0, 0, this._config.scaledCharWidth, this._config.scaledCharHeight);
130+
}
131+
122132
public draw(
123133
ctx: CanvasRenderingContext2D,
124134
glyph: IGlyphIdentifier,

src/browser/services/RenderService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ export class RenderService extends Disposable implements IRenderService {
168168
}
169169
}
170170

171+
public clearTextureAtlas(): void {
172+
this._renderer?.clearTextureAtlas?.();
173+
this._fullRefresh();
174+
}
175+
171176
public setColors(colors: IColorSet): void {
172177
this._renderer.setColors(colors);
173178
this._fullRefresh();

0 commit comments

Comments
 (0)