Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get ViewCursors rendering when the line is rendered using GPU #228970

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vs/editor/browser/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ export class View extends ViewEventHandler {
this._viewLinesGpu.onDidRender();
}

return [viewPartsToRender, new RenderingContext(this._context.viewLayout, viewportData, this._viewLines)];
return [viewPartsToRender, new RenderingContext(this._context.viewLayout, viewportData, this._viewLines, this._viewLinesGpu)];
},
prepareRender: (viewPartsToRender: ViewPart[], ctx: RenderingContext) => {
for (const viewPart of viewPartsToRender) {
Expand Down
8 changes: 5 additions & 3 deletions src/vs/editor/browser/view/renderingContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,20 @@ export class RenderingContext extends RestrictedRenderingContext {
_renderingContextBrand: void = undefined;

private readonly _viewLines: IViewLines;
private readonly _viewLinesGpu?: IViewLines;

constructor(viewLayout: IViewLayout, viewportData: ViewportData, viewLines: IViewLines) {
constructor(viewLayout: IViewLayout, viewportData: ViewportData, viewLines: IViewLines, viewLinesGpu?: IViewLines) {
super(viewLayout, viewportData);
this._viewLines = viewLines;
this._viewLinesGpu = viewLinesGpu;
}

public linesVisibleRangesForRange(range: Range, includeNewLines: boolean): LineVisibleRanges[] | null {
return this._viewLines.linesVisibleRangesForRange(range, includeNewLines);
return this._viewLines.linesVisibleRangesForRange(range, includeNewLines) ?? this._viewLinesGpu?.linesVisibleRangesForRange(range, includeNewLines) ?? null;
}

public visibleRangeForPosition(position: Position): HorizontalPosition | null {
return this._viewLines.visibleRangeForPosition(position);
return this._viewLines.visibleRangeForPosition(position) ?? this._viewLinesGpu?.visibleRangeForPosition(position) ?? null;
}
}

Expand Down
47 changes: 45 additions & 2 deletions src/vs/editor/browser/viewParts/viewLinesGpu/viewLinesGpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { autorun } from '../../../../base/common/observable.js';
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { ILogService } from '../../../../platform/log/common/log.js';
import { EditorOption } from '../../../common/config/editorOptions.js';
import type { Position } from '../../../common/core/position.js';
import type { Range } from '../../../common/core/range.js';
import type { ViewLinesChangedEvent, ViewScrollChangedEvent } from '../../../common/viewEvents.js';
import type { ViewportData } from '../../../common/viewLayout/viewLinesViewportData.js';
import type { ViewContext } from '../../../common/viewModel/viewContext.js';
Expand All @@ -18,7 +20,7 @@ import { BindingId, type IGpuRenderStrategy } from '../../gpu/gpu.js';
import { GPULifecycle } from '../../gpu/gpuDisposable.js';
import { observeDevicePixelDimensions, quadVertices } from '../../gpu/gpuUtils.js';
import { ViewGpuContext } from '../../gpu/viewGpuContext.js';
import type { RenderingContext, RestrictedRenderingContext } from '../../view/renderingContext.js';
import { FloatHorizontalRange, HorizontalPosition, IViewLines, LineVisibleRanges, RenderingContext, RestrictedRenderingContext, VisibleRanges } from '../../view/renderingContext.js';
import { ViewPart } from '../../view/viewPart.js';
import { ViewLineOptions } from '../viewLines/viewLineOptions.js';

Expand All @@ -34,10 +36,13 @@ const enum GlyphStorageBufferInfo {
/**
* The GPU implementation of the ViewLines part.
*/
export class ViewLinesGpu extends ViewPart {
export class ViewLinesGpu extends ViewPart implements IViewLines {

private readonly canvas: HTMLCanvasElement;

private _lastViewportData?: ViewportData;
private _lastViewLineOptions?: ViewLineOptions;

private _device!: GPUDevice;
private _renderPassDescriptor!: GPURenderPassDescriptor;
private _renderPassColorAttachment!: GPURenderPassColorAttachment;
Expand Down Expand Up @@ -389,5 +394,43 @@ export class ViewLinesGpu extends ViewPart {
const commandBuffer = encoder.finish();

this._device.queue.submit([commandBuffer]);

this._lastViewportData = viewportData;
this._lastViewLineOptions = options;
}

linesVisibleRangesForRange(range: Range, includeNewLines: boolean): LineVisibleRanges[] | null {
return null;
}

private _visibleRangesForLineRange(lineNumber: number, startColumn: number, endColumn: number): VisibleRanges | null {
if (this.shouldRender()) {
// Cannot read from the DOM because it is dirty
// i.e. the model & the dom are out of sync, so I'd be reading something stale
return null;
}

const viewportData = this._lastViewportData;
const viewLineOptions = this._lastViewLineOptions;

if (!viewportData || !viewLineOptions || lineNumber < viewportData.startLineNumber || lineNumber > viewportData.endLineNumber) {
return null;
}

// Visible horizontal range in _scaled_ pixels
const result = new VisibleRanges(false, [new FloatHorizontalRange(
(startColumn - 1) * viewLineOptions.spaceWidth,
(endColumn - startColumn - 1) * viewLineOptions.spaceWidth)
]);

return result;
}

visibleRangeForPosition(position: Position): HorizontalPosition | null {
const visibleRanges = this._visibleRangesForLineRange(position.lineNumber, position.column, position.column);
if (!visibleRanges) {
return null;
}
return new HorizontalPosition(visibleRanges.outsideRenderedLine, visibleRanges.ranges[0].left);
}
}
Loading