blob: 3d4eea9bc540bda5b0ff2fe88d2b2a83583df99c [file] [log] [blame]
Hector Dearman3d26fdb2018-07-09 13:54:06 +01001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
Micha Schwab01b35682018-06-28 13:56:49 +010014
Deepanjan Roy75b46a92018-07-24 09:11:29 -040015import {TrackState} from '../common/state';
Deepanjan Roy424485b2018-07-26 08:37:35 -040016import {TimeScale} from './time_scale';
Michail Schwabbbdd9832018-07-12 12:02:53 -040017import {VirtualCanvasContext} from './virtual_canvas_context';
Micha Schwab01b35682018-06-28 13:56:49 +010018
Deepanjan Roy424485b2018-07-26 08:37:35 -040019/**
20 * This interface forces track implementations to have two static properties:
Hector Dearmanc62a5e32018-07-27 12:54:44 +010021 * kind and a create function.
Deepanjan Roy424485b2018-07-26 08:37:35 -040022 *
Hector Dearmanc62a5e32018-07-27 12:54:44 +010023 * Kindscript does not have abstract static members, which is why this needs to
Deepanjan Roy424485b2018-07-26 08:37:35 -040024 * be in a seperate interface. We need the |create| method because the stored
25 * value in the registry is an abstract class, and we cannot call 'new'
26 * on an abstract class.
27 */
28export interface TrackCreator {
Hector Dearmanc62a5e32018-07-27 12:54:44 +010029 // Store the kind explicitly as a string as opposed to using class.kind in
Deepanjan Roy424485b2018-07-26 08:37:35 -040030 // case we ever minify our code.
Hector Dearmanc62a5e32018-07-27 12:54:44 +010031 readonly kind: string;
Deepanjan Roy75b46a92018-07-24 09:11:29 -040032
Deepanjan Roy424485b2018-07-26 08:37:35 -040033 create(TrackState: TrackState): Track;
34}
Michail Schwabbeb34522018-07-20 08:15:17 -040035
Deepanjan Roy424485b2018-07-26 08:37:35 -040036/**
37 * The abstract class that needs to be implemented by all tracks.
38 */
39export abstract class Track {
40 constructor(protected trackState: TrackState) {}
41 abstract renderCanvas(
Michail Schwab405002c2018-07-26 13:19:10 -040042 vCtx: VirtualCanvasContext, width: number, timeScale: TimeScale,
43 visibleWindowMs: {start: number, end: number}): void;
Deepanjan Roy424485b2018-07-26 08:37:35 -040044}