Move DynamicCharAtlas to browser
This commit is contained in:
+13
-7
@@ -3,10 +3,9 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ICharAtlasConfig } from './Types';
|
|
||||||
import { DIM_OPACITY, INVERTED_DEFAULT_COLOR } from 'browser/renderer/atlas/Constants';
|
import { DIM_OPACITY, INVERTED_DEFAULT_COLOR } from 'browser/renderer/atlas/Constants';
|
||||||
import { IGlyphIdentifier } from 'browser/renderer/atlas/Types';
|
import { IGlyphIdentifier, ICharAtlasConfig } from 'browser/renderer/atlas/Types';
|
||||||
import { BaseCharAtlas } from '../../browser/renderer/atlas/BaseCharAtlas';
|
import { BaseCharAtlas } from 'browser/renderer/atlas/BaseCharAtlas';
|
||||||
import { DEFAULT_ANSI_COLORS } from 'browser/ColorManager';
|
import { DEFAULT_ANSI_COLORS } from 'browser/ColorManager';
|
||||||
import { LRUMap } from 'browser/renderer/atlas/LRUMap';
|
import { LRUMap } from 'browser/renderer/atlas/LRUMap';
|
||||||
import { isFirefox, isSafari } from 'common/Platform';
|
import { isFirefox, isSafari } from 'common/Platform';
|
||||||
@@ -90,12 +89,12 @@ export class DynamicCharAtlas extends BaseCharAtlas {
|
|||||||
// 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}));
|
||||||
|
|
||||||
const tmpCanvas = document.createElement('canvas');
|
const tmpCanvas = document.createElement('canvas');
|
||||||
tmpCanvas.width = this._config.scaledCharWidth;
|
tmpCanvas.width = this._config.scaledCharWidth;
|
||||||
tmpCanvas.height = this._config.scaledCharHeight;
|
tmpCanvas.height = this._config.scaledCharHeight;
|
||||||
this._tmpCtx = tmpCanvas.getContext('2d', {alpha: this._config.allowTransparency});
|
this._tmpCtx = throwIfFalsy(tmpCanvas.getContext('2d', {alpha: this._config.allowTransparency}));
|
||||||
|
|
||||||
this._width = Math.floor(TEXTURE_WIDTH / this._config.scaledCharWidth);
|
this._width = Math.floor(TEXTURE_WIDTH / this._config.scaledCharWidth);
|
||||||
this._height = Math.floor(TEXTURE_HEIGHT / this._config.scaledCharHeight);
|
this._height = Math.floor(TEXTURE_HEIGHT / this._config.scaledCharHeight);
|
||||||
@@ -145,7 +144,7 @@ export class DynamicCharAtlas extends BaseCharAtlas {
|
|||||||
index = this._cacheMap.size;
|
index = this._cacheMap.size;
|
||||||
} else {
|
} else {
|
||||||
// we're out of space, so our call to set will delete this item
|
// we're out of space, so our call to set will delete this item
|
||||||
index = this._cacheMap.peek().index;
|
index = this._cacheMap.peek()!.index;
|
||||||
}
|
}
|
||||||
const cacheValue = this._drawToCache(glyph, index);
|
const cacheValue = this._drawToCache(glyph, index);
|
||||||
this._cacheMap.set(glyphKey, cacheValue);
|
this._cacheMap.set(glyphKey, cacheValue);
|
||||||
@@ -187,7 +186,7 @@ export class DynamicCharAtlas extends BaseCharAtlas {
|
|||||||
const cacheX = this._toCoordinateX(cacheValue.index);
|
const cacheX = this._toCoordinateX(cacheValue.index);
|
||||||
const cacheY = this._toCoordinateY(cacheValue.index);
|
const cacheY = this._toCoordinateY(cacheValue.index);
|
||||||
ctx.drawImage(
|
ctx.drawImage(
|
||||||
cacheValue.inBitmap ? this._bitmap : this._cacheCanvas,
|
cacheValue.inBitmap ? this._bitmap! : this._cacheCanvas,
|
||||||
cacheX,
|
cacheX,
|
||||||
cacheY,
|
cacheY,
|
||||||
this._config.scaledCharWidth,
|
this._config.scaledCharWidth,
|
||||||
@@ -367,3 +366,10 @@ function clearColor(imageData: ImageData, color: IColor): boolean {
|
|||||||
}
|
}
|
||||||
return isEmpty;
|
return isEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function throwIfFalsy<T>(value: T | undefined | null): T {
|
||||||
|
if (!value) {
|
||||||
|
throw new Error('value must not be falsy');
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
+15
@@ -3,6 +3,9 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { FontWeight } from 'common/services/Services';
|
||||||
|
import { IColorSet } from 'browser/Types';
|
||||||
|
|
||||||
export interface IGlyphIdentifier {
|
export interface IGlyphIdentifier {
|
||||||
chars: string;
|
chars: string;
|
||||||
code: number;
|
code: number;
|
||||||
@@ -12,3 +15,15 @@ export interface IGlyphIdentifier {
|
|||||||
dim: boolean;
|
dim: boolean;
|
||||||
italic: boolean;
|
italic: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ICharAtlasConfig {
|
||||||
|
devicePixelRatio: number;
|
||||||
|
fontSize: number;
|
||||||
|
fontFamily: string;
|
||||||
|
fontWeight: FontWeight;
|
||||||
|
fontWeightBold: FontWeight;
|
||||||
|
scaledCharWidth: number;
|
||||||
|
scaledCharHeight: number;
|
||||||
|
allowTransparency: boolean;
|
||||||
|
colors: IColorSet;
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
import { ITerminal } from '../../Types';
|
import { ITerminal } from '../../Types';
|
||||||
import { generateConfig, configEquals } from './CharAtlasUtils';
|
import { generateConfig, configEquals } from './CharAtlasUtils';
|
||||||
import { BaseCharAtlas } from 'browser/renderer/atlas/BaseCharAtlas';
|
import { BaseCharAtlas } from 'browser/renderer/atlas/BaseCharAtlas';
|
||||||
import { DynamicCharAtlas } from './DynamicCharAtlas';
|
import { DynamicCharAtlas } from '../../browser/renderer/atlas/DynamicCharAtlas';
|
||||||
import { ICharAtlasConfig } from './Types';
|
import { ICharAtlasConfig } from 'browser/renderer/atlas/Types';
|
||||||
import { IColorSet } from 'browser/Types';
|
import { IColorSet } from 'browser/Types';
|
||||||
|
|
||||||
interface ICharAtlasCacheEntry {
|
interface ICharAtlasCacheEntry {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { ITerminal } from '../../Types';
|
import { ITerminal } from '../../Types';
|
||||||
import { ICharAtlasConfig } from './Types';
|
import { ICharAtlasConfig } from 'browser/renderer/atlas/Types';
|
||||||
import { DEFAULT_COLOR } from 'common/buffer/Constants';
|
import { DEFAULT_COLOR } from 'common/buffer/Constants';
|
||||||
import { IColorSet } from 'browser/Types';
|
import { IColorSet } from 'browser/Types';
|
||||||
|
|
||||||
|
|||||||
Vendored
-19
@@ -1,19 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
|
|
||||||
* @license MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { FontWeight } from 'xterm';
|
|
||||||
import { IColorSet } from 'browser/Types';
|
|
||||||
|
|
||||||
export interface ICharAtlasConfig {
|
|
||||||
devicePixelRatio: number;
|
|
||||||
fontSize: number;
|
|
||||||
fontFamily: string;
|
|
||||||
fontWeight: FontWeight;
|
|
||||||
fontWeightBold: FontWeight;
|
|
||||||
scaledCharWidth: number;
|
|
||||||
scaledCharHeight: number;
|
|
||||||
allowTransparency: boolean;
|
|
||||||
colors: IColorSet;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user