diff --git a/src/browser/renderer/shared/CellColorResolver.ts b/addons/addon-webgl/src/CellColorResolver.ts similarity index 100% rename from src/browser/renderer/shared/CellColorResolver.ts rename to addons/addon-webgl/src/CellColorResolver.ts diff --git a/src/browser/renderer/shared/CharAtlasCache.ts b/addons/addon-webgl/src/CharAtlasCache.ts similarity index 92% rename from src/browser/renderer/shared/CharAtlasCache.ts rename to addons/addon-webgl/src/CharAtlasCache.ts index 33e5807855..ea02581b8d 100644 --- a/src/browser/renderer/shared/CharAtlasCache.ts +++ b/addons/addon-webgl/src/CharAtlasCache.ts @@ -3,11 +3,11 @@ * @license MIT */ -import { TextureAtlas } from 'browser/renderer/shared/TextureAtlas'; +import { TextureAtlas } from './TextureAtlas'; import { ITerminalOptions, Terminal } from '@xterm/xterm'; import { ITerminal, ReadonlyColorSet } from 'browser/Types'; -import { ICharAtlasConfig, ITextureAtlas } from 'browser/renderer/shared/Types'; -import { generateConfig, configEquals } from 'browser/renderer/shared/CharAtlasUtils'; +import { ICharAtlasConfig, ITextureAtlas } from './Types'; +import { generateConfig, configEquals } from './CharAtlasUtils'; interface ITextureAtlasCacheEntry { atlas: ITextureAtlas; diff --git a/src/browser/renderer/shared/CharAtlasUtils.ts b/addons/addon-webgl/src/CharAtlasUtils.ts similarity index 100% rename from src/browser/renderer/shared/CharAtlasUtils.ts rename to addons/addon-webgl/src/CharAtlasUtils.ts diff --git a/addons/addon-webgl/src/Constants.ts b/addons/addon-webgl/src/Constants.ts new file mode 100644 index 0000000000..a00434d619 --- /dev/null +++ b/addons/addon-webgl/src/Constants.ts @@ -0,0 +1,12 @@ +/** + * Copyright (c) 2017 The xterm.js authors. All rights reserved. + * @license MIT + */ + +import { isFirefox, isLegacyEdge } from 'common/Platform'; + +export const DIM_OPACITY = 0.5; +// The text baseline is set conditionally by browser. Using 'ideographic' for Firefox or Legacy Edge +// would result in truncated text (Issue 3353). Using 'bottom' for Chrome would result in slightly +// unaligned Powerline fonts (PR 3356#issuecomment-850928179). +export const TEXT_BASELINE: CanvasTextBaseline = isFirefox || isLegacyEdge ? 'bottom' : 'ideographic'; diff --git a/src/browser/renderer/shared/CursorBlinkStateManager.ts b/addons/addon-webgl/src/CursorBlinkStateManager.ts similarity index 100% rename from src/browser/renderer/shared/CursorBlinkStateManager.ts rename to addons/addon-webgl/src/CursorBlinkStateManager.ts diff --git a/src/browser/renderer/shared/CustomGlyphs.ts b/addons/addon-webgl/src/CustomGlyphs.ts similarity index 100% rename from src/browser/renderer/shared/CustomGlyphs.ts rename to addons/addon-webgl/src/CustomGlyphs.ts diff --git a/src/browser/renderer/shared/DevicePixelObserver.ts b/addons/addon-webgl/src/DevicePixelObserver.ts similarity index 100% rename from src/browser/renderer/shared/DevicePixelObserver.ts rename to addons/addon-webgl/src/DevicePixelObserver.ts diff --git a/addons/addon-webgl/src/GlyphRenderer.ts b/addons/addon-webgl/src/GlyphRenderer.ts index f76804fdbb..10c9ad7222 100644 --- a/addons/addon-webgl/src/GlyphRenderer.ts +++ b/addons/addon-webgl/src/GlyphRenderer.ts @@ -2,16 +2,15 @@ * Copyright (c) 2018 The xterm.js authors. All rights reserved. * @license MIT */ - -import { allowRescaling, throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; -import { TextureAtlas } from 'browser/renderer/shared/TextureAtlas'; -import { IRasterizedGlyph, IRenderDimensions, ITextureAtlas } from 'browser/renderer/shared/Types'; +import { TextureAtlas } from './TextureAtlas'; +import { IRenderDimensions } from 'browser/renderer/shared/Types'; import { NULL_CELL_CODE } from 'common/buffer/Constants'; import { Disposable, toDisposable } from 'vs/base/common/lifecycle'; import { Terminal } from '@xterm/xterm'; -import { IRenderModel, IWebGL2RenderingContext, IWebGLVertexArrayObject } from './Types'; +import { IRenderModel, IWebGL2RenderingContext, IWebGLVertexArrayObject, type IRasterizedGlyph, type ITextureAtlas } from './Types'; import { createProgram, GLTexture, PROJECTION_MATRIX } from './WebglUtils'; import type { IOptionsService } from 'common/services/Services'; +import { allowRescaling, throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; interface IVertices { attributes: Float32Array; diff --git a/addons/addon-webgl/src/RectangleRenderer.ts b/addons/addon-webgl/src/RectangleRenderer.ts index 6dbedf0902..8ace9076e9 100644 --- a/addons/addon-webgl/src/RectangleRenderer.ts +++ b/addons/addon-webgl/src/RectangleRenderer.ts @@ -3,7 +3,6 @@ * @license MIT */ -import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; import { IRenderDimensions } from 'browser/renderer/shared/Types'; import { IThemeService } from 'browser/services/Services'; import { ReadonlyColorSet } from 'browser/Types'; @@ -14,6 +13,7 @@ import { Terminal } from '@xterm/xterm'; import { RENDER_MODEL_BG_OFFSET, RENDER_MODEL_FG_OFFSET, RENDER_MODEL_INDICIES_PER_CELL } from './RenderModel'; import { IRenderModel, IWebGL2RenderingContext, IWebGLVertexArrayObject } from './Types'; import { createProgram, expandFloat32Array, PROJECTION_MATRIX } from './WebglUtils'; +import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; const enum VertexAttribLocations { POSITION = 0, diff --git a/src/browser/renderer/shared/TextureAtlas.ts b/addons/addon-webgl/src/TextureAtlas.ts similarity index 99% rename from src/browser/renderer/shared/TextureAtlas.ts rename to addons/addon-webgl/src/TextureAtlas.ts index 7343d8909a..a7d1138ee0 100644 --- a/src/browser/renderer/shared/TextureAtlas.ts +++ b/addons/addon-webgl/src/TextureAtlas.ts @@ -4,10 +4,10 @@ */ import { IColorContrastCache } from 'browser/Types'; -import { DIM_OPACITY, TEXT_BASELINE } from 'browser/renderer/shared/Constants'; -import { tryDrawCustomChar } from 'browser/renderer/shared/CustomGlyphs'; +import { DIM_OPACITY, TEXT_BASELINE } from './Constants'; +import { tryDrawCustomChar } from './CustomGlyphs'; import { computeNextVariantOffset, treatGlyphAsBackgroundColor, isPowerlineGlyph, isRestrictedPowerlineGlyph, throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; -import { IBoundingBox, ICharAtlasConfig, IRasterizedGlyph, ITextureAtlas } from 'browser/renderer/shared/Types'; +import { IBoundingBox, ICharAtlasConfig, IRasterizedGlyph, ITextureAtlas } from './Types'; import { NULL_COLOR, channels, color, rgba } from 'common/Color'; import { FourKeyMap } from 'common/MultiKeyMap'; import { IdleTaskQueue } from 'common/TaskQueue'; diff --git a/addons/addon-webgl/src/Types.ts b/addons/addon-webgl/src/Types.ts index fe6e10c729..e030e579ed 100644 --- a/addons/addon-webgl/src/Types.ts +++ b/addons/addon-webgl/src/Types.ts @@ -3,8 +3,11 @@ * @license MIT */ +import { FontWeight } from '@xterm/xterm'; +import { IColorSet } from 'browser/Types'; import { ISelectionRenderModel } from 'browser/renderer/shared/Types'; -import { CursorInactiveStyle, CursorStyle } from 'common/Types'; +import { CursorInactiveStyle, CursorStyle, type IDisposable } from 'common/Types'; +import type { Event } from 'vs/base/common/event'; export interface IRenderModel { cells: Uint32Array; @@ -31,3 +34,93 @@ export interface IWebGL2RenderingContext extends WebGLRenderingContext { export interface IWebGLVertexArrayObject { } + +export interface ICharAtlasConfig { + customGlyphs: boolean; + devicePixelRatio: number; + deviceMaxTextureSize: number; + letterSpacing: number; + lineHeight: number; + fontSize: number; + fontFamily: string; + fontWeight: FontWeight; + fontWeightBold: FontWeight; + deviceCellWidth: number; + deviceCellHeight: number; + deviceCharWidth: number; + deviceCharHeight: number; + allowTransparency: boolean; + drawBoldTextInBrightColors: boolean; + minimumContrastRatio: number; + colors: IColorSet; +} + +export interface ITextureAtlas extends IDisposable { + readonly pages: { canvas: HTMLCanvasElement, version: number }[]; + + onAddTextureAtlasCanvas: Event; + onRemoveTextureAtlasCanvas: Event; + + /** + * Warm up the texture atlas, adding common glyphs to avoid slowing early frame. + */ + warmUp(): void; + + /** + * Call when a frame is being drawn, this will return true if the atlas was cleared to make room + * for a new set of glyphs. + */ + beginFrame(): boolean; + + /** + * Clear all glyphs from the texture atlas. + */ + clearTexture(): void; + getRasterizedGlyph(code: number, bg: number, fg: number, ext: number, restrictToCellHeight: boolean, domContainer: HTMLElement | undefined): IRasterizedGlyph; + getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number, restrictToCellHeight: boolean, domContainer: HTMLElement | undefined): IRasterizedGlyph; +} + +/** + * Represents a rasterized glyph within a texture atlas. Some numbers are + * tracked in CSS pixels as well in order to reduce calculations during the + * render loop. + */ +export interface IRasterizedGlyph { + /** + * The x and y offset between the glyph's top/left and the top/left of a cell + * in pixels. + */ + offset: IVector; + /** + * The index of the texture page that the glyph is on. + */ + texturePage: number; + /** + * the x and y position of the glyph in the texture in pixels. + */ + texturePosition: IVector; + /** + * the x and y position of the glyph in the texture in clip space coordinates. + */ + texturePositionClipSpace: IVector; + /** + * The width and height of the glyph in the texture in pixels. + */ + size: IVector; + /** + * The width and height of the glyph in the texture in clip space coordinates. + */ + sizeClipSpace: IVector; +} + +export interface IVector { + x: number; + y: number; +} + +export interface IBoundingBox { + top: number; + left: number; + right: number; + bottom: number; +} diff --git a/addons/addon-webgl/src/WebglRenderer.ts b/addons/addon-webgl/src/WebglRenderer.ts index 4be864c1bf..398594d942 100644 --- a/addons/addon-webgl/src/WebglRenderer.ts +++ b/addons/addon-webgl/src/WebglRenderer.ts @@ -4,12 +4,11 @@ */ import { ITerminal } from 'browser/Types'; -import { CellColorResolver } from 'browser/renderer/shared/CellColorResolver'; -import { acquireTextureAtlas, removeTerminalFromCache } from 'browser/renderer/shared/CharAtlasCache'; -import { CursorBlinkStateManager } from 'browser/renderer/shared/CursorBlinkStateManager'; -import { observeDevicePixelDimensions } from 'browser/renderer/shared/DevicePixelObserver'; -import { createRenderDimensions } from 'browser/renderer/shared/RendererUtils'; -import { IRenderDimensions, IRenderer, IRequestRedrawEvent, ITextureAtlas } from 'browser/renderer/shared/Types'; +import { CellColorResolver } from './CellColorResolver'; +import { acquireTextureAtlas, removeTerminalFromCache } from './CharAtlasCache'; +import { CursorBlinkStateManager } from './CursorBlinkStateManager'; +import { observeDevicePixelDimensions } from './DevicePixelObserver'; +import { IRenderDimensions, IRenderer, IRequestRedrawEvent } from 'browser/renderer/shared/Types'; import { ICharSizeService, ICharacterJoinerService, ICoreBrowserService, IThemeService } from 'browser/services/Services'; import { CharData, IBufferLine, ICellData } from 'common/Types'; import { AttributeData } from 'common/buffer/AttributeData'; @@ -20,12 +19,13 @@ import { Terminal } from '@xterm/xterm'; import { GlyphRenderer } from './GlyphRenderer'; import { RectangleRenderer } from './RectangleRenderer'; 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'; -import { IWebGL2RenderingContext } from './Types'; +import { IWebGL2RenderingContext, type ITextureAtlas } from './Types'; import { LinkRenderLayer } from './renderLayer/LinkRenderLayer'; import { IRenderLayer } from './renderLayer/Types'; import { Emitter, Event } from 'vs/base/common/event'; import { addDisposableListener } from 'vs/base/browser/dom'; import { combinedDisposable, Disposable, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle'; +import { createRenderDimensions } from 'browser/renderer/shared/RendererUtils'; export class WebglRenderer extends Disposable implements IRenderer { private _renderLayers: IRenderLayer[]; diff --git a/addons/addon-webgl/src/renderLayer/BaseRenderLayer.ts b/addons/addon-webgl/src/renderLayer/BaseRenderLayer.ts index 0cac7eb3f5..85b170e76c 100644 --- a/addons/addon-webgl/src/renderLayer/BaseRenderLayer.ts +++ b/addons/addon-webgl/src/renderLayer/BaseRenderLayer.ts @@ -4,16 +4,17 @@ */ import { ReadonlyColorSet } from 'browser/Types'; -import { acquireTextureAtlas } from 'browser/renderer/shared/CharAtlasCache'; -import { TEXT_BASELINE } from 'browser/renderer/shared/Constants'; -import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; -import { IRenderDimensions, ITextureAtlas } from 'browser/renderer/shared/Types'; +import { acquireTextureAtlas } from '../CharAtlasCache'; +import { IRenderDimensions } from 'browser/renderer/shared/Types'; import { ICoreBrowserService, IThemeService } from 'browser/services/Services'; import { Disposable, toDisposable } from 'vs/base/common/lifecycle'; import { CellData } from 'common/buffer/CellData'; import { IOptionsService } from 'common/services/Services'; import { Terminal } from '@xterm/xterm'; import { IRenderLayer } from './Types'; +import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; +import { TEXT_BASELINE } from '../Constants'; +import type { ITextureAtlas } from '../Types'; export abstract class BaseRenderLayer extends Disposable implements IRenderLayer { private _canvas: HTMLCanvasElement; diff --git a/addons/addon-webgl/src/renderLayer/LinkRenderLayer.ts b/addons/addon-webgl/src/renderLayer/LinkRenderLayer.ts index 1357dec659..faceac44fa 100644 --- a/addons/addon-webgl/src/renderLayer/LinkRenderLayer.ts +++ b/addons/addon-webgl/src/renderLayer/LinkRenderLayer.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { is256Color } from 'browser/renderer/shared/CharAtlasUtils'; +import { is256Color } from '../CharAtlasUtils'; import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/shared/Constants'; import { IRenderDimensions } from 'browser/renderer/shared/Types'; import { ICoreBrowserService, IThemeService } from 'browser/services/Services'; diff --git a/src/browser/renderer/shared/Constants.ts b/src/browser/renderer/shared/Constants.ts index b5105ec787..4bc4f9852a 100644 --- a/src/browser/renderer/shared/Constants.ts +++ b/src/browser/renderer/shared/Constants.ts @@ -3,12 +3,4 @@ * @license MIT */ -import { isFirefox, isLegacyEdge } from 'common/Platform'; - export const INVERTED_DEFAULT_COLOR = 257; - -export const DIM_OPACITY = 0.5; -// The text baseline is set conditionally by browser. Using 'ideographic' for Firefox or Legacy Edge -// would result in truncated text (Issue 3353). Using 'bottom' for Chrome would result in slightly -// unaligned Powerline fonts (PR 3356#issuecomment-850928179). -export const TEXT_BASELINE: CanvasTextBaseline = isFirefox || isLegacyEdge ? 'bottom' : 'ideographic'; diff --git a/src/browser/renderer/shared/README.md b/src/browser/renderer/shared/README.md index 5808423566..25b9a23961 100644 --- a/src/browser/renderer/shared/README.md +++ b/src/browser/renderer/shared/README.md @@ -1 +1 @@ -This folder contains files that are shared between the renderer addons, but not necessarily bundled into the `xterm` module. +This folder contains files that are shared between the renderers. diff --git a/src/browser/renderer/shared/Types.ts b/src/browser/renderer/shared/Types.ts index 6b4881cb19..f783ffecb8 100644 --- a/src/browser/renderer/shared/Types.ts +++ b/src/browser/renderer/shared/Types.ts @@ -3,31 +3,11 @@ * @license MIT */ -import { FontWeight, Terminal } from '@xterm/xterm'; -import { IColorSet, ITerminal } from 'browser/Types'; +import { Terminal } from '@xterm/xterm'; +import { ITerminal } from 'browser/Types'; import { IDisposable } from 'common/Types'; import type { Event } from 'vs/base/common/event'; -export interface ICharAtlasConfig { - customGlyphs: boolean; - devicePixelRatio: number; - deviceMaxTextureSize: number; - letterSpacing: number; - lineHeight: number; - fontSize: number; - fontFamily: string; - fontWeight: FontWeight; - fontWeightBold: FontWeight; - deviceCellWidth: number; - deviceCellHeight: number; - deviceCharWidth: number; - deviceCharHeight: number; - allowTransparency: boolean; - drawBoldTextInBrightColors: boolean; - minimumContrastRatio: number; - colors: IColorSet; -} - export interface IDimensions { width: number; height: number; @@ -87,76 +67,6 @@ export interface IRenderer extends IDisposable { clearTextureAtlas?(): void; } -export interface ITextureAtlas extends IDisposable { - readonly pages: { canvas: HTMLCanvasElement, version: number }[]; - - onAddTextureAtlasCanvas: Event; - onRemoveTextureAtlasCanvas: Event; - - /** - * Warm up the texture atlas, adding common glyphs to avoid slowing early frame. - */ - warmUp(): void; - - /** - * Call when a frame is being drawn, this will return true if the atlas was cleared to make room - * for a new set of glyphs. - */ - beginFrame(): boolean; - - /** - * Clear all glyphs from the texture atlas. - */ - clearTexture(): void; - getRasterizedGlyph(code: number, bg: number, fg: number, ext: number, restrictToCellHeight: boolean, domContainer: HTMLElement | undefined): IRasterizedGlyph; - getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number, restrictToCellHeight: boolean, domContainer: HTMLElement | undefined): IRasterizedGlyph; -} - -/** - * Represents a rasterized glyph within a texture atlas. Some numbers are - * tracked in CSS pixels as well in order to reduce calculations during the - * render loop. - */ -export interface IRasterizedGlyph { - /** - * The x and y offset between the glyph's top/left and the top/left of a cell - * in pixels. - */ - offset: IVector; - /** - * The index of the texture page that the glyph is on. - */ - texturePage: number; - /** - * the x and y position of the glyph in the texture in pixels. - */ - texturePosition: IVector; - /** - * the x and y position of the glyph in the texture in clip space coordinates. - */ - texturePositionClipSpace: IVector; - /** - * The width and height of the glyph in the texture in pixels. - */ - size: IVector; - /** - * The width and height of the glyph in the texture in clip space coordinates. - */ - sizeClipSpace: IVector; -} - -export interface IVector { - x: number; - y: number; -} - -export interface IBoundingBox { - top: number; - left: number; - right: number; - bottom: number; -} - export interface ISelectionRenderModel { readonly hasSelection: boolean; readonly columnSelectMode: boolean;