Get canvas renderer addon working

This commit is contained in:
Daniel Imms
2022-07-27 16:04:24 -07:00
parent 48cfd23219
commit cbddd2029e
3 changed files with 31 additions and 25 deletions
+25 -21
View File
@@ -3,40 +3,44 @@
* @license MIT
*/
import { IRenderService } from 'browser/services/Services';
import { IColorSet } from 'browser/Types';
import { CanvasRenderer } from './CanvasRenderer';
import { IBufferService, IInstantiationService } from 'common/services/Services';
import { ITerminalAddon, Terminal } from 'xterm';
export class CanvasAddon implements ITerminalAddon {
private _terminal?: Terminal;
// private _renderer?: WebglRenderer;
private _renderer?: CanvasRenderer;
// private _onContextLoss = new EventEmitter<void>();
// public get onContextLoss(): IEvent<void> { return this._onContextLoss.event; }
public activate(terminal: Terminal): void {
// if (!terminal.element) {
// throw new Error('Cannot activate WebglAddon before Terminal.open');
// }
// if (isSafari) {
// throw new Error('Webgl is not currently supported on Safari');
// }
if (!terminal.element) {
throw new Error('Cannot activate CanvasAddon before Terminal.open');
}
this._terminal = terminal;
// const renderService: IRenderService = (terminal as any)._core._renderService;
// const characterJoinerService: ICharacterJoinerService = (terminal as any)._core._characterJoinerService;
// const decorationService: IDecorationService = (terminal as any)._core._decorationService;
// const colors: IColorSet = (terminal as any)._core._colorManager.colors;
// this._renderer = new WebglRenderer(terminal, colors, characterJoinerService, decorationService, this._preserveDrawingBuffer);
const instantiationService: IInstantiationService = (terminal as any)._core._instantiationService;
const bufferService: IBufferService = (terminal as any)._core._renderService;
const renderService: IRenderService = (terminal as any)._core._renderService;
const colors: IColorSet = (terminal as any)._core._colorManager.colors;
const screenElement: HTMLElement = (terminal as any)._core.screenElement;
const linkifier = (terminal as any)._core.linkifier2;
this._renderer = instantiationService.createInstance(CanvasRenderer, colors, screenElement, linkifier);
// this._renderer.onContextLoss(() => this._onContextLoss.fire());
// renderService.setRenderer(this._renderer);
renderService.setRenderer(this._renderer);
renderService.onResize(bufferService.cols, bufferService.rows);
}
public dispose(): void {
// if (!this._terminal) {
// throw new Error('Cannot dispose WebglAddon because it is activated');
// }
// const renderService: IRenderService = (this._terminal as any)._core._renderService;
// renderService.setRenderer((this._terminal as any)._core._createRenderer());
// renderService.onResize(this._terminal.cols, this._terminal.rows);
// this._renderer?.dispose();
// this._renderer = undefined;
if (!this._terminal) {
throw new Error('Cannot dispose CanvasAddon because it is activated');
}
const renderService: IRenderService = (this._terminal as any)._core._renderService;
renderService.setRenderer((this._terminal as any)._core._createRenderer());
renderService.onResize(this._terminal.cols, this._terminal.rows);
this._renderer?.dispose();
this._renderer = undefined;
}
// public get textureAtlas(): HTMLCanvasElement | undefined {
@@ -18,7 +18,7 @@ import { EventEmitter, IEvent } from 'common/EventEmitter';
let nextRendererId = 1;
export class Renderer extends Disposable implements IRenderer {
export class CanvasRenderer extends Disposable implements IRenderer {
private _id = nextRendererId++;
private _renderLayers: IRenderLayer[];