Add API to clear canvas renderer texture atlas

Fixes #3455
This commit is contained in:
Daniel Imms
2021-09-22 06:38:47 -07:00
parent be7fcbe485
commit 189ff56224
12 changed files with 56 additions and 0 deletions
+4
View File
@@ -1290,6 +1290,10 @@ export class Terminal extends CoreTerminal implements ITerminal {
this.viewport?.syncScrollArea(); this.viewport?.syncScrollArea();
} }
public clearTextureAtlas(): void {
this._renderService?.clearTextureAtlas();
}
private _reportWindowsOptions(type: WindowsOptionsReportType): void { private _reportWindowsOptions(type: WindowsOptionsReportType): void {
if (!this._renderService) { if (!this._renderService) {
return; return;
+6
View File
@@ -195,6 +195,9 @@ export class MockTerminal implements ITerminal {
public reset(): void { public reset(): void {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
public clearTextureAtlas(): void {
throw new Error('Method not implemented.');
}
public refresh(start: number, end: number): void { public refresh(start: number, end: number): void {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
@@ -374,6 +377,9 @@ export class MockRenderService implements IRenderService {
public refreshRows(start: number, end: number): void { public refreshRows(start: number, end: number): void {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
public clearTextureAtlas(): void {
throw new Error('Method not implemented.');
}
public resize(cols: number, rows: number): void { public resize(cols: number, rows: number): void {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
+1
View File
@@ -79,6 +79,7 @@ export interface IPublicTerminal extends IDisposable {
write(data: string | Uint8Array, callback?: () => void): void; write(data: string | Uint8Array, callback?: () => void): void;
paste(data: string): void; paste(data: string): void;
refresh(start: number, end: number): void; refresh(start: number, end: number): void;
clearTextureAtlas(): void;
reset(): void; reset(): void;
} }
+3
View File
@@ -222,6 +222,9 @@ export class Terminal implements ITerminalApi {
public reset(): void { public reset(): void {
this._core.reset(); this._core.reset();
} }
public clearTextureAtlas(): void {
this._core.clearTextureAtlas();
}
public loadAddon(addon: ITerminalAddon): void { public loadAddon(addon: ITerminalAddon): void {
return this._addonManager.loadAddon(this, addon); return this._addonManager.loadAddon(this, addon);
} }
+4
View File
@@ -138,6 +138,10 @@ export abstract class BaseRenderLayer implements IRenderLayer {
public abstract reset(): void; public abstract reset(): void;
public clearTextureAtlas(): void {
this._charAtlas?.clear();
}
/** /**
* Fills 1+ cells completely. This uses the existing fillStyle on the context. * Fills 1+ cells completely. This uses the existing fillStyle on the context.
* @param x The column to start at. * @param x The column to start at.
+6
View File
@@ -149,6 +149,12 @@ export class Renderer extends Disposable implements IRenderer {
} }
} }
public clearTextureAtlas(): void {
for (const layer of this._renderLayers) {
layer.clearTextureAtlas();
}
}
/** /**
* Recalculates the character and canvas dimensions. * Recalculates the character and canvas dimensions.
*/ */
+6
View File
@@ -52,6 +52,7 @@ export interface IRenderer extends IDisposable {
onOptionsChanged(): void; onOptionsChanged(): void;
clear(): void; clear(): void;
renderRows(start: number, end: number): void; renderRows(start: number, end: number): void;
clearTextureAtlas?(): void;
} }
export interface IRenderLayer extends IDisposable { export interface IRenderLayer extends IDisposable {
@@ -100,4 +101,9 @@ export interface IRenderLayer extends IDisposable {
* Clear the state of the render layer. * Clear the state of the render layer.
*/ */
reset(): void; reset(): void;
/**
* Clears the texture atlas.
*/
clearTextureAtlas(): void;
} }
@@ -28,6 +28,8 @@ export abstract class BaseCharAtlas implements IDisposable {
*/ */
private _doWarmUp(): void { } private _doWarmUp(): void { }
public clear(): void { }
/** /**
* Called when we start drawing a new frame. * Called when we start drawing a new frame.
* *
@@ -119,6 +119,16 @@ export class DynamicCharAtlas extends BaseCharAtlas {
this._drawToCacheCount = 0; this._drawToCacheCount = 0;
} }
public clear(): void {
if (this._cacheMap.size > 0) {
const capacity = this._width * this._height;
this._cacheMap = new LRUMap(capacity);
this._cacheMap.prealloc(capacity);
}
this._cacheCtx.clearRect(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);
this._tmpCtx.clearRect(0, 0, this._config.scaledCharWidth, this._config.scaledCharHeight);
}
public draw( public draw(
ctx: CanvasRenderingContext2D, ctx: CanvasRenderingContext2D,
glyph: IGlyphIdentifier, glyph: IGlyphIdentifier,
+5
View File
@@ -168,6 +168,11 @@ export class RenderService extends Disposable implements IRenderService {
} }
} }
public clearTextureAtlas(): void {
this._renderer?.clearTextureAtlas?.();
this._fullRefresh();
}
public setColors(colors: IColorSet): void { public setColors(colors: IColorSet): void {
this._renderer.setColors(colors); this._renderer.setColors(colors);
this._fullRefresh(); this._fullRefresh();
+1
View File
@@ -53,6 +53,7 @@ export interface IRenderService extends IDisposable {
dimensions: IRenderDimensions; dimensions: IRenderDimensions;
refreshRows(start: number, end: number): void; refreshRows(start: number, end: number): void;
clearTextureAtlas(): void;
resize(cols: number, rows: number): void; resize(cols: number, rows: number): void;
changeOptions(): void; changeOptions(): void;
setRenderer(renderer: IRenderer): void; setRenderer(renderer: IRenderer): void;
+8
View File
@@ -1056,6 +1056,14 @@ declare module 'xterm' {
*/ */
refresh(start: number, end: number): void; refresh(start: number, end: number): void;
/**
* Clears the texture atlas of the canvas renderer if it's active. Doing this will force a
* redraw of all glyphs which can workaround issues causing the texture to become corrupt, for
* example Chromium/Nvidia has an issue where the texture gets messed up when resuming the OS
* from sleep.
*/
clearTextureAtlas(): void;
/** /**
* Perform a full reset (RIS, aka '\x1bc'). * Perform a full reset (RIS, aka '\x1bc').
*/ */