@xterm/addon-webgl 0.19.0-beta.13 → 0.19.0-beta.131

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.
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Copyright (c) 2022 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { toDisposable, IDisposable } from 'vs/base/common/lifecycle';
7
+
8
+ export function observeDevicePixelDimensions(element: HTMLElement, parentWindow: Window & typeof globalThis, callback: (deviceWidth: number, deviceHeight: number) => void): IDisposable {
9
+ // Observe any resizes to the element and extract the actual pixel size of the element if the
10
+ // devicePixelContentBoxSize API is supported. This allows correcting rounding errors when
11
+ // converting between CSS pixels and device pixels which causes blurry rendering when device
12
+ // pixel ratio is not a round number.
13
+ let observer: ResizeObserver | undefined = new parentWindow.ResizeObserver((entries) => {
14
+ const entry = entries.find((entry) => entry.target === element);
15
+ if (!entry) {
16
+ return;
17
+ }
18
+
19
+ // Disconnect if devicePixelContentBoxSize isn't supported by the browser
20
+ if (!('devicePixelContentBoxSize' in entry)) {
21
+ observer?.disconnect();
22
+ observer = undefined;
23
+ return;
24
+ }
25
+
26
+ // Fire the callback, ignore events where the dimensions are 0x0 as the canvas is likely hidden
27
+ const width = entry.devicePixelContentBoxSize[0].inlineSize;
28
+ const height = entry.devicePixelContentBoxSize[0].blockSize;
29
+ if (width > 0 && height > 0) {
30
+ callback(width, height);
31
+ }
32
+ });
33
+ try {
34
+ observer.observe(element, { box: ['device-pixel-content-box'] } as any);
35
+ } catch {
36
+ observer.disconnect();
37
+ observer = undefined;
38
+ }
39
+ return toDisposable(() => observer?.disconnect());
40
+ }
@@ -2,16 +2,15 @@
2
2
  * Copyright (c) 2018 The xterm.js authors. All rights reserved.
3
3
  * @license MIT
4
4
  */
