From 454fd4bfb1ab5c9ecea60a8db102d786dcbb8452 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Sun, 4 Mar 2018 18:50:46 -0800 Subject: [PATCH 1/4] Split CharAtlas types and utility functions off I'm starting to pull some changes off of my large WIP branch/commit that adds an alternative dynamic character atlas. We're going to need to support multiple CharAtlas implementations, and this should make that easier. --- src/renderer/CharAtlas.ts | 51 ++-------------------------- src/renderer/atlas/CharAtlasUtils.ts | 47 +++++++++++++++++++++++++ src/renderer/atlas/Types.ts | 22 ++++++++++++ 3 files changed, 71 insertions(+), 49 deletions(-) create mode 100644 src/renderer/atlas/CharAtlasUtils.ts create mode 100644 src/renderer/atlas/Types.ts diff --git a/src/renderer/CharAtlas.ts b/src/renderer/CharAtlas.ts index ff8990b3..0c8e90ca 100644 --- a/src/renderer/CharAtlas.ts +++ b/src/renderer/CharAtlas.ts @@ -5,22 +5,13 @@ import { ITerminal } from '../Types'; import { IColorSet } from './Types'; +import { ICharAtlasConfig } from './atlas/Types'; import { isFirefox } from '../shared/utils/Browser'; import { generateCharAtlas, ICharAtlasRequest } from '../shared/CharAtlasGenerator'; +import { generateConfig, configEquals } from './atlas/CharAtlasUtils'; export const CHAR_ATLAS_CELL_SPACING = 1; -interface ICharAtlasConfig { - fontSize: number; - fontFamily: string; - fontWeight: string; - fontWeightBold: string; - scaledCharWidth: number; - scaledCharHeight: number; - allowTransparency: boolean; - colors: IColorSet; -} - interface ICharAtlasCacheEntry { bitmap: HTMLCanvasElement | Promise; config: ICharAtlasConfig; @@ -96,41 +87,3 @@ export function acquireCharAtlas(terminal: ITerminal, colors: IColorSet, scaledC charAtlasCache.push(newEntry); return newEntry.bitmap; } - -function generateConfig(scaledCharWidth: number, scaledCharHeight: number, terminal: ITerminal, colors: IColorSet): ICharAtlasConfig { - const clonedColors = { - foreground: colors.foreground, - background: colors.background, - cursor: null, - cursorAccent: null, - selection: null, - ansi: colors.ansi.slice(0, 16) - }; - return { - scaledCharWidth, - scaledCharHeight, - fontFamily: terminal.options.fontFamily, - fontSize: terminal.options.fontSize, - fontWeight: terminal.options.fontWeight, - fontWeightBold: terminal.options.fontWeightBold, - allowTransparency: terminal.options.allowTransparency, - colors: clonedColors - }; -} - -function configEquals(a: ICharAtlasConfig, b: ICharAtlasConfig): boolean { - for (let i = 0; i < a.colors.ansi.length; i++) { - if (a.colors.ansi[i] !== b.colors.ansi[i]) { - return false; - } - } - return a.fontFamily === b.fontFamily && - a.fontSize === b.fontSize && - a.fontWeight === b.fontWeight && - a.fontWeightBold === b.fontWeightBold && - a.allowTransparency === b.allowTransparency && - a.scaledCharWidth === b.scaledCharWidth && - a.scaledCharHeight === b.scaledCharHeight && - a.colors.foreground === b.colors.foreground && - a.colors.background === b.colors.background; -} diff --git a/src/renderer/atlas/CharAtlasUtils.ts b/src/renderer/atlas/CharAtlasUtils.ts new file mode 100644 index 00000000..57e362af --- /dev/null +++ b/src/renderer/atlas/CharAtlasUtils.ts @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2017 The xterm.js authors. All rights reserved. + * @license MIT + */ + +import { ITerminal } from '../../Types'; +import { ITheme } from 'xterm'; +import { IColorSet } from '../Types'; +import { ICharAtlasConfig } from './Types'; + +export function generateConfig(scaledCharWidth: number, scaledCharHeight: number, terminal: ITerminal, colors: IColorSet): ICharAtlasConfig { + const clonedColors = { + foreground: colors.foreground, + background: colors.background, + cursor: null, + cursorAccent: null, + selection: null, + ansi: colors.ansi.slice(0, 16) + }; + return { + scaledCharWidth, + scaledCharHeight, + fontFamily: terminal.options.fontFamily, + fontSize: terminal.options.fontSize, + fontWeight: terminal.options.fontWeight, + fontWeightBold: terminal.options.fontWeightBold, + allowTransparency: terminal.options.allowTransparency, + colors: clonedColors + }; +} + +export function configEquals(a: ICharAtlasConfig, b: ICharAtlasConfig): boolean { + for (let i = 0; i < a.colors.ansi.length; i++) { + if (a.colors.ansi[i] !== b.colors.ansi[i]) { + return false; + } + } + return a.fontFamily === b.fontFamily && + a.fontSize === b.fontSize && + a.fontWeight === b.fontWeight && + a.fontWeightBold === b.fontWeightBold && + a.allowTransparency === b.allowTransparency && + a.scaledCharWidth === b.scaledCharWidth && + a.scaledCharHeight === b.scaledCharHeight && + a.colors.foreground === b.colors.foreground && + a.colors.background === b.colors.background; +} diff --git a/src/renderer/atlas/Types.ts b/src/renderer/atlas/Types.ts new file mode 100644 index 00000000..3142ce3a --- /dev/null +++ b/src/renderer/atlas/Types.ts @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2017 The xterm.js authors. All rights reserved. + * @license MIT + */ + +import { FontWeight } from 'xterm'; +import { IColorSet } from '../Types'; + +export const CHAR_ATLAS_CELL_SPACING = 1; +export const INVERTED_DEFAULT_COLOR = -1; +export const DIM_OPACITY = 0.5; + +export interface ICharAtlasConfig { + fontSize: number; + fontFamily: string; + fontWeight: FontWeight; + fontWeightBold: FontWeight; + scaledCharWidth: number; + scaledCharHeight: number; + allowTransparency: boolean; + colors: IColorSet; +} From 70771430b55c085bc5c632b8cfaab7285dc63de3 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Wed, 7 Mar 2018 22:13:41 -0800 Subject: [PATCH 2/4] Clean up char atlas constant imports/exports - Ensures that everything is only defined in one place, and everything imports from that place. - Moves CHAR_ATLAS_CELL_SPACING into a subdirectory of shared/ so that CharAtlasGenerator can pull from it. This addresses the comments on https://github.com/xtermjs/xterm.js/pull/1307/files/454fd4bfb1ab5c9ece --- src/renderer/BaseRenderLayer.ts | 7 +++---- src/renderer/CharAtlas.ts | 2 -- src/renderer/LinkRenderLayer.ts | 3 ++- src/renderer/TextRenderLayer.ts | 3 ++- src/renderer/atlas/Types.ts | 1 - src/shared/CharAtlasGenerator.ts | 3 +-- src/shared/atlas/Types.ts | 1 + 7 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 src/shared/atlas/Types.ts diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index 9423f65d..8a236ada 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -5,12 +5,11 @@ import { IRenderLayer, IColorSet, IRenderDimensions } from './Types'; import { CharData, ITerminal, ITerminalOptions } from '../Types'; -import { acquireCharAtlas, CHAR_ATLAS_CELL_SPACING } from './CharAtlas'; +import { DIM_OPACITY, INVERTED_DEFAULT_COLOR } from './atlas/Types'; +import { CHAR_ATLAS_CELL_SPACING } from '../shared/atlas/Types'; +import { acquireCharAtlas } from './CharAtlas'; import { CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX } from '../Buffer'; -export const INVERTED_DEFAULT_COLOR = -1; -const DIM_OPACITY = 0.5; - export abstract class BaseRenderLayer implements IRenderLayer { private _canvas: HTMLCanvasElement; protected _ctx: CanvasRenderingContext2D; diff --git a/src/renderer/CharAtlas.ts b/src/renderer/CharAtlas.ts index 0c8e90ca..c157ff3d 100644 --- a/src/renderer/CharAtlas.ts +++ b/src/renderer/CharAtlas.ts @@ -10,8 +10,6 @@ import { isFirefox } from '../shared/utils/Browser'; import { generateCharAtlas, ICharAtlasRequest } from '../shared/CharAtlasGenerator'; import { generateConfig, configEquals } from './atlas/CharAtlasUtils'; -export const CHAR_ATLAS_CELL_SPACING = 1; - interface ICharAtlasCacheEntry { bitmap: HTMLCanvasElement | Promise; config: ICharAtlasConfig; diff --git a/src/renderer/LinkRenderLayer.ts b/src/renderer/LinkRenderLayer.ts index 61352f15..16d788b5 100644 --- a/src/renderer/LinkRenderLayer.ts +++ b/src/renderer/LinkRenderLayer.ts @@ -7,7 +7,8 @@ import { ILinkHoverEvent, ITerminal, ILinkifierAccessor, IBuffer, ICharMeasure, import { CHAR_DATA_ATTR_INDEX } from '../Buffer'; import { GridCache } from './GridCache'; import { FLAGS, IColorSet, IRenderDimensions } from './Types'; -import { BaseRenderLayer, INVERTED_DEFAULT_COLOR } from './BaseRenderLayer'; +import { INVERTED_DEFAULT_COLOR } from './atlas/Types'; +import { BaseRenderLayer } from './BaseRenderLayer'; export class LinkRenderLayer extends BaseRenderLayer { private _state: ILinkHoverEvent = null; diff --git a/src/renderer/TextRenderLayer.ts b/src/renderer/TextRenderLayer.ts index a2ab9f19..6e82a05a 100644 --- a/src/renderer/TextRenderLayer.ts +++ b/src/renderer/TextRenderLayer.ts @@ -6,8 +6,9 @@ import { CHAR_DATA_ATTR_INDEX, CHAR_DATA_CODE_INDEX, CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX } from '../Buffer'; import { FLAGS, IColorSet, IRenderDimensions } from './Types'; import { CharData, IBuffer, ICharMeasure, ITerminal } from '../Types'; +import { INVERTED_DEFAULT_COLOR } from './atlas/Types'; import { GridCache } from './GridCache'; -import { BaseRenderLayer, INVERTED_DEFAULT_COLOR } from './BaseRenderLayer'; +import { BaseRenderLayer } from './BaseRenderLayer'; /** * This CharData looks like a null character, which will forc a clear and render diff --git a/src/renderer/atlas/Types.ts b/src/renderer/atlas/Types.ts index 3142ce3a..a79cb327 100644 --- a/src/renderer/atlas/Types.ts +++ b/src/renderer/atlas/Types.ts @@ -6,7 +6,6 @@ import { FontWeight } from 'xterm'; import { IColorSet } from '../Types'; -export const CHAR_ATLAS_CELL_SPACING = 1; export const INVERTED_DEFAULT_COLOR = -1; export const DIM_OPACITY = 0.5; diff --git a/src/shared/CharAtlasGenerator.ts b/src/shared/CharAtlasGenerator.ts index 96cf6cc6..fbf66ac3 100644 --- a/src/shared/CharAtlasGenerator.ts +++ b/src/shared/CharAtlasGenerator.ts @@ -4,6 +4,7 @@ */ import { FontWeight } from 'xterm'; +import { CHAR_ATLAS_CELL_SPACING } from './atlas/Types'; import { isFirefox } from './utils/Browser'; declare const Promise: any; @@ -29,8 +30,6 @@ export interface ICharAtlasRequest { allowTransparency: boolean; } -export const CHAR_ATLAS_CELL_SPACING = 1; - /** * Generates a char atlas. * @param context The window or worker context. diff --git a/src/shared/atlas/Types.ts b/src/shared/atlas/Types.ts new file mode 100644 index 00000000..b69dfe0d --- /dev/null +++ b/src/shared/atlas/Types.ts @@ -0,0 +1 @@ +export const CHAR_ATLAS_CELL_SPACING = 1; From ab69bfbb3260a791e65ea59e00bd935bcab03a2c Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Wed, 7 Mar 2018 22:23:19 -0800 Subject: [PATCH 3/4] Move rest of atlas implementations to atlas dirs Moves CharAtlas into src/renderer/atlas/ and CharAtlasGenerator into src/shared/atlas/. --- src/renderer/BaseRenderLayer.ts | 2 +- src/renderer/{ => atlas}/CharAtlas.ts | 12 ++++++------ src/shared/{ => atlas}/CharAtlasGenerator.ts | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) rename src/renderer/{ => atlas}/CharAtlas.ts (88%) rename src/shared/{ => atlas}/CharAtlasGenerator.ts (97%) diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index 8a236ada..7957eed0 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -7,7 +7,7 @@ import { IRenderLayer, IColorSet, IRenderDimensions } from './Types'; import { CharData, ITerminal, ITerminalOptions } from '../Types'; import { DIM_OPACITY, INVERTED_DEFAULT_COLOR } from './atlas/Types'; import { CHAR_ATLAS_CELL_SPACING } from '../shared/atlas/Types'; -import { acquireCharAtlas } from './CharAtlas'; +import { acquireCharAtlas } from './atlas/CharAtlas'; import { CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX } from '../Buffer'; export abstract class BaseRenderLayer implements IRenderLayer { diff --git a/src/renderer/CharAtlas.ts b/src/renderer/atlas/CharAtlas.ts similarity index 88% rename from src/renderer/CharAtlas.ts rename to src/renderer/atlas/CharAtlas.ts index c157ff3d..d688d328 100644 --- a/src/renderer/CharAtlas.ts +++ b/src/renderer/atlas/CharAtlas.ts @@ -3,12 +3,12 @@ * @license MIT */ -import { ITerminal } from '../Types'; -import { IColorSet } from './Types'; -import { ICharAtlasConfig } from './atlas/Types'; -import { isFirefox } from '../shared/utils/Browser'; -import { generateCharAtlas, ICharAtlasRequest } from '../shared/CharAtlasGenerator'; -import { generateConfig, configEquals } from './atlas/CharAtlasUtils'; +import { ITerminal } from '../../Types'; +import { IColorSet } from '../Types'; +import { ICharAtlasConfig } from './Types'; +import { isFirefox } from '../../shared/utils/Browser'; +import { generateCharAtlas, ICharAtlasRequest } from '../../shared/atlas/CharAtlasGenerator'; +import { generateConfig, configEquals } from './CharAtlasUtils'; interface ICharAtlasCacheEntry { bitmap: HTMLCanvasElement | Promise; diff --git a/src/shared/CharAtlasGenerator.ts b/src/shared/atlas/CharAtlasGenerator.ts similarity index 97% rename from src/shared/CharAtlasGenerator.ts rename to src/shared/atlas/CharAtlasGenerator.ts index fbf66ac3..cf17bbb8 100644 --- a/src/shared/CharAtlasGenerator.ts +++ b/src/shared/atlas/CharAtlasGenerator.ts @@ -4,8 +4,8 @@ */ import { FontWeight } from 'xterm'; -import { CHAR_ATLAS_CELL_SPACING } from './atlas/Types'; -import { isFirefox } from './utils/Browser'; +import { CHAR_ATLAS_CELL_SPACING } from './Types'; +import { isFirefox } from '../utils/Browser'; declare const Promise: any; From 735dfb4710bac33fae32ae8faae7c02269fb8d38 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Wed, 7 Mar 2018 23:19:38 -0800 Subject: [PATCH 4/4] Add copyright header to shared/atlas/Types.ts --- src/shared/atlas/Types.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/shared/atlas/Types.ts b/src/shared/atlas/Types.ts index b69dfe0d..e8bb6b0a 100644 --- a/src/shared/atlas/Types.ts +++ b/src/shared/atlas/Types.ts @@ -1 +1,6 @@ +/** + * Copyright (c) 2017 The xterm.js authors. All rights reserved. + * @license MIT + */ + export const CHAR_ATLAS_CELL_SPACING = 1;