From 03f15a7fb77d45741475d516a49e6691009174a4 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 23 Jul 2022 11:12:17 -0700 Subject: [PATCH] Store extended attributes in single number --- addons/xterm-addon-webgl/src/WebglRenderer.ts | 3 +- .../src/atlas/WebglCharAtlas.ts | 4 +-- src/common/Types.d.ts | 1 + src/common/buffer/AttributeData.ts | 28 +++++++++++-------- src/common/buffer/Constants.ts | 7 +++++ 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/addons/xterm-addon-webgl/src/WebglRenderer.ts b/addons/xterm-addon-webgl/src/WebglRenderer.ts index eb8b8d8d..7790b8c2 100644 --- a/addons/xterm-addon-webgl/src/WebglRenderer.ts +++ b/addons/xterm-addon-webgl/src/WebglRenderer.ts @@ -384,8 +384,7 @@ export class WebglRenderer extends Disposable implements IRenderer { private _loadColorsForCell(x: number, y: number): void { this._workColors.bg = this._workCell.bg; this._workColors.fg = this._workCell.fg; - // TODO: Use extended packed format as key - this._workColors.ext = this._workCell.extended.underlineStyle; + this._workColors.ext = this._workCell.extended.ext; // Get any foreground/background overrides, this happens on the model to avoid spreading // override logic throughout the different sub-renderers diff --git a/addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts b/addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts index 501aec86..19e7d992 100644 --- a/addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts +++ b/addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts @@ -333,8 +333,7 @@ export class WebglCharAtlas implements IDisposable { this._workAttributeData.fg = fg; this._workAttributeData.bg = bg; - // TODO: Use packed ext format - this._workAttributeData.extended.underlineStyle = ext; + this._workAttributeData.extended.ext = ext; const invisible = !!this._workAttributeData.isInvisible(); if (invisible) { @@ -423,6 +422,7 @@ export class WebglCharAtlas implements IDisposable { this._tmpCtx.strokeStyle = this._tmpCtx.fillStyle; this._tmpCtx.beginPath(); if (underline) { + console.log('ext', ext, this._workAttributeData.extended.underlineColor, this._workAttributeData.extended.underlineStyle); const xLeft = padding; const xRight = padding + this._config.scaledCharWidth; const yMid = padding + this._config.scaledCharHeight - yOffset; diff --git a/src/common/Types.d.ts b/src/common/Types.d.ts index ed9a7124..56815da0 100644 --- a/src/common/Types.d.ts +++ b/src/common/Types.d.ts @@ -113,6 +113,7 @@ export interface IColor { export type IColorRGB = [number, number, number]; export interface IExtendedAttrs { + ext: number; underlineStyle: number; underlineColor: number; clone(): IExtendedAttrs; diff --git a/src/common/buffer/AttributeData.ts b/src/common/buffer/AttributeData.ts index 1ee608a7..6878069a 100644 --- a/src/common/buffer/AttributeData.ts +++ b/src/common/buffer/AttributeData.ts @@ -4,7 +4,7 @@ */ import { IAttributeData, IColorRGB, IExtendedAttrs } from 'common/Types'; -import { Attributes, FgFlags, BgFlags, UnderlineStyle } from 'common/buffer/Constants'; +import { Attributes, FgFlags, BgFlags, UnderlineStyle, ExtFlags } from 'common/buffer/Constants'; export class AttributeData implements IAttributeData { public static toColorRGB(value: number): IColorRGB { @@ -127,26 +127,32 @@ export class AttributeData implements IAttributeData { * Holds information about different underline styles and color. */ export class ExtendedAttrs implements IExtendedAttrs { - // underline style, NONE is empty - private _underlineStyle: UnderlineStyle = UnderlineStyle.NONE; - public get underlineStyle(): UnderlineStyle { return this._underlineStyle; } + private _ext: number = 0; + public get ext(): number { return this._ext; } + public set ext(value: number) { this._ext = value; } + + public get underlineStyle(): UnderlineStyle { + return (this._ext & ExtFlags.UNDERLINE_STYLE) >> 26; + } public set underlineStyle(value: UnderlineStyle) { - this._underlineStyle = value; + this._ext &= ~ExtFlags.UNDERLINE_STYLE; + this._ext |= (value << 26) & ExtFlags.UNDERLINE_STYLE; } - // underline color, -1 is empty (same as FG) - private _underlineColor: number = -1; - public get underlineColor(): number { return this._underlineColor; } + public get underlineColor(): number { + return this._ext & (Attributes.CM_MASK | Attributes.RGB_MASK); + } public set underlineColor(value: number) { - this._underlineColor = value; + this._ext &= ~(Attributes.CM_MASK | Attributes.RGB_MASK); + this._ext |= value & (Attributes.CM_MASK | Attributes.RGB_MASK); } constructor( underlineStyle: UnderlineStyle = UnderlineStyle.NONE, underlineColor: number = -1 ) { - this._underlineStyle = underlineStyle; - this._underlineColor = underlineColor; + this.underlineStyle = underlineStyle; + this.underlineColor = underlineColor; } public clone(): IExtendedAttrs { diff --git a/src/common/buffer/Constants.ts b/src/common/buffer/Constants.ts index 13dec2c1..0dfa86fd 100644 --- a/src/common/buffer/Constants.ts +++ b/src/common/buffer/Constants.ts @@ -130,6 +130,13 @@ export const enum BgFlags { HAS_EXTENDED = 0x10000000 } +export const enum ExtFlags { + /** + * bit 27..32 (upper 3 unused) + */ + UNDERLINE_STYLE = 0x1C000000 +} + export const enum UnderlineStyle { NONE = 0, SINGLE = 1,