Skip to content

Commit 2f72682

Browse files
committed
Add canvas renderer addon
1 parent 852b4ae commit 2f72682

File tree

11 files changed

+83
-9
lines changed

11 files changed

+83
-9
lines changed

.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@
259259
"windows-process-tree",
260260
"worker_threads",
261261
"xterm",
262+
"xterm-addon-canvas",
262263
"xterm-addon-search",
263264
"xterm-addon-serialize",
264265
"xterm-addon-unicode11",

build/.webignore

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ vscode-textmate/webpack.config.js
2020

2121
xterm/src/**
2222

23+
xterm-addon-canvas/src/**
24+
xterm-addon-canvas/out/**
25+
2326
xterm-addon-search/src/**
2427
xterm-addon-search/out/**
2528
xterm-addon-search/fixtures/**

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"vscode-regexpp": "^3.1.0",
8888
"vscode-textmate": "7.0.1",
8989
"xterm": "5.0.0-beta.32",
90+
"xterm-addon-canvas": "0.2.0-beta.15",
9091
"xterm-addon-search": "0.10.0-beta.3",
9192
"xterm-addon-serialize": "0.8.0-beta.3",
9293
"xterm-addon-unicode11": "0.4.0-beta.3",

remote/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"vscode-regexpp": "^3.1.0",
2626
"vscode-textmate": "7.0.1",
2727
"xterm": "5.0.0-beta.32",
28+
"xterm-addon-canvas": "0.2.0-beta.15",
2829
"xterm-addon-search": "0.10.0-beta.3",
2930
"xterm-addon-serialize": "0.8.0-beta.3",
3031
"xterm-addon-unicode11": "0.4.0-beta.3",

remote/web/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"vscode-oniguruma": "1.6.1",
1313
"vscode-textmate": "7.0.1",
1414
"xterm": "5.0.0-beta.32",
15+
"xterm-addon-canvas": "0.2.0-beta.15",
1516
"xterm-addon-search": "0.10.0-beta.3",
1617
"xterm-addon-unicode11": "0.4.0-beta.3",
1718
"xterm-addon-webgl": "0.13.0-beta.32"

remote/web/yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ [email protected]:
6868
resolved "https://registry.yarnpkg.com/vscode-textmate/-/vscode-textmate-7.0.1.tgz#8118a32b02735dccd14f893b495fa5389ad7de79"
6969
integrity sha512-zQ5U/nuXAAMsh691FtV0wPz89nSkHbs+IQV8FDk+wew9BlSDhf4UmWGlWJfTR2Ti6xZv87Tj5fENzKf6Qk7aLw==
7070

71+
72+
version "0.2.0-beta.15"
73+
resolved "https://registry.yarnpkg.com/xterm-addon-canvas/-/xterm-addon-canvas-0.2.0-beta.15.tgz#de863e46410b1de357b153abf1984227777760e4"
74+
integrity sha512-E1pNCDSVTINchwWLysZ9ZD/BPv1WLGV52xRHB00US1PHHELbhtvms+6dZ44WZEDXhtfpptRZ1VBx+QpvfJIuvw==
75+
7176
7277
version "0.10.0-beta.3"
7378
resolved "https://registry.yarnpkg.com/xterm-addon-search/-/xterm-addon-search-0.10.0-beta.3.tgz#5194434d86105637c71f6f20139a9d0b5c1a956a"

remote/yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,11 @@ wrappy@1:
788788
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
789789
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
790790

791+
792+
version "0.2.0-beta.15"
793+
resolved "https://registry.yarnpkg.com/xterm-addon-canvas/-/xterm-addon-canvas-0.2.0-beta.15.tgz#de863e46410b1de357b153abf1984227777760e4"
794+
integrity sha512-E1pNCDSVTINchwWLysZ9ZD/BPv1WLGV52xRHB00US1PHHELbhtvms+6dZ44WZEDXhtfpptRZ1VBx+QpvfJIuvw==
795+
791796
792797
version "0.10.0-beta.3"
793798
resolved "https://registry.yarnpkg.com/xterm-addon-search/-/xterm-addon-search-0.10.0-beta.3.tgz#5194434d86105637c71f6f20139a9d0b5c1a956a"

scripts/update-xterm.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const path = require('path');
88

99
const moduleNames = [
1010
'xterm',
11+
'xterm-addon-canvas',
1112
'xterm-addon-search',
1213
'xterm-addon-unicode11',
1314
'xterm-addon-webgl'

src/bootstrap-window.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
'vscode-textmate': `${baseNodeModulesPath}/vscode-textmate/release/main.js`,
137137
'vscode-oniguruma': `${baseNodeModulesPath}/vscode-oniguruma/release/main.js`,
138138
'xterm': `${baseNodeModulesPath}/xterm/lib/xterm.js`,
139+
'xterm-addon-canvas': `${baseNodeModulesPath}/xterm-addon-canvas/lib/xterm-addon-canvas.js`,
139140
'xterm-addon-search': `${baseNodeModulesPath}/xterm-addon-search/lib/xterm-addon-search.js`,
140141
'xterm-addon-unicode11': `${baseNodeModulesPath}/xterm-addon-unicode11/lib/xterm-addon-unicode11.js`,
141142
'xterm-addon-webgl': `${baseNodeModulesPath}/xterm-addon-webgl/lib/xterm-addon-webgl.js`,
@@ -150,7 +151,7 @@
150151
// which has a fallback to using node.js `require`
151152
// (node.js enabled renderers only)
152153
if (!safeProcess.sandboxed) {
153-
loaderConfig.amdModulesPattern = /(^vs\/)|(^vscode-textmate$)|(^vscode-oniguruma$)|(^xterm$)|(^xterm-addon-search$)|(^xterm-addon-unicode11$)|(^xterm-addon-webgl$)|(^@vscode\/iconv-lite-umd$)|(^jschardet$)|(^@vscode\/vscode-languagedetection$)|(^vscode-regexp-languagedetection$)|(^tas-client-umd$)/;
154+
loaderConfig.amdModulesPattern = /(^vs\/)|(^vscode-textmate$)|(^vscode-oniguruma$)|(^xterm$)|(^xterm-addon-canvas$)|(^xterm-addon-search$)|(^xterm-addon-unicode11$)|(^xterm-addon-webgl$)|(^@vscode\/iconv-lite-umd$)|(^jschardet$)|(^@vscode\/vscode-languagedetection$)|(^vscode-regexp-languagedetection$)|(^tas-client-umd$)/;
154155
}
155156

156157
// Signal before require.config()

src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.ts

+58-8
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import type { IBuffer, IMarker, ITheme, Terminal as RawXtermTerminal } from 'xterm';
7+
import type { CanvasAddon as CanvasAddonType } from 'xterm-addon-canvas';
78
import type { ISearchOptions, SearchAddon as SearchAddonType } from 'xterm-addon-search';
89
import type { Unicode11Addon as Unicode11AddonType } from 'xterm-addon-unicode11';
910
import type { WebglAddon as WebglAddonType } from 'xterm-addon-webgl';
10-
import { SerializeAddon as SerializeAddonType } from 'xterm-addon-serialize';
11+
import type { SerializeAddon as SerializeAddonType } from 'xterm-addon-serialize';
1112
import { IXtermCore } from 'vs/workbench/contrib/terminal/browser/xterm-private';
1213
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
1314
import { TerminalConfigHelper } from 'vs/workbench/contrib/terminal/browser/terminalConfigHelper';
@@ -42,10 +43,11 @@ import { IGenericMarkProperties } from 'vs/platform/terminal/common/terminalProc
4243
const SLOW_CANVAS_RENDER_THRESHOLD = 50;
4344
const NUMBER_OF_FRAMES_TO_MEASURE = 20;
4445

46+
let CanvasAddon: typeof CanvasAddonType;
4547
let SearchAddon: typeof SearchAddonType;
48+
let SerializeAddon: typeof SerializeAddonType;
4649
let Unicode11Addon: typeof Unicode11AddonType;
4750
let WebglAddon: typeof WebglAddonType;
48-
let SerializeAddon: typeof SerializeAddonType;
4951

5052
/**
5153
* Wraps the xterm object with additional functionality. Interaction with the backing process is out
@@ -65,6 +67,7 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal, II
6567
private _decorationAddon: DecorationAddon;
6668

6769
// Optional addons
70+
private _canvasAddon?: CanvasAddonType;
6871
private _searchAddon?: SearchAddonType;
6972
private _unicode11Addon?: Unicode11AddonType;
7073
private _webglAddon?: WebglAddonType;
@@ -140,7 +143,6 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal, II
140143
fastScrollModifier: 'alt',
141144
fastScrollSensitivity: config.fastScrollSensitivity,
142145
scrollSensitivity: config.mouseWheelScrollSensitivity,
143-
// rendererType: this._getBuiltInXtermRenderer(config.gpuAcceleration, XtermTerminal._suggestedRendererType),
144146
wordSeparator: config.wordSeparators,
145147
overviewRulerWidth: 10
146148
}));
@@ -214,6 +216,9 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal, II
214216
this._container = container;
215217
if (this._shouldLoadWebgl()) {
216218
this._enableWebglRenderer();
219+
} else if (this._shouldLoadCanvas()) {
220+
this._enableCanvasRenderer();
221+
// rendererType: this._getBuiltInXtermRenderer(config.gpuAcceleration, XtermTerminal._suggestedRendererType),
217222
}
218223
// Screen must be created at this point as xterm.open is called
219224
return this._container.querySelector('.xterm-screen')!;
@@ -241,15 +246,22 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal, II
241246
this._enableWebglRenderer();
242247
} else {
243248
this._disposeOfWebglRenderer();
244-
// TODO: Fix renderer
245-
// this.raw.options.rendererType = this._getBuiltInXtermRenderer(config.gpuAcceleration, XtermTerminal._suggestedRendererType);
249+
if (this._shouldLoadCanvas()) {
250+
this._enableCanvasRenderer();
251+
} else {
252+
this._disposeOfCanvasRenderer();
253+
}
246254
}
247255
}
248256

249257
private _shouldLoadWebgl(): boolean {
250258
return !isSafari && (this._configHelper.config.gpuAcceleration === 'auto' && XtermTerminal._suggestedRendererType === undefined) || this._configHelper.config.gpuAcceleration === 'on';
251259
}
252260

261+
private _shouldLoadCanvas(): boolean {
262+
return (this._configHelper.config.gpuAcceleration === 'auto' && (XtermTerminal._suggestedRendererType === undefined || XtermTerminal._suggestedRendererType === 'canvas')) || this._configHelper.config.gpuAcceleration === 'canvas';
263+
}
264+
253265
forceRedraw() {
254266
this._webglAddon?.clearTextureAtlas();
255267
this.raw.clearTextureAtlas();
@@ -436,6 +448,7 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal, II
436448
}
437449
const Addon = await this._getWebglAddonConstructor();
438450
this._webglAddon = new Addon();
451+
this._disposeOfCanvasRenderer();
439452
try {
440453
this.raw.loadAddon(this._webglAddon);
441454
this._logService.trace('Webgl was loaded');
@@ -458,13 +471,41 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal, II
458471
if (!neverMeasureRenderTime && this._configHelper.config.gpuAcceleration !== 'off') {
459472
this._measureRenderTime();
460473
}
461-
// TODO: Fix renderer
462-
// this.raw.options.rendererType = 'canvas';
463-
// XtermTerminal._suggestedRendererType = 'canvas';
474+
XtermTerminal._suggestedRendererType = 'canvas';
464475
this._disposeOfWebglRenderer();
476+
this._enableCanvasRenderer();
465477
}
466478
}
467479

480+
private async _enableCanvasRenderer(): Promise<void> {
481+
if (!this.raw.element || this._canvasAddon) {
482+
return;
483+
}
484+
const Addon = await this._getCanvasAddonConstructor();
485+
this._canvasAddon = new Addon();
486+
this._disposeOfWebglRenderer();
487+
try {
488+
this.raw.loadAddon(this._canvasAddon);
489+
this._logService.trace('Canvas was loaded');
490+
} catch (e) {
491+
this._logService.warn(`Canvas could not be loaded. Falling back to the dom renderer type.`, e);
492+
const neverMeasureRenderTime = this._storageService.getBoolean(TerminalStorageKeys.NeverMeasureRenderTime, StorageScope.APPLICATION, false);
493+
// if it's already set to dom, no need to measure render time
494+
if (!neverMeasureRenderTime && this._configHelper.config.gpuAcceleration !== 'off') {
495+
this._measureRenderTime();
496+
}
497+
XtermTerminal._suggestedRendererType = 'dom';
498+
this._disposeOfCanvasRenderer();
499+
}
500+
}
501+
502+
protected async _getCanvasAddonConstructor(): Promise<typeof CanvasAddonType> {
503+
if (!CanvasAddon) {
504+
CanvasAddon = (await import('xterm-addon-canvas')).CanvasAddon;
505+
}
506+
return CanvasAddon;
507+
}
508+
468509
protected async _getSearchAddonConstructor(): Promise<typeof SearchAddonType> {
469510
if (!SearchAddon) {
470511
SearchAddon = (await import('xterm-addon-search')).SearchAddon;
@@ -493,6 +534,15 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal, II
493534
return SerializeAddon;
494535
}
495536

537+
private _disposeOfCanvasRenderer(): void {
538+
try {
539+
this._canvasAddon?.dispose();
540+
} catch {
541+
// ignore
542+
}
543+
this._canvasAddon = undefined;
544+
}
545+
496546
private _disposeOfWebglRenderer(): void {
497547
try {
498548
this._webglAddon?.dispose();

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -12072,6 +12072,11 @@ xtend@~2.1.1:
1207212072
dependencies:
1207312073
object-keys "~0.4.0"
1207412074

12075+
12076+
version "0.2.0-beta.15"
12077+
resolved "https://registry.yarnpkg.com/xterm-addon-canvas/-/xterm-addon-canvas-0.2.0-beta.15.tgz#de863e46410b1de357b153abf1984227777760e4"
12078+
integrity sha512-E1pNCDSVTINchwWLysZ9ZD/BPv1WLGV52xRHB00US1PHHELbhtvms+6dZ44WZEDXhtfpptRZ1VBx+QpvfJIuvw==
12079+
1207512080
1207612081
version "0.10.0-beta.3"
1207712082
resolved "https://registry.yarnpkg.com/xterm-addon-search/-/xterm-addon-search-0.10.0-beta.3.tgz#5194434d86105637c71f6f20139a9d0b5c1a956a"

0 commit comments

Comments
 (0)