Using ext to store variants.

This commit is contained in:
tisilent
2023-08-21 20:54:16 +08:00
parent cb175e513d
commit c81dfee43c
7 changed files with 49 additions and 24 deletions
@@ -12,7 +12,7 @@ import { createSelectionRenderModel } from 'browser/renderer/shared/SelectionRen
import { ICoreBrowserService, IThemeService } from 'browser/services/Services'; import { ICoreBrowserService, IThemeService } from 'browser/services/Services';
import { ReadonlyColorSet } from 'browser/Types'; import { ReadonlyColorSet } from 'browser/Types';
import { CellData } from 'common/buffer/CellData'; import { CellData } from 'common/buffer/CellData';
import { WHITESPACE_CELL_CODE } from 'common/buffer/Constants'; import { ExtFlags, WHITESPACE_CELL_CODE } from 'common/buffer/Constants';
import { IBufferService, IDecorationService, IOptionsService } from 'common/services/Services'; import { IBufferService, IDecorationService, IOptionsService } from 'common/services/Services';
import { ICellData, IDisposable } from 'common/Types'; import { ICellData, IDisposable } from 'common/Types';
import { Terminal } from 'xterm'; import { Terminal } from 'xterm';
@@ -369,15 +369,18 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
const chars = cell.getChars(); const chars = cell.getChars();
this._cellColorResolver.resolve(cell, x, this._bufferService.buffer.ydisp + y); this._cellColorResolver.resolve(cell, x, this._bufferService.buffer.ydisp + y);
this._cellColorResolver.result.ext &= ~ExtFlags.VARIANT_OFFSET;
this._cellColorResolver.result.ext |= (variantOffset << 29) & ExtFlags.VARIANT_OFFSET;
if (!this._charAtlas) { if (!this._charAtlas) {
return; return;
} }
let glyph: IRasterizedGlyph; let glyph: IRasterizedGlyph;
if (chars && chars.length > 1) { if (chars && chars.length > 1) {
glyph = this._charAtlas.getRasterizedGlyphCombinedChar(chars, this._cellColorResolver.result.bg, this._cellColorResolver.result.fg, this._cellColorResolver.result.ext, variantOffset, true); glyph = this._charAtlas.getRasterizedGlyphCombinedChar(chars, this._cellColorResolver.result.bg, this._cellColorResolver.result.fg, this._cellColorResolver.result.ext, true);
} else { } else {
glyph = this._charAtlas.getRasterizedGlyph(cell.getCode() || WHITESPACE_CELL_CODE, this._cellColorResolver.result.bg, this._cellColorResolver.result.fg, this._cellColorResolver.result.ext, variantOffset, true); glyph = this._charAtlas.getRasterizedGlyph(cell.getCode() || WHITESPACE_CELL_CODE, this._cellColorResolver.result.bg, this._cellColorResolver.result.fg, this._cellColorResolver.result.ext, true);
} }
if (!glyph.size.x || !glyph.size.y) { if (!glyph.size.x || !glyph.size.y) {
return; return;
@@ -53,6 +53,14 @@ class ExtendedAttrsImage implements IExtendedAttrsImage {
this._ext |= value & (Attributes.CM_MASK | Attributes.RGB_MASK); this._ext |= value & (Attributes.CM_MASK | Attributes.RGB_MASK);
} }
public get underlineVarinatOffset(): number {
return (this._ext & ExtFlags.VARIANT_OFFSET) >> 29;
}
public set underlineVarinatOffset(value: number) {
this._ext &= ~ExtFlags.VARIANT_OFFSET;
this._ext |= (value << 29) & ExtFlags.VARIANT_OFFSET;
}
private _urlId: number = 0; private _urlId: number = 0;
public get urlId(): number { public get urlId(): number {
return this._urlId; return this._urlId;
@@ -239,9 +239,9 @@ export class GlyphRenderer extends Disposable {
// Get the glyph // Get the glyph
if (chars && chars.length > 1) { if (chars && chars.length > 1) {
$glyph = this._atlas.getRasterizedGlyphCombinedChar(chars, bg, fg, ext, variantOffset, false); $glyph = this._atlas.getRasterizedGlyphCombinedChar(chars, bg, fg, ext, false);
} else { } else {
$glyph = this._atlas.getRasterizedGlyph(code, bg, fg, ext, variantOffset, false); $glyph = this._atlas.getRasterizedGlyph(code, bg, fg, ext, false);
} }
$leftCellPadding = Math.floor((this._dimensions.device.cell.width - this._dimensions.device.char.width) / 2); $leftCellPadding = Math.floor((this._dimensions.device.cell.width - this._dimensions.device.char.width) / 2);
+16 -17
View File
@@ -11,7 +11,7 @@ import { color, NULL_COLOR, rgba } from 'common/Color';
import { tryDrawCustomChar } from 'browser/renderer/shared/CustomGlyphs'; import { tryDrawCustomChar } from 'browser/renderer/shared/CustomGlyphs';
import { excludeFromContrastRatioDemands, isPowerlineGlyph, isRestrictedPowerlineGlyph, throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; import { excludeFromContrastRatioDemands, isPowerlineGlyph, isRestrictedPowerlineGlyph, throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
import { IUnicodeService } from 'common/services/Services'; import { IUnicodeService } from 'common/services/Services';
import { FiveKeyMap } from 'common/MultiKeyMap'; import { FourKeyMap } from 'common/MultiKeyMap';
import { IdleTaskQueue } from 'common/TaskQueue'; import { IdleTaskQueue } from 'common/TaskQueue';
import { IBoundingBox, ICharAtlasConfig, IRasterizedGlyph, IRequestRedrawEvent, ITextureAtlas } from 'browser/renderer/shared/Types'; import { IBoundingBox, ICharAtlasConfig, IRasterizedGlyph, IRequestRedrawEvent, ITextureAtlas } from 'browser/renderer/shared/Types';
import { EventEmitter } from 'common/EventEmitter'; import { EventEmitter } from 'common/EventEmitter';
@@ -58,8 +58,8 @@ let $glyph = undefined;
export class TextureAtlas implements ITextureAtlas { export class TextureAtlas implements ITextureAtlas {
private _didWarmUp: boolean = false; private _didWarmUp: boolean = false;
private _cacheMap: FiveKeyMap<number, number, number, number, number, IRasterizedGlyph> = new FiveKeyMap(); private _cacheMap: FourKeyMap<number, number, number, number, IRasterizedGlyph> = new FourKeyMap();
private _cacheMapCombined: FiveKeyMap<string, number, number, number, number, IRasterizedGlyph> = new FiveKeyMap(); private _cacheMapCombined: FourKeyMap<string, number, number, number, IRasterizedGlyph> = new FourKeyMap();
// The texture that the atlas is drawn to // The texture that the atlas is drawn to
private _pages: AtlasPage[] = []; private _pages: AtlasPage[] = [];
@@ -121,9 +121,9 @@ export class TextureAtlas implements ITextureAtlas {
const queue = new IdleTaskQueue(); const queue = new IdleTaskQueue();
for (let i = 33; i < 126; i++) { for (let i = 33; i < 126; i++) {
queue.enqueue(() => { queue.enqueue(() => {
if (!this._cacheMap.get(i, DEFAULT_COLOR, DEFAULT_COLOR, DEFAULT_EXT, 1)) { if (!this._cacheMap.get(i, DEFAULT_COLOR, DEFAULT_COLOR, DEFAULT_EXT)) {
const rasterizedGlyph = this._drawToCache(i, DEFAULT_COLOR, DEFAULT_COLOR, DEFAULT_EXT, 0); const rasterizedGlyph = this._drawToCache(i, DEFAULT_COLOR, DEFAULT_COLOR, DEFAULT_EXT);
this._cacheMap.set(i, DEFAULT_COLOR, DEFAULT_COLOR, DEFAULT_EXT, 1, rasterizedGlyph); this._cacheMap.set(i, DEFAULT_COLOR, DEFAULT_COLOR, DEFAULT_EXT, rasterizedGlyph);
} }
}); });
} }
@@ -244,30 +244,29 @@ export class TextureAtlas implements ITextureAtlas {
} }
} }
public getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number, variantOffset: number, restrictToCellHeight: boolean): IRasterizedGlyph { public getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number, restrictToCellHeight: boolean): IRasterizedGlyph {
return this._getFromCacheMap(this._cacheMapCombined, chars, bg, fg, ext, variantOffset, restrictToCellHeight); return this._getFromCacheMap(this._cacheMapCombined, chars, bg, fg, ext, restrictToCellHeight);
} }
public getRasterizedGlyph(code: number, bg: number, fg: number, ext: number, variantOffset: number, restrictToCellHeight: boolean): IRasterizedGlyph { public getRasterizedGlyph(code: number, bg: number, fg: number, ext: number, restrictToCellHeight: boolean): IRasterizedGlyph {
return this._getFromCacheMap(this._cacheMap, code, bg, fg, ext, variantOffset, restrictToCellHeight); return this._getFromCacheMap(this._cacheMap, code, bg, fg, ext, restrictToCellHeight);
} }
/** /**
* Gets the glyphs texture coords, drawing the texture if it's not already * Gets the glyphs texture coords, drawing the texture if it's not already
*/ */
private _getFromCacheMap( private _getFromCacheMap(
cacheMap: FiveKeyMap<string | number, number, number, number, number, IRasterizedGlyph>, cacheMap: FourKeyMap<string | number, number, number, number, IRasterizedGlyph>,
key: string | number, key: string | number,
bg: number, bg: number,
fg: number, fg: number,
ext: number, ext: number,
variantOffset: number,
restrictToCellHeight: boolean = false restrictToCellHeight: boolean = false
): IRasterizedGlyph { ): IRasterizedGlyph {
$glyph = cacheMap.get(key, bg, fg, ext, variantOffset); $glyph = cacheMap.get(key, bg, fg, ext);
if (!$glyph) { if (!$glyph) {
$glyph = this._drawToCache(key, bg, fg, ext, variantOffset, restrictToCellHeight); $glyph = this._drawToCache(key, bg, fg, ext, restrictToCellHeight);
cacheMap.set(key, bg, fg, ext, variantOffset, $glyph); cacheMap.set(key, bg, fg, ext, $glyph);
} }
return $glyph; return $glyph;
} }
@@ -428,7 +427,7 @@ export class TextureAtlas implements ITextureAtlas {
} }
@traceCall @traceCall
private _drawToCache(codeOrChars: number | string, bg: number, fg: number, ext: number,variantOffset: number = 0, restrictToCellHeight: boolean = false): IRasterizedGlyph { private _drawToCache(codeOrChars: number | string, bg: number, fg: number, ext: number, restrictToCellHeight: boolean = false): IRasterizedGlyph {
const chars = typeof codeOrChars === 'number' ? String.fromCharCode(codeOrChars) : codeOrChars; const chars = typeof codeOrChars === 'number' ? String.fromCharCode(codeOrChars) : codeOrChars;
// Uncomment for debugging // Uncomment for debugging
@@ -548,7 +547,7 @@ export class TextureAtlas implements ITextureAtlas {
const yTop = Math.ceil(padding + this._config.deviceCharHeight) - yOffset - (restrictToCellHeight ? lineWidth * 2 : 0); const yTop = Math.ceil(padding + this._config.deviceCharHeight) - yOffset - (restrictToCellHeight ? lineWidth * 2 : 0);
const yMid = yTop + lineWidth; const yMid = yTop + lineWidth;
const yBot = yTop + lineWidth * 2; const yBot = yTop + lineWidth * 2;
let nextOffset = variantOffset; let nextOffset = this._workAttributeData.getUnderlineVarinatOffset();
for (let i = 0; i < chWidth; i++) { for (let i = 0; i < chWidth; i++) {
this._tmpCtx.save(); this._tmpCtx.save();
+2 -2
View File
@@ -109,8 +109,8 @@ export interface ITextureAtlas extends IDisposable {
* Clear all glyphs from the texture atlas. * Clear all glyphs from the texture atlas.
*/ */
clearTexture(): void; clearTexture(): void;
getRasterizedGlyph(code: number, bg: number, fg: number, ext: number, variantOffset: number, restrictToCellHeight: boolean): IRasterizedGlyph; getRasterizedGlyph(code: number, bg: number, fg: number, ext: number, restrictToCellHeight: boolean): IRasterizedGlyph;
getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number, variantOffset: number, restrictToCellHeight: boolean): IRasterizedGlyph; getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number, restrictToCellHeight: boolean): IRasterizedGlyph;
} }
/** /**
+2
View File
@@ -119,6 +119,7 @@ export interface IExtendedAttrs {
ext: number; ext: number;
underlineStyle: UnderlineStyle; underlineStyle: UnderlineStyle;
underlineColor: number; underlineColor: number;
underlineVarinatOffset: number;
urlId: number; urlId: number;
clone(): IExtendedAttrs; clone(): IExtendedAttrs;
isEmpty(): boolean; isEmpty(): boolean;
@@ -209,6 +210,7 @@ export interface IAttributeData {
isUnderlineColorPalette(): boolean; isUnderlineColorPalette(): boolean;
isUnderlineColorDefault(): boolean; isUnderlineColorDefault(): boolean;
getUnderlineStyle(): number; getUnderlineStyle(): number;
getUnderlineVarinatOffset(): number;
} }
/** Cell data */ /** Cell data */
+13
View File
@@ -126,6 +126,11 @@ export class AttributeData implements IAttributeData {
? (this.bg & BgFlags.HAS_EXTENDED ? this.extended.underlineStyle : UnderlineStyle.SINGLE) ? (this.bg & BgFlags.HAS_EXTENDED ? this.extended.underlineStyle : UnderlineStyle.SINGLE)
: UnderlineStyle.NONE; : UnderlineStyle.NONE;
} }
public getUnderlineVarinatOffset(): number {
return this.fg & FgFlags.UNDERLINE
? (this.bg & BgFlags.HAS_EXTENDED ? this.extended.underlineVarinatOffset : 0)
: 0;
}
} }
@@ -174,6 +179,14 @@ export class ExtendedAttrs implements IExtendedAttrs {
this._urlId = value; this._urlId = value;
} }
public get underlineVarinatOffset(): number {
return (this._ext & ExtFlags.VARIANT_OFFSET) >> 29;
}
public set underlineVarinatOffset(value: number) {
this._ext &= ~ExtFlags.VARIANT_OFFSET;
this._ext |= (value << 29) & ExtFlags.VARIANT_OFFSET;
}
constructor( constructor(
ext: number = 0, ext: number = 0,
urlId: number = 0 urlId: number = 0