Skip to content

Commit

Permalink
Merge pull request #234618 from microsoft/tyriar/234474__234614
Browse files Browse the repository at this point in the history
Handle line mapping changed and don't update buffers after decoration change
  • Loading branch information
Tyriar authored Nov 25, 2024
2 parents dbcc14b + f1d52a7 commit 9324d6c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 34 deletions.
55 changes: 21 additions & 34 deletions src/vs/editor/browser/gpu/fullFileRenderStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EditorOption } from '../../common/config/editorOptions.js';
import { CursorColumns } from '../../common/core/cursorColumns.js';
import type { IViewLineTokens } from '../../common/tokens/lineTokens.js';
import { ViewEventHandler } from '../../common/viewEventHandler.js';
import { ViewEventType, type ViewConfigurationChangedEvent, type ViewDecorationsChangedEvent, type ViewLinesChangedEvent, type ViewLinesDeletedEvent, type ViewLinesInsertedEvent, type ViewScrollChangedEvent, type ViewThemeChangedEvent, type ViewTokensChangedEvent, type ViewZonesChangedEvent } from '../../common/viewEvents.js';
import { ViewEventType, type ViewConfigurationChangedEvent, type ViewDecorationsChangedEvent, type ViewLineMappingChangedEvent, type ViewLinesChangedEvent, type ViewLinesDeletedEvent, type ViewLinesInsertedEvent, type ViewScrollChangedEvent, type ViewThemeChangedEvent, type ViewTokensChangedEvent, type ViewZonesChangedEvent } from '../../common/viewEvents.js';
import type { ViewportData } from '../../common/viewLayout/viewLinesViewportData.js';
import type { InlineDecoration, ViewLineRenderingData } from '../../common/viewModel.js';
import type { ViewContext } from '../../common/viewModel/viewContext.js';
Expand Down Expand Up @@ -41,7 +41,7 @@ const enum CellBufferInfo {

type QueuedBufferEvent = (
ViewConfigurationChangedEvent |
ViewDecorationsChangedEvent |
ViewLineMappingChangedEvent |
ViewLinesDeletedEvent |
ViewZonesChangedEvent
);
Expand Down Expand Up @@ -139,10 +139,7 @@ export class FullFileRenderStrategy extends ViewEventHandler implements IGpuRend
}

public override onDecorationsChanged(e: ViewDecorationsChangedEvent): boolean {
// console.log('FullFileRenderStrategy.onDecorationsChanged');
// TODO: Don't clear all cells if we can avoid it
this._invalidateAllLines();
this._queueBufferUpdate(e);
return true;
}

Expand All @@ -160,12 +157,7 @@ export class FullFileRenderStrategy extends ViewEventHandler implements IGpuRend
// line data up to retain some up to date lines
// TODO: This does not invalidate lines that are no longer in the file
this._invalidateLinesFrom(e.fromLineNumber);

// Queue updates that need to happen on the active buffer, not just the cache. This is
// deferred since the active buffer could be locked by the GPU which would block the main
// thread.
this._queueBufferUpdate(e);

return true;
}

Expand Down Expand Up @@ -194,12 +186,14 @@ export class FullFileRenderStrategy extends ViewEventHandler implements IGpuRend
return true;
}

public override onZonesChanged(e: ViewZonesChangedEvent): boolean {
public override onLineMappingChanged(e: ViewLineMappingChangedEvent): boolean {
this._invalidateAllLines();
this._queueBufferUpdate(e);
return true;
}

// Queue updates that need to happen on the active buffer, not just the cache. This is
// deferred since the active buffer could be locked by the GPU which would block the main
// thread.
public override onZonesChanged(e: ViewZonesChangedEvent): boolean {
this._invalidateAllLines();
this._queueBufferUpdate(e);

return true;
Expand Down Expand Up @@ -290,16 +284,10 @@ export class FullFileRenderStrategy extends ViewEventHandler implements IGpuRend
while (queuedBufferUpdates.length) {
const e = queuedBufferUpdates.shift()!;
switch (e.type) {
case ViewEventType.ViewConfigurationChanged: {
// TODO: Refine the cases for when we throw away all the data
cellBuffer.fill(0);

dirtyLineStart = 1;
dirtyLineEnd = Math.max(dirtyLineEnd, this._finalRenderedLine);
this._finalRenderedLine = 0;
break;
}
case ViewEventType.ViewDecorationsChanged: {
// TODO: Refine these cases so we're not throwing away everything
case ViewEventType.ViewConfigurationChanged:
case ViewEventType.ViewLineMappingChanged:
case ViewEventType.ViewZonesChanged: {
cellBuffer.fill(0);

dirtyLineStart = 1;
Expand All @@ -323,16 +311,6 @@ export class FullFileRenderStrategy extends ViewEventHandler implements IGpuRend
this._finalRenderedLine -= e.toLineNumber - e.fromLineNumber + 1;
break;
}
case ViewEventType.ViewZonesChanged: {
// TODO: We could retain render data if we know what view zones changed and how
// Zero out content on all lines
cellBuffer.fill(0);

dirtyLineStart = 1;
dirtyLineEnd = Math.max(dirtyLineEnd, this._finalRenderedLine);
this._finalRenderedLine = 0;
break;
}
}
}

Expand All @@ -343,6 +321,10 @@ export class FullFileRenderStrategy extends ViewEventHandler implements IGpuRend
fillStartIndex = ((y - 1) * this._viewGpuContext.maxGpuCols) * Constants.IndicesPerCell;
fillEndIndex = (y * this._viewGpuContext.maxGpuCols) * Constants.IndicesPerCell;
cellBuffer.fill(0, fillStartIndex, fillEndIndex);

dirtyLineStart = Math.min(dirtyLineStart, y);
dirtyLineEnd = Math.max(dirtyLineEnd, y);

continue;
}

Expand Down Expand Up @@ -491,6 +473,11 @@ export class FullFileRenderStrategy extends ViewEventHandler implements IGpuRend
);
}

/**
* Queue updates that need to happen on the active buffer, not just the cache. This will be
* deferred to when the actual cell buffer is changed since the active buffer could be locked by
* the GPU which would block the main thread.
*/
private _queueBufferUpdate(e: QueuedBufferEvent) {
this._queuedBufferUpdates[0].push(e);
this._queuedBufferUpdates[1].push(e);
Expand Down
2 changes: 2 additions & 0 deletions src/vs/editor/browser/viewParts/viewLinesGpu/viewLinesGpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,11 @@ export class ViewLinesGpu extends ViewPart implements IViewLines {
override onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean { return true; }
override onDecorationsChanged(e: viewEvents.ViewDecorationsChangedEvent): boolean { return true; }
override onFlushed(e: viewEvents.ViewFlushedEvent): boolean { return true; }

override onLinesChanged(e: viewEvents.ViewLinesChangedEvent): boolean { return true; }
override onLinesDeleted(e: viewEvents.ViewLinesDeletedEvent): boolean { return true; }
override onLinesInserted(e: viewEvents.ViewLinesInsertedEvent): boolean { return true; }
override onLineMappingChanged(e: viewEvents.ViewLineMappingChangedEvent): boolean { return true; }
override onRevealRangeRequest(e: viewEvents.ViewRevealRangeRequestEvent): boolean { return true; }
override onScrollChanged(e: viewEvents.ViewScrollChangedEvent): boolean { return true; }
override onThemeChanged(e: viewEvents.ViewThemeChangedEvent): boolean { return true; }
Expand Down

0 comments on commit 9324d6c

Please sign in to comment.