Adopt new [bg][fg] map in char cache

This commit is contained in:
Daniel
2019-11-09 22:43:25 -08:00
parent 8f0f8bf827
commit e15476704c
4 changed files with 34 additions and 17 deletions
@@ -169,11 +169,11 @@ export class GlyphRenderer {
return this._atlas ? this._atlas.beginFrame() : true; return this._atlas ? this._atlas.beginFrame() : true;
} }
public updateCell(x: number, y: number, code: number, attr: number, bg: number, fg: number, chars: string): void { public updateCell(x: number, y: number, code: number, bg: number, fg: number, chars: string): void {
this._updateCell(this._vertices.attributes, x, y, code, attr, bg, fg, chars); this._updateCell(this._vertices.attributes, x, y, code, bg, fg, chars);
} }
private _updateCell(array: Float32Array, x: number, y: number, code: number | undefined, attr: number, bg: number, fg: number, chars?: string): void { private _updateCell(array: Float32Array, x: number, y: number, code: number | undefined, bg: number, fg: number, chars?: string): void {
const terminal = this._terminal; const terminal = this._terminal;
const i = (y * terminal.cols + x) * INDICES_PER_CELL; const i = (y * terminal.cols + x) * INDICES_PER_CELL;
@@ -189,9 +189,9 @@ export class GlyphRenderer {
throw new Error('atlas must be set before updating cell'); 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, bg, fg);
} else { } else {
rasterizedGlyph = this._atlas.getRasterizedGlyph(code, attr, bg, fg); rasterizedGlyph = this._atlas.getRasterizedGlyph(code, bg, fg);
} }
// Fill empty if no glyph was found // Fill empty if no glyph was found
@@ -269,9 +269,9 @@ export class GlyphRenderer {
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], 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], bg, fg);
} }
} }
} }
+1 -1
View File
@@ -4,7 +4,7 @@
*/ */
export interface IRasterizedGlyphSet { export interface IRasterizedGlyphSet {
[flags: number]: IRasterizedGlyph; [bg: number]: { [fg: number]: IRasterizedGlyph } | undefined;
} }
/** /**
@@ -304,11 +304,12 @@ export class WebglRenderer extends Disposable implements IRenderer {
} }
this._model.cells[i ] = code; this._model.cells[i ] = code;
// TODO: Remove attr from model
this._model.cells[i + 1] = attr; this._model.cells[i + 1] = attr;
this._model.cells[i + 2] = bg; this._model.cells[i + 2] = bg;
this._model.cells[i + 3] = fg; this._model.cells[i + 3] = fg;
this._glyphRenderer.updateCell(x, y, code, attr, bg, fg, chars); this._glyphRenderer.updateCell(x, y, code, bg, fg, chars);
} }
} }
this._rectangleRenderer.updateBackgrounds(this._model); this._rectangleRenderer.updateBackgrounds(this._model);
@@ -4,7 +4,7 @@
*/ */
import { ICharAtlasConfig } from './Types'; import { ICharAtlasConfig } from './Types';
import { DIM_OPACITY, INVERTED_DEFAULT_COLOR } from 'browser/renderer/atlas/Constants'; import { DIM_OPACITY } from 'browser/renderer/atlas/Constants';
import { IRasterizedGlyph, IBoundingBox, IRasterizedGlyphSet } from '../Types'; import { IRasterizedGlyph, IBoundingBox, IRasterizedGlyphSet } from '../Types';
import { DEFAULT_COLOR, DEFAULT_ATTR, FgFlags, Attributes, BgFlags } from 'common/buffer/Constants'; import { DEFAULT_COLOR, DEFAULT_ATTR, FgFlags, Attributes, BgFlags } from 'common/buffer/Constants';
import { is256Color } from './CharAtlasUtils'; import { is256Color } from './CharAtlasUtils';
@@ -105,7 +105,9 @@ export class WebglCharAtlas implements IDisposable {
for (let i = 33; i < 126; i++) { for (let i = 33; i < 126; i++) {
const rasterizedGlyph = this._drawToCache(i, DEFAULT_COLOR, DEFAULT_COLOR); const rasterizedGlyph = this._drawToCache(i, DEFAULT_COLOR, DEFAULT_COLOR);
this._cacheMap[i] = { this._cacheMap[i] = {
[DEFAULT_ATTR]: rasterizedGlyph [DEFAULT_COLOR]: {
[DEFAULT_COLOR]: rasterizedGlyph
}
}; };
} }
} }
@@ -123,16 +125,23 @@ export class WebglCharAtlas implements IDisposable {
return false; return false;
} }
public getRasterizedGlyphCombinedChar(chars: string, attr: number, bg: number, fg: number): IRasterizedGlyph { public getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number): IRasterizedGlyph {
let rasterizedGlyphSet = this._cacheMapCombined[chars]; let rasterizedGlyphSet = this._cacheMapCombined[chars];
if (!rasterizedGlyphSet) { if (!rasterizedGlyphSet) {
rasterizedGlyphSet = {}; rasterizedGlyphSet = {};
this._cacheMapCombined[chars] = rasterizedGlyphSet; this._cacheMapCombined[chars] = rasterizedGlyphSet;
} }
let rasterizedGlyph = rasterizedGlyphSet[attr]; let rasterizedGlyph: IRasterizedGlyph | undefined;
const rasterizedGlyphSetBg = rasterizedGlyphSet[bg];
if (rasterizedGlyphSetBg) {
rasterizedGlyph = rasterizedGlyphSetBg[fg];
}
if (!rasterizedGlyph) { if (!rasterizedGlyph) {
rasterizedGlyph = this._drawToCache(chars, bg, fg); rasterizedGlyph = this._drawToCache(chars, bg, fg);
rasterizedGlyphSet[attr] = rasterizedGlyph; if (!rasterizedGlyphSet[bg]) {
rasterizedGlyphSet[bg] = {};
}
rasterizedGlyphSet[bg]![fg] = rasterizedGlyph;
} }
return rasterizedGlyph; return rasterizedGlyph;
} }
@@ -140,16 +149,23 @@ export class WebglCharAtlas implements IDisposable {
/** /**
* 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
*/ */
public getRasterizedGlyph(code: number, attr: number, bg: number, fg: number): IRasterizedGlyph { public getRasterizedGlyph(code: number, bg: number, fg: number): IRasterizedGlyph {
let rasterizedGlyphSet = this._cacheMap[code]; let rasterizedGlyphSet = this._cacheMap[code];
if (!rasterizedGlyphSet) { if (!rasterizedGlyphSet) {
rasterizedGlyphSet = {}; rasterizedGlyphSet = {};
this._cacheMap[code] = rasterizedGlyphSet; this._cacheMap[code] = rasterizedGlyphSet;
} }
let rasterizedGlyph = rasterizedGlyphSet[attr]; let rasterizedGlyph: IRasterizedGlyph | undefined;
const rasterizedGlyphSetBg = rasterizedGlyphSet[bg];
if (rasterizedGlyphSetBg) {
rasterizedGlyph = rasterizedGlyphSetBg[fg];
}
if (!rasterizedGlyph) { if (!rasterizedGlyph) {
rasterizedGlyph = this._drawToCache(code, bg, fg); rasterizedGlyph = this._drawToCache(code, bg, fg);
rasterizedGlyphSet[attr] = rasterizedGlyph; if (!rasterizedGlyphSet[bg]) {
rasterizedGlyphSet[bg] = {};
}
rasterizedGlyphSet[bg]![fg] = rasterizedGlyph;
} }
return rasterizedGlyph; return rasterizedGlyph;
} }