@xterm/addon-webgl 0.20.0-beta.231 → 0.20.0-beta.233
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/lib/addon-webgl.mjs +3 -3
- package/lib/addon-webgl.mjs.map +3 -3
- package/package.json +3 -3
- package/src/GlyphRenderer.ts +4 -3
- package/src/RectangleRenderer.ts +4 -2
- package/src/TextureAtlas.ts +1 -1
- package/src/WebglAddon.ts +3 -1
- package/src/WebglRenderer.ts +7 -6
- package/src/WebglUtils.ts +7 -6
- package/src/customGlyphs/CustomGlyphRasterizer.ts +11 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xterm/addon-webgl",
|
|
3
|
-
"version": "0.20.0-beta.
|
|
3
|
+
"version": "0.20.0-beta.233",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "The xterm.js authors",
|
|
6
6
|
"url": "https://xtermjs.org/"
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"prepublishOnly": "npm run package",
|
|
24
24
|
"start": "node ../../demo/start"
|
|
25
25
|
},
|
|
26
|
-
"commit": "
|
|
26
|
+
"commit": "80e832e4172e00f96d588c7f073614a419099e70",
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@xterm/xterm": "^6.1.0-beta.
|
|
28
|
+
"@xterm/xterm": "^6.1.0-beta.234"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/GlyphRenderer.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { Disposable, toDisposable } from 'common/Lifecycle';
|
|
|
9
9
|
import { Terminal } from '@xterm/xterm';
|
|
10
10
|
import { IRenderModel, IWebGL2RenderingContext, IWebGLVertexArrayObject, type IRasterizedGlyph, type ITextureAtlas } from './Types';
|
|
11
11
|
import { createProgram, GLTexture, PROJECTION_MATRIX } from './WebglUtils';
|
|
12
|
-
import type { IOptionsService } from 'common/services/Services';
|
|
12
|
+
import type { ILogService, IOptionsService } from 'common/services/Services';
|
|
13
13
|
import { allowRescaling, throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
|
|
14
14
|
|
|
15
15
|
interface IVertices {
|
|
@@ -114,7 +114,8 @@ export class GlyphRenderer extends Disposable {
|
|
|
114
114
|
private readonly _terminal: Terminal,
|
|
115
115
|
private readonly _gl: IWebGL2RenderingContext,
|
|
116
116
|
private _dimensions: IRenderDimensions,
|
|
117
|
-
private readonly _optionsService: IOptionsService
|
|
117
|
+
private readonly _optionsService: IOptionsService,
|
|
118
|
+
private readonly _logService: ILogService
|
|
118
119
|
) {
|
|
119
120
|
super();
|
|
120
121
|
|
|
@@ -127,7 +128,7 @@ export class GlyphRenderer extends Disposable {
|
|
|
127
128
|
TextureAtlas.maxTextureSize = throwIfFalsy(gl.getParameter(gl.MAX_TEXTURE_SIZE) as number | null);
|
|
128
129
|
}
|
|
129
130
|
|
|
130
|
-
this._program = throwIfFalsy(createProgram(gl, vertexShaderSource, createFragmentShaderSource(TextureAtlas.maxAtlasPages)));
|
|
131
|
+
this._program = throwIfFalsy(createProgram(gl, vertexShaderSource, createFragmentShaderSource(TextureAtlas.maxAtlasPages), this._logService));
|
|
131
132
|
this._register(toDisposable(() => gl.deleteProgram(this._program)));
|
|
132
133
|
|
|
133
134
|
// Uniform locations
|
package/src/RectangleRenderer.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { RenderModelConstants } from './RenderModel';
|
|
|
14
14
|
import { IRenderModel, IWebGL2RenderingContext, IWebGLVertexArrayObject } from './Types';
|
|
15
15
|
import { createProgram, expandFloat32Array, PROJECTION_MATRIX } from './WebglUtils';
|
|
16
16
|
import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
|
|
17
|
+
import type { ILogService } from 'common/services/Services';
|
|
17
18
|
|
|
18
19
|
const enum VertexAttribLocations {
|
|
19
20
|
POSITION = 0,
|
|
@@ -89,13 +90,14 @@ export class RectangleRenderer extends Disposable {
|
|
|
89
90
|
private _terminal: Terminal,
|
|
90
91
|
private _gl: IWebGL2RenderingContext,
|
|
91
92
|
private _dimensions: IRenderDimensions,
|
|
92
|
-
private readonly _themeService: IThemeService
|
|
93
|
+
private readonly _themeService: IThemeService,
|
|
94
|
+
private readonly _logService: ILogService
|
|
93
95
|
) {
|
|
94
96
|
super();
|
|
95
97
|
|
|
96
98
|
const gl = this._gl;
|
|
97
99
|
|
|
98
|
-
this._program = throwIfFalsy(createProgram(gl, vertexShaderSource, fragmentShaderSource));
|
|
100
|
+
this._program = throwIfFalsy(createProgram(gl, vertexShaderSource, fragmentShaderSource, this._logService));
|
|
99
101
|
this._register(toDisposable(() => gl.deleteProgram(this._program)));
|
|
100
102
|
|
|
101
103
|
// Uniform locations
|
package/src/TextureAtlas.ts
CHANGED
|
@@ -529,7 +529,7 @@ export class TextureAtlas implements ITextureAtlas {
|
|
|
529
529
|
let customGlyph = false;
|
|
530
530
|
if (this._config.customGlyphs !== false) {
|
|
531
531
|
const variantOffset = this._workAttributeData.getUnderlineVariantOffset();
|
|
532
|
-
customGlyph = tryDrawCustomGlyph(this._tmpCtx, chars, padding, padding, this._config.deviceCellWidth, this._config.deviceCellHeight, this._config.deviceCharWidth, this._config.deviceCharHeight, this._config.fontSize, this._config.devicePixelRatio, backgroundColor.css, variantOffset);
|
|
532
|
+
customGlyph = tryDrawCustomGlyph(this._tmpCtx, chars, padding, padding, this._config.deviceCellWidth, this._config.deviceCellHeight, this._config.deviceCharWidth, this._config.deviceCharHeight, this._config.fontSize, this._config.devicePixelRatio, this._logService, backgroundColor.css, variantOffset);
|
|
533
533
|
}
|
|
534
534
|
|
|
535
535
|
// Whether to clear pixels based on a threshold difference between the glyph color and the
|
package/src/WebglAddon.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IRender
|
|
|
9
9
|
import { ITerminal } from 'browser/Types';
|
|
10
10
|
import { Disposable, toDisposable } from 'common/Lifecycle';
|
|
11
11
|
import { getSafariVersion, isSafari } from 'common/Platform';
|
|
12
|
-
import { ICoreService, IDecorationService, IOptionsService } from 'common/services/Services';
|
|
12
|
+
import { ICoreService, IDecorationService, ILogService, IOptionsService } from 'common/services/Services';
|
|
13
13
|
import { IWebGL2RenderingContext } from './Types';
|
|
14
14
|
import { WebglRenderer } from './WebglRenderer';
|
|
15
15
|
import { Emitter, EventUtils } from 'common/Event';
|
|
@@ -65,6 +65,7 @@ export class WebglAddon extends Disposable implements ITerminalAddon, IWebglApi
|
|
|
65
65
|
const charSizeService: ICharSizeService = unsafeCore._charSizeService;
|
|
66
66
|
const coreBrowserService: ICoreBrowserService = unsafeCore._coreBrowserService;
|
|
67
67
|
const decorationService: IDecorationService = unsafeCore._decorationService;
|
|
68
|
+
const logService: ILogService = unsafeCore._logService;
|
|
68
69
|
const themeService: IThemeService = unsafeCore._themeService;
|
|
69
70
|
|
|
70
71
|
this._renderer = this._register(new WebglRenderer(
|
|
@@ -74,6 +75,7 @@ export class WebglAddon extends Disposable implements ITerminalAddon, IWebglApi
|
|
|
74
75
|
coreBrowserService,
|
|
75
76
|
coreService,
|
|
76
77
|
decorationService,
|
|
78
|
+
logService,
|
|
77
79
|
optionsService,
|
|
78
80
|
themeService,
|
|
79
81
|
this._customGlyphs,
|
package/src/WebglRenderer.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { AttributeData } from 'common/buffer/AttributeData';
|
|
|
15
15
|
import { CellData } from 'common/buffer/CellData';
|
|
16
16
|
import { Attributes, Content, FgFlags, NULL_CELL_CHAR, NULL_CELL_CODE } from 'common/buffer/Constants';
|
|
17
17
|
import { TextBlinkStateManager } from 'browser/renderer/shared/TextBlinkStateManager';
|
|
18
|
-
import { ICoreService, IDecorationService, IOptionsService } from 'common/services/Services';
|
|
18
|
+
import { ICoreService, IDecorationService, ILogService, IOptionsService } from 'common/services/Services';
|
|
19
19
|
import { Terminal } from '@xterm/xterm';
|
|
20
20
|
import { GlyphRenderer } from './GlyphRenderer';
|
|
21
21
|
import { RectangleRenderer } from './RectangleRenderer';
|
|
@@ -77,6 +77,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
|
|
77
77
|
private readonly _coreBrowserService: ICoreBrowserService,
|
|
78
78
|
private readonly _coreService: ICoreService,
|
|
79
79
|
private readonly _decorationService: IDecorationService,
|
|
80
|
+
private readonly _logService: ILogService,
|
|
80
81
|
private readonly _optionsService: IOptionsService,
|
|
81
82
|
private readonly _themeService: IThemeService,
|
|
82
83
|
private readonly _customGlyphs: boolean = true,
|
|
@@ -122,19 +123,19 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
|
|
122
123
|
this._deviceMaxTextureSize = this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE);
|
|
123
124
|
|
|
124
125
|
this._register(addDisposableListener(this._canvas, 'webglcontextlost', (e) => {
|
|
125
|
-
|
|
126
|
+
this._logService.debug('webglcontextlost event received');
|
|
126
127
|
// Prevent the default behavior in order to enable WebGL context restoration.
|
|
127
128
|
e.preventDefault();
|
|
128
129
|
// Wait a few seconds to see if the 'webglcontextrestored' event is fired.
|
|
129
130
|
// If not, dispatch the onContextLoss notification to observers.
|
|
130
131
|
this._contextRestorationTimeout = setTimeout(() => {
|
|
131
132
|
this._contextRestorationTimeout = undefined;
|
|
132
|
-
|
|
133
|
+
this._logService.warn('webgl context not restored; firing onContextLoss');
|
|
133
134
|
this._onContextLoss.fire(e);
|
|
134
135
|
}, 3000 /* ms */);
|
|
135
136
|
}));
|
|
136
137
|
this._register(addDisposableListener(this._canvas, 'webglcontextrestored', (e) => {
|
|
137
|
-
|
|
138
|
+
this._logService.warn('webglcontextrestored event received');
|
|
138
139
|
clearTimeout(this._contextRestorationTimeout);
|
|
139
140
|
this._contextRestorationTimeout = undefined;
|
|
140
141
|
// The texture atlas and glyph renderer must be fully reinitialized
|
|
@@ -276,8 +277,8 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
|
|
276
277
|
* Initializes members dependent on WebGL context state.
|
|
277
278
|
*/
|
|
278
279
|
private _initializeWebGLState(): [RectangleRenderer, GlyphRenderer] {
|
|
279
|
-
this._rectangleRenderer.value = new RectangleRenderer(this._terminal, this._gl, this.dimensions, this._themeService);
|
|
280
|
-
this._glyphRenderer.value = new GlyphRenderer(this._terminal, this._gl, this.dimensions, this._optionsService);
|
|
280
|
+
this._rectangleRenderer.value = new RectangleRenderer(this._terminal, this._gl, this.dimensions, this._themeService, this._logService);
|
|
281
|
+
this._glyphRenderer.value = new GlyphRenderer(this._terminal, this._gl, this.dimensions, this._optionsService, this._logService);
|
|
281
282
|
|
|
282
283
|
// Update dimensions and acquire char atlas
|
|
283
284
|
this.handleCharSizeChanged();
|
package/src/WebglUtils.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
|
|
7
|
+
import type { ILogService } from 'common/services/Services';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* A matrix that when multiplies will translate 0-1 coordinates (left to right,
|
|
@@ -16,21 +17,21 @@ export const PROJECTION_MATRIX = new Float32Array([
|
|
|
16
17
|
-1, 1, 0, 1
|
|
17
18
|
]);
|
|
18
19
|
|
|
19
|
-
export function createProgram(gl: WebGLRenderingContext, vertexSource: string, fragmentSource: string): WebGLProgram | undefined {
|
|
20
|
+
export function createProgram(gl: WebGLRenderingContext, vertexSource: string, fragmentSource: string, logService: ILogService): WebGLProgram | undefined {
|
|
20
21
|
const program = throwIfFalsy(gl.createProgram());
|
|
21
|
-
gl.attachShader(program, throwIfFalsy(createShader(gl, gl.VERTEX_SHADER, vertexSource)));
|
|
22
|
-
gl.attachShader(program, throwIfFalsy(createShader(gl, gl.FRAGMENT_SHADER, fragmentSource)));
|
|
22
|
+
gl.attachShader(program, throwIfFalsy(createShader(gl, gl.VERTEX_SHADER, vertexSource, logService)));
|
|
23
|
+
gl.attachShader(program, throwIfFalsy(createShader(gl, gl.FRAGMENT_SHADER, fragmentSource, logService)));
|
|
23
24
|
gl.linkProgram(program);
|
|
24
25
|
const success = gl.getProgramParameter(program, gl.LINK_STATUS);
|
|
25
26
|
if (success) {
|
|
26
27
|
return program;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
logService.error(gl.getProgramInfoLog(program));
|
|
30
31
|
gl.deleteProgram(program);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export function createShader(gl: WebGLRenderingContext, type: number, source: string): WebGLShader | undefined {
|
|
34
|
+
export function createShader(gl: WebGLRenderingContext, type: number, source: string, logService: ILogService): WebGLShader | undefined {
|
|
34
35
|
const shader = throwIfFalsy(gl.createShader(type));
|
|
35
36
|
gl.shaderSource(shader, source);
|
|
36
37
|
gl.compileShader(shader);
|
|
@@ -39,7 +40,7 @@ export function createShader(gl: WebGLRenderingContext, type: number, source: st
|
|
|
39
40
|
return shader;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
logService.error(gl.getShaderInfoLog(shader));
|
|
43
44
|
gl.deleteShader(shader);
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
|
|
7
|
+
import type { ILogService } from 'common/services/Services';
|
|
7
8
|
import { customGlyphDefinitions } from './CustomGlyphDefinitions';
|
|
8
9
|
import { CustomGlyphDefinitionType, CustomGlyphScaleType, CustomGlyphVectorType, type CustomGlyphDefinitionPart, type CustomGlyphPathDrawFunctionDefinition, type CustomGlyphPatternDefinition, type ICustomGlyphSolidOctantBlockVector, type ICustomGlyphVectorShape } from './Types';
|
|
9
10
|
|
|
@@ -22,6 +23,7 @@ export function tryDrawCustomGlyph(
|
|
|
22
23
|
deviceCharHeight: number,
|
|
23
24
|
fontSize: number,
|
|
24
25
|
devicePixelRatio: number,
|
|
26
|
+
logService: ILogService,
|
|
25
27
|
backgroundColor?: string,
|
|
26
28
|
variantOffset: number = 0
|
|
27
29
|
): boolean {
|
|
@@ -30,7 +32,7 @@ export function tryDrawCustomGlyph(
|
|
|
30
32
|
// Normalize to array for uniform handling
|
|
31
33
|
const parts = Array.isArray(unifiedCharDefinition) ? unifiedCharDefinition : [unifiedCharDefinition];
|
|
32
34
|
for (const part of parts) {
|
|
33
|
-
drawDefinitionPart(ctx, part, xOffset, yOffset, deviceCellWidth, deviceCellHeight, deviceCharWidth, deviceCharHeight, fontSize, devicePixelRatio, backgroundColor, variantOffset);
|
|
35
|
+
drawDefinitionPart(ctx, part, xOffset, yOffset, deviceCellWidth, deviceCellHeight, deviceCharWidth, deviceCharHeight, fontSize, devicePixelRatio, logService, backgroundColor, variantOffset);
|
|
34
36
|
}
|
|
35
37
|
return true;
|
|
36
38
|
}
|
|
@@ -49,6 +51,7 @@ function drawDefinitionPart(
|
|
|
49
51
|
deviceCharHeight: number,
|
|
50
52
|
fontSize: number,
|
|
51
53
|
devicePixelRatio: number,
|
|
54
|
+
logService: ILogService,
|
|
52
55
|
backgroundColor?: string,
|
|
53
56
|
variantOffset: number = 0
|
|
54
57
|
): void {
|
|
@@ -79,7 +82,7 @@ function drawDefinitionPart(
|
|
|
79
82
|
drawPatternChar(ctx, part.data, drawXOffset, drawYOffset, drawWidth, drawHeight, variantOffset);
|
|
80
83
|
break;
|
|
81
84
|
case CustomGlyphDefinitionType.PATH_FUNCTION:
|
|
82
|
-
drawPathFunctionCharacter(ctx, part.data, drawXOffset, drawYOffset, drawWidth, drawHeight, devicePixelRatio, part.strokeWidth);
|
|
85
|
+
drawPathFunctionCharacter(ctx, part.data, drawXOffset, drawYOffset, drawWidth, drawHeight, devicePixelRatio, logService, part.strokeWidth);
|
|
83
86
|
break;
|
|
84
87
|
case CustomGlyphDefinitionType.PATH:
|
|
85
88
|
drawPathDefinitionCharacter(ctx, part.data, drawXOffset, drawYOffset, drawWidth, drawHeight, devicePixelRatio, part.strokeWidth);
|
|
@@ -88,7 +91,7 @@ function drawDefinitionPart(
|
|
|
88
91
|
drawPathNegativeDefinitionCharacter(ctx, part.data, drawXOffset, drawYOffset, drawWidth, drawHeight, devicePixelRatio, backgroundColor);
|
|
89
92
|
break;
|
|
90
93
|
case CustomGlyphDefinitionType.VECTOR_SHAPE:
|
|
91
|
-
drawVectorShape(ctx, part.data, drawXOffset, drawYOffset, drawWidth, drawHeight, fontSize, devicePixelRatio);
|
|
94
|
+
drawVectorShape(ctx, part.data, drawXOffset, drawYOffset, drawWidth, drawHeight, fontSize, devicePixelRatio, logService);
|
|
92
95
|
break;
|
|
93
96
|
case CustomGlyphDefinitionType.BRAILLE:
|
|
94
97
|
drawBrailleCharacter(ctx, part.data, drawXOffset, drawYOffset, drawWidth, drawHeight);
|
|
@@ -510,6 +513,7 @@ function drawPathFunctionCharacter(
|
|
|
510
513
|
deviceCellWidth: number,
|
|
511
514
|
deviceCellHeight: number,
|
|
512
515
|
devicePixelRatio: number,
|
|
516
|
+
logService: ILogService,
|
|
513
517
|
strokeWidth?: number
|
|
514
518
|
): void {
|
|
515
519
|
ctx.save();
|
|
@@ -536,7 +540,7 @@ function drawPathFunctionCharacter(
|
|
|
536
540
|
}
|
|
537
541
|
const f = svgToCanvasInstructionMap[type];
|
|
538
542
|
if (!f) {
|
|
539
|
-
|
|
543
|
+
logService.error(`Could not find drawing instructions for "${type}"`);
|
|
540
544
|
continue;
|
|
541
545
|
}
|
|
542
546
|
const args: string[] = instruction.substring(1).split(',');
|
|
@@ -598,7 +602,8 @@ function drawVectorShape(
|
|
|
598
602
|
deviceCellWidth: number,
|
|
599
603
|
deviceCellHeight: number,
|
|
600
604
|
fontSize: number,
|
|
601
|
-
devicePixelRatio: number
|
|
605
|
+
devicePixelRatio: number,
|
|
606
|
+
logService: ILogService
|
|
602
607
|
): void {
|
|
603
608
|
// Clip the cell to make sure drawing doesn't occur beyond bounds
|
|
604
609
|
const clipRegion = new Path2D();
|
|
@@ -619,7 +624,7 @@ function drawVectorShape(
|
|
|
619
624
|
}
|
|
620
625
|
const f = svgToCanvasInstructionMap[type];
|
|
621
626
|
if (!f) {
|
|
622
|
-
|
|
627
|
+
logService.error(`Could not find drawing instructions for "${type}"`);
|
|
623
628
|
continue;
|
|
624
629
|
}
|
|
625
630
|
const args: string[] = instruction.substring(1).split(',');
|