Skip to content

Commit

Permalink
Make canRender call non-static
Browse files Browse the repository at this point in the history
Since this now depends on the DOM, it's too difficult and inconsistent to
pass in a DOM node to do the inline decoration test on. It's simplest to
pass it in to whatever view parts need it.
  • Loading branch information
Tyriar committed Nov 22, 2024
1 parent 6de7763 commit 27687b2
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/vs/editor/browser/gpu/fullFileRenderStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export class FullFileRenderStrategy extends ViewEventHandler implements IGpuRend
for (y = viewportData.startLineNumber; y <= viewportData.endLineNumber; y++) {

// Only attempt to render lines that the GPU renderer can handle
if (!ViewGpuContext.canRender(this._viewGpuContext.canvas.domNode, viewLineOptions, viewportData, y)) {
if (!this._viewGpuContext.canRender(viewLineOptions, viewportData, y)) {
fillStartIndex = ((y - 1) * this._viewGpuContext.maxGpuCols) * Constants.IndicesPerCell;
fillEndIndex = (y * this._viewGpuContext.maxGpuCols) * Constants.IndicesPerCell;
cellBuffer.fill(0, fillStartIndex, fillEndIndex);
Expand Down
6 changes: 0 additions & 6 deletions src/vs/editor/browser/gpu/raster/glyphRasterizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ export class GlyphRasterizer extends Disposable implements IGlyphRasterizer {
this._ctx.textBaseline = 'top';
this._ctx.fillText(chars, originX, originY);

// TODO: Don't draw beyond glyph - how to handle monospace, wide and proportional?
// TODO: Support strikethrough color
if (fontStyle & FontStyle.Strikethrough) {
this._ctx.fillRect(originX, originY + Math.round(devicePixelFontSize / 2), devicePixelFontSize, Math.max(Math.floor(getActiveWindow().devicePixelRatio), 1));
}

const imageData = this._ctx.getImageData(0, 0, this._canvas.width, this._canvas.height);
this._findGlyphBoundingBox(imageData, this._workGlyph.boundingBox);
// const offset = {
Expand Down
8 changes: 4 additions & 4 deletions src/vs/editor/browser/gpu/viewGpuContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class ViewGpuContext extends Disposable {
* renderer. Eventually this should trend all lines, except maybe exceptional cases like
* decorations that use class names.
*/
public static canRender(container: HTMLElement, options: ViewLineOptions, viewportData: ViewportData, lineNumber: number): boolean {
public canRender(options: ViewLineOptions, viewportData: ViewportData, lineNumber: number): boolean {
const data = viewportData.getViewLineRenderingData(lineNumber);

// Check if the line has simple attributes that aren't supported
Expand All @@ -158,7 +158,7 @@ export class ViewGpuContext extends Disposable {
if (data.inlineDecorations.length > 0) {
let supported = true;
for (const decoration of data.inlineDecorations) {
const styleRules = ViewGpuContext._decorationCssRuleExtractor.getStyleRules(container, decoration.inlineClassName);
const styleRules = ViewGpuContext._decorationCssRuleExtractor.getStyleRules(this.canvas.domNode, decoration.inlineClassName);
supported &&= styleRules.every(rule => {
// Pseudo classes aren't supported currently
if (rule.selectorText.includes(':')) {
Expand All @@ -184,7 +184,7 @@ export class ViewGpuContext extends Disposable {
/**
* Like {@link canRender} but returns detailed information about why the line cannot be rendered.
*/
public static canRenderDetailed(container: HTMLElement, options: ViewLineOptions, viewportData: ViewportData, lineNumber: number): string[] {
public canRenderDetailed(options: ViewLineOptions, viewportData: ViewportData, lineNumber: number): string[] {
const data = viewportData.getViewLineRenderingData(lineNumber);
const reasons: string[] = [];
if (data.containsRTL) {
Expand All @@ -201,7 +201,7 @@ export class ViewGpuContext extends Disposable {
const problemSelectors: string[] = [];
const problemRules: string[] = [];
for (const decoration of data.inlineDecorations) {
const styleRules = ViewGpuContext._decorationCssRuleExtractor.getStyleRules(container, decoration.inlineClassName);
const styleRules = ViewGpuContext._decorationCssRuleExtractor.getStyleRules(this.canvas.domNode, decoration.inlineClassName);
supported &&= styleRules.every(rule => {
// Pseudo classes aren't supported currently
if (rule.selectorText.includes(':')) {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/browser/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class View extends ViewEventHandler {
this._viewParts.push(this._scrollbar);

// View Lines
this._viewLines = new ViewLines(this._context, this._linesContent);
this._viewLines = new ViewLines(this._context, this._viewGpuContext, this._linesContent);
if (this._viewGpuContext) {
this._viewLinesGpu = this._instantiationService.createInstance(ViewLinesGpu, this._context, this._viewGpuContext);
}
Expand Down Expand Up @@ -199,7 +199,7 @@ export class View extends ViewEventHandler {
marginViewOverlays.addDynamicOverlay(new LinesDecorationsOverlay(this._context));
marginViewOverlays.addDynamicOverlay(new LineNumbersOverlay(this._context));
if (this._viewGpuContext) {
marginViewOverlays.addDynamicOverlay(new GpuMarkOverlay(this._context));
marginViewOverlays.addDynamicOverlay(new GpuMarkOverlay(this._context, this._viewGpuContext));
}

// Glyph margin widgets
Expand Down
6 changes: 2 additions & 4 deletions src/vs/editor/browser/viewParts/gpuMark/gpuMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { getActiveDocument } from '../../../../base/browser/dom.js';
import * as viewEvents from '../../../common/viewEvents.js';
import { ViewContext } from '../../../common/viewModel/viewContext.js';
import { ViewGpuContext } from '../../gpu/viewGpuContext.js';
Expand All @@ -23,7 +22,7 @@ export class GpuMarkOverlay extends DynamicViewOverlay {

private _renderResult: string[] | null;

constructor(context: ViewContext) {
constructor(context: ViewContext, private readonly _viewGpuContext: ViewGpuContext) {
super();
this._context = context;
this._renderResult = null;
Expand Down Expand Up @@ -78,8 +77,7 @@ export class GpuMarkOverlay extends DynamicViewOverlay {
const output: string[] = [];
for (let lineNumber = visibleStartLineNumber; lineNumber <= visibleEndLineNumber; lineNumber++) {
const lineIndex = lineNumber - visibleStartLineNumber;
// TODO: How to get the container?
const cannotRenderReasons = ViewGpuContext.canRenderDetailed(getActiveDocument().querySelector('.view-lines')!, options, viewportData, lineNumber);
const cannotRenderReasons = this._viewGpuContext.canRenderDetailed(options, viewportData, lineNumber);
output[lineIndex] = cannotRenderReasons.length ? `<div class="${GpuMarkOverlay.CLASS_NAME}" title="Cannot render on GPU: ${cannotRenderReasons.join(', ')}"></div>` : '';
}

Expand Down
6 changes: 2 additions & 4 deletions src/vs/editor/browser/viewParts/viewLines/viewLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { EditorFontLigatures } from '../../../common/config/editorOptions.js';
import { DomReadingContext } from './domReadingContext.js';
import type { ViewLineOptions } from './viewLineOptions.js';
import { ViewGpuContext } from '../../gpu/viewGpuContext.js';
import { getActiveDocument } from '../../../../base/browser/dom.js';

const canUseFastRenderedViewLine = (function () {
if (platform.isNative) {
Expand Down Expand Up @@ -55,7 +54,7 @@ export class ViewLine implements IVisibleLine {
private _isMaybeInvalid: boolean;
private _renderedViewLine: IRenderedViewLine | null;

constructor(options: ViewLineOptions) {
constructor(private readonly _viewGpuContext: ViewGpuContext | undefined, options: ViewLineOptions) {
this._options = options;
this._isMaybeInvalid = true;
this._renderedViewLine = null;
Expand Down Expand Up @@ -99,8 +98,7 @@ export class ViewLine implements IVisibleLine {
}

public renderLine(lineNumber: number, deltaTop: number, lineHeight: number, viewportData: ViewportData, sb: StringBuilder): boolean {
// TODO: How to get the container?
if (this._options.useGpu && ViewGpuContext.canRender(getActiveDocument().querySelector('.view-lines')!, this._options, viewportData, lineNumber)) {
if (this._options.useGpu && this._viewGpuContext?.canRender(this._options, viewportData, lineNumber)) {
this._renderedViewLine?.domNode?.domNode.remove();
this._renderedViewLine = null;
return false;
Expand Down
5 changes: 3 additions & 2 deletions src/vs/editor/browser/viewParts/viewLines/viewLines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ViewportData } from '../../../common/viewLayout/viewLinesViewportData.j
import { Viewport } from '../../../common/viewModel.js';
import { ViewContext } from '../../../common/viewModel/viewContext.js';
import { ViewLineOptions } from './viewLineOptions.js';
import type { ViewGpuContext } from '../../gpu/viewGpuContext.js';

class LastRenderedData {

Expand Down Expand Up @@ -125,7 +126,7 @@ export class ViewLines extends ViewPart implements IViewLines {
private _stickyScrollEnabled: boolean;
private _maxNumberStickyLines: number;

constructor(context: ViewContext, linesContent: FastDomNode<HTMLElement>) {
constructor(context: ViewContext, viewGpuContext: ViewGpuContext | undefined, linesContent: FastDomNode<HTMLElement>) {
super(context);

const conf = this._context.configuration;
Expand All @@ -145,7 +146,7 @@ export class ViewLines extends ViewPart implements IViewLines {
this._linesContent = linesContent;
this._textRangeRestingSpot = document.createElement('div');
this._visibleLines = new VisibleLinesCollection({
createLine: () => new ViewLine(this._viewLineOptions),
createLine: () => new ViewLine(viewGpuContext, this._viewLineOptions),
});
this.domNode = this._visibleLines.domNode;

Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/browser/viewParts/viewLinesGpu/viewLinesGpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ export class ViewLinesGpu extends ViewPart implements IViewLines {
if (!this._lastViewportData || !this._lastViewLineOptions) {
return undefined;
}
if (!ViewGpuContext.canRender(this._viewGpuContext.canvas.domNode, this._lastViewLineOptions, this._lastViewportData, lineNumber)) {
if (!this._viewGpuContext.canRender(this._lastViewLineOptions, this._lastViewportData, lineNumber)) {
return undefined;
}

Expand All @@ -573,7 +573,7 @@ export class ViewLinesGpu extends ViewPart implements IViewLines {
if (!this._lastViewportData || !this._lastViewLineOptions) {
return undefined;
}
if (!ViewGpuContext.canRender(this._viewGpuContext.canvas.domNode, this._lastViewLineOptions, this._lastViewportData, lineNumber)) {
if (!this._viewGpuContext.canRender(this._lastViewLineOptions, this._lastViewportData, lineNumber)) {
return undefined;
}
const lineData = this._lastViewportData.getViewLineRenderingData(lineNumber);
Expand Down

0 comments on commit 27687b2

Please sign in to comment.