Skip to content

Commit fd5d399

Browse files
committed
Remove cycling dep in editor gpu code
1 parent 2e2ca2d commit fd5d399

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { NKeyMap } from '../../../../base/common/map.js';
1212
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
1313
import { IThemeService } from '../../../../platform/theme/common/themeService.js';
1414
import { MetadataConsts } from '../../../common/encodedTokenAttributes.js';
15+
import type { DecorationStyleCache } from '../css/decorationStyleCache.js';
1516
import { GlyphRasterizer } from '../raster/glyphRasterizer.js';
1617
import type { IGlyphRasterizer } from '../raster/raster.js';
1718
import { IdleTaskQueue, type ITaskQueue } from '../taskQueue.js';
@@ -59,6 +60,7 @@ export class TextureAtlas extends Disposable {
5960
/** The maximum texture size supported by the GPU. */
6061
private readonly _maxTextureSize: number,
6162
options: ITextureAtlasOptions | undefined,
63+
private readonly _decorationStyleCache: DecorationStyleCache,
6264
@IThemeService private readonly _themeService: IThemeService,
6365
@IInstantiationService private readonly _instantiationService: IInstantiationService
6466
) {
@@ -88,7 +90,7 @@ export class TextureAtlas extends Disposable {
8890
// IMPORTANT: The first glyph on the first page must be an empty glyph such that zeroed out
8991
// cells end up rendering nothing
9092
// TODO: This currently means the first slab is for 0x0 glyphs and is wasted
91-
const nullRasterizer = new GlyphRasterizer(1, '', 1);
93+
const nullRasterizer = new GlyphRasterizer(1, '', 1, this._decorationStyleCache);
9294
firstPage.getGlyph(nullRasterizer, '', 0, 0);
9395
nullRasterizer.dispose();
9496
}

src/vs/editor/browser/gpu/raster/glyphRasterizer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { Disposable } from '../../../../base/common/lifecycle.js';
88
import { isMacintosh } from '../../../../base/common/platform.js';
99
import { StringBuilder } from '../../../common/core/stringBuilder.js';
1010
import { FontStyle, TokenMetadata } from '../../../common/encodedTokenAttributes.js';
11+
import type { DecorationStyleCache } from '../css/decorationStyleCache.js';
1112
import { ensureNonNullable } from '../gpuUtils.js';
12-
import { ViewGpuContext } from '../viewGpuContext.js';
1313
import { type IBoundingBox, type IGlyphRasterizer, type IRasterizedGlyph } from './raster.js';
1414

1515
let nextId = 0;
@@ -50,7 +50,8 @@ export class GlyphRasterizer extends Disposable implements IGlyphRasterizer {
5050
constructor(
5151
readonly fontSize: number,
5252
readonly fontFamily: string,
53-
readonly devicePixelRatio: number
53+
readonly devicePixelRatio: number,
54+
private readonly _decorationStyleCache: DecorationStyleCache,
5455
) {
5556
super();
5657

@@ -119,7 +120,7 @@ export class GlyphRasterizer extends Disposable implements IGlyphRasterizer {
119120
const bgId = TokenMetadata.getBackground(tokenMetadata);
120121
const bg = colorMap[bgId];
121122

122-
const decorationStyleSet = ViewGpuContext.decorationStyleCache.getStyleSet(decorationStyleSetId);
123+
const decorationStyleSet = this._decorationStyleCache.getStyleSet(decorationStyleSetId);
123124

124125
// When SPAA is used, the background color must be present to get the right glyph
125126
if (this._antiAliasing === 'subpixel') {

src/vs/editor/browser/gpu/viewGpuContext.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ import { Event } from '../../../base/common/event.js';
2424
import { EditorOption, type IEditorOptions } from '../../common/config/editorOptions.js';
2525
import { InlineDecorationType } from '../../common/viewModel.js';
2626
import { DecorationStyleCache } from './css/decorationStyleCache.js';
27-
import { ViewportRenderStrategy } from './renderStrategy/viewportRenderStrategy.js';
2827

2928
export class ViewGpuContext extends Disposable {
3029
/**
3130
* The hard cap for line columns rendered by the GPU renderer.
3231
*/
33-
readonly maxGpuCols = ViewportRenderStrategy.maxSupportedColumns;
32+
readonly maxGpuCols = 2000;
3433

3534
readonly canvas: FastDomNode<HTMLCanvasElement>;
3635
readonly ctx: GPUCanvasContext;
@@ -111,7 +110,7 @@ export class ViewGpuContext extends Disposable {
111110
}).then(ref => {
112111
ViewGpuContext.deviceSync = ref.object;
113112
if (!ViewGpuContext._atlas) {
114-
ViewGpuContext._atlas = this._instantiationService.createInstance(TextureAtlas, ref.object.limits.maxTextureDimension2D, undefined);
113+
ViewGpuContext._atlas = this._instantiationService.createInstance(TextureAtlas, ref.object.limits.maxTextureDimension2D, undefined, ViewGpuContext.decorationStyleCache);
115114
}
116115
return ref.object;
117116
});

src/vs/editor/browser/viewParts/viewLinesGpu/viewLinesGpu.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export class ViewLinesGpu extends ViewPart implements IViewLines {
196196

197197
const fontFamily = this._context.configuration.options.get(EditorOption.fontFamily);
198198
const fontSize = this._context.configuration.options.get(EditorOption.fontSize);
199-
this._glyphRasterizer.value = this._register(new GlyphRasterizer(fontSize, fontFamily, this._viewGpuContext.devicePixelRatio.get()));
199+
this._glyphRasterizer.value = this._register(new GlyphRasterizer(fontSize, fontFamily, this._viewGpuContext.devicePixelRatio.get(), ViewGpuContext.decorationStyleCache));
200200
this._register(runOnChange(this._viewGpuContext.devicePixelRatio, () => {
201201
this._refreshGlyphRasterizer();
202202
}));
@@ -454,7 +454,7 @@ export class ViewLinesGpu extends ViewPart implements IViewLines {
454454
glyphRasterizer.fontSize !== fontSize ||
455455
glyphRasterizer.devicePixelRatio !== devicePixelRatio
456456
) {
457-
this._glyphRasterizer.value = new GlyphRasterizer(fontSize, fontFamily, devicePixelRatio);
457+
this._glyphRasterizer.value = new GlyphRasterizer(fontSize, fontFamily, devicePixelRatio, ViewGpuContext.decorationStyleCache);
458458
}
459459
}
460460

src/vs/editor/contrib/gpu/browser/gpuActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class DebugEditorGpuRendererAction extends EditorAction {
105105
const atlas = ViewGpuContext.atlas;
106106
const fontFamily = configurationService.getValue<string>('editor.fontFamily');
107107
const fontSize = configurationService.getValue<number>('editor.fontSize');
108-
const rasterizer = new GlyphRasterizer(fontSize, fontFamily, getActiveWindow().devicePixelRatio);
108+
const rasterizer = new GlyphRasterizer(fontSize, fontFamily, getActiveWindow().devicePixelRatio, ViewGpuContext.decorationStyleCache);
109109
let chars = await quickInputService.input({
110110
prompt: 'Enter a character to draw (prefix with 0x for code point))'
111111
});

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { TextureAtlas } from '../../../../browser/gpu/atlas/textureAtlas.js';
1212
import { createCodeEditorServices } from '../../testCodeEditor.js';
1313
import { assertIsValidGlyph } from './testUtil.js';
1414
import { TextureAtlasSlabAllocator } from '../../../../browser/gpu/atlas/textureAtlasSlabAllocator.js';
15+
import { DecorationStyleCache } from '../../../../browser/gpu/css/decorationStyleCache.js';
1516

1617
const blackInt = 0x000000FF;
1718
const nullCharMetadata = 0x0;
@@ -79,7 +80,7 @@ suite('TextureAtlas', () => {
7980

8081
setup(() => {
8182
instantiationService = createCodeEditorServices(store);
82-
atlas = store.add(instantiationService.createInstance(TextureAtlas, 2, undefined));
83+
atlas = store.add(instantiationService.createInstance(TextureAtlas, 2, undefined, new DecorationStyleCache()));
8384
glyphRasterizer = new TestGlyphRasterizer();
8485
glyphRasterizer.nextGlyphDimensions = [1, 1];
8586
glyphRasterizer.nextGlyphColor = [0, 0, 0, 0xFF];
@@ -90,7 +91,7 @@ suite('TextureAtlas', () => {
9091
});
9192

9293
test('get multiple glyphs', () => {
93-
atlas = store.add(instantiationService.createInstance(TextureAtlas, 32, undefined));
94+
atlas = store.add(instantiationService.createInstance(TextureAtlas, 32, undefined, new DecorationStyleCache()));
9495
for (let i = 0; i < 10; i++) {
9596
assertIsValidGlyph(atlas.getGlyph(glyphRasterizer, ...getUniqueGlyphId()), atlas);
9697
}
@@ -119,14 +120,14 @@ suite('TextureAtlas', () => {
119120
glyphRasterizer.nextGlyphDimensions = [2, 2];
120121
atlas = store.add(instantiationService.createInstance(TextureAtlas, 32, {
121122
allocatorType: (canvas, textureIndex) => new TextureAtlasSlabAllocator(canvas, textureIndex, { slabW: 1, slabH: 1 })
122-
}));
123+
}, new DecorationStyleCache()));
123124
assertIsValidGlyph(atlas.getGlyph(glyphRasterizer, ...getUniqueGlyphId()), atlas);
124125
});
125126

126127
test('adding a non-first glyph larger than the standard slab size, causing an overflow to a new page', () => {
127128
atlas = store.add(instantiationService.createInstance(TextureAtlas, 2, {
128129
allocatorType: (canvas, textureIndex) => new TextureAtlasSlabAllocator(canvas, textureIndex, { slabW: 1, slabH: 1 })
129-
}));
130+
}, new DecorationStyleCache()));
130131
assertIsValidGlyph(atlas.getGlyph(glyphRasterizer, ...getUniqueGlyphId()), atlas);
131132
strictEqual(atlas.pages.length, 1);
132133
glyphRasterizer.nextGlyphDimensions = [2, 2];

0 commit comments

Comments
 (0)