From e882f4a46a099a9ab5339009f57bd55684d896a6 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:50:08 -0800 Subject: [PATCH] Prototype of adding a large atlas page for overflow glyphs Part of #5246 --- src/browser/renderer/shared/TextureAtlas.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/browser/renderer/shared/TextureAtlas.ts b/src/browser/renderer/shared/TextureAtlas.ts index a86cd459..0eca83e2 100644 --- a/src/browser/renderer/shared/TextureAtlas.ts +++ b/src/browser/renderer/shared/TextureAtlas.ts @@ -75,6 +75,8 @@ export class TextureAtlas implements ITextureAtlas { private _workAttributeData: AttributeData = new AttributeData(); private _textureSize: number = 512; + // TODO: Use actual value + private _deviceMaxTextureSize: number = 2048; public static maxAtlasPages: number | undefined; public static maxTextureSize: number | undefined; @@ -431,7 +433,7 @@ export class TextureAtlas implements ITextureAtlas { // Allow 1 cell width per character, with a minimum of 2 (CJK), plus some padding. This is used // to draw the glyph to the canvas as well as to restrict the bounding box search to ensure // giant ligatures (eg. =====>) don't impact overall performance. - const allowedWidth = Math.min(this._config.deviceCellWidth * Math.max(chars.length, 2) + TMP_CANVAS_GLYPH_PADDING * 2, this._textureSize); + const allowedWidth = Math.min(this._config.deviceCellWidth * Math.max(chars.length, 2) + TMP_CANVAS_GLYPH_PADDING * 2, this._deviceMaxTextureSize); if (this._tmpCanvas.width < allowedWidth) { this._tmpCanvas.width = allowedWidth; } @@ -772,6 +774,21 @@ export class TextureAtlas implements ITextureAtlas { } } + // Create a new page for oversized glyphs as they come up + if (rasterizedGlyph.size.x > this._textureSize) { + // TODO: Move below after page merging to ensure page limit isn't hit + const newPage = new AtlasPage(this._document, this._deviceMaxTextureSize); + this.pages.push(newPage); + + // Request the model to be cleared to refresh all texture pages. + this._requestClearModel = true; + this._onAddTextureAtlasCanvas.fire(newPage.canvas); + + newPage.addGlyph(rasterizedGlyph); + activePage.fixedRows.push(newPage.currentRow); + break; + } + // Create a new page if too much vertical space would be wasted or there is not enough room // left in the page. The previous active row will become fixed in the process as it now has a // fixed height