Skip to content

Commit 4a35ffa

Browse files
authored
Merge pull request microsoft#232975 from microsoft/tyriar/227111
Clear texture atlas when theme changes
2 parents 1fea7d9 + 065d72c commit 4a35ffa

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/vs/editor/browser/gpu/atlas/textureAtlas.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { getActiveWindow } from '../../../../base/browser/dom.js';
77
import { CharCode } from '../../../../base/common/charCode.js';
8+
import { BugIndicatingError } from '../../../../base/common/errors.js';
89
import { Emitter, Event } from '../../../../base/common/event.js';
910
import { Disposable, dispose, MutableDisposable, toDisposable } from '../../../../base/common/lifecycle.js';
1011
import { ThreeKeyMap } from '../../../../base/common/map.js';
@@ -22,7 +23,7 @@ export interface ITextureAtlasOptions {
2223
}
2324

2425
export class TextureAtlas extends Disposable {
25-
private _colorMap!: string[];
26+
private _colorMap?: string[];
2627
private readonly _warmUpTask: MutableDisposable<IdleTaskQueue> = this._register(new MutableDisposable());
2728
private readonly _warmedUpRasterizers = new Set<number>();
2829
private readonly _allocatorType: AllocatorType;
@@ -60,7 +61,9 @@ export class TextureAtlas extends Disposable {
6061
this._allocatorType = options?.allocatorType ?? 'slab';
6162

6263
this._register(Event.runAndSubscribe(this._themeService.onDidColorThemeChange, () => {
63-
// TODO: Clear entire atlas on theme change
64+
if (this._colorMap) {
65+
this.clear();
66+
}
6467
this._colorMap = this._themeService.getColorTheme().tokenColorMap;
6568
}));
6669

@@ -147,29 +150,33 @@ export class TextureAtlas extends Disposable {
147150
* is distrubuted over multiple idle callbacks to avoid blocking the main thread.
148151
*/
149152
private _warmUpAtlas(rasterizer: IGlyphRasterizer): void {
153+
const colorMap = this._colorMap;
154+
if (!colorMap) {
155+
throw new BugIndicatingError('Cannot warm atlas without color map');
156+
}
150157
this._warmUpTask.value?.clear();
151158
const taskQueue = this._warmUpTask.value = new IdleTaskQueue();
152159
// Warm up using roughly the larger glyphs first to help optimize atlas allocation
153160
// A-Z
154161
for (let code = CharCode.A; code <= CharCode.Z; code++) {
155162
taskQueue.enqueue(() => {
156-
for (const fgColor of this._colorMap.keys()) {
163+
for (const fgColor of colorMap.keys()) {
157164
this.getGlyph(rasterizer, String.fromCharCode(code), (fgColor << MetadataConsts.FOREGROUND_OFFSET) & MetadataConsts.FOREGROUND_MASK);
158165
}
159166
});
160167
}
161168
// a-z
162169
for (let code = CharCode.a; code <= CharCode.z; code++) {
163170
taskQueue.enqueue(() => {
164-
for (const fgColor of this._colorMap.keys()) {
171+
for (const fgColor of colorMap.keys()) {
165172
this.getGlyph(rasterizer, String.fromCharCode(code), (fgColor << MetadataConsts.FOREGROUND_OFFSET) & MetadataConsts.FOREGROUND_MASK);
166173
}
167174
});
168175
}
169176
// Remaining ascii
170177
for (let code = CharCode.ExclamationMark; code <= CharCode.Tilde; code++) {
171178
taskQueue.enqueue(() => {
172-
for (const fgColor of this._colorMap.keys()) {
179+
for (const fgColor of colorMap.keys()) {
173180
this.getGlyph(rasterizer, String.fromCharCode(code), (fgColor << MetadataConsts.FOREGROUND_OFFSET) & MetadataConsts.FOREGROUND_MASK);
174181
}
175182
});

src/vs/editor/browser/gpu/atlas/textureAtlasPage.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Event } from '../../../../base/common/event.js';
76
import { Disposable, toDisposable } from '../../../../base/common/lifecycle.js';
87
import { ThreeKeyMap } from '../../../../base/common/map.js';
98
import { ILogService, LogLevel } from '../../../../platform/log/common/log.js';
@@ -46,23 +45,19 @@ export class TextureAtlasPage extends Disposable implements IReadableTextureAtla
4645
pageSize: number,
4746
allocatorType: AllocatorType,
4847
@ILogService private readonly _logService: ILogService,
49-
@IThemeService private readonly _themeService: IThemeService,
48+
@IThemeService themeService: IThemeService,
5049
) {
5150
super();
5251

5352
this._canvas = new OffscreenCanvas(pageSize, pageSize);
53+
this._colorMap = themeService.getColorTheme().tokenColorMap;
5454

5555
switch (allocatorType) {
5656
case 'shelf': this._allocator = new TextureAtlasShelfAllocator(this._canvas, textureIndex); break;
5757
case 'slab': this._allocator = new TextureAtlasSlabAllocator(this._canvas, textureIndex); break;
5858
default: this._allocator = allocatorType(this._canvas, textureIndex); break;
5959
}
6060

61-
this._register(Event.runAndSubscribe(this._themeService.onDidColorThemeChange, () => {
62-
// TODO: Clear entire atlas on theme change
63-
this._colorMap = this._themeService.getColorTheme().tokenColorMap;
64-
}));
65-
6661
// Reduce impact of a memory leak if this object is not released
6762
this._register(toDisposable(() => {
6863
this._canvas.width = 1;

0 commit comments

Comments
 (0)