1 /*
2  * Copyright (c) 2022-2022 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 #ifndef NDK_INCLUDE_NATIVE_VSYNC_H_
17 #define NDK_INCLUDE_NATIVE_VSYNC_H_
18 
19 /**
20  * @addtogroup NativeVsync
21  * @{
22  *
23  * @brief Provides the native vsync capability.
24  *
25  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
26  * @since 9
27  * @version 1.0
28  */
29 
30 /**
31  * @file native_vsync.h
32  *
33  * @brief Defines the functions for obtaining and using a native vsync.
34  *
35  * @kit ArkGraphics2D
36  * @library libnative_vsync.so
37  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
38  * @since 9
39  * @version 1.0
40  */
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 struct OH_NativeVSync;
47 typedef struct OH_NativeVSync OH_NativeVSync;
48 typedef void (*OH_NativeVSync_FrameCallback)(long long timestamp, void *data);
49 
50 /**
51  * @brief Creates a <b>NativeVsync</b> instance.\n
52  * A new <b>NativeVsync</b> instance is created each time this function is called.
53  *
54  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
55  * @param name Indicates the vsync connection name.
56  * @param length Indicates the name's length.
57  * @return Returns the pointer to the <b>NativeVsync</b> instance created.
58  * @since 9
59  * @version 1.0
60  */
61 OH_NativeVSync* OH_NativeVSync_Create(const char* name, unsigned int length);
62 
63 /**
64  * @brief Delete the NativeVsync instance.
65  *
66  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
67  * @param window Indicates the pointer to a <b>NativeVsync</b> instance.
68  * @since 9
69  * @version 1.0
70  */
71 void OH_NativeVSync_Destroy(OH_NativeVSync* nativeVsync);
72 
73 /**
74  * @brief Request next vsync with callback.
75  * If you call this interface multiple times in one frame, it will only call the last callback.
76  *
77  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
78  * @param nativeVsync Indicates the pointer to a NativeVsync.
79  * @param callback Indicates the OH_NativeVSync_FrameCallback which will be called when next vsync coming.
80  * @param data Indicates data which will be used in callback.
81  * @return {@link NATIVE_ERROR_OK} 0 - Success.
82  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - the parameter nativeVsync is NULL or callback is NULL.
83  *     {@link NATIVE_ERROR_BINDER_ERROR} 50401000 - ipc send failed.
84  * @since 9
85  * @version 1.0
86  */
87 int OH_NativeVSync_RequestFrame(OH_NativeVSync* nativeVsync, OH_NativeVSync_FrameCallback callback, void* data);
88 
89 /**
90  * @brief Request next vsync with callback.
91  * If this function is called multiple times in one vsync period, all these callbacks and dataset will be called.
92  *
93  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
94  * @param nativeVsync Indicates the pointer to a NativeVsync.
95  * @param callback Indicates the OH_NativeVSync_FrameCallback which will be called when next vsync coming.
96  * @param data Indicates data which will be used in callback.
97  * @return {@link NATIVE_ERROR_OK} 0 - Success.
98  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - the parameter nativeVsync is NULL or callback is NULL.
99  *     {@link NATIVE_ERROR_BINDER_ERROR} 50401000 - ipc send failed.
100  * @since 12
101  * @version 1.0
102  */
103 int OH_NativeVSync_RequestFrameWithMultiCallback(
104     OH_NativeVSync* nativeVsync, OH_NativeVSync_FrameCallback callback, void* data);
105 
106 /**
107  * @brief Get vsync period.
108  *
109  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
110  * @param nativeVsync Indicates the pointer to a NativeVsync.
111  * @param period Indicates the vsync period.
112  * @return Returns int32_t, return value == 0, success, otherwise, failed.
113  * @since 10
114  * @version 1.0
115  */
116 int OH_NativeVSync_GetPeriod(OH_NativeVSync* nativeVsync, long long* period);
117 #ifdef __cplusplus
118 }
119 #endif
120 
121 #endif