Skip to content

Commit

Permalink
Fix a memory management bug which prevented saving memory from off sc…
Browse files Browse the repository at this point in the history
…reen canvases

This problem resulted in large memory use and very slow updates when changing
text size, DPI, and other attributes of the terminal text.
  • Loading branch information
sedwards2009 committed Feb 2, 2020
1 parent 9ab3d76 commit 842ca1a
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class TerminalCanvasRenderer extends Renderer {
private _canvasTextLayer: CanvasTextLayer;
private _terminalCanvasRendererConfig: TerminalCanvasRendererConfig = null;
private _canvasFontMetricsMonitor: CanvasFontMetricsMonitor = null;
private _isLowMemoryMode = false;

constructor(container: HTMLElement, terminalCanvasRendererConfig: TerminalCanvasRendererConfig) {
super(container, { injectCss: false, fontSize: null });
Expand All @@ -52,7 +53,7 @@ export class TerminalCanvasRenderer extends Renderer {
this._terminalCanvasRendererConfig.ligatureMarker);
return this._canvasTextLayer;
}

protected createFontMetricsMonitor(): FontMetricsMonitor {
this._canvasFontMetricsMonitor = new CanvasFontMetricsMonitor(this._terminalCanvasRendererConfig);
return this._canvasFontMetricsMonitor;
Expand All @@ -71,22 +72,32 @@ export class TerminalCanvasRenderer extends Renderer {
if (this._canvasFontMetricsMonitor != null) {
this._canvasFontMetricsMonitor.setTerminalCanvasRendererConfig(terminalCanvasRendererConfig);
}
this.rerenderText();
if ( ! this._isLowMemoryMode) {
this.rerenderText();
}
}

setRenderCursorStyle(cursorStyle: CursorStyle): void {
if (this._canvasTextLayer != null) {
this._canvasTextLayer.setCursorStyle(cursorStyle);
}
}

/**
* Free up the canvas memory
*
* The canvas memory will remain freed until an explicit request to
* rerender the text is given.
*/
reduceMemory(): void {
this._isLowMemoryMode = true;
if (this._canvasTextLayer != null) {
this._canvasTextLayer.reduceMemory();
}
}

rerenderText(): void {
this._isLowMemoryMode = false;
if (this._canvasTextLayer != null) {
this._canvasTextLayer.rerender();
}
Expand Down

0 comments on commit 842ca1a

Please sign in to comment.