Merge pull request #2287 from Tyriar/webgl_simplify_atlas
Enable strict mode in webgl addon
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createProgram, PROJECTION_MATRIX } from './WebglUtils';
|
import { createProgram, PROJECTION_MATRIX, throwIfFalsy } from './WebglUtils';
|
||||||
import { WebglCharAtlas } from './atlas/WebglCharAtlas';
|
import { WebglCharAtlas } from './atlas/WebglCharAtlas';
|
||||||
import { IWebGL2RenderingContext, IWebGLVertexArrayObject, IRenderModel, IRasterizedGlyph } from './Types';
|
import { IWebGL2RenderingContext, IWebGLVertexArrayObject, IRenderModel, IRasterizedGlyph } from './Types';
|
||||||
import { INDICIES_PER_CELL } from './WebglRenderer';
|
import { INDICIES_PER_CELL } from './WebglRenderer';
|
||||||
@@ -75,7 +75,7 @@ const BYTES_PER_CELL = INDICES_PER_CELL * Float32Array.BYTES_PER_ELEMENT;
|
|||||||
const CELL_POSITION_INDICES = 2;
|
const CELL_POSITION_INDICES = 2;
|
||||||
|
|
||||||
export class GlyphRenderer {
|
export class GlyphRenderer {
|
||||||
private _atlas: WebglCharAtlas;
|
private _atlas: WebglCharAtlas | undefined;
|
||||||
|
|
||||||
private _program: WebGLProgram;
|
private _program: WebGLProgram;
|
||||||
private _vertexArrayObject: IWebGLVertexArrayObject;
|
private _vertexArrayObject: IWebGLVertexArrayObject;
|
||||||
@@ -104,12 +104,16 @@ export class GlyphRenderer {
|
|||||||
) {
|
) {
|
||||||
const gl = this._gl;
|
const gl = this._gl;
|
||||||
|
|
||||||
this._program = createProgram(gl, vertexShaderSource, fragmentShaderSource);
|
const program = throwIfFalsy(createProgram(gl, vertexShaderSource, fragmentShaderSource));
|
||||||
|
if (program === undefined) {
|
||||||
|
throw new Error('Could not create WebGL program');
|
||||||
|
}
|
||||||
|
this._program = program;
|
||||||
|
|
||||||
// Uniform locations
|
// Uniform locations
|
||||||
this._projectionLocation = gl.getUniformLocation(this._program, 'u_projection');
|
this._projectionLocation = throwIfFalsy(gl.getUniformLocation(this._program, 'u_projection'));
|
||||||
this._resolutionLocation = gl.getUniformLocation(this._program, 'u_resolution');
|
this._resolutionLocation = throwIfFalsy(gl.getUniformLocation(this._program, 'u_resolution'));
|
||||||
this._textureLocation = gl.getUniformLocation(this._program, 'u_texture');
|
this._textureLocation = throwIfFalsy(gl.getUniformLocation(this._program, 'u_texture'));
|
||||||
|
|
||||||
// Create and set the vertex array object
|
// Create and set the vertex array object
|
||||||
this._vertexArrayObject = gl.createVertexArray();
|
this._vertexArrayObject = gl.createVertexArray();
|
||||||
@@ -131,7 +135,7 @@ export class GlyphRenderer {
|
|||||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, unitQuadElementIndices, gl.STATIC_DRAW);
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, unitQuadElementIndices, gl.STATIC_DRAW);
|
||||||
|
|
||||||
// Setup attributes
|
// Setup attributes
|
||||||
this._attributesBuffer = gl.createBuffer();
|
this._attributesBuffer = throwIfFalsy(gl.createBuffer());
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._attributesBuffer);
|
gl.bindBuffer(gl.ARRAY_BUFFER, this._attributesBuffer);
|
||||||
gl.enableVertexAttribArray(VertexAttribLocations.OFFSET);
|
gl.enableVertexAttribArray(VertexAttribLocations.OFFSET);
|
||||||
gl.vertexAttribPointer(VertexAttribLocations.OFFSET, 2, gl.FLOAT, false, BYTES_PER_CELL, 0);
|
gl.vertexAttribPointer(VertexAttribLocations.OFFSET, 2, gl.FLOAT, false, BYTES_PER_CELL, 0);
|
||||||
@@ -150,7 +154,7 @@ export class GlyphRenderer {
|
|||||||
gl.vertexAttribDivisor(VertexAttribLocations.CELL_POSITION, 1);
|
gl.vertexAttribDivisor(VertexAttribLocations.CELL_POSITION, 1);
|
||||||
|
|
||||||
// Setup empty texture atlas
|
// Setup empty texture atlas
|
||||||
this._atlasTexture = gl.createTexture();
|
this._atlasTexture = throwIfFalsy(gl.createTexture());
|
||||||
gl.bindTexture(gl.TEXTURE_2D, this._atlasTexture);
|
gl.bindTexture(gl.TEXTURE_2D, this._atlasTexture);
|
||||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 255, 255]));
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 255, 255]));
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||||
@@ -184,6 +188,9 @@ export class GlyphRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let rasterizedGlyph: IRasterizedGlyph;
|
let rasterizedGlyph: IRasterizedGlyph;
|
||||||
|
if (!this._atlas) {
|
||||||
|
throw new Error('atlas must be set before updating cell');
|
||||||
|
}
|
||||||
if (chars && chars.length > 1) {
|
if (chars && chars.length > 1) {
|
||||||
rasterizedGlyph = this._atlas.getRasterizedGlyphCombinedChar(chars, attr, bg, fg);
|
rasterizedGlyph = this._atlas.getRasterizedGlyphCombinedChar(chars, attr, bg, fg);
|
||||||
} else {
|
} else {
|
||||||
@@ -264,7 +271,7 @@ export class GlyphRenderer {
|
|||||||
if (!line) {
|
if (!line) {
|
||||||
line = terminal.buffer.getLine(row);
|
line = terminal.buffer.getLine(row);
|
||||||
}
|
}
|
||||||
const chars = line.getCell(x).char;
|
const chars = line!.getCell(x)!.char;
|
||||||
this._updateCell(this._vertices.selectionAttributes, x, y, model.cells[offset], attr, bg, fg, chars);
|
this._updateCell(this._vertices.selectionAttributes, x, y, model.cells[offset], attr, bg, fg, chars);
|
||||||
} else {
|
} else {
|
||||||
this._updateCell(this._vertices.selectionAttributes, x, y, model.cells[offset], attr, bg, fg);
|
this._updateCell(this._vertices.selectionAttributes, x, y, model.cells[offset], attr, bg, fg);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createProgram, expandFloat32Array, PROJECTION_MATRIX } from './WebglUtils';
|
import { createProgram, expandFloat32Array, PROJECTION_MATRIX, throwIfFalsy } from './WebglUtils';
|
||||||
import { IRenderModel, IWebGLVertexArrayObject, IWebGL2RenderingContext, ISelectionRenderModel } from './Types';
|
import { IRenderModel, IWebGLVertexArrayObject, IWebGL2RenderingContext, ISelectionRenderModel } from './Types';
|
||||||
import { fill } from 'common/TypedArrayUtils';
|
import { fill } from 'common/TypedArrayUtils';
|
||||||
import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/atlas/Constants';
|
import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/atlas/Constants';
|
||||||
@@ -66,8 +66,8 @@ export class RectangleRenderer {
|
|||||||
private _resolutionLocation: WebGLUniformLocation;
|
private _resolutionLocation: WebGLUniformLocation;
|
||||||
private _attributesBuffer: WebGLBuffer;
|
private _attributesBuffer: WebGLBuffer;
|
||||||
private _projectionLocation: WebGLUniformLocation;
|
private _projectionLocation: WebGLUniformLocation;
|
||||||
private _bgFloat: Float32Array;
|
private _bgFloat!: Float32Array;
|
||||||
private _selectionFloat: Float32Array;
|
private _selectionFloat!: Float32Array;
|
||||||
|
|
||||||
private _vertices: IVertices = {
|
private _vertices: IVertices = {
|
||||||
count: 0,
|
count: 0,
|
||||||
@@ -83,11 +83,11 @@ export class RectangleRenderer {
|
|||||||
) {
|
) {
|
||||||
const gl = this._gl;
|
const gl = this._gl;
|
||||||
|
|
||||||
this._program = createProgram(gl, vertexShaderSource, fragmentShaderSource);
|
this._program = throwIfFalsy(createProgram(gl, vertexShaderSource, fragmentShaderSource));
|
||||||
|
|
||||||
// Uniform locations
|
// Uniform locations
|
||||||
this._resolutionLocation = gl.getUniformLocation(this._program, 'u_resolution');
|
this._resolutionLocation = throwIfFalsy(gl.getUniformLocation(this._program, 'u_resolution'));
|
||||||
this._projectionLocation = gl.getUniformLocation(this._program, 'u_projection');
|
this._projectionLocation = throwIfFalsy(gl.getUniformLocation(this._program, 'u_projection'));
|
||||||
|
|
||||||
// Create and set the vertex array object
|
// Create and set the vertex array object
|
||||||
this._vertexArrayObject = gl.createVertexArray();
|
this._vertexArrayObject = gl.createVertexArray();
|
||||||
@@ -109,7 +109,7 @@ export class RectangleRenderer {
|
|||||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, unitQuadElementIndices, gl.STATIC_DRAW);
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, unitQuadElementIndices, gl.STATIC_DRAW);
|
||||||
|
|
||||||
// Setup attributes
|
// Setup attributes
|
||||||
this._attributesBuffer = gl.createBuffer();
|
this._attributesBuffer = throwIfFalsy(gl.createBuffer());
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._attributesBuffer);
|
gl.bindBuffer(gl.ARRAY_BUFFER, this._attributesBuffer);
|
||||||
gl.enableVertexAttribArray(VertexAttribLocations.POSITION);
|
gl.enableVertexAttribArray(VertexAttribLocations.POSITION);
|
||||||
gl.vertexAttribPointer(VertexAttribLocations.POSITION, 2, gl.FLOAT, false, BYTES_PER_RECTANGLE, 0);
|
gl.vertexAttribPointer(VertexAttribLocations.POSITION, 2, gl.FLOAT, false, BYTES_PER_RECTANGLE, 0);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export const INDICIES_PER_CELL = 4;
|
|||||||
|
|
||||||
export class WebglRenderer extends Disposable implements IRenderer {
|
export class WebglRenderer extends Disposable implements IRenderer {
|
||||||
private _renderLayers: IRenderLayer[];
|
private _renderLayers: IRenderLayer[];
|
||||||
private _charAtlas: WebglCharAtlas;
|
private _charAtlas: WebglCharAtlas | undefined;
|
||||||
private _devicePixelRatio: number;
|
private _devicePixelRatio: number;
|
||||||
|
|
||||||
private _model: RenderModel = new RenderModel();
|
private _model: RenderModel = new RenderModel();
|
||||||
@@ -57,18 +57,18 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
|||||||
new CursorRenderLayer(this._core.screenElement, 3, this._colors)
|
new CursorRenderLayer(this._core.screenElement, 3, this._colors)
|
||||||
];
|
];
|
||||||
this.dimensions = {
|
this.dimensions = {
|
||||||
scaledCharWidth: null,
|
scaledCharWidth: 0,
|
||||||
scaledCharHeight: null,
|
scaledCharHeight: 0,
|
||||||
scaledCellWidth: null,
|
scaledCellWidth: 0,
|
||||||
scaledCellHeight: null,
|
scaledCellHeight: 0,
|
||||||
scaledCharLeft: null,
|
scaledCharLeft: 0,
|
||||||
scaledCharTop: null,
|
scaledCharTop: 0,
|
||||||
scaledCanvasWidth: null,
|
scaledCanvasWidth: 0,
|
||||||
scaledCanvasHeight: null,
|
scaledCanvasHeight: 0,
|
||||||
canvasWidth: null,
|
canvasWidth: 0,
|
||||||
canvasHeight: null,
|
canvasHeight: 0,
|
||||||
actualCellWidth: null,
|
actualCellWidth: 0,
|
||||||
actualCellHeight: null
|
actualCellHeight: 0
|
||||||
};
|
};
|
||||||
this._devicePixelRatio = window.devicePixelRatio;
|
this._devicePixelRatio = window.devicePixelRatio;
|
||||||
this._updateDimensions();
|
this._updateDimensions();
|
||||||
@@ -252,7 +252,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
|||||||
|
|
||||||
for (let y = start; y <= end; y++) {
|
for (let y = start; y <= end; y++) {
|
||||||
const row = y + terminal.buffer.ydisp;
|
const row = y + terminal.buffer.ydisp;
|
||||||
const line = terminal.buffer.lines.get(row);
|
const line = terminal.buffer.lines.get(row)!;
|
||||||
this._model.lineLengths[y] = 0;
|
this._model.lineLengths[y] = 0;
|
||||||
for (let x = 0; x < terminal.cols; x++) {
|
for (let x = 0; x < terminal.cols; x++) {
|
||||||
const charData = line.get(x);
|
const charData = line.get(x);
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ export const PROJECTION_MATRIX = new Float32Array([
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
export function createProgram(gl: WebGLRenderingContext, vertexSource: string, fragmentSource: string): WebGLProgram | undefined {
|
export function createProgram(gl: WebGLRenderingContext, vertexSource: string, fragmentSource: string): WebGLProgram | undefined {
|
||||||
const program = gl.createProgram();
|
const program = throwIfFalsy(gl.createProgram());
|
||||||
gl.attachShader(program, createShader(gl, gl.VERTEX_SHADER, vertexSource));
|
gl.attachShader(program, throwIfFalsy(createShader(gl, gl.VERTEX_SHADER, vertexSource)));
|
||||||
gl.attachShader(program, createShader(gl, gl.FRAGMENT_SHADER, fragmentSource));
|
gl.attachShader(program, throwIfFalsy(createShader(gl, gl.FRAGMENT_SHADER, fragmentSource)));
|
||||||
gl.linkProgram(program);
|
gl.linkProgram(program);
|
||||||
const success = gl.getProgramParameter(program, gl.LINK_STATUS);
|
const success = gl.getProgramParameter(program, gl.LINK_STATUS);
|
||||||
if (success) {
|
if (success) {
|
||||||
@@ -29,7 +29,7 @@ export function createProgram(gl: WebGLRenderingContext, vertexSource: string, f
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createShader(gl: WebGLRenderingContext, type: number, source: string): WebGLShader | undefined {
|
export function createShader(gl: WebGLRenderingContext, type: number, source: string): WebGLShader | undefined {
|
||||||
const shader = gl.createShader(type);
|
const shader = throwIfFalsy(gl.createShader(type));
|
||||||
gl.shaderSource(shader, source);
|
gl.shaderSource(shader, source);
|
||||||
gl.compileShader(shader);
|
gl.compileShader(shader);
|
||||||
const success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
const success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
||||||
@@ -49,3 +49,10 @@ export function expandFloat32Array(source: Float32Array, max: number): Float32Ar
|
|||||||
}
|
}
|
||||||
return newArray;
|
return newArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function throwIfFalsy<T>(value: T | undefined | null): T {
|
||||||
|
if (!value) {
|
||||||
|
throw new Error('value must not be falsy');
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,16 +6,21 @@
|
|||||||
import { ICharAtlasConfig } from './Types';
|
import { ICharAtlasConfig } from './Types';
|
||||||
import { DEFAULT_COLOR } from 'common/buffer/Constants';
|
import { DEFAULT_COLOR } from 'common/buffer/Constants';
|
||||||
import { Terminal, FontWeight } from 'xterm';
|
import { Terminal, FontWeight } from 'xterm';
|
||||||
import { IColorSet } from 'browser/Types';
|
import { IColorSet, IColor } from 'browser/Types';
|
||||||
|
|
||||||
|
const NULL_COLOR: IColor = {
|
||||||
|
css: '',
|
||||||
|
rgba: 0
|
||||||
|
};
|
||||||
|
|
||||||
export function generateConfig(scaledCharWidth: number, scaledCharHeight: number, terminal: Terminal, colors: IColorSet): ICharAtlasConfig {
|
export function generateConfig(scaledCharWidth: number, scaledCharHeight: number, terminal: Terminal, colors: IColorSet): ICharAtlasConfig {
|
||||||
// null out some fields that don't matter
|
// null out some fields that don't matter
|
||||||
const clonedColors: IColorSet = {
|
const clonedColors: IColorSet = {
|
||||||
foreground: colors.foreground,
|
foreground: colors.foreground,
|
||||||
background: colors.background,
|
background: colors.background,
|
||||||
cursor: null,
|
cursor: NULL_COLOR,
|
||||||
cursorAccent: null,
|
cursorAccent: NULL_COLOR,
|
||||||
selection: null,
|
selection: NULL_COLOR,
|
||||||
// For the static char atlas, we only use the first 16 colors, but we need all 256 for the
|
// For the static char atlas, we only use the first 16 colors, but we need all 256 for the
|
||||||
// dynamic character atlas.
|
// dynamic character atlas.
|
||||||
ansi: colors.ansi.slice()
|
ansi: colors.ansi.slice()
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { DIM_OPACITY, INVERTED_DEFAULT_COLOR } from 'browser/renderer/atlas/Cons
|
|||||||
import { IRasterizedGlyph, IBoundingBox, IRasterizedGlyphSet } from '../Types';
|
import { IRasterizedGlyph, IBoundingBox, IRasterizedGlyphSet } from '../Types';
|
||||||
import { DEFAULT_COLOR, DEFAULT_ATTR } from 'common/buffer/Constants';
|
import { DEFAULT_COLOR, DEFAULT_ATTR } from 'common/buffer/Constants';
|
||||||
import { is256Color } from './CharAtlasUtils';
|
import { is256Color } from './CharAtlasUtils';
|
||||||
|
import { throwIfFalsy } from '../WebglUtils';
|
||||||
import { IColor } from 'browser/Types';
|
import { IColor } from 'browser/Types';
|
||||||
import { FLAGS } from '../Constants';
|
import { FLAGS } from '../Constants';
|
||||||
import { IDisposable } from 'xterm';
|
import { IDisposable } from 'xterm';
|
||||||
@@ -75,12 +76,12 @@ export class WebglCharAtlas implements IDisposable {
|
|||||||
// The canvas needs alpha because we use clearColor to convert the background color to alpha.
|
// The canvas needs alpha because we use clearColor to convert the background color to alpha.
|
||||||
// It might also contain some characters with transparent backgrounds if allowTransparency is
|
// It might also contain some characters with transparent backgrounds if allowTransparency is
|
||||||
// set.
|
// set.
|
||||||
this._cacheCtx = this.cacheCanvas.getContext('2d', {alpha: true});
|
this._cacheCtx = throwIfFalsy(this.cacheCanvas.getContext('2d', {alpha: true}));
|
||||||
|
|
||||||
this._tmpCanvas = document.createElement('canvas');
|
this._tmpCanvas = document.createElement('canvas');
|
||||||
this._tmpCanvas.width = this._config.scaledCharWidth * 2 + TMP_CANVAS_GLYPH_PADDING * 2;
|
this._tmpCanvas.width = this._config.scaledCharWidth * 2 + TMP_CANVAS_GLYPH_PADDING * 2;
|
||||||
this._tmpCanvas.height = this._config.scaledCharHeight + TMP_CANVAS_GLYPH_PADDING * 2;
|
this._tmpCanvas.height = this._config.scaledCharHeight + TMP_CANVAS_GLYPH_PADDING * 2;
|
||||||
this._tmpCtx = this._tmpCanvas.getContext('2d', {alpha: this._config.allowTransparency});
|
this._tmpCtx = throwIfFalsy(this._tmpCanvas.getContext('2d', {alpha: this._config.allowTransparency}));
|
||||||
|
|
||||||
// This is useful for debugging
|
// This is useful for debugging
|
||||||
document.body.appendChild(this.cacheCanvas);
|
document.body.appendChild(this.cacheCanvas);
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ import { IRenderDimensions } from 'browser/renderer/Types';
|
|||||||
import { CellData } from 'common/buffer/CellData';
|
import { CellData } from 'common/buffer/CellData';
|
||||||
import { AttributeData } from 'common/buffer/AttributeData';
|
import { AttributeData } from 'common/buffer/AttributeData';
|
||||||
import { WebglCharAtlas } from 'atlas/WebglCharAtlas';
|
import { WebglCharAtlas } from 'atlas/WebglCharAtlas';
|
||||||
|
import { throwIfFalsy } from '../WebglUtils';
|
||||||
|
|
||||||
export abstract class BaseRenderLayer implements IRenderLayer {
|
export abstract class BaseRenderLayer implements IRenderLayer {
|
||||||
private _canvas: HTMLCanvasElement;
|
private _canvas: HTMLCanvasElement;
|
||||||
protected _ctx: CanvasRenderingContext2D;
|
protected _ctx!: CanvasRenderingContext2D;
|
||||||
private _scaledCharWidth: number = 0;
|
private _scaledCharWidth: number = 0;
|
||||||
private _scaledCharHeight: number = 0;
|
private _scaledCharHeight: number = 0;
|
||||||
private _scaledCellWidth: number = 0;
|
private _scaledCellWidth: number = 0;
|
||||||
@@ -26,7 +27,7 @@ export abstract class BaseRenderLayer implements IRenderLayer {
|
|||||||
private _scaledCharLeft: number = 0;
|
private _scaledCharLeft: number = 0;
|
||||||
private _scaledCharTop: number = 0;
|
private _scaledCharTop: number = 0;
|
||||||
|
|
||||||
protected _charAtlas: WebglCharAtlas;
|
protected _charAtlas: WebglCharAtlas | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An object that's reused when drawing glyphs in order to reduce GC.
|
* An object that's reused when drawing glyphs in order to reduce GC.
|
||||||
@@ -63,7 +64,7 @@ export abstract class BaseRenderLayer implements IRenderLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _initCanvas(): void {
|
private _initCanvas(): void {
|
||||||
this._ctx = this._canvas.getContext('2d', {alpha: this._alpha});
|
this._ctx = throwIfFalsy(this._canvas.getContext('2d', {alpha: this._alpha}));
|
||||||
// Draw the background if this is an opaque layer
|
// Draw the background if this is an opaque layer
|
||||||
if (!this._alpha) {
|
if (!this._alpha) {
|
||||||
this._clearAll();
|
this._clearAll();
|
||||||
|
|||||||
@@ -26,17 +26,17 @@ const BLINK_INTERVAL = 600;
|
|||||||
export class CursorRenderLayer extends BaseRenderLayer {
|
export class CursorRenderLayer extends BaseRenderLayer {
|
||||||
private _state: ICursorState;
|
private _state: ICursorState;
|
||||||
private _cursorRenderers: {[key: string]: (terminal: Terminal, x: number, y: number, cell: ICellData) => void};
|
private _cursorRenderers: {[key: string]: (terminal: Terminal, x: number, y: number, cell: ICellData) => void};
|
||||||
private _cursorBlinkStateManager: CursorBlinkStateManager;
|
private _cursorBlinkStateManager: CursorBlinkStateManager | undefined;
|
||||||
private _cell: ICellData = new CellData();
|
private _cell: ICellData = new CellData();
|
||||||
|
|
||||||
constructor(container: HTMLElement, zIndex: number, colors: IColorSet) {
|
constructor(container: HTMLElement, zIndex: number, colors: IColorSet) {
|
||||||
super(container, 'cursor', zIndex, true, colors);
|
super(container, 'cursor', zIndex, true, colors);
|
||||||
this._state = {
|
this._state = {
|
||||||
x: null,
|
x: 0,
|
||||||
y: null,
|
y: 0,
|
||||||
isFocused: null,
|
isFocused: false,
|
||||||
style: null,
|
style: '',
|
||||||
width: null
|
width: 0
|
||||||
};
|
};
|
||||||
this._cursorRenderers = {
|
this._cursorRenderers = {
|
||||||
'bar': this._renderBarCursor.bind(this),
|
'bar': this._renderBarCursor.bind(this),
|
||||||
@@ -50,11 +50,11 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
|||||||
super.resize(terminal, dim);
|
super.resize(terminal, dim);
|
||||||
// Resizing the canvas discards the contents of the canvas so clear state
|
// Resizing the canvas discards the contents of the canvas so clear state
|
||||||
this._state = {
|
this._state = {
|
||||||
x: null,
|
x: 0,
|
||||||
y: null,
|
y: 0,
|
||||||
isFocused: null,
|
isFocused: false,
|
||||||
style: null,
|
style: '',
|
||||||
width: null
|
width: 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +62,6 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
|||||||
this._clearCursor();
|
this._clearCursor();
|
||||||
if (this._cursorBlinkStateManager) {
|
if (this._cursorBlinkStateManager) {
|
||||||
this._cursorBlinkStateManager.dispose();
|
this._cursorBlinkStateManager.dispose();
|
||||||
this._cursorBlinkStateManager = null;
|
|
||||||
this.onOptionsChanged(terminal);
|
this.onOptionsChanged(terminal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +91,6 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
|||||||
} else {
|
} else {
|
||||||
if (this._cursorBlinkStateManager) {
|
if (this._cursorBlinkStateManager) {
|
||||||
this._cursorBlinkStateManager.dispose();
|
this._cursorBlinkStateManager.dispose();
|
||||||
this._cursorBlinkStateManager = null;
|
|
||||||
}
|
}
|
||||||
// Request a refresh from the terminal as management of rendering is being
|
// Request a refresh from the terminal as management of rendering is being
|
||||||
// moved back to the terminal
|
// moved back to the terminal
|
||||||
@@ -184,11 +182,11 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
|||||||
if (this._state) {
|
if (this._state) {
|
||||||
this._clearCells(this._state.x, this._state.y, this._state.width, 1);
|
this._clearCells(this._state.x, this._state.y, this._state.width, 1);
|
||||||
this._state = {
|
this._state = {
|
||||||
x: null,
|
x: 0,
|
||||||
y: null,
|
y: 0,
|
||||||
isFocused: null,
|
isFocused: false,
|
||||||
style: null,
|
style: '',
|
||||||
width: null
|
width: 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,16 +225,16 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
|||||||
class CursorBlinkStateManager {
|
class CursorBlinkStateManager {
|
||||||
public isCursorVisible: boolean;
|
public isCursorVisible: boolean;
|
||||||
|
|
||||||
private _animationFrame: number;
|
private _animationFrame: number | undefined;
|
||||||
private _blinkStartTimeout: number;
|
private _blinkStartTimeout: number | undefined;
|
||||||
private _blinkInterval: number;
|
private _blinkInterval: number | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time at which the animation frame was restarted, this is used on the
|
* The time at which the animation frame was restarted, this is used on the
|
||||||
* next render to restart the timers so they don't need to restart the timers
|
* next render to restart the timers so they don't need to restart the timers
|
||||||
* multiple times over a short period.
|
* multiple times over a short period.
|
||||||
*/
|
*/
|
||||||
private _animationTimeRestarted: number;
|
private _animationTimeRestarted: number | undefined;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
terminal: Terminal,
|
terminal: Terminal,
|
||||||
@@ -253,15 +251,15 @@ class CursorBlinkStateManager {
|
|||||||
public dispose(): void {
|
public dispose(): void {
|
||||||
if (this._blinkInterval) {
|
if (this._blinkInterval) {
|
||||||
window.clearInterval(this._blinkInterval);
|
window.clearInterval(this._blinkInterval);
|
||||||
this._blinkInterval = null;
|
this._blinkInterval = undefined;
|
||||||
}
|
}
|
||||||
if (this._blinkStartTimeout) {
|
if (this._blinkStartTimeout) {
|
||||||
window.clearTimeout(this._blinkStartTimeout);
|
window.clearTimeout(this._blinkStartTimeout);
|
||||||
this._blinkStartTimeout = null;
|
this._blinkStartTimeout = undefined;
|
||||||
}
|
}
|
||||||
if (this._animationFrame) {
|
if (this._animationFrame) {
|
||||||
window.cancelAnimationFrame(this._animationFrame);
|
window.cancelAnimationFrame(this._animationFrame);
|
||||||
this._animationFrame = null;
|
this._animationFrame = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,7 +274,7 @@ class CursorBlinkStateManager {
|
|||||||
if (!this._animationFrame) {
|
if (!this._animationFrame) {
|
||||||
this._animationFrame = window.requestAnimationFrame(() => {
|
this._animationFrame = window.requestAnimationFrame(() => {
|
||||||
this._renderCallback();
|
this._renderCallback();
|
||||||
this._animationFrame = null;
|
this._animationFrame = undefined;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -296,7 +294,7 @@ class CursorBlinkStateManager {
|
|||||||
// started
|
// started
|
||||||
if (this._animationTimeRestarted) {
|
if (this._animationTimeRestarted) {
|
||||||
const time = BLINK_INTERVAL - (Date.now() - this._animationTimeRestarted);
|
const time = BLINK_INTERVAL - (Date.now() - this._animationTimeRestarted);
|
||||||
this._animationTimeRestarted = null;
|
this._animationTimeRestarted = undefined;
|
||||||
if (time > 0) {
|
if (time > 0) {
|
||||||
this._restartInterval(time);
|
this._restartInterval(time);
|
||||||
return;
|
return;
|
||||||
@@ -307,7 +305,7 @@ class CursorBlinkStateManager {
|
|||||||
this.isCursorVisible = false;
|
this.isCursorVisible = false;
|
||||||
this._animationFrame = window.requestAnimationFrame(() => {
|
this._animationFrame = window.requestAnimationFrame(() => {
|
||||||
this._renderCallback();
|
this._renderCallback();
|
||||||
this._animationFrame = null;
|
this._animationFrame = undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Setup the blink interval
|
// Setup the blink interval
|
||||||
@@ -317,7 +315,7 @@ class CursorBlinkStateManager {
|
|||||||
// calc time diff
|
// calc time diff
|
||||||
// Make restart interval do a setTimeout initially?
|
// Make restart interval do a setTimeout initially?
|
||||||
const time = BLINK_INTERVAL - (Date.now() - this._animationTimeRestarted);
|
const time = BLINK_INTERVAL - (Date.now() - this._animationTimeRestarted);
|
||||||
this._animationTimeRestarted = null;
|
this._animationTimeRestarted = undefined;
|
||||||
this._restartInterval(time);
|
this._restartInterval(time);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -326,7 +324,7 @@ class CursorBlinkStateManager {
|
|||||||
this.isCursorVisible = !this.isCursorVisible;
|
this.isCursorVisible = !this.isCursorVisible;
|
||||||
this._animationFrame = window.requestAnimationFrame(() => {
|
this._animationFrame = window.requestAnimationFrame(() => {
|
||||||
this._renderCallback();
|
this._renderCallback();
|
||||||
this._animationFrame = null;
|
this._animationFrame = undefined;
|
||||||
});
|
});
|
||||||
}, BLINK_INTERVAL);
|
}, BLINK_INTERVAL);
|
||||||
}, timeToStart);
|
}, timeToStart);
|
||||||
@@ -336,20 +334,20 @@ class CursorBlinkStateManager {
|
|||||||
this.isCursorVisible = true;
|
this.isCursorVisible = true;
|
||||||
if (this._blinkInterval) {
|
if (this._blinkInterval) {
|
||||||
window.clearInterval(this._blinkInterval);
|
window.clearInterval(this._blinkInterval);
|
||||||
this._blinkInterval = null;
|
this._blinkInterval = undefined;
|
||||||
}
|
}
|
||||||
if (this._blinkStartTimeout) {
|
if (this._blinkStartTimeout) {
|
||||||
window.clearTimeout(this._blinkStartTimeout);
|
window.clearTimeout(this._blinkStartTimeout);
|
||||||
this._blinkStartTimeout = null;
|
this._blinkStartTimeout = undefined;
|
||||||
}
|
}
|
||||||
if (this._animationFrame) {
|
if (this._animationFrame) {
|
||||||
window.cancelAnimationFrame(this._animationFrame);
|
window.cancelAnimationFrame(this._animationFrame);
|
||||||
this._animationFrame = null;
|
this._animationFrame = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public resume(terminal: Terminal): void {
|
public resume(terminal: Terminal): void {
|
||||||
this._animationTimeRestarted = null;
|
this._animationTimeRestarted = undefined;
|
||||||
this._restartInterval();
|
this._restartInterval();
|
||||||
this.restartBlinkAnimation(terminal);
|
this.restartBlinkAnimation(terminal);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { IColorSet } from 'browser/Types';
|
|||||||
import { IRenderDimensions } from 'browser/renderer/Types';
|
import { IRenderDimensions } from 'browser/renderer/Types';
|
||||||
|
|
||||||
export class LinkRenderLayer extends BaseRenderLayer {
|
export class LinkRenderLayer extends BaseRenderLayer {
|
||||||
private _state: ILinkifierEvent = null;
|
private _state: ILinkifierEvent | undefined;
|
||||||
|
|
||||||
constructor(container: HTMLElement, zIndex: number, colors: IColorSet, terminal: ILinkifierAccessor) {
|
constructor(container: HTMLElement, zIndex: number, colors: IColorSet, terminal: ILinkifierAccessor) {
|
||||||
super(container, 'link', zIndex, true, colors);
|
super(container, 'link', zIndex, true, colors);
|
||||||
@@ -23,7 +23,7 @@ export class LinkRenderLayer extends BaseRenderLayer {
|
|||||||
public resize(terminal: Terminal, dim: IRenderDimensions): void {
|
public resize(terminal: Terminal, dim: IRenderDimensions): void {
|
||||||
super.resize(terminal, dim);
|
super.resize(terminal, dim);
|
||||||
// Resizing the canvas discards the contents of the canvas so clear state
|
// Resizing the canvas discards the contents of the canvas so clear state
|
||||||
this._state = null;
|
this._state = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
public reset(terminal: Terminal): void {
|
public reset(terminal: Terminal): void {
|
||||||
@@ -38,7 +38,7 @@ export class LinkRenderLayer extends BaseRenderLayer {
|
|||||||
this._clearCells(0, this._state.y1 + 1, this._state.cols, middleRowCount);
|
this._clearCells(0, this._state.y1 + 1, this._state.cols, middleRowCount);
|
||||||
}
|
}
|
||||||
this._clearCells(0, this._state.y2, this._state.x2, 1);
|
this._clearCells(0, this._state.y2, this._state.x2, 1);
|
||||||
this._state = null;
|
this._state = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
"paths": {
|
"paths": {
|
||||||
"common/*": [ "../../../src/common/*" ],
|
"common/*": [ "../../../src/common/*" ],
|
||||||
"browser/*": [ "../../../src/browser/*" ]
|
"browser/*": [ "../../../src/browser/*" ]
|
||||||
}
|
},
|
||||||
|
"strict": true
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"./**/*",
|
"./**/*",
|
||||||
|
|||||||
Reference in New Issue
Block a user