1e9297d28Sopenharmony_ci/*
2e9297d28Sopenharmony_ci * Copyright (c) 2022-2022 Huawei Device Co., Ltd.
3e9297d28Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e9297d28Sopenharmony_ci * you may not use this file except in compliance with the License.
5e9297d28Sopenharmony_ci * You may obtain a copy of the License at
6e9297d28Sopenharmony_ci *
7e9297d28Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e9297d28Sopenharmony_ci *
9e9297d28Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e9297d28Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e9297d28Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e9297d28Sopenharmony_ci * See the License for the specific language governing permissions and
13e9297d28Sopenharmony_ci * limitations under the License.
14e9297d28Sopenharmony_ci */
15e9297d28Sopenharmony_ci
16e9297d28Sopenharmony_ci#ifndef NDK_INCLUDE_NATIVE_VSYNC_H_
17e9297d28Sopenharmony_ci#define NDK_INCLUDE_NATIVE_VSYNC_H_
18e9297d28Sopenharmony_ci
19e9297d28Sopenharmony_ci/**
20e9297d28Sopenharmony_ci * @addtogroup NativeVsync
21e9297d28Sopenharmony_ci * @{
22e9297d28Sopenharmony_ci *
23e9297d28Sopenharmony_ci * @brief Provides the native vsync capability.
24e9297d28Sopenharmony_ci *
25e9297d28Sopenharmony_ci * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
26e9297d28Sopenharmony_ci * @since 9
27e9297d28Sopenharmony_ci * @version 1.0
28e9297d28Sopenharmony_ci */
29e9297d28Sopenharmony_ci
30e9297d28Sopenharmony_ci/**
31e9297d28Sopenharmony_ci * @file native_vsync.h
32e9297d28Sopenharmony_ci *
33e9297d28Sopenharmony_ci * @brief Defines the functions for obtaining and using a native vsync.
34e9297d28Sopenharmony_ci *
35e9297d28Sopenharmony_ci * @library libnative_vsync.so
36e9297d28Sopenharmony_ci * @since 9
37e9297d28Sopenharmony_ci * @version 1.0
38e9297d28Sopenharmony_ci */
39e9297d28Sopenharmony_ci
40e9297d28Sopenharmony_ci#ifdef __cplusplus
41e9297d28Sopenharmony_ciextern "C" {
42e9297d28Sopenharmony_ci#endif
43e9297d28Sopenharmony_ci
44e9297d28Sopenharmony_cistruct OH_NativeVSync;
45e9297d28Sopenharmony_citypedef struct OH_NativeVSync OH_NativeVSync;
46e9297d28Sopenharmony_citypedef void (*OH_NativeVSync_FrameCallback)(long long timestamp, void *data);
47e9297d28Sopenharmony_ci
48e9297d28Sopenharmony_ci/**
49e9297d28Sopenharmony_ci * @brief Creates a <b>NativeVsync</b> instance.\n
50e9297d28Sopenharmony_ci * A new <b>NativeVsync</b> instance is created each time this function is called.
51e9297d28Sopenharmony_ci *
52e9297d28Sopenharmony_ci * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
53e9297d28Sopenharmony_ci * @param name Indicates the vsync connection name.
54e9297d28Sopenharmony_ci * @param length Indicates the name's length.
55e9297d28Sopenharmony_ci * @return Returns the pointer to the <b>NativeVsync</b> instance created.
56e9297d28Sopenharmony_ci * @since 9
57e9297d28Sopenharmony_ci * @version 1.0
58e9297d28Sopenharmony_ci */
59e9297d28Sopenharmony_ciOH_NativeVSync* OH_NativeVSync_Create(const char* name, unsigned int length);
60e9297d28Sopenharmony_ci
61e9297d28Sopenharmony_ci/**
62e9297d28Sopenharmony_ci * @brief Delete the NativeVsync instance.
63e9297d28Sopenharmony_ci *
64e9297d28Sopenharmony_ci * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
65e9297d28Sopenharmony_ci * @param window Indicates the pointer to a <b>NativeVsync</b> instance.
66e9297d28Sopenharmony_ci * @since 9
67e9297d28Sopenharmony_ci * @version 1.0
68e9297d28Sopenharmony_ci */
69e9297d28Sopenharmony_civoid OH_NativeVSync_Destroy(OH_NativeVSync* nativeVsync);
70e9297d28Sopenharmony_ci
71e9297d28Sopenharmony_ci/**
72e9297d28Sopenharmony_ci * @brief Request next vsync with callback.
73e9297d28Sopenharmony_ci * If you call this Interface multi times in one frame, it will only call the last callback.
74e9297d28Sopenharmony_ci *
75e9297d28Sopenharmony_ci * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
76e9297d28Sopenharmony_ci * @param nativeVsync Indicates the pointer to a NativeVsync.
77e9297d28Sopenharmony_ci * @param callback Indicates the OH_NativeVSync_FrameCallback which will be called when next vsync coming.
78e9297d28Sopenharmony_ci * @param data Indicates data which will be used in callback.
79e9297d28Sopenharmony_ci * @return {@link NATIVE_ERROR_OK} 0 - Success.
80e9297d28Sopenharmony_ci *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - the parameter nativeVsync is NULL or callback is NULL.
81e9297d28Sopenharmony_ci *     {@link NATIVE_ERROR_BINDER_ERROR} 50401000 - ipc send failed.
82e9297d28Sopenharmony_ci * @since 9
83e9297d28Sopenharmony_ci * @version 1.0
84e9297d28Sopenharmony_ci */
85e9297d28Sopenharmony_ciint OH_NativeVSync_RequestFrame(OH_NativeVSync* nativeVsync, OH_NativeVSync_FrameCallback callback, void* data);
86e9297d28Sopenharmony_ci
87e9297d28Sopenharmony_ci/**
88e9297d28Sopenharmony_ci * @brief Request next vsync with callback.
89e9297d28Sopenharmony_ci * If this function is called multiple times in one vsync period, all these callbacks and datas be callbacked.
90e9297d28Sopenharmony_ci *
91e9297d28Sopenharmony_ci * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
92e9297d28Sopenharmony_ci * @param nativeVsync Indicates the pointer to a NativeVsync.
93e9297d28Sopenharmony_ci * @param callback Indicates the OH_NativeVSync_FrameCallback which will be called when next vsync coming.
94e9297d28Sopenharmony_ci * @param data Indicates data which will be used in callback.
95e9297d28Sopenharmony_ci * @return {@link NATIVE_ERROR_OK} 0 - Success.
96e9297d28Sopenharmony_ci *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - the parameter nativeVsync is NULL or callback is NULL.
97e9297d28Sopenharmony_ci *     {@link NATIVE_ERROR_BINDER_ERROR} 50401000 - ipc send failed.
98e9297d28Sopenharmony_ci * @since 12
99e9297d28Sopenharmony_ci * @version 1.0
100e9297d28Sopenharmony_ci */
101e9297d28Sopenharmony_ciint OH_NativeVSync_RequestFrameWithMultiCallback(
102e9297d28Sopenharmony_ci    OH_NativeVSync* nativeVsync, OH_NativeVSync_FrameCallback callback, void* data);
103e9297d28Sopenharmony_ci
104e9297d28Sopenharmony_ci/**
105e9297d28Sopenharmony_ci * @brief Get vsync period.
106e9297d28Sopenharmony_ci *
107e9297d28Sopenharmony_ci * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
108e9297d28Sopenharmony_ci * @param nativeVsync Indicates the pointer to a NativeVsync.
109e9297d28Sopenharmony_ci * @param period Indicates the vsync period.
110e9297d28Sopenharmony_ci * @return Returns int32_t, return value == 0, success, otherwise, failed.
111e9297d28Sopenharmony_ci * @since 10
112e9297d28Sopenharmony_ci * @version 1.0
113e9297d28Sopenharmony_ci */
114e9297d28Sopenharmony_ciint OH_NativeVSync_GetPeriod(OH_NativeVSync* nativeVsync, long long* period);
115e9297d28Sopenharmony_ci
116e9297d28Sopenharmony_ci/**
117e9297d28Sopenharmony_ci * @brief Enables DVSync to improve the smoothness of self-drawing animations.
118e9297d28Sopenharmony_ci * DVSync, short for Decoupled VSync, is a frame timing management policy that is decoupled from the hardware's VSync.
119e9297d28Sopenharmony_ci * DVSync drives the early rendering of upcoming animation frames by sending VSync signals with future timestamps.
120e9297d28Sopenharmony_ci * These frames are stored in a frame buffer queue. This helps DVSync reduce potential frame drop and therefore
121e9297d28Sopenharmony_ci * enhances the smoothness of animations.
122e9297d28Sopenharmony_ci * DVSync requires free self-drawing frame buffers to store these pre-rendered animation frames.
123e9297d28Sopenharmony_ci * Therefore, you must ensure that at least one free frame buffer is available. Otherwise, do not enable DVSync.
124e9297d28Sopenharmony_ci * After DVSync is enabled, you must correctly respond to the early VSync signals and request the subsequent VSync
125e9297d28Sopenharmony_ci * after the animation frame associated with the previous VSync is complete. In addition, the self-drawing frames must
126e9297d28Sopenharmony_ci * carry timestamps that align with VSync.
127e9297d28Sopenharmony_ci * After the animation ends, disable DVSync.
128e9297d28Sopenharmony_ci * On a platform that does not support DVSync or if another application has enabled DVSync, the attempt to enable it
129e9297d28Sopenharmony_ci * will not take effect, and the application still receives normal VSync signals.
130e9297d28Sopenharmony_ci *
131e9297d28Sopenharmony_ci * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
132e9297d28Sopenharmony_ci * @param nativeVsync Indicates the pointer to a NativeVsync.
133e9297d28Sopenharmony_ci * @param enable Whether to enable DVSync.The value true means to enable DVSync, and false means the opposite.
134e9297d28Sopenharmony_ci * @return {@link NATIVE_ERROR_OK} 0 - Success.
135e9297d28Sopenharmony_ci *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - the parameter nativeVsync is NULL.
136e9297d28Sopenharmony_ci *     {@link NATIVE_ERROR_BINDER_ERROR} 50401000 - ipc send failed.
137e9297d28Sopenharmony_ci * @since 14
138e9297d28Sopenharmony_ci * @version 1.0
139e9297d28Sopenharmony_ci */
140e9297d28Sopenharmony_ciint OH_NativeVSync_DVSyncSwitch(OH_NativeVSync* nativeVsync, bool enable);
141e9297d28Sopenharmony_ci#ifdef __cplusplus
142e9297d28Sopenharmony_ci}
143e9297d28Sopenharmony_ci#endif
144e9297d28Sopenharmony_ci
145e9297d28Sopenharmony_ci#endif