xterm
[VSoRC/.git] / node_modules / xterm / src / browser / renderer / atlas / BaseCharAtlas.ts
1 /**
2  * Copyright (c) 2017 The xterm.js authors. All rights reserved.
3  * @license MIT
4  */
5
6 import { IGlyphIdentifier } from 'browser/renderer/atlas/Types';
7 import { IDisposable } from 'common/Types';
8
9 export abstract class BaseCharAtlas implements IDisposable {
10   private _didWarmUp: boolean = false;
11
12   public dispose(): void { }
13
14   /**
15    * Perform any work needed to warm the cache before it can be used. May be called multiple times.
16    * Implement _doWarmUp instead if you only want to get called once.
17    */
18   public warmUp(): void {
19     if (!this._didWarmUp) {
20       this._doWarmUp();
21       this._didWarmUp = true;
22     }
23   }
24
25   /**
26    * Perform any work needed to warm the cache before it can be used. Used by the default
27    * implementation of warmUp(), and will only be called once.
28    */
29   protected _doWarmUp(): void { }
30
31   /**
32    * Called when we start drawing a new frame.
33    *
34    * TODO: We rely on this getting called by TextRenderLayer. This should really be called by
35    * Renderer instead, but we need to make Renderer the source-of-truth for the char atlas, instead
36    * of BaseRenderLayer.
37    */
38   public beginFrame(): void { }
39
40   /**
41    * May be called before warmUp finishes, however it is okay for the implementation to
42    * do nothing and return false in that case.
43    *
44    * @param ctx Where to draw the character onto.
45    * @param glyph Information about what to draw
46    * @param x The position on the context to start drawing at
47    * @param y The position on the context to start drawing at
48    * @returns The success state. True if we drew the character.
49    */
50   public abstract draw(
51     ctx: CanvasRenderingContext2D,
52     glyph: IGlyphIdentifier,
53     x: number,
54     y: number
55   ): boolean;
56 }