Split renderer safe vs unsafe api on activate

This commit is contained in:
Daniel Imms
2022-10-09 10:12:19 -07:00
parent e47296c1b9
commit 8d7137417b
2 changed files with 28 additions and 19 deletions
+14 -12
View File
@@ -4,7 +4,7 @@
*/ */
import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services'; import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services';
import { IColorSet } from 'browser/Types'; import { IColorSet, ITerminal } from 'browser/Types';
import { CanvasRenderer } from './CanvasRenderer'; import { CanvasRenderer } from './CanvasRenderer';
import { IBufferService, ICoreService, IDecorationService, IOptionsService } from 'common/services/Services'; import { IBufferService, ICoreService, IDecorationService, IOptionsService } from 'common/services/Services';
import { ITerminalAddon, Terminal } from 'xterm'; import { ITerminalAddon, Terminal } from 'xterm';
@@ -23,25 +23,27 @@ export class CanvasAddon extends Disposable implements ITerminalAddon {
} }
public activate(terminal: Terminal): void { public activate(terminal: Terminal): void {
const core = (terminal as any)._core; const core = (terminal as any)._core as ITerminal;
const unsafeCore = core as any;
if (!terminal.element) { if (!terminal.element) {
this.register(core.onWillOpen(() => this.activate(terminal))); this.register(core.onWillOpen(() => this.activate(terminal)));
return; return;
} }
this._terminal = terminal; this._terminal = terminal;
const bufferService: IBufferService = core._bufferService; const coreService = core.coreService;
const renderService: IRenderService = core._renderService; const optionsService = core.optionsService;
const characterJoinerService: ICharacterJoinerService = core._characterJoinerService; const screenElement = core.screenElement!;
const charSizeService: ICharSizeService = core._charSizeService;
const coreService: ICoreService = core.coreService;
const coreBrowserService: ICoreBrowserService = core._coreBrowserService;
const decorationService: IDecorationService = core._decorationService;
const optionsService: IOptionsService = core.optionsService;
const themeService: IThemeService = core._themeService;
const screenElement: HTMLElement = core.screenElement;
const linkifier = core.linkifier2; const linkifier = core.linkifier2;
const bufferService: IBufferService = unsafeCore._bufferService;
const renderService: IRenderService = unsafeCore._renderService;
const characterJoinerService: ICharacterJoinerService = unsafeCore._characterJoinerService;
const charSizeService: ICharSizeService = unsafeCore._charSizeService;
const coreBrowserService: ICoreBrowserService = unsafeCore._coreBrowserService;
const decorationService: IDecorationService = unsafeCore._decorationService;
const themeService: IThemeService = unsafeCore._themeService;
this._renderer = new CanvasRenderer(terminal, screenElement, linkifier, bufferService, charSizeService, optionsService, characterJoinerService, coreService, coreBrowserService, decorationService, themeService); this._renderer = new CanvasRenderer(terminal, screenElement, linkifier, bufferService, charSizeService, optionsService, characterJoinerService, coreService, coreBrowserService, decorationService, themeService);
this.register(forwardEvent(this._renderer.onChangeTextureAtlas, this._onChangeTextureAtlas)); this.register(forwardEvent(this._renderer.onChangeTextureAtlas, this._onChangeTextureAtlas));
renderService.setRenderer(this._renderer); renderService.setRenderer(this._renderer);
+14 -7
View File
@@ -4,10 +4,12 @@
*/ */
import { ICharacterJoinerService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services'; import { ICharacterJoinerService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services';
import { ITerminal } from 'browser/Types';
import { EventEmitter, forwardEvent } from 'common/EventEmitter'; import { EventEmitter, forwardEvent } from 'common/EventEmitter';
import { Disposable, toDisposable } from 'common/Lifecycle'; import { Disposable, toDisposable } from 'common/Lifecycle';
import { isSafari } from 'common/Platform'; import { isSafari } from 'common/Platform';
import { ICoreService, IDecorationService, IOptionsService } from 'common/services/Services'; import { ICoreService, IDecorationService, IOptionsService } from 'common/services/Services';
import { ICoreTerminal } from 'common/Types';
import { ITerminalAddon, Terminal } from 'xterm'; import { ITerminalAddon, Terminal } from 'xterm';
import { WebglRenderer } from './WebglRenderer'; import { WebglRenderer } from './WebglRenderer';
@@ -30,19 +32,24 @@ export class WebglAddon extends Disposable implements ITerminalAddon {
if (isSafari) { if (isSafari) {
throw new Error('Webgl is not currently supported on Safari'); throw new Error('Webgl is not currently supported on Safari');
} }
const core = (terminal as any)._core;
const core = (terminal as any)._core as ITerminal;
const unsafeCore = core as any;
if (!terminal.element) { if (!terminal.element) {
this.register(core.onWillOpen(() => this.activate(terminal))); this.register(unsafeCore.onWillOpen(() => this.activate(terminal)));
return; return;
} }
this._terminal = terminal; this._terminal = terminal;
const renderService: IRenderService = core._renderService;
const characterJoinerService: ICharacterJoinerService = core._characterJoinerService;
const coreBrowserService: ICoreBrowserService = core._coreBrowserService;
const coreService: ICoreService = core.coreService; const coreService: ICoreService = core.coreService;
const decorationService: IDecorationService = core._decorationService;
const themeService: IThemeService = core._themeService;
const optionsService: IOptionsService = core.optionsService; const optionsService: IOptionsService = core.optionsService;
const renderService: IRenderService = unsafeCore._renderService;
const characterJoinerService: ICharacterJoinerService = unsafeCore._characterJoinerService;
const coreBrowserService: ICoreBrowserService = unsafeCore._coreBrowserService;
const decorationService: IDecorationService = unsafeCore._decorationService;
const themeService: IThemeService = unsafeCore._themeService;
this._renderer = this.register(new WebglRenderer(terminal, themeService, characterJoinerService, coreBrowserService, optionsService, coreService, decorationService, this._preserveDrawingBuffer)); this._renderer = this.register(new WebglRenderer(terminal, themeService, characterJoinerService, coreBrowserService, optionsService, coreService, decorationService, this._preserveDrawingBuffer));
this.register(forwardEvent(this._renderer.onContextLoss, this._onContextLoss)); this.register(forwardEvent(this._renderer.onContextLoss, this._onContextLoss));
this.register(forwardEvent(this._renderer.onChangeTextureAtlas, this._onChangeTextureAtlas)); this.register(forwardEvent(this._renderer.onChangeTextureAtlas, this._onChangeTextureAtlas));