5
-
6
- import { allowRescaling, throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
7
- import { TextureAtlas } from 'browser/renderer/shared/TextureAtlas';
8
- import { IRasterizedGlyph, IRenderDimensions, ITextureAtlas } from 'browser/renderer/shared/Types';
5
+ import { TextureAtlas } from './TextureAtlas';
6
+ import { IRenderDimensions } from 'browser/renderer/shared/Types';
9
7
  import { NULL_CELL_CODE } from 'common/buffer/Constants';
10
- import { Disposable, toDisposable } from 'common/Lifecycle';
8
+ import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
11
9
  import { Terminal } from '@xterm/xterm';
12
- import { IRenderModel, IWebGL2RenderingContext, IWebGLVertexArrayObject } from './Types';
10
+ import { IRenderModel, IWebGL2RenderingContext, IWebGLVertexArrayObject, type IRasterizedGlyph, type ITextureAtlas } from './Types';
13
11
  import { createProgram, GLTexture, PROJECTION_MATRIX } from './WebglUtils';
14
12
  import type { IOptionsService } from 'common/services/Services';
13
+ import { allowRescaling, throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
15
14
 
16
15
  interface IVertices {
17
16
  attributes: Float32Array;
@@ -127,7 +126,7 @@ export class GlyphRenderer extends Disposable {
127
126
  }
128
127
 
129
128
  this._program = throwIfFalsy(createProgram(gl, vertexShaderSource, createFragmentShaderSource(TextureAtlas.maxAtlasPages)));
130
- this.register(toDisposable(() => gl.deleteProgram(this._program)));
129
+ this._register(toDisposable(() => gl.deleteProgram(this._program)));
131
130
 
132
131
  // Uniform locations
133
132
  this._projectionLocation = throwIfFalsy(gl.getUniformLocation(this._program, 'u_projection'));
@@ -141,7 +140,7 @@ export class GlyphRenderer extends Disposable {
141
140
  // Setup a_unitquad, this defines the 4 vertices of a rectangle
142
141
  const unitQuadVertices = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
143
142
  const unitQuadVerticesBuffer = gl.createBuffer();
144
- this.register(toDisposable(() => gl.deleteBuffer(unitQuadVerticesBuffer)));
143
+ this._register(toDisposable(() => gl.deleteBuffer(unitQuadVerticesBuffer)));
145
144
  gl.bindBuffer(gl.ARRAY_BUFFER, unitQuadVerticesBuffer);
146
145
  gl.bufferData(gl.ARRAY_BUFFER, unitQuadVertices, gl.STATIC_DRAW);
147
146
  gl.enableVertexAttribArray(VertexAttribLocations.UNIT_QUAD);
@@ -152,13 +151,13 @@ export class GlyphRenderer extends Disposable {
152
151
  // triangle strip
153
152
  const unitQuadElementIndices = new Uint8Array([0, 1, 2, 3]);
154
153
  const elementIndicesBuffer = gl.createBuffer();
155
- this.register(toDisposable(() => gl.deleteBuffer(elementIndicesBuffer)));
154
+ this._register(toDisposable(() => gl.deleteBuffer(elementIndicesBuffer)));
156
155
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementIndicesBuffer);
157
156
  gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, unitQuadElementIndices, gl.STATIC_DRAW);
158
157
 
159
158
  // Setup attributes
160
159
  this._attributesBuffer = throwIfFalsy(gl.createBuffer());
161
- this.register(toDisposable(() => gl.deleteBuffer(this._attributesBuffer)));
160
+ this._register(toDisposable(() => gl.deleteBuffer(this._attributesBuffer)));
162
161
  gl.bindBuffer(gl.ARRAY_BUFFER, this._attributesBuffer);
163
162
  gl.enableVertexAttribArray(VertexAttribLocations.OFFSET);
164
163
  gl.vertexAttribPointer(VertexAttribLocations.OFFSET, 2, gl.FLOAT, false, BYTES_PER_CELL, 0);
@@ -193,7 +192,7 @@ export class GlyphRenderer extends Disposable {
193
192
  this._atlasTextures = [];
194
193
  for (let i = 0; i < TextureAtlas.maxAtlasPages; i++) {
195
194
  const glTexture = new GLTexture(throwIfFalsy(gl.createTexture()));
196
- this.register(toDisposable(() => gl.deleteTexture(glTexture.texture)));
195
+ this._register(toDisposable(() => gl.deleteTexture(glTexture.texture)));
197
196
  gl.activeTexture(gl.TEXTURE0 + i);
198
197
  gl.bindTexture(gl.TEXTURE_2D, glTexture.texture);
199
198
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
@@ -238,9 +237,9 @@ export class GlyphRenderer extends Disposable {
238
237
 
239
238
  // Get the glyph
240
239
  if (chars && chars.length > 1) {
241
- $glyph = this._atlas.getRasterizedGlyphCombinedChar(chars, bg, fg, ext, false);
240
+ $glyph = this._atlas.getRasterizedGlyphCombinedChar(chars, bg, fg, ext, false, this._terminal.element);
242
241
  } else {
243
- $glyph = this._atlas.getRasterizedGlyph(code, bg, fg, ext, false);
242
+ $glyph = this._atlas.getRasterizedGlyph(code, bg, fg, ext, false, this._terminal.element);
244
243
  }
245
244
 
246
245
  $leftCellPadding = Math.floor((this._dimensions.device.cell.width - this._dimensions.device.char.width) / 2);
@@ -3,17 +3,17 @@
3
3
  * @license MIT
4
4
  */
5
5
 
6
- import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
7
6
  import { IRenderDimensions } from 'browser/renderer/shared/Types';
8
7
  import { IThemeService } from 'browser/services/Services';
9
8
  import { ReadonlyColorSet } from 'browser/Types';
10
9
  import { Attributes, FgFlags } from 'common/buffer/Constants';
11
- import { Disposable, toDisposable } from 'common/Lifecycle';
10
+ import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
12
11
  import { IColor } from 'common/Types';
13
12
  import { Terminal } from '@xterm/xterm';
14
13
  import { RENDER_MODEL_BG_OFFSET, RENDER_MODEL_FG_OFFSET, RENDER_MODEL_INDICIES_PER_CELL } from './RenderModel';
15
14
  import { IRenderModel, IWebGL2RenderingContext, IWebGLVertexArrayObject } from './Types';
16
15
  import { createProgram, expandFloat32Array, PROJECTION_MATRIX } from './WebglUtils';
16
+ import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
17
17
 
18
18
  const enum VertexAttribLocations {
19
19
  POSITION = 0,
@@ -96,7 +96,7 @@ export class RectangleRenderer extends Disposable {
96
96
  const gl = this._gl;
97
97
 
98
98
  this._program = throwIfFalsy(createProgram(gl, vertexShaderSource, fragmentShaderSource));
99
- this.register(toDisposable(() => gl.deleteProgram(this._program)));
99
+ this._register(toDisposable(() => gl.deleteProgram(this._program)));
100
100
 
101
101
  // Uniform locations
102
102
  this._projectionLocation = throwIfFalsy(gl.getUniformLocation(this._program, 'u_projection'));
@@ -108,7 +108,7 @@ export class RectangleRenderer extends Disposable {
108
108
  // Setup a_unitquad, this defines the 4 vertices of a rectangle
109
109
  const unitQuadVertices = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
110
110
  const unitQuadVerticesBuffer = gl.createBuffer();
111
- this.register(toDisposable(() => gl.deleteBuffer(unitQuadVerticesBuffer)));
111
+ this._register(toDisposable(() => gl.deleteBuffer(unitQuadVerticesBuffer)));
112
112
  gl.bindBuffer(gl.ARRAY_BUFFER, unitQuadVerticesBuffer);
113
113
  gl.bufferData(gl.ARRAY_BUFFER, unitQuadVertices, gl.STATIC_DRAW);
114
114
  gl.enableVertexAttribArray(VertexAttribLocations.UNIT_QUAD);
@@ -119,13 +119,13 @@ export class RectangleRenderer extends Disposable {
119
119
  // triangle strip
120
120
  const unitQuadElementIndices = new Uint8Array([0, 1, 2, 3]);
121
121
  const elementIndicesBuffer = gl.createBuffer();
122
- this.register(toDisposable(() => gl.deleteBuffer(elementIndicesBuffer)));
122
+ this._register(toDisposable(() => gl.deleteBuffer(elementIndicesBuffer)));
123
123
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementIndicesBuffer);
124
124
  gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, unitQuadElementIndices, gl.STATIC_DRAW);
125
125
 
126
126
  // Setup attributes
127
127
  this._attributesBuffer = throwIfFalsy(gl.createBuffer());
128
- this.register(toDisposable(() => gl.deleteBuffer(this._attributesBuffer)));
128
+ this._register(toDisposable(() => gl.deleteBuffer(this._attributesBuffer)));
129
129
  gl.bindBuffer(gl.ARRAY_BUFFER, this._attributesBuffer);
130
130
  gl.enableVertexAttribArray(VertexAttribLocations.POSITION);
131
131
  gl.vertexAttribPointer(VertexAttribLocations.POSITION, 2, gl.FLOAT, false, BYTES_PER_RECTANGLE, 0);
@@ -138,7 +138,7 @@ export class RectangleRenderer extends Disposable {
138
138
  gl.vertexAttribDivisor(VertexAttribLocations.COLOR, 1);
139
139
 
140
140
  this._updateCachedColors(_themeService.colors);
141
- this.register(this._themeService.onChangeColors(e => {
141
+ this._register(this._themeService.onChangeColors(e => {
142
142
  this._updateCachedColors(e);
143
143
  this._updateViewportRectangle();
144
144
  }));