@xterm/addon-webgl 0.17.0-beta.2 → 0.17.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/addon-webgl.js +1 -1
- package/lib/addon-webgl.js.map +1 -1
- package/package.json +1 -1
- package/src/WebglAddon.ts +14 -3
- package/src/WebglRenderer.ts +11 -6
package/package.json
CHANGED
package/src/WebglAddon.ts
CHANGED
|
@@ -3,17 +3,19 @@
|
|
|
3
3
|
* @license MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import type { ITerminalAddon, Terminal } from '@xterm/xterm';
|
|
7
|
+
import type { WebglAddon as IWebglApi } from '@xterm/addon-webgl';
|
|
6
8
|
import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services';
|
|
7
9
|
import { ITerminal } from 'browser/Types';
|
|
8
10
|
import { EventEmitter, forwardEvent } from 'common/EventEmitter';
|
|
9
11
|
import { Disposable, toDisposable } from 'common/Lifecycle';
|
|
10
12
|
import { getSafariVersion, isSafari } from 'common/Platform';
|
|
11
13
|
import { ICoreService, IDecorationService, ILogService, IOptionsService } from 'common/services/Services';
|
|
12
|
-
import {
|
|
14
|
+
import { IWebGL2RenderingContext } from './Types';
|
|
13
15
|
import { WebglRenderer } from './WebglRenderer';
|
|
14
16
|
import { setTraceLogger } from 'common/services/LogService';
|
|
15
17
|
|
|
16
|
-
export class WebglAddon extends Disposable implements ITerminalAddon {
|
|
18
|
+
export class WebglAddon extends Disposable implements ITerminalAddon , IWebglApi {
|
|
17
19
|
private _terminal?: Terminal;
|
|
18
20
|
private _renderer?: WebglRenderer;
|
|
19
21
|
|
|
@@ -30,7 +32,16 @@ export class WebglAddon extends Disposable implements ITerminalAddon {
|
|
|
30
32
|
private _preserveDrawingBuffer?: boolean
|
|
31
33
|
) {
|
|
32
34
|
if (isSafari && getSafariVersion() < 16) {
|
|
33
|
-
|
|
35
|
+
// Perform an extra check to determine if Webgl2 is manually enabled in developer settings
|
|
36
|
+
const contextAttributes = {
|
|
37
|
+
antialias: false,
|
|
38
|
+
depth: false,
|
|
39
|
+
preserveDrawingBuffer: true
|
|
40
|
+
};
|
|
41
|
+
const gl = document.createElement('canvas').getContext('webgl2', contextAttributes) as IWebGL2RenderingContext;
|
|
42
|
+
if (!gl) {
|
|
43
|
+
throw new Error('Webgl2 is only supported on Safari 16 and above');
|
|
44
|
+
}
|
|
34
45
|
}
|
|
35
46
|
super();
|
|
36
47
|
}
|
package/src/WebglRenderer.ts
CHANGED
|
@@ -33,6 +33,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
|
|
33
33
|
private _charAtlasDisposable = this.register(new MutableDisposable());
|
|
34
34
|
private _charAtlas: ITextureAtlas | undefined;
|
|
35
35
|
private _devicePixelRatio: number;
|
|
36
|
+
private _observerDisposable = this.register(new MutableDisposable());
|
|
36
37
|
|
|
37
38
|
private _model: RenderModel = new RenderModel();
|
|
38
39
|
private _workCell: CellData = new CellData();
|
|
@@ -75,12 +76,12 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
|
|
75
76
|
|
|
76
77
|
this.register(this._themeService.onChangeColors(() => this._handleColorChange()));
|
|
77
78
|
|
|
78
|
-
this._cellColorResolver = new CellColorResolver(this._terminal, this._model.selection, this._decorationService, this._coreBrowserService, this._themeService);
|
|
79
|
+
this._cellColorResolver = new CellColorResolver(this._terminal, this._optionsService, this._model.selection, this._decorationService, this._coreBrowserService, this._themeService);
|
|
79
80
|
|
|
80
81
|
this._core = (this._terminal as any)._core;
|
|
81
82
|
|
|
82
83
|
this._renderLayers = [
|
|
83
|
-
new LinkRenderLayer(this._core.screenElement!, 2, this._terminal, this._core.
|
|
84
|
+
new LinkRenderLayer(this._core.screenElement!, 2, this._terminal, this._core.linkifier!, this._coreBrowserService, _optionsService, this._themeService)
|
|
84
85
|
];
|
|
85
86
|
this.dimensions = createRenderDimensions();
|
|
86
87
|
this._devicePixelRatio = this._coreBrowserService.dpr;
|
|
@@ -123,7 +124,10 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
|
|
123
124
|
this._requestRedrawViewport();
|
|
124
125
|
}));
|
|
125
126
|
|
|
126
|
-
this.
|
|
127
|
+
this._observerDisposable.value = observeDevicePixelDimensions(this._canvas, this._coreBrowserService.window, (w, h) => this._setCanvasDevicePixelDimensions(w, h));
|
|
128
|
+
this.register(this._coreBrowserService.onWindowChange(w => {
|
|
129
|
+
this._observerDisposable.value = observeDevicePixelDimensions(this._canvas, w, (w, h) => this._setCanvasDevicePixelDimensions(w, h));
|
|
130
|
+
}));
|
|
127
131
|
|
|
128
132
|
this._core.screenElement!.appendChild(this._canvas);
|
|
129
133
|
|
|
@@ -219,7 +223,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
|
|
219
223
|
for (const l of this._renderLayers) {
|
|
220
224
|
l.handleSelectionChanged(this._terminal, start, end, columnSelectMode);
|
|
221
225
|
}
|
|
222
|
-
this._model.selection.update(this.
|
|
226
|
+
this._model.selection.update(this._core, start, end, columnSelectMode);
|
|
223
227
|
this._requestRedrawViewport();
|
|
224
228
|
}
|
|
225
229
|
|
|
@@ -391,6 +395,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
|
|
391
395
|
end = clamp(end, terminal.rows - 1, 0);
|
|
392
396
|
|
|
393
397
|
const cursorY = this._terminal.buffer.active.baseY + this._terminal.buffer.active.cursorY;
|
|
398
|
+
const viewportRelativeCursorY = cursorY - terminal.buffer.ydisp;
|
|
394
399
|
// in case cursor.x == cols adjust visual cursor to cols - 1
|
|
395
400
|
const cursorX = Math.min(this._terminal.buffer.active.cursorX, terminal.cols - 1);
|
|
396
401
|
let lastCursorX = -1;
|
|
@@ -442,14 +447,14 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
|
|
442
447
|
i = ((y * terminal.cols) + x) * RENDER_MODEL_INDICIES_PER_CELL;
|
|
443
448
|
|
|
444
449
|
// Load colors/resolve overrides into work colors
|
|
445
|
-
this._cellColorResolver.resolve(cell, x, row);
|
|
450
|
+
this._cellColorResolver.resolve(cell, x, row, this.dimensions.device.cell.width);
|
|
446
451
|
|
|
447
452
|
// Override colors for cursor cell
|
|
448
453
|
if (isCursorVisible && row === cursorY) {
|
|
449
454
|
if (x === cursorX) {
|
|
450
455
|
this._model.cursor = {
|
|
451
456
|
x: cursorX,
|
|
452
|
-
y:
|
|
457
|
+
y: viewportRelativeCursorY,
|
|
453
458
|
width: cell.getWidth(),
|
|
454
459
|
style: this._coreBrowserService.isFocused ?
|
|
455
460
|
(terminal.options.cursorStyle || 'block') : terminal.options.cursorInactiveStyle,
|