Path: blob/main/src/vs/editor/browser/gpu/atlas/atlas.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import type { NKeyMap } from '../../../../base/common/map.js';6import type { IBoundingBox, IRasterizedGlyph } from '../raster/raster.js';78/**9* Information about a {@link IRasterizedGlyph rasterized glyph} that has been drawn to a texture10* atlas page.11*/12export interface ITextureAtlasPageGlyph {13/**14* The page index of the texture atlas page that the glyph was drawn to.15*/16pageIndex: number;17/**18* The index of the glyph in the texture atlas page.19*/20glyphIndex: number;21/** The x coordinate of the glyph on the texture atlas page. */22x: number;23/** The y coordinate of the glyph on the texture atlas page. */24y: number;25/** The width of the glyph in pixels. */26w: number;27/** The height of the glyph in pixels. */28h: number;29/** The x offset from {@link x} of the glyph's origin. */30originOffsetX: number;31/** The y offset from {@link y} of the glyph's origin. */32originOffsetY: number;33/**34* The distance from the glyph baseline to the top of the highest bounding rectangle of all35* fonts used to render the text.36*37* @see {@link TextMetrics.fontBoundingBoxAscent}38*/39fontBoundingBoxAscent: number;40/**41* The distance from the glyph baseline to the bottom of the bounding rectangle of all fonts42* used to render the text.43*44* @see {@link TextMetrics.fontBoundingBoxDescent}45*/46fontBoundingBoxDescent: number;47}4849/**50* A texture atlas allocator is responsible for taking rasterized glyphs, drawing them to a texture51* atlas page canvas and return information on the texture atlas glyph.52*/53export interface ITextureAtlasAllocator {54/**55* Allocates a rasterized glyph to the canvas, drawing it and returning information on its56* position in the canvas. This will return undefined if the glyph does not fit on the canvas.57*/58allocate(rasterizedGlyph: Readonly<IRasterizedGlyph>): Readonly<ITextureAtlasPageGlyph> | undefined;59/**60* Gets a usage preview of the atlas for debugging purposes.61*/62getUsagePreview(): Promise<Blob>;63/**64* Gets statistics about the allocator's current state for debugging purposes.65*/66getStats(): string;67}6869/**70* A texture atlas page that can be read from but not modified.71*/72export interface IReadableTextureAtlasPage {73/**74* A unique identifier for the current state of the texture atlas page. This is a number that75* increments whenever a glyph is drawn to the page.76*/77readonly version: number;78/**79* A bounding box representing the area of the texture atlas page that is currently in use.80*/81readonly usedArea: Readonly<IBoundingBox>;82/**83* An iterator over all glyphs that have been drawn to the page. This will iterate through84* glyphs in the order they have been drawn.85*/86readonly glyphs: IterableIterator<Readonly<ITextureAtlasPageGlyph>>;87/**88* The source canvas for the texture atlas page.89*/90readonly source: OffscreenCanvas;91/**92* Gets a usage preview of the atlas for debugging purposes.93*/94getUsagePreview(): Promise<Blob>;95/**96* Gets statistics about the allocator's current state for debugging purposes.97*/98getStats(): string;99}100101export const enum UsagePreviewColors {102Unused = '#808080',103Used = '#4040FF',104Wasted = '#FF0000',105Restricted = '#FF000088',106}107108export type GlyphMap<T> = NKeyMap<T, [109chars: string,110tokenMetadata: number,111decorationStyleSetId: number,112rasterizerCacheKey: string,113]>;114115116