From d62b4531c3a6e72b964c4a6c4e8706a2b55be9fa Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 24 Sep 2022 06:58:01 -0700 Subject: [PATCH] Optimize contexts for reading frequently This was a recommendation from Edge. Docs here: https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-will-read-frequently --- addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts | 5 ++++- src/browser/ColorManager.ts | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts b/addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts index 9ba83de6..092cf2e5 100644 --- a/addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts +++ b/addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts @@ -110,7 +110,10 @@ export class WebglCharAtlas implements IDisposable { this._tmpCanvas = document.createElement('canvas'); this._tmpCanvas.width = this._config.scaledCellWidth * 4 + TMP_CANVAS_GLYPH_PADDING * 2; this._tmpCanvas.height = this._config.scaledCellHeight + TMP_CANVAS_GLYPH_PADDING * 2; - this._tmpCtx = throwIfFalsy(this._tmpCanvas.getContext('2d', { alpha: this._config.allowTransparency })); + this._tmpCtx = throwIfFalsy(this._tmpCanvas.getContext('2d', { + alpha: this._config.allowTransparency, + willReadFrequently: true + })); } public dispose(): void { diff --git a/src/browser/ColorManager.ts b/src/browser/ColorManager.ts index d8dcde6f..4ec0053c 100644 --- a/src/browser/ColorManager.ts +++ b/src/browser/ColorManager.ts @@ -89,7 +89,9 @@ export class ColorManager implements IColorManager { const canvas = document.createElement('canvas'); canvas.width = 1; canvas.height = 1; - const ctx = canvas.getContext('2d'); + const ctx = canvas.getContext('2d', { + willReadFrequently: true + }); if (!ctx) { throw new Error('Could not get rendering context'); }