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