• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
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.
14 */
15
16/**
17 * @file
18 * @kit ArkGraphics2D
19 */
20
21import type { Callback } from './@ohos.base';
22/*** if arkts 1.2 */
23import { ExpectedFrameRateRange } from './arkui/component/common';
24/*** endif */
25
26/**
27 * Provides functions of applying an independent draw frame rate used for drawing the UI.
28 *
29 * @namespace displaySync
30 * @syscap SystemCapability.ArkUI.ArkUI.Full
31 * @since arkts {'1.1': '11', '1.2': '20'}
32 * @arkts 1.1&1.2
33 */
34declare namespace displaySync {
35  /**
36   * Provides the IntervalInfo interface, which includes timestamp and targetTimestamp.
37   * @interface IntervalInfo
38   * @syscap SystemCapability.ArkUI.ArkUI.Full
39   * @since arkts {'1.1': '11', '1.2': '20'}
40   * @arkts 1.1&1.2
41   */
42  interface IntervalInfo {
43    /**
44     * The timestamp means the current drawing frame time.
45     * @type { long }
46     * @syscap SystemCapability.ArkUI.ArkUI.Full
47     * @since arkts {'1.1': '11', '1.2': '20'}
48     * @arkts 1.1&1.2
49     */
50    timestamp: long;
51
52    /**
53     * The timestamp means the next drawing frame time.
54     * @type { long }
55     * @syscap SystemCapability.ArkUI.ArkUI.Full
56     * @since arkts {'1.1': '11', '1.2': '20'}
57     * @arkts 1.1&1.2
58     */
59    targetTimestamp: long;
60  }
61
62  /**
63   * Provides the DisplaySync interface, which can be used to control
64   * the frequency of triggering callback function.
65   * @interface DisplaySync
66   * @syscap SystemCapability.ArkUI.ArkUI.Full
67   * @since arkts {'1.1': '11', '1.2': '20'}
68   * @arkts 1.1&1.2
69   */
70  interface DisplaySync {
71    /**
72     * The expected frame rate of dynamical rate range.
73     * If the function isn't be called. The DisplaySync's
74     * minimum/maximum/expected rate default value is 60.
75     * @param { ExpectedFrameRateRange } rateRange - Indicates ExpectedFrameRateRange.
76     * @throws { BusinessError } 401 - Parameter error. Possible causes:
77     * <br> 1. Mandatory parameters are left unspecified.
78     * <br> 2. Incorrect parameters types.
79     * <br> 3. Parameter verification failed.
80     * or check ExpectedFrameRateRange if valid.
81     * @syscap SystemCapability.ArkUI.ArkUI.Full
82     * @since arkts {'1.1': '11', '1.2': '20'}
83     * @arkts 1.1&1.2
84     */
85    setExpectedFrameRateRange(rateRange: ExpectedFrameRateRange) : void;
86
87    /**
88     * Registers a callback with the corresponding query condition by using the handle.
89     * This callback is triggered when DisplaySync dispatching.
90     * @param { 'frame' } type - The type of event to remove the listener for. Must be 'frame'.
91     * @param { Callback<IntervalInfo> } callback - The callback function to be called when DisplaySync dispatching.
92     * @syscap SystemCapability.ArkUI.ArkUI.Full
93     * @since arkts {'1.1': '11', '1.2': '20'}
94     * @arkts 1.1&1.2
95     */
96    on(type: 'frame', callback: Callback<IntervalInfo>): void;
97
98    /**
99     * Deregisters a callback with the corresponding query condition by using the handle.
100     * This callback is triggered when DisplaySync dispatching.
101     * @param { 'frame' } type - The type of event to remove the listener for. Must be 'frame'.
102     * @param { Callback<IntervalInfo> } [callback] - The callback function to remove. If not provided, all callbacks for the given event type
103     *                                                will be removed.
104     * @syscap SystemCapability.ArkUI.ArkUI.Full
105     * @since arkts {'1.1': '11', '1.2': '20'}
106     * @arkts 1.1&1.2
107     */
108    off(type: 'frame', callback?: Callback<IntervalInfo>): void;
109
110    /**
111     * Add DisplaySync to Pipeline. It means that
112     * the callback function be enabled.
113     * @syscap SystemCapability.ArkUI.ArkUI.Full
114     * @since arkts {'1.1': '11', '1.2': '20'}
115     * @arkts 1.1&1.2
116     */
117    start(): void;
118
119    /**
120     * Delete DisplaySync from Pipeline. It means that
121     * the callback function be disabled.
122     * @syscap SystemCapability.ArkUI.ArkUI.Full
123     * @since arkts {'1.1': '11', '1.2': '20'}
124     * @arkts 1.1&1.2
125     */
126    stop(): void;
127  }
128
129  /**
130   * Create a new DisplaySync object.
131   * @returns { DisplaySync } DisplaySync
132   * @syscap SystemCapability.ArkUI.ArkUI.Full
133   * @since arkts {'1.1': '11', '1.2': '20'}
134   * @arkts 1.1&1.2
135   */
136  function create(): DisplaySync;
137}
138
139export default displaySync;
140