Skip to content

Commit 0692d48

Browse files
authored
Merge pull request #5286 from Tyriar/webgl_only_from_shared
Move WebGL addon-specific code into addon
2 parents dce403a + cfc1071 commit 0692d48

17 files changed

+133
-126
lines changed

src/browser/renderer/shared/CharAtlasCache.ts addons/addon-webgl/src/CharAtlasCache.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* @license MIT
44
*/
55

6-
import { TextureAtlas } from 'browser/renderer/shared/TextureAtlas';
6+
import { TextureAtlas } from './TextureAtlas';
77
import { ITerminalOptions, Terminal } from '@xterm/xterm';
88
import { ITerminal, ReadonlyColorSet } from 'browser/Types';
9-
import { ICharAtlasConfig, ITextureAtlas } from 'browser/renderer/shared/Types';
10-
import { generateConfig, configEquals } from 'browser/renderer/shared/CharAtlasUtils';
9+
import { ICharAtlasConfig, ITextureAtlas } from './Types';
10+
import { generateConfig, configEquals } from './CharAtlasUtils';
1111

1212
interface ITextureAtlasCacheEntry {
1313
atlas: ITextureAtlas;

addons/addon-webgl/src/Constants.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
3+
* @license MIT
4+
*/
5+
6+
import { isFirefox, isLegacyEdge } from 'common/Platform';
7+
8+
export const DIM_OPACITY = 0.5;
9+
// The text baseline is set conditionally by browser. Using 'ideographic' for Firefox or Legacy Edge
10+
// would result in truncated text (Issue 3353). Using 'bottom' for Chrome would result in slightly
11+
// unaligned Powerline fonts (PR 3356#issuecomment-850928179).
12+
export const TEXT_BASELINE: CanvasTextBaseline = isFirefox || isLegacyEdge ? 'bottom' : 'ideographic';

addons/addon-webgl/src/GlyphRenderer.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
33
* @license MIT
44
*/
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';
97
import { NULL_CELL_CODE } from 'common/buffer/Constants';
108
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
119
import { Terminal } from '@xterm/xterm';
12-
import { IRenderModel, IWebGL2RenderingContext, IWebGLVertexArrayObject } from './Types';
10+
import { IRenderModel, IWebGL2RenderingContext, IWebGLVertexArrayObject, type IRasterizedGlyph, type ITextureAtlas } from './Types';
1311
import { createProgram, GLTexture, PROJECTION_MATRIX } from './WebglUtils';
1412
import type { IOptionsService } from 'common/services/Services';
13+
import { allowRescaling, throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
1514

1615
interface IVertices {
1716
attributes: Float32Array;

addons/addon-webgl/src/RectangleRenderer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @license MIT
44
*/
55

6-
import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
76
import { IRenderDimensions } from 'browser/renderer/shared/Types';
87
import { IThemeService } from 'browser/services/Services';
98
import { ReadonlyColorSet } from 'browser/Types';
@@ -14,6 +13,7 @@ import { Terminal } from '@xterm/xterm';
1413
import { RENDER_MODEL_BG_OFFSET, RENDER_MODEL_FG_OFFSET, RENDER_MODEL_INDICIES_PER_CELL } from './RenderModel';
1514
import { IRenderModel, IWebGL2RenderingContext, IWebGLVertexArrayObject } from './Types';
1615
import { createProgram, expandFloat32Array, PROJECTION_MATRIX } from './WebglUtils';
16+
import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
1717

1818
const enum VertexAttribLocations {
1919
POSITION = 0,

src/browser/renderer/shared/TextureAtlas.ts addons/addon-webgl/src/TextureAtlas.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
*/
55

66
import { IColorContrastCache } from 'browser/Types';
7-
import { DIM_OPACITY, TEXT_BASELINE } from 'browser/renderer/shared/Constants';
8-
import { tryDrawCustomChar } from 'browser/renderer/shared/CustomGlyphs';
7+
import { DIM_OPACITY, TEXT_BASELINE } from './Constants';
8+
import { tryDrawCustomChar } from './CustomGlyphs';
99
import { computeNextVariantOffset, treatGlyphAsBackgroundColor, isPowerlineGlyph, isRestrictedPowerlineGlyph, throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
10-
import { IBoundingBox, ICharAtlasConfig, IRasterizedGlyph, ITextureAtlas } from 'browser/renderer/shared/Types';
10+
import { IBoundingBox, ICharAtlasConfig, IRasterizedGlyph, ITextureAtlas } from './Types';
1111
import { NULL_COLOR, channels, color, rgba } from 'common/Color';
1212
import { FourKeyMap } from 'common/MultiKeyMap';
1313
import { IdleTaskQueue } from 'common/TaskQueue';

addons/addon-webgl/src/Types.ts

+94-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
* @license MIT
44
*/
55

6+
import { FontWeight } from '@xterm/xterm';
7+
import { IColorSet } from 'browser/Types';
68
import { ISelectionRenderModel } from 'browser/renderer/shared/Types';
7-
import { CursorInactiveStyle, CursorStyle } from 'common/Types';
9+
import { CursorInactiveStyle, CursorStyle, type IDisposable } from 'common/Types';
10+
import type { Event } from 'vs/base/common/event';
811

912
export interface IRenderModel {
1013
cells: Uint32Array;
@@ -31,3 +34,93 @@ export interface IWebGL2RenderingContext extends WebGLRenderingContext {
3134

3235
export interface IWebGLVertexArrayObject {
3336
}
37+
38+
export interface ICharAtlasConfig {
39+
customGlyphs: boolean;
40+
devicePixelRatio: number;
41+
deviceMaxTextureSize: number;
42+
letterSpacing: number;
43+
lineHeight: number;
44+
fontSize: number;
45+
fontFamily: string;
46+
fontWeight: FontWeight;
47+
fontWeightBold: FontWeight;
48+
deviceCellWidth: number;
49+
deviceCellHeight: number;
50+
deviceCharWidth: number;
51+
deviceCharHeight: number;
52+
allowTransparency: boolean;
53+
drawBoldTextInBrightColors: boolean;
54+
minimumContrastRatio: number;
55+
colors: IColorSet;
56+
}
57+
58+
export interface ITextureAtlas extends IDisposable {
59+
readonly pages: { canvas: HTMLCanvasElement, version: number }[];
60+
61+
onAddTextureAtlasCanvas: Event<HTMLCanvasElement>;
62+
onRemoveTextureAtlasCanvas: Event<HTMLCanvasElement>;
63+
64+
/**
65+
* Warm up the texture atlas, adding common glyphs to avoid slowing early frame.
66+
*/
67+
warmUp(): void;
68+
69+
/**
70+
* Call when a frame is being drawn, this will return true if the atlas was cleared to make room
71+
* for a new set of glyphs.
72+
*/
73+
beginFrame(): boolean;
74+
75+
/**
76+
* Clear all glyphs from the texture atlas.
77+
*/
78+
clearTexture(): void;
79+
getRasterizedGlyph(code: number, bg: number, fg: number, ext: number, restrictToCellHeight: boolean, domContainer: HTMLElement | undefined): IRasterizedGlyph;
80+
getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number, restrictToCellHeight: boolean, domContainer: HTMLElement | undefined): IRasterizedGlyph;
81+
}
82+
83+
/**
84+
* Represents a rasterized glyph within a texture atlas. Some numbers are
85+
* tracked in CSS pixels as well in order to reduce calculations during the
86+
* render loop.
87+
*/
88+
export interface IRasterizedGlyph {
89+
/**
90+
* The x and y offset between the glyph's top/left and the top/left of a cell
91+
* in pixels.
92+
*/
93+
offset: IVector;
94+
/**
95+
* The index of the texture page that the glyph is on.
96+
*/
97+
texturePage: number;
98+
/**
99+
* the x and y position of the glyph in the texture in pixels.
100+
*/
101+
texturePosition: IVector;
102+
/**
103+
* the x and y position of the glyph in the texture in clip space coordinates.
104+
*/
105+
texturePositionClipSpace: IVector;
106+
/**
107+
* The width and height of the glyph in the texture in pixels.
108+
*/
109+
size: IVector;
110+
/**
111+
* The width and height of the glyph in the texture in clip space coordinates.
112+
*/
113+
sizeClipSpace: IVector;
114+
}
115+
116+
export interface IVector {
117+
x: number;
118+
y: number;
119+
}
120+
121+
export interface IBoundingBox {
122+
top: number;
123+
left: number;
124+
right: number;
125+
bottom: number;
126+
}

addons/addon-webgl/src/WebglRenderer.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
*/
55

66
import { ITerminal } from 'browser/Types';
7-
import { CellColorResolver } from 'browser/renderer/shared/CellColorResolver';
8-
import { acquireTextureAtlas, removeTerminalFromCache } from 'browser/renderer/shared/CharAtlasCache';
9-
import { CursorBlinkStateManager } from 'browser/renderer/shared/CursorBlinkStateManager';
10-
import { observeDevicePixelDimensions } from 'browser/renderer/shared/DevicePixelObserver';
11-
import { createRenderDimensions } from 'browser/renderer/shared/RendererUtils';
12-
import { IRenderDimensions, IRenderer, IRequestRedrawEvent, ITextureAtlas } from 'browser/renderer/shared/Types';
7+
import { CellColorResolver } from './CellColorResolver';
8+
import { acquireTextureAtlas, removeTerminalFromCache } from './CharAtlasCache';
9+
import { CursorBlinkStateManager } from './CursorBlinkStateManager';
10+
import { observeDevicePixelDimensions } from './DevicePixelObserver';
11+
import { IRenderDimensions, IRenderer, IRequestRedrawEvent } from 'browser/renderer/shared/Types';
1312
import { ICharSizeService, ICharacterJoinerService, ICoreBrowserService, IThemeService } from 'browser/services/Services';
1413
import { CharData, IBufferLine, ICellData } from 'common/Types';
1514
import { AttributeData } from 'common/buffer/AttributeData';
@@ -20,12 +19,13 @@ import { Terminal } from '@xterm/xterm';
2019
import { GlyphRenderer } from './GlyphRenderer';
2120
import { RectangleRenderer } from './RectangleRenderer';
2221
import { COMBINED_CHAR_BIT_MASK, RENDER_MODEL_BG_OFFSET, RENDER_MODEL_EXT_OFFSET, RENDER_MODEL_FG_OFFSET, RENDER_MODEL_INDICIES_PER_CELL, RenderModel } from './RenderModel';
23-
import { IWebGL2RenderingContext } from './Types';
22+
import { IWebGL2RenderingContext, type ITextureAtlas } from './Types';
2423
import { LinkRenderLayer } from './renderLayer/LinkRenderLayer';
2524
import { IRenderLayer } from './renderLayer/Types';
2625
import { Emitter, Event } from 'vs/base/common/event';
2726
import { addDisposableListener } from 'vs/base/browser/dom';
2827
import { combinedDisposable, Disposable, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
28+
import { createRenderDimensions } from 'browser/renderer/shared/RendererUtils';
2929

3030
export class WebglRenderer extends Disposable implements IRenderer {
3131
private _renderLayers: IRenderLayer[];

addons/addon-webgl/src/renderLayer/BaseRenderLayer.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
*/
55

66
import { ReadonlyColorSet } from 'browser/Types';
7-
import { acquireTextureAtlas } from 'browser/renderer/shared/CharAtlasCache';
8-
import { TEXT_BASELINE } from 'browser/renderer/shared/Constants';
9-
import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
10-
import { IRenderDimensions, ITextureAtlas } from 'browser/renderer/shared/Types';
7+
import { acquireTextureAtlas } from '../CharAtlasCache';
8+
import { IRenderDimensions } from 'browser/renderer/shared/Types';
119
import { ICoreBrowserService, IThemeService } from 'browser/services/Services';
1210
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
1311
import { CellData } from 'common/buffer/CellData';
1412
import { IOptionsService } from 'common/services/Services';
1513
import { Terminal } from '@xterm/xterm';
1614
import { IRenderLayer } from './Types';
15+
import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
16+
import { TEXT_BASELINE } from '../Constants';
17+
import type { ITextureAtlas } from '../Types';
1718

1819
export abstract class BaseRenderLayer extends Disposable implements IRenderLayer {
1920
private _canvas: HTMLCanvasElement;

addons/addon-webgl/src/renderLayer/LinkRenderLayer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @license MIT
44
*/
55

6-
import { is256Color } from 'browser/renderer/shared/CharAtlasUtils';
6+
import { is256Color } from '../CharAtlasUtils';
77
import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/shared/Constants';
88
import { IRenderDimensions } from 'browser/renderer/shared/Types';
99
import { ICoreBrowserService, IThemeService } from 'browser/services/Services';

src/browser/renderer/shared/Constants.ts

-8
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,4 @@
33
* @license MIT
44
*/
55

6-
import { isFirefox, isLegacyEdge } from 'common/Platform';
7-
86
export const INVERTED_DEFAULT_COLOR = 257;
9-
10-
export const DIM_OPACITY = 0.5;
11-
// The text baseline is set conditionally by browser. Using 'ideographic' for Firefox or Legacy Edge
12-
// would result in truncated text (Issue 3353). Using 'bottom' for Chrome would result in slightly
13-
// unaligned Powerline fonts (PR 3356#issuecomment-850928179).
14-
export const TEXT_BASELINE: CanvasTextBaseline = isFirefox || isLegacyEdge ? 'bottom' : 'ideographic';

src/browser/renderer/shared/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
This folder contains files that are shared between the renderer addons, but not necessarily bundled into the `xterm` module.
1+
This folder contains files that are shared between the renderers.

src/browser/renderer/shared/Types.ts

+2-92
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,11 @@
33
* @license MIT
44
*/
55

6-
import { FontWeight, Terminal } from '@xterm/xterm';
7-
import { IColorSet, ITerminal } from 'browser/Types';
6+
import { Terminal } from '@xterm/xterm';
7+
import { ITerminal } from 'browser/Types';
88
import { IDisposable } from 'common/Types';
99
import type { Event } from 'vs/base/common/event';
1010

11-
export interface ICharAtlasConfig {
12-
customGlyphs: boolean;
13-
devicePixelRatio: number;
14-
deviceMaxTextureSize: number;
15-
letterSpacing: number;
16-
lineHeight: number;
17-
fontSize: number;
18-
fontFamily: string;
19-
fontWeight: FontWeight;
20-
fontWeightBold: FontWeight;
21-
deviceCellWidth: number;
22-
deviceCellHeight: number;
23-
deviceCharWidth: number;
24-
deviceCharHeight: number;
25-
allowTransparency: boolean;
26-
drawBoldTextInBrightColors: boolean;
27-
minimumContrastRatio: number;
28-
colors: IColorSet;
29-
}
30-
3111
export interface IDimensions {
3212
width: number;
3313
height: number;
@@ -87,76 +67,6 @@ export interface IRenderer extends IDisposable {
8767
clearTextureAtlas?(): void;
8868
}
8969

90-
export interface ITextureAtlas extends IDisposable {
91-
readonly pages: { canvas: HTMLCanvasElement, version: number }[];
92-
93-
onAddTextureAtlasCanvas: Event<HTMLCanvasElement>;
94-
onRemoveTextureAtlasCanvas: Event<HTMLCanvasElement>;
95-
96-
/**
97-
* Warm up the texture atlas, adding common glyphs to avoid slowing early frame.
98-
*/
99-
warmUp(): void;
100-
101-
/**
102-
* Call when a frame is being drawn, this will return true if the atlas was cleared to make room
103-
* for a new set of glyphs.
104-
*/
105-
beginFrame(): boolean;
106-
107-
/**
108-
* Clear all glyphs from the texture atlas.
109-
*/
110-
clearTexture(): void;
111-
getRasterizedGlyph(code: number, bg: number, fg: number, ext: number, restrictToCellHeight: boolean, domContainer: HTMLElement | undefined): IRasterizedGlyph;
112-
getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number, restrictToCellHeight: boolean, domContainer: HTMLElement | undefined): IRasterizedGlyph;
113-
}
114-
115-
/**
116-
* Represents a rasterized glyph within a texture atlas. Some numbers are
117-
* tracked in CSS pixels as well in order to reduce calculations during the
118-
* render loop.
119-
*/
120-
export interface IRasterizedGlyph {
121-
/**
122-
* The x and y offset between the glyph's top/left and the top/left of a cell
123-
* in pixels.
124-
*/
125-
offset: IVector;
126-
/**
127-
* The index of the texture page that the glyph is on.
128-
*/
129-
texturePage: number;
130-
/**
131-
* the x and y position of the glyph in the texture in pixels.
132-
*/
133-
texturePosition: IVector;
134-
/**
135-
* the x and y position of the glyph in the texture in clip space coordinates.
136-
*/
137-
texturePositionClipSpace: IVector;
138-
/**
139-
* The width and height of the glyph in the texture in pixels.
140-
*/
141-
size: IVector;
142-
/**
143-
* The width and height of the glyph in the texture in clip space coordinates.
144-
*/
145-
sizeClipSpace: IVector;
146-
}
147-
148-
export interface IVector {
149-
x: number;
150-
y: number;
151-
}
152-
153-
export interface IBoundingBox {
154-
top: number;
155-
left: number;
156-
right: number;
157-
bottom: number;
158-
}
159-
16070
export interface ISelectionRenderModel {
16171
readonly hasSelection: boolean;
16272
readonly columnSelectMode: boolean;

0 commit comments

Comments
 (0